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
51    /// Subdirectory name within a multi-workspace root: `<repo>-<id>`.
52    ///
53    /// For example, `GitHub { repo: "backend", number: 7 }` → `"backend-7"`.
54    ///
55    /// # Panics
56    ///
57    /// Panics for `IssueRef::Local` — local issues are not supported in
58    /// multi-workspace mode.
59    #[must_use]
60    pub fn multi_dir_name(&self) -> String {
61        match self {
62            Self::GitHub { repo, number, .. } | Self::GitLab { repo, number, .. } => {
63                format!("{repo}-{number}")
64            }
65            Self::Linear { repo, id, .. } => format!("{repo}-{id}"),
66            Self::AzureDevOps { repo, id, .. } => format!("{repo}-{id}"),
67            Self::Jira {
68                repo, issue_key, ..
69            } => {
70                format!("{repo}-{}", issue_key.to_lowercase())
71            }
72            Self::Local { .. } => {
73                unreachable!("multi_dir_name is not supported for IssueRef::Local")
74            }
75        }
76    }
77}