Skip to main content

worktree_io/issue/
impls.rs

1use super::IssueRef;
2
3impl IssueRef {
4    /// Directory name used inside the bare clone for this worktree.
5    #[must_use]
6    pub fn workspace_dir_name(&self) -> String {
7        match self {
8            Self::GitHub { number, .. } | Self::GitLab { number, .. } => {
9                format!("issue-{number}")
10            }
11            Self::Linear { id, .. } => format!("linear-{id}"),
12            Self::AzureDevOps { id, .. } => format!("workitem-{id}"),
13            Self::Jira { issue_key, .. } => format!("jira-{}", issue_key.to_lowercase()),
14            Self::Local { display_number, .. } => format!("issue-{display_number}"),
15        }
16    }
17
18    /// Git branch name for this issue worktree.
19    #[must_use]
20    pub fn branch_name(&self) -> String {
21        self.workspace_dir_name()
22    }
23
24    /// HTTPS clone URL for the repository.
25    ///
26    /// # Panics
27    ///
28    /// Always panics for `IssueRef::Local` — local repos are never cloned.
29    #[must_use]
30    pub fn clone_url(&self) -> String {
31        match self {
32            Self::GitHub { owner, repo, .. }
33            | Self::Linear { owner, repo, .. }
34            | Self::Jira { owner, repo, .. } => {
35                format!("https://github.com/{owner}/{repo}.git")
36            }
37            Self::GitLab { owner, repo, .. } => {
38                format!("https://gitlab.com/{owner}/{repo}.git")
39            }
40            Self::AzureDevOps {
41                org, project, repo, ..
42            } => {
43                format!("https://dev.azure.com/{org}/{project}/_git/{repo}")
44            }
45            Self::Local { .. } => {
46                unreachable!("clone_url is never called for IssueRef::Local")
47            }
48        }
49    }
50}