Skip to content

Find, verify, and analyze leaked credentials

Update Azure Repos link format (#4598)

Amaan Ullah05cccb53bc9e
diff --git a/pkg/engine/engine_test.go b/pkg/engine/engine_test.go
index 18800715f..5f3dbe6ff 100644
--- a/pkg/engine/engine_test.go
+++ b/pkg/engine/engine_test.go
@@ -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",
diff --git a/pkg/giturl/giturl.go b/pkg/giturl/giturl.go
index 7c2648bcf..839f3f1a6 100644
--- a/pkg/giturl/giturl.go
+++ b/pkg/giturl/giturl.go
@@ -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:
diff --git a/pkg/giturl/giturl_test.go b/pkg/giturl/giturl_test.go
index 5e40d27db..1839dc020 100644
--- a/pkg/giturl/giturl_test.go
+++ b/pkg/giturl/giturl_test.go
@@ -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",