refactor: issue tracker configuration (#884)
Some checks are pending
Continuous Integration / Build (push) Waiting to run
Continuous Integration / Prepare version string (push) Waiting to run
Continuous Integration / Package (push) Blocked by required conditions
Localization Check / localization-check (push) Waiting to run

This commit is contained in:
leo 2025-01-09 12:27:50 +08:00
parent f74dbdf8ed
commit 495b3a9296
No known key found for this signature in database
2 changed files with 31 additions and 111 deletions

View file

@ -456,91 +456,13 @@ namespace SourceGit.Models
CommitMessages.Insert(0, message); CommitMessages.Insert(0, message);
} }
public IssueTrackerRule AddNewIssueTracker() public IssueTrackerRule AddIssueTracker(string name, string regex, string url)
{ {
var rule = new IssueTrackerRule() var rule = new IssueTrackerRule()
{ {
Name = "New Issue Tracker", Name = name,
RegexString = "#(\\d+)", RegexString = regex,
URLTemplate = "https://xxx/$1", URLTemplate = url,
};
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",
}; };
IssueTrackerRules.Add(rule); IssueTrackerRules.Add(rule);

View file

@ -188,91 +188,89 @@ namespace SourceGit.ViewModels
public void AddSampleGithubIssueTracker() public void AddSampleGithubIssueTracker()
{ {
var link = "https://github.com/username/repository/issues/$1";
foreach (var remote in _repo.Remotes) 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)) link = $"{url}/issues/$1";
{ break;
SelectedIssueTrackerRule = _repo.Settings.AddGithubIssueTracker(url);
return;
}
} }
} }
SelectedIssueTrackerRule = _repo.Settings.AddGithubIssueTracker(null); SelectedIssueTrackerRule = _repo.Settings.AddIssueTracker("Github ISSUE", "#(\\d+)", link);
} }
public void AddSampleJiraIssueTracker() 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() public void AddSampleGitLabIssueTracker()
{ {
var link = "https://gitlab.com/username/repository/-/issues/$1";
foreach (var remote in _repo.Remotes) foreach (var remote in _repo.Remotes)
{ {
if (remote.TryGetVisitURL(out string url)) if (remote.TryGetVisitURL(out string url))
{ {
SelectedIssueTrackerRule = _repo.Settings.AddGitLabIssueTracker(url); link = $"{url}/-/issues/$1";
return; break;
} }
} }
SelectedIssueTrackerRule = _repo.Settings.AddGitLabIssueTracker(null); SelectedIssueTrackerRule = _repo.Settings.AddIssueTracker("GitLab ISSUE", "#(\\d+)", link);
} }
public void AddSampleGitLabMergeRequestTracker() public void AddSampleGitLabMergeRequestTracker()
{ {
var link = "https://gitlab.com/username/repository/-/merge_requests/$1";
foreach (var remote in _repo.Remotes) foreach (var remote in _repo.Remotes)
{ {
if (remote.TryGetVisitURL(out string url)) if (remote.TryGetVisitURL(out string url))
{ {
SelectedIssueTrackerRule = _repo.Settings.AddGitLabMergeRequestTracker(url); link = $"{url}/-/merge_requests/$1";
return; break;
} }
} }
SelectedIssueTrackerRule = _repo.Settings.AddGitLabMergeRequestTracker(null); SelectedIssueTrackerRule = _repo.Settings.AddIssueTracker("GitLab MR", "!(\\d+)", link);
} }
public void AddSampleGiteeIssueTracker() public void AddSampleGiteeIssueTracker()
{ {
var link = "https://gitee.com/username/repository/issues/$1";
foreach (var remote in _repo.Remotes) 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)) link = $"{url}/issues/$1";
{ break;
SelectedIssueTrackerRule = _repo.Settings.AddGiteeIssueTracker(url);
return;
}
} }
} }
SelectedIssueTrackerRule = _repo.Settings.AddGiteeIssueTracker(null); SelectedIssueTrackerRule = _repo.Settings.AddIssueTracker("Gitee ISSUE", "#([0-9A-Z]{6,10})", link);
} }
public void AddSampleGiteePullRequestTracker() public void AddSampleGiteePullRequestTracker()
{ {
var link = "https://gitee.com/username/repository/pulls/$1";
foreach (var remote in _repo.Remotes) 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)) link = $"{url}/pulls/$1";
{
SelectedIssueTrackerRule = _repo.Settings.AddGiteePullRequestTracker(url);
return;
}
} }
} }
SelectedIssueTrackerRule = _repo.Settings.AddGiteePullRequestTracker(null); SelectedIssueTrackerRule = _repo.Settings.AddIssueTracker("Gitee Pull Request", "!(\\d+)", link);
} }
public void NewIssueTracker() public void NewIssueTracker()
{ {
SelectedIssueTrackerRule = _repo.Settings.AddNewIssueTracker(); SelectedIssueTrackerRule = _repo.Settings.AddIssueTracker("New Issue Tracker", "#(\\d+)", "https://xxx/$1");
} }
public void RemoveSelectedIssueTracker() public void RemoveSelectedIssueTracker()