mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-12-01 05:24:22 +01:00
add support for Azure DevOps platform in SCM detection and link (#1807)
* feat: add support for Azure DevOps platform in SCM detection and link generation * feat: add support for visualstudio.com in Azure DevOps platform detection * feat: consolidate Azure DevOps platform detection for dev.azure.com and visualstudio.com
This commit is contained in:
1 parent
3e8cd2d1ab
commit
af7d5bcb83
4 files changed
+44
No files matched your search
@@ -12,6 +12,7 @@ const (
|
|||||||
NoPlatform // Explicitly disable the feature
|
NoPlatform // Explicitly disable the feature
|
||||||
GitHubPlatform
|
GitHubPlatform
|
||||||
GitLabPlatform
|
GitLabPlatform
|
||||||
|
AzureDevOpsPlatform
|
||||||
// TODO: Add others.
|
// TODO: Add others.
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ func (p Platform) String() string {
|
|||||||
"none",
|
"none",
|
||||||
"github",
|
"github",
|
||||||
"gitlab",
|
"gitlab",
|
||||||
|
"azuredevops",
|
||||||
}[p]
|
}[p]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +36,8 @@ func PlatformFromString(s string) (Platform, error) {
|
|||||||
return GitHubPlatform, nil
|
return GitHubPlatform, nil
|
||||||
case "gitlab":
|
case "gitlab":
|
||||||
return GitLabPlatform, nil
|
return GitLabPlatform, nil
|
||||||
|
case "azuredevops":
|
||||||
|
return AzureDevOpsPlatform, nil
|
||||||
default:
|
default:
|
||||||
return UnknownPlatform, fmt.Errorf("invalid scm platform value: %s", s)
|
return UnknownPlatform, fmt.Errorf("invalid scm platform value: %s", s)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,6 +171,8 @@ func platformFromHost(u *url.URL) scm.Platform {
|
|||||||
return scm.GitHubPlatform
|
return scm.GitHubPlatform
|
||||||
case "gitlab.com":
|
case "gitlab.com":
|
||||||
return scm.GitLabPlatform
|
return scm.GitLabPlatform
|
||||||
|
case "dev.azure.com", "visualstudio.com":
|
||||||
|
return scm.AzureDevOpsPlatform
|
||||||
default:
|
default:
|
||||||
return scm.UnknownPlatform
|
return scm.UnknownPlatform
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,18 @@ func createScmLink(scmPlatform scm.Platform, remoteUrl string, finding report.Fi
|
|||||||
link += fmt.Sprintf("-%d", finding.EndLine)
|
link += fmt.Sprintf("-%d", finding.EndLine)
|
||||||
}
|
}
|
||||||
return link
|
return link
|
||||||
|
case scm.AzureDevOpsPlatform:
|
||||||
|
link := fmt.Sprintf("%s/commit/%s?path=/%s", remoteUrl, finding.Commit, filePath)
|
||||||
|
// Add line information if applicable
|
||||||
|
if finding.StartLine != 0 {
|
||||||
|
link += fmt.Sprintf("&line=%d", finding.StartLine)
|
||||||
|
}
|
||||||
|
if finding.EndLine != finding.StartLine {
|
||||||
|
link += fmt.Sprintf("&lineEnd=%d", finding.EndLine)
|
||||||
|
}
|
||||||
|
// This is a bit dirty, but Azure DevOps does not highlight the line when the lineStartColumn and lineEndColumn are not provided
|
||||||
|
link += "&lineStartColumn=1&lineEndColumn=10000000&type=2&lineStyle=plain&_a=files"
|
||||||
|
return link
|
||||||
default:
|
default:
|
||||||
// This should never happen.
|
// This should never happen.
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
@@ -91,6 +91,32 @@ func Test_createScmLink(t *testing.T) {
|
|||||||
},
|
},
|
||||||
want: "https://gitlab.com/example-org/example-group/gitleaks/blob/63410f74e23a4e51e1f60b9feb073b5d325af878/.vscode/launchSettings.json#L6-8",
|
want: "https://gitlab.com/example-org/example-group/gitleaks/blob/63410f74e23a4e51e1f60b9feb073b5d325af878/.vscode/launchSettings.json#L6-8",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Azure DevOps
|
||||||
|
"azuredevops - single line": {
|
||||||
|
platform: scm.AzureDevOpsPlatform,
|
||||||
|
url: "https://dev.azure.com/exampleorganisation/exampleproject/_git/exampleRepository",
|
||||||
|
finding: report.Finding{
|
||||||
|
Commit: "20553ad96a4a080c94a54d677db97eed8ce2560d",
|
||||||
|
File: "examplefile.json",
|
||||||
|
StartLine: 25,
|
||||||
|
EndLine: 25,
|
||||||
|
},
|
||||||
|
want: "https://dev.azure.com/exampleorganisation/exampleproject/_git/exampleRepository/commit/20553ad96a4a080c94a54d677db97eed8ce2560d?path=/examplefile.json&line=25&lineStartColumn=1&lineEndColumn=10000000&type=2&lineStyle=plain&_a=files",
|
||||||
|
},
|
||||||
|
|
||||||
|
// Azure DevOps
|
||||||
|
"azuredevops - multi line": {
|
||||||
|
platform: scm.AzureDevOpsPlatform,
|
||||||
|
url: "https://dev.azure.com/exampleorganisation/exampleproject/_git/exampleRepository",
|
||||||
|
finding: report.Finding{
|
||||||
|
Commit: "20553ad96a4a080c94a54d677db97eed8ce2560d",
|
||||||
|
File: "examplefile.json",
|
||||||
|
StartLine: 25,
|
||||||
|
EndLine: 30,
|
||||||
|
},
|
||||||
|
want: "https://dev.azure.com/exampleorganisation/exampleproject/_git/exampleRepository/commit/20553ad96a4a080c94a54d677db97eed8ce2560d?path=/examplefile.json&line=25&lineEnd=30&lineStartColumn=1&lineEndColumn=10000000&type=2&lineStyle=plain&_a=files",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for name, tt := range tests {
|
for name, tt := range tests {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
|
|||||||
Reference in new issue
Block a user