Tilo Brueckner 8 месяцев назад
Родитель
Сommit
20f9a1d4eb
4 измененных файлов с 45 добавлено и 0 удалено
  1. 4 0
      cmd/scm/scm.go
  2. 12 0
      detect/utils.go
  3. 27 0
      detect/utils_test.go
  4. 2 0
      sources/git.go

+ 4 - 0
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)
 	}

+ 12 - 0
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 ""

+ 27 - 0
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) {

+ 2 - 0
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
 	}