diff --git a/src/Models/RepositorySettings.cs b/src/Models/RepositorySettings.cs index e10e9760..1d0b3c10 100644 --- a/src/Models/RepositorySettings.cs +++ b/src/Models/RepositorySettings.cs @@ -456,91 +456,13 @@ namespace SourceGit.Models CommitMessages.Insert(0, message); } - public IssueTrackerRule AddNewIssueTracker() + public IssueTrackerRule AddIssueTracker(string name, string regex, string url) { var rule = new IssueTrackerRule() { - Name = "New Issue Tracker", - RegexString = "#(\\d+)", - URLTemplate = "https://xxx/$1", - }; - - IssueTrackerRules.Add(rule); - return rule; - } - - public IssueTrackerRule AddGithubIssueTracker(string repoURL) - { - var rule = new IssueTrackerRule() - { - Name = "Github ISSUE", - RegexString = "#(\\d+)", - URLTemplate = string.IsNullOrEmpty(repoURL) ? "https://github.com/username/repository/issues/$1" : $"{repoURL}/issues/$1", - }; - - IssueTrackerRules.Add(rule); - return rule; - } - - public IssueTrackerRule AddJiraIssueTracker() - { - var rule = new IssueTrackerRule() - { - Name = "Jira Tracker", - RegexString = "PROJ-(\\d+)", - URLTemplate = "https://jira.yourcompany.com/browse/PROJ-$1", - }; - - IssueTrackerRules.Add(rule); - return rule; - } - - public IssueTrackerRule AddGitLabIssueTracker(string repoURL) - { - var rule = new IssueTrackerRule() - { - Name = "GitLab ISSUE", - RegexString = "#(\\d+)", - URLTemplate = string.IsNullOrEmpty(repoURL) ? "https://gitlab.com/username/repository/-/issues/$1" : $"{repoURL}/-/issues/$1", - }; - - IssueTrackerRules.Add(rule); - return rule; - } - - public IssueTrackerRule AddGitLabMergeRequestTracker(string repoURL) - { - var rule = new IssueTrackerRule() - { - Name = "GitLab MR", - RegexString = "!(\\d+)", - URLTemplate = string.IsNullOrEmpty(repoURL) ? "https://gitlab.com/username/repository/-/merge_requests/$1" : $"{repoURL}/-/merge_requests/$1", - }; - - IssueTrackerRules.Add(rule); - return rule; - } - - public IssueTrackerRule AddGiteeIssueTracker(string repoURL) - { - var rule = new IssueTrackerRule() - { - Name = "Gitee ISSUE", - RegexString = "#([0-9A-Z]{6,10})", - URLTemplate = string.IsNullOrEmpty(repoURL) ? "https://gitee.com/username/repository/issues/$1" : $"{repoURL}/issues/$1", - }; - - IssueTrackerRules.Add(rule); - return rule; - } - - public IssueTrackerRule AddGiteePullRequestTracker(string repoURL) - { - var rule = new IssueTrackerRule() - { - Name = "Gitee Pull Request", - RegexString = "!(\\d+)", - URLTemplate = string.IsNullOrEmpty(repoURL) ? "https://gitee.com/username/repository/pulls/$1" : $"{repoURL}/pulls/$1", + Name = name, + RegexString = regex, + URLTemplate = url, }; IssueTrackerRules.Add(rule); diff --git a/src/ViewModels/RepositoryConfigure.cs b/src/ViewModels/RepositoryConfigure.cs index fb8cbfdb..cd726d67 100644 --- a/src/ViewModels/RepositoryConfigure.cs +++ b/src/ViewModels/RepositoryConfigure.cs @@ -188,91 +188,89 @@ namespace SourceGit.ViewModels public void AddSampleGithubIssueTracker() { + var link = "https://github.com/username/repository/issues/$1"; foreach (var remote in _repo.Remotes) { - if (remote.URL.Contains("github.com", System.StringComparison.Ordinal)) + if (remote.URL.Contains("github.com", System.StringComparison.Ordinal) && + remote.TryGetVisitURL(out string url)) { - if (remote.TryGetVisitURL(out string url)) - { - SelectedIssueTrackerRule = _repo.Settings.AddGithubIssueTracker(url); - return; - } + link = $"{url}/issues/$1"; + break; } } - SelectedIssueTrackerRule = _repo.Settings.AddGithubIssueTracker(null); + SelectedIssueTrackerRule = _repo.Settings.AddIssueTracker("Github ISSUE", "#(\\d+)", link); } public void AddSampleJiraIssueTracker() { - SelectedIssueTrackerRule = _repo.Settings.AddJiraIssueTracker(); + SelectedIssueTrackerRule = _repo.Settings.AddIssueTracker("Jira Tracker", "PROJ-(\\d+)", "https://jira.yourcompany.com/browse/PROJ-$1"); } public void AddSampleGitLabIssueTracker() { + var link = "https://gitlab.com/username/repository/-/issues/$1"; foreach (var remote in _repo.Remotes) { if (remote.TryGetVisitURL(out string url)) { - SelectedIssueTrackerRule = _repo.Settings.AddGitLabIssueTracker(url); - return; + link = $"{url}/-/issues/$1"; + break; } } - SelectedIssueTrackerRule = _repo.Settings.AddGitLabIssueTracker(null); + SelectedIssueTrackerRule = _repo.Settings.AddIssueTracker("GitLab ISSUE", "#(\\d+)", link); } public void AddSampleGitLabMergeRequestTracker() { + var link = "https://gitlab.com/username/repository/-/merge_requests/$1"; foreach (var remote in _repo.Remotes) { if (remote.TryGetVisitURL(out string url)) { - SelectedIssueTrackerRule = _repo.Settings.AddGitLabMergeRequestTracker(url); - return; + link = $"{url}/-/merge_requests/$1"; + break; } } - SelectedIssueTrackerRule = _repo.Settings.AddGitLabMergeRequestTracker(null); + SelectedIssueTrackerRule = _repo.Settings.AddIssueTracker("GitLab MR", "!(\\d+)", link); } public void AddSampleGiteeIssueTracker() { + var link = "https://gitee.com/username/repository/issues/$1"; foreach (var remote in _repo.Remotes) { - if (remote.URL.Contains("gitee.com", System.StringComparison.Ordinal)) + if (remote.URL.Contains("gitee.com", System.StringComparison.Ordinal) && + remote.TryGetVisitURL(out string url)) { - if (remote.TryGetVisitURL(out string url)) - { - SelectedIssueTrackerRule = _repo.Settings.AddGiteeIssueTracker(url); - return; - } + link = $"{url}/issues/$1"; + break; } } - SelectedIssueTrackerRule = _repo.Settings.AddGiteeIssueTracker(null); + SelectedIssueTrackerRule = _repo.Settings.AddIssueTracker("Gitee ISSUE", "#([0-9A-Z]{6,10})", link); } public void AddSampleGiteePullRequestTracker() { + var link = "https://gitee.com/username/repository/pulls/$1"; foreach (var remote in _repo.Remotes) { - if (remote.URL.Contains("gitee.com", System.StringComparison.Ordinal)) + if (remote.URL.Contains("gitee.com", System.StringComparison.Ordinal) && + remote.TryGetVisitURL(out string url)) { - if (remote.TryGetVisitURL(out string url)) - { - SelectedIssueTrackerRule = _repo.Settings.AddGiteePullRequestTracker(url); - return; - } + link = $"{url}/pulls/$1"; } } - SelectedIssueTrackerRule = _repo.Settings.AddGiteePullRequestTracker(null); + SelectedIssueTrackerRule = _repo.Settings.AddIssueTracker("Gitee Pull Request", "!(\\d+)", link); } public void NewIssueTracker() { - SelectedIssueTrackerRule = _repo.Settings.AddNewIssueTracker(); + SelectedIssueTrackerRule = _repo.Settings.AddIssueTracker("New Issue Tracker", "#(\\d+)", "https://xxx/$1"); } public void RemoveSelectedIssueTracker()