From 82e88e55096562efb1bfe3648667e81024457a1e Mon Sep 17 00:00:00 2001 From: James Williams Date: Sat, 17 Dec 2022 19:25:36 +0000 Subject: [PATCH 1/3] Switch clone URL structure for visualstudio.com URLs --- server/events/event_parser.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/events/event_parser.go b/server/events/event_parser.go index 3d8dc6550a..ca7ad04942 100644 --- a/server/events/event_parser.go +++ b/server/events/event_parser.go @@ -939,7 +939,12 @@ func (e *EventParser) ParseAzureDevopsRepo(adRepo *azuredevops.GitRepository) (m host = "dev.azure.com" } - cloneURL := fmt.Sprintf("https://%s/%s/%s/_git/%s", host, owner, project, repo) + cloneURL := "" + if strings.Contains(host, "visualstudio.com") { + cloneURL = fmt.Sprintf("https://%s/%s/_git/%s", host, project, repo) + } else { + cloneURL = fmt.Sprintf("https://%s/%s/%s/_git/%s", host, owner, project, repo) + } fmt.Println("%", cloneURL) fullName := fmt.Sprintf("%s/%s/%s", owner, project, repo) return models.NewRepo(models.AzureDevops, fullName, cloneURL, e.AzureDevopsUser, e.AzureDevopsToken) From 28c89777d73becd6d610ab6141e519496435c058 Mon Sep 17 00:00:00 2001 From: James Williams Date: Sun, 18 Dec 2022 20:25:33 +0000 Subject: [PATCH 2/3] Add comment for ADO URL if statement. Add test --- server/events/event_parser.go | 2 ++ server/events/event_parser_test.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/server/events/event_parser.go b/server/events/event_parser.go index ca7ad04942..10a8aa8df1 100644 --- a/server/events/event_parser.go +++ b/server/events/event_parser.go @@ -940,6 +940,8 @@ func (e *EventParser) ParseAzureDevopsRepo(adRepo *azuredevops.GitRepository) (m } cloneURL := "" + // If statement allows compatibility with legacy Visual Studio Team Foundation Services URLs. + // Else statement covers Azure DevOps Services URLs if strings.Contains(host, "visualstudio.com") { cloneURL = fmt.Sprintf("https://%s/%s/_git/%s", host, project, repo) } else { diff --git a/server/events/event_parser_test.go b/server/events/event_parser_test.go index 09de53d548..bc647eab19 100644 --- a/server/events/event_parser_test.go +++ b/server/events/event_parser_test.go @@ -1235,6 +1235,22 @@ func TestParseAzureDevopsRepo(t *testing.T) { }, }, r) + // this should be successful + repo = ADRepo + repo.WebURL = azuredevops.String("https://owner.visualstudio.com/project/_git/repo") + r, err = parser.ParseAzureDevopsRepo(&repo) + Ok(t, err) + Equals(t, models.Repo{ + Owner: "owner/project", + FullName: "owner/project/repo", + CloneURL: "https://azuredevops-user:azuredevops-token@owner.visualstudio.com/project/_git/repo", + SanitizedCloneURL: "https://azuredevops-user:@owner.visualstudio.com/project/_git/repo", + Name: "repo", + VCSHost: models.VCSHost{ + Hostname: "owner.visualstudio.com", + Type: models.AzureDevops, + }, + }, r) } func TestParseAzureDevopsPullEvent(t *testing.T) { From b752955dbf9b41890bae3b41a9001bb9ba62417a Mon Sep 17 00:00:00 2001 From: James Williams Date: Sun, 18 Dec 2022 22:50:45 +0000 Subject: [PATCH 3/3] Test else statement in ParseAzureDevopsRepo --- server/events/event_parser_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/server/events/event_parser_test.go b/server/events/event_parser_test.go index bc647eab19..4e7d35ac7b 100644 --- a/server/events/event_parser_test.go +++ b/server/events/event_parser_test.go @@ -1251,6 +1251,23 @@ func TestParseAzureDevopsRepo(t *testing.T) { Type: models.AzureDevops, }, }, r) + + // this should be successful + repo = ADRepo + repo.WebURL = azuredevops.String("https://dev.azure.com/owner/project/_git/repo") + r, err = parser.ParseAzureDevopsRepo(&repo) + Ok(t, err) + Equals(t, models.Repo{ + Owner: "owner/project", + FullName: "owner/project/repo", + CloneURL: "https://azuredevops-user:azuredevops-token@dev.azure.com/owner/project/_git/repo", + SanitizedCloneURL: "https://azuredevops-user:@dev.azure.com/owner/project/_git/repo", + Name: "repo", + VCSHost: models.VCSHost{ + Hostname: "dev.azure.com", + Type: models.AzureDevops, + }, + }, r) } func TestParseAzureDevopsPullEvent(t *testing.T) {