Add Platform Gitea (#1884)

This commit is contained in:
Tilo Brueckner authored and GitHub committed 2025-06-04 09:15:06 -05:00
1 parent c5683ca6a3
commit 722ce8213a
4 files changed
+63

No files matched your search

+4
View File
@@ -13,6 +13,7 @@ const (
GitHubPlatform GitHubPlatform
GitLabPlatform GitLabPlatform
AzureDevOpsPlatform AzureDevOpsPlatform
GiteaPlatform
// TODO: Add others. // TODO: Add others.
) )
@@ -23,6 +24,7 @@ func (p Platform) String() string {
"github", "github",
"gitlab", "gitlab",
"azuredevops", "azuredevops",
"gitea",
}[p] }[p]
} }
@@ -38,6 +40,8 @@ func PlatformFromString(s string) (Platform, error) {
return GitLabPlatform, nil return GitLabPlatform, nil
case "azuredevops": case "azuredevops":
return AzureDevOpsPlatform, nil return AzureDevOpsPlatform, nil
case "gitea":
return GiteaPlatform, nil
default: default:
return UnknownPlatform, fmt.Errorf("invalid scm platform value: %s", s) return UnknownPlatform, fmt.Errorf("invalid scm platform value: %s", s)
} }
+16
View File
@@ -75,6 +75,22 @@ func createScmLink(remote *sources.RemoteInfo, finding report.Finding) string {
// This is a bit dirty, but Azure DevOps does not highlight the line when the lineStartColumn and lineEndColumn are not provided // 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" link += "&lineStartColumn=1&lineEndColumn=10000000&type=2&lineStyle=plain&_a=files"
return link return link
case scm.GiteaPlatform:
link := fmt.Sprintf("%s/src/commit/%s/%s", remote.Url, finding.Commit, filePath)
if hasInnerPath {
return link
}
ext := strings.ToLower(filepath.Ext(filePath))
if ext == ".ipynb" || ext == ".md" {
link += "?display=source"
}
if finding.StartLine != 0 {
link += fmt.Sprintf("#L%d", finding.StartLine)
}
if finding.EndLine != finding.StartLine {
link += fmt.Sprintf("-L%d", finding.EndLine)
}
return link
default: default:
// This should never happen. // This should never happen.
return "" return ""
+41
View File
@@ -136,6 +136,47 @@ func Test_createScmLink(t *testing.T) {
}, },
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", 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",
}, },
// Gitea
"gitea - single line": {
remote: &sources.RemoteInfo{
Platform: scm.GiteaPlatform,
Url: "https://gitea.com/exampleorganisation/exampleproject",
},
finding: report.Finding{
Commit: "20553ad96a4a080c94a54d677db97eed8ce2560d",
File: "examplefile.json",
StartLine: 25,
EndLine: 25,
},
want: "https://gitea.com/exampleorganisation/exampleproject/src/commit/20553ad96a4a080c94a54d677db97eed8ce2560d/examplefile.json#L25",
},
"gitea- multi line": {
remote: &sources.RemoteInfo{
Platform: scm.GiteaPlatform,
Url: "https://gitea.com/exampleorganisation/exampleproject",
},
finding: report.Finding{
Commit: "20553ad96a4a080c94a54d677db97eed8ce2560d",
File: "examplefile.json",
StartLine: 25,
EndLine: 30,
},
want: "https://gitea.com/exampleorganisation/exampleproject/src/commit/20553ad96a4a080c94a54d677db97eed8ce2560d/examplefile.json#L25-L30",
},
"gitea - markdown": {
remote: &sources.RemoteInfo{
Platform: scm.GiteaPlatform,
Url: "https://gitea.com/exampleorganisation/exampleproject",
},
finding: report.Finding{
Commit: "20553ad96a4a080c94a54d677db97eed8ce2560d",
File: "Readme.md",
StartLine: 34,
EndLine: 34,
},
want: "https://gitea.com/exampleorganisation/exampleproject/src/commit/20553ad96a4a080c94a54d677db97eed8ce2560d/Readme.md?display=source#L34",
},
} }
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
@@ -482,6 +482,8 @@ func platformFromHost(u *url.URL) scm.Platform {
return scm.GitLabPlatform return scm.GitLabPlatform
case "dev.azure.com", "visualstudio.com": case "dev.azure.com", "visualstudio.com":
return scm.AzureDevOpsPlatform return scm.AzureDevOpsPlatform
case "gitea.com", "code.forgejo.org", "codeberg.org":
return scm.GiteaPlatform
default: default:
return scm.UnknownPlatform return scm.UnknownPlatform
} }