Update Azure Repos link format (#4598)
Lint / golangci-lint (push) Waiting to run
Lint / semgrep (push) Waiting to run
Release / Release (push) Waiting to run
Scan for secrets / test (push) Waiting to run
Test / test (push) Waiting to run
Test / test-community (push) Waiting to run

* fix(giturl): correct Azure Repos link format to use query parameters

* lineEnd should not be same as line

* update azure repos link engine test
This commit is contained in:
Amaan Ullah
2025-12-11 16:40:06 +05:00
committed by GitHub
parent bf930a2cd9
commit 05cccb53bc
3 changed files with 29 additions and 9 deletions
+1 -1
View File
@@ -889,7 +889,7 @@ func TestSetLink(t *testing.T) {
},
link: "https://dev.azure.com/example",
line: 3,
wantLink: "https://dev.azure.com/example?line=3",
wantLink: "https://dev.azure.com/example?line=3&lineEnd=4&lineStartColumn=1",
},
{
name: "Unsupported metadata type",
+15 -4
View File
@@ -130,9 +130,16 @@ func GenerateLink(repo, commit, file string, line int64) string {
return repo[:len(repo)-4] + "/commits/" + commit
case providerAzure:
baseLink := repo + "/commit/" + commit + "/" + file
// Azure Repos format: ?path=/file&version=GC<commit>&line=N&lineEnd=N+1&lineStartColumn=1
// where GC prefix stands for "Git Commit" (vs GB for Git Branch, GT for Git Tag)
baseLink := repo + "?version=GC" + commit
if file != "" {
baseLink = repo + "?path=/" + file + "&version=GC" + commit
}
if line > 0 {
baseLink += "?line=" + strconv.FormatInt(line, 10)
lineStr := strconv.FormatInt(line, 10)
lineEndStr := strconv.FormatInt(line+1, 10)
baseLink += "&line=" + lineStr + "&lineEnd=" + lineEndStr + "&lineStartColumn=1"
}
return baseLink
@@ -211,9 +218,13 @@ func UpdateLinkLineNumber(ctx context.Context, link string, newLine int64) strin
return link
case providerAzure:
// For Azure, line numbers are appended as ?line=<number>.
// For Azure, line numbers use query parameters: ?line=N&lineEnd=N+1&lineStartColumn=1
query := parsedURL.Query()
query.Set("line", strconv.FormatInt(newLine, 10))
lineStr := strconv.FormatInt(newLine, 10)
lineEndStr := strconv.FormatInt(newLine+1, 10)
query.Set("line", lineStr)
query.Set("lineEnd", lineEndStr)
query.Set("lineStartColumn", "1")
parsedURL.RawQuery = query.Encode()
case providerGithub, providerGitlab:
+13 -4
View File
@@ -150,7 +150,7 @@ func TestGenerateLink(t *testing.T) {
commit: "abcdef",
file: "main.go",
},
want: "https://dev.azure.com/org/project/_git/repo/commit/abcdef/main.go",
want: "https://dev.azure.com/org/project/_git/repo?path=/main.go&version=GCabcdef",
},
{
name: "Azure link gen with line",
@@ -160,7 +160,16 @@ func TestGenerateLink(t *testing.T) {
file: "main.go",
line: int64(20),
},
want: "https://dev.azure.com/org/project/_git/repo/commit/abcdef/main.go?line=20",
want: "https://dev.azure.com/org/project/_git/repo?path=/main.go&version=GCabcdef&line=20&lineEnd=21&lineStartColumn=1",
},
{
name: "Azure link gen - no file",
args: args{
repo: "https://dev.azure.com/org/project/_git/repo",
commit: "abcdef",
file: "",
},
want: "https://dev.azure.com/org/project/_git/repo?version=GCabcdef",
},
{
name: "Unknown provider on-prem instance",
@@ -279,10 +288,10 @@ func TestUpdateLinkLineNumber(t *testing.T) {
{
name: "Update Azure link with line",
args: args{
link: "https://dev.azure.com/org/project/_git/repo/commit/abcdef/main.go?line=20",
link: "https://dev.azure.com/org/project/_git/repo?path=/main.go&version=GCabcdef&line=20&lineEnd=21&lineStartColumn=1",
newLine: int64(40),
},
want: "https://dev.azure.com/org/project/_git/repo/commit/abcdef/main.go?line=40",
want: "https://dev.azure.com/org/project/_git/repo?line=40&lineEnd=41&lineStartColumn=1&path=%2Fmain.go&version=GCabcdef",
},
{
name: "Add line to github link without line",