diff --git a/cmd/scm/scm.go b/cmd/scm/scm.go index 8e021e64..23022a9d 100644 --- a/cmd/scm/scm.go +++ b/cmd/scm/scm.go @@ -14,6 +14,7 @@ const ( GitLabPlatform AzureDevOpsPlatform GiteaPlatform + BitbucketPlatform // TODO: Add others. ) @@ -25,6 +26,7 @@ func (p Platform) String() string { "gitlab", "azuredevops", "gitea", + "bitbucket", }[p] } @@ -42,6 +44,8 @@ func PlatformFromString(s string) (Platform, error) { return AzureDevOpsPlatform, nil case "gitea": return GiteaPlatform, nil + case "bitbucket": + return BitbucketPlatform, nil default: return UnknownPlatform, fmt.Errorf("invalid scm platform value: %s", s) } diff --git a/detect/utils.go b/detect/utils.go index cecbcc92..0bf9ed75 100644 --- a/detect/utils.go +++ b/detect/utils.go @@ -91,6 +91,18 @@ func createScmLink(remote *sources.RemoteInfo, finding report.Finding) string { link += fmt.Sprintf("-L%d", finding.EndLine) } 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: // This should never happen. return "" diff --git a/detect/utils_test.go b/detect/utils_test.go index 0b655b55..03a6e32e 100644 --- a/detect/utils_test.go +++ b/detect/utils_test.go @@ -177,6 +177,33 @@ func Test_createScmLink(t *testing.T) { }, 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 { t.Run(name, func(t *testing.T) { diff --git a/sources/git.go b/sources/git.go index 7490ef38..73f713f2 100644 --- a/sources/git.go +++ b/sources/git.go @@ -484,6 +484,8 @@ func platformFromHost(u *url.URL) scm.Platform { return scm.AzureDevOpsPlatform case "gitea.com", "code.forgejo.org", "codeberg.org": return scm.GiteaPlatform + case "bitbucket.org": + return scm.BitbucketPlatform default: return scm.UnknownPlatform }