Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 15 additions & 4 deletions pkg/giturl/giturl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
17 changes: 13 additions & 4 deletions pkg/giturl/giturl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Loading