mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-28 20:24:22 +01:00
Add Platform Gitea (#1884)
This commit is contained in:
1 parent
c5683ca6a3
commit
722ce8213a
4 files changed
+63
No files matched your search
@@ -13,6 +13,7 @@ const (
|
||||
GitHubPlatform
|
||||
GitLabPlatform
|
||||
AzureDevOpsPlatform
|
||||
GiteaPlatform
|
||||
// TODO: Add others.
|
||||
)
|
||||
|
||||
@@ -23,6 +24,7 @@ func (p Platform) String() string {
|
||||
"github",
|
||||
"gitlab",
|
||||
"azuredevops",
|
||||
"gitea",
|
||||
}[p]
|
||||
}
|
||||
|
||||
@@ -38,6 +40,8 @@ func PlatformFromString(s string) (Platform, error) {
|
||||
return GitLabPlatform, nil
|
||||
case "azuredevops":
|
||||
return AzureDevOpsPlatform, nil
|
||||
case "gitea":
|
||||
return GiteaPlatform, nil
|
||||
default:
|
||||
return UnknownPlatform, fmt.Errorf("invalid scm platform value: %s", s)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
link += "&lineStartColumn=1&lineEndColumn=10000000&type=2&lineStyle=plain&_a=files"
|
||||
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:
|
||||
// This should never happen.
|
||||
return ""
|
||||
|
||||
@@ -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",
|
||||
},
|
||||
|
||||
// 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 {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
|
||||
@@ -482,6 +482,8 @@ func platformFromHost(u *url.URL) scm.Platform {
|
||||
return scm.GitLabPlatform
|
||||
case "dev.azure.com", "visualstudio.com":
|
||||
return scm.AzureDevOpsPlatform
|
||||
case "gitea.com", "code.forgejo.org", "codeberg.org":
|
||||
return scm.GiteaPlatform
|
||||
default:
|
||||
return scm.UnknownPlatform
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user