Repository: preslavmihaylov/todocheck
Pull request #213 (2025-03-04 18:21:05)

Add support for Gitlab groups

amirsalarsafaei: Hi, @preslavmihaylov  I notice there is no development in this project for 2  years. Is this project deprecated? should I make my own fork and use that?
preslavmihaylov: Thanks for the contribution, let's see how the tests go against existing gitlab projects
preslavmihaylov: Just saw your previous question - the project is not in active development anymore, but I'm still accepting contributions like yours. If you want to expand it with additional features, feel free to fork or make further contributions, happy to review them & merge if they make sense

Patch:
diff --git a/config/issuetracker.go b/config/issuetracker.go
index aee7669..b5e6af7 100644
--- a/config/issuetracker.go
+++ b/config/issuetracker.go
@@ -42,7 +42,7 @@ var validIssueTrackers = []IssueTracker{
 var originPatterns = map[IssueTracker]*regexp.Regexp{
 	IssueTrackerJira:     regexp.MustCompile(`^(https?://)?[a-zA-Z0-9\-\.]+(:[0-9]+)?$`),
 	IssueTrackerGithub:   regexp.MustCompile(`^(https?://)?(www\.)?github\.com/[\w-]+/[\w-]+`),
-	IssueTrackerGitlab:   regexp.MustCompile(`^(https?://)?[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)+(:[0-9]+)?/[\w-]+/[\w-]+$`),
+	IssueTrackerGitlab:   regexp.MustCompile(`^(https?://)?[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)+(:[0-9]+)?/([\w-]+/)?[\w-]+/[\w-]+$`),
 	IssueTrackerPivotal:  regexp.MustCompile(`^(https?://)?(www\.)?pivotaltracker\.com/n/projects/[0-9]+`),
 	IssueTrackerRedmine:  regexp.MustCompile(`^(https?://)?[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)+(:[0-9]+)?$`),
 	IssueTrackerYoutrack: regexp.MustCompile(`^(https?://)?(www\.)?[0-9A-z-]{2,}\/?.*$`),
diff --git a/issuetracker/internal/gitlab/gitlab.go b/issuetracker/internal/gitlab/gitlab.go
index a0531b4..c1cfdbb 100644
--- a/issuetracker/internal/gitlab/gitlab.go
+++ b/issuetracker/internal/gitlab/gitlab.go
@@ -78,8 +78,8 @@ func (it *IssueTracker) issueAPIOrigin() string {
 		tokens = append([]string{"https:"}, tokens...)
 	}
 
-	scheme, host, owner, repo := tokens[0], tokens[1], tokens[2], tokens[3]
-	urlEncodedProject := url.QueryEscape(fmt.Sprintf("%s/%s", owner, repo))
+	scheme, host, repositoryPath := tokens[0], tokens[1], tokens[2:]
+	urlEncodedProject := url.QueryEscape(strings.Join(repositoryPath, "/"))
 	return fmt.Sprintf("%s//%s/api/v4/projects/%s/issues/", scheme, host, urlEncodedProject)
 }
 
diff --git a/validation/fixtures/origin/valid/valid_gitlab_group.yaml b/validation/fixtures/origin/valid/valid_gitlab_group.yaml
new file mode 100644
index 0000000..dfcd45b
--- /dev/null
+++ b/validation/fixtures/origin/valid/valid_gitlab_group.yaml
@@ -0,0 +1,2 @@
+origin: https://custom.domain.com/group/subgroup/project
+issue_tracker: GITLAB


Test patch:
diff --git a/validation/validation_test.go b/validation/validation_test.go
index 1499bcb..716a857 100644
--- a/validation/validation_test.go
+++ b/validation/validation_test.go
@@ -72,6 +72,7 @@ func TestValidOrigins(t *testing.T) {
 		"./fixtures/origin/valid/valid_gitlab_origin.yaml",
 		"./fixtures/origin/valid/valid_gitlab_port.yaml",
 		"./fixtures/origin/valid/valid_gitlab_subdomain.yaml",
+		"./fixtures/origin/valid/valid_gitlab_group.yaml",
 		"./fixtures/origin/valid/valid_jira_origin.yaml",
 		"./fixtures/origin/valid/valid_jira_port.yaml",
 		"./fixtures/origin/valid/valid_jira_subdomain.yaml",