Add Platform Bitbucket (#1886)

This commit is contained in:
Tilo Brueckner authored and GitHub committed 2025-06-04 19:46:01 -05:00
1 parent 722ce8213a
commit 20f9a1d4eb
4 files changed
+45

No files matched your search

+4
View File
@@ -14,6 +14,7 @@ const (
GitLabPlatform GitLabPlatform
AzureDevOpsPlatform AzureDevOpsPlatform
GiteaPlatform GiteaPlatform
BitbucketPlatform
// TODO: Add others. // TODO: Add others.
) )
@@ -25,6 +26,7 @@ func (p Platform) String() string {
"gitlab", "gitlab",
"azuredevops", "azuredevops",
"gitea", "gitea",
"bitbucket",
}[p] }[p]
} }
@@ -42,6 +44,8 @@ func PlatformFromString(s string) (Platform, error) {
return AzureDevOpsPlatform, nil return AzureDevOpsPlatform, nil
case "gitea": case "gitea":
return GiteaPlatform, nil return GiteaPlatform, nil
case "bitbucket":
return BitbucketPlatform, nil
default: default:
return UnknownPlatform, fmt.Errorf("invalid scm platform value: %s", s) return UnknownPlatform, fmt.Errorf("invalid scm platform value: %s", s)
} }
+12
View File
@@ -91,6 +91,18 @@ func createScmLink(remote *sources.RemoteInfo, finding report.Finding) string {
link += fmt.Sprintf("-L%d", finding.EndLine) link += fmt.Sprintf("-L%d", finding.EndLine)
} }
return link return link
case scm.BitbucketPlatform:
link := fmt.Sprintf("%s/src/%s/%s", remote.Url, finding.Commit, filePath)
if hasInnerPath {
return link
}
if finding.StartLine != 0 {
link += fmt.Sprintf("#lines-%d", finding.StartLine)
}
if finding.EndLine != finding.StartLine {
link += fmt.Sprintf(":%d", finding.EndLine)
}
return link
default: default:
// This should never happen. // This should never happen.
return "" return ""
+27
View File
@@ -177,6 +177,33 @@ func Test_createScmLink(t *testing.T) {
}, },
want: "https://gitea.com/exampleorganisation/exampleproject/src/commit/20553ad96a4a080c94a54d677db97eed8ce2560d/Readme.md?display=source#L34", want: "https://gitea.com/exampleorganisation/exampleproject/src/commit/20553ad96a4a080c94a54d677db97eed8ce2560d/Readme.md?display=source#L34",
}, },
// bitbucket
"bitbucket - single line": {
remote: &sources.RemoteInfo{
Platform: scm.BitbucketPlatform,
Url: "https://bitbucket.org/exampleorganisation/exampleproject",
},
finding: report.Finding{
Commit: "20553ad96a4a080c94a54d677db97eed8ce2560d",
File: "examplefile.json",
StartLine: 25,
EndLine: 25,
},
want: "https://bitbucket.org/exampleorganisation/exampleproject/src/20553ad96a4a080c94a54d677db97eed8ce2560d/examplefile.json#lines-25",
},
"bitbucket- multi line": {
remote: &sources.RemoteInfo{
Platform: scm.BitbucketPlatform,
Url: "https://bitbucket.org/exampleorganisation/exampleproject",
},
finding: report.Finding{
Commit: "20553ad96a4a080c94a54d677db97eed8ce2560d",
File: "examplefile.json",
StartLine: 25,
EndLine: 30,
},
want: "https://bitbucket.org/exampleorganisation/exampleproject/src/20553ad96a4a080c94a54d677db97eed8ce2560d/examplefile.json#lines-25:30",
},
} }
for name, tt := range tests { for name, tt := range tests {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
+2
View File
@@ -484,6 +484,8 @@ func platformFromHost(u *url.URL) scm.Platform {
return scm.AzureDevOpsPlatform return scm.AzureDevOpsPlatform
case "gitea.com", "code.forgejo.org", "codeberg.org": case "gitea.com", "code.forgejo.org", "codeberg.org":
return scm.GiteaPlatform return scm.GiteaPlatform
case "bitbucket.org":
return scm.BitbucketPlatform
default: default:
return scm.UnknownPlatform return scm.UnknownPlatform
} }