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::Adhoc { name, .. } => name.clone(),
12            Self::Linear { id, .. } => format!("linear-{id}"),
13            Self::AzureDevOps { id, .. } => format!("workitem-{id}"),
14            Self::Jira { issue_key, .. } => format!("jira-{}", issue_key.to_lowercase()),
15            Self::Local { display_number, .. } => format!("issue-{display_number}"),
16        }
17    }
18
19    /// Git branch name for this issue worktree.
20    #[must_use]
21    pub fn branch_name(&self) -> String {
22        self.workspace_dir_name()
23    }
24
25    /// HTTPS clone URL for the repository.
26    ///
27    /// # Panics
28    ///
29    /// Always panics for `IssueRef::Local` — local repos are never cloned.
30    #[must_use]
31    pub fn clone_url(&self) -> String {
32        match self {
33            Self::GitHub { owner, repo, .. }
34            | Self::Linear { owner, repo, .. }
35            | Self::Jira { owner, repo, .. }
36            | Self::Adhoc { owner, repo, .. } => {
37                format!("https://github.com/{owner}/{repo}.git")
38            }
39            Self::GitLab { owner, repo, .. } => {
40                format!("https://gitlab.com/{owner}/{repo}.git")
41            }
42            Self::AzureDevOps {
43                org, project, repo, ..
44            } => {
45                format!("https://dev.azure.com/{org}/{project}/_git/{repo}")
46            }
47            Self::Local { .. } => {
48                unreachable!("clone_url is never called for IssueRef::Local")
49            }
50        }
51    }
52
53    /// Subdirectory name within a multi-workspace root: `<repo>-<id>`.
54    ///
55    /// For example, `GitHub { repo: "backend", number: 7 }` → `"backend-7"`.
56    ///
57    /// # Panics
58    ///
59    /// Panics for `IssueRef::Local` — local issues are not supported in
60    /// multi-workspace mode.
61    #[must_use]
62    pub fn multi_dir_name(&self) -> String {
63        match self {
64            Self::GitHub { repo, number, .. } | Self::GitLab { repo, number, .. } => {
65                format!("{repo}-{number}")
66            }
67            Self::Adhoc { repo, name, .. } => format!("{repo}-{name}"),
68            Self::Linear { repo, id, .. } => format!("{repo}-{id}"),
69            Self::AzureDevOps { repo, id, .. } => format!("{repo}-{id}"),
70            Self::Jira {
71                repo, issue_key, ..
72            } => {
73                format!("{repo}-{}", issue_key.to_lowercase())
74            }
75            Self::Local { .. } => {
76                unreachable!("multi_dir_name is not supported for IssueRef::Local")
77            }
78        }
79    }
80}