fix: badge presets API compatibility
- GetLatestCommitStatus takes db.ListOptions not int - Use GetRepoLicenses() instead of non-existent repo.License field - Use repo.Topics instead of repo.HasWiki() (not a method) - licenseBadge now takes ctx parameter Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+19
-10
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
git_model "code.gitea.io/gitea/models/git"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
)
|
||||
@@ -20,7 +21,7 @@ func Generate(ctx context.Context, repo *repo_model.Repository, badgeType string
|
||||
case "build":
|
||||
return buildBadge(ctx, repo)
|
||||
case "license":
|
||||
return licenseBadge(repo)
|
||||
return licenseBadge(ctx, repo)
|
||||
case "health":
|
||||
return healthBadge(ctx, repo)
|
||||
default:
|
||||
@@ -38,7 +39,7 @@ func versionBadge(ctx context.Context, repo *repo_model.Repository) (Badge, erro
|
||||
}
|
||||
|
||||
func buildBadge(ctx context.Context, repo *repo_model.Repository) (Badge, error) {
|
||||
status, err := git_model.GetLatestCommitStatus(ctx, repo.ID, repo.DefaultBranch, 1)
|
||||
status, err := git_model.GetLatestCommitStatus(ctx, repo.ID, repo.DefaultBranch, db.ListOptions{PageSize: 1})
|
||||
if err != nil || len(status) == 0 {
|
||||
return Badge{Label: "build", Message: "unknown", Color: ColorGrey}, nil
|
||||
}
|
||||
@@ -55,25 +56,33 @@ func buildBadge(ctx context.Context, repo *repo_model.Repository) (Badge, error)
|
||||
}
|
||||
}
|
||||
|
||||
func licenseBadge(repo *repo_model.Repository) (Badge, error) {
|
||||
if len(repo.License) > 0 {
|
||||
return Badge{Label: "license", Message: repo.License, Color: ColorBlue}, nil
|
||||
func licenseBadge(ctx context.Context, repo *repo_model.Repository) (Badge, error) {
|
||||
licenses, err := repo_model.GetRepoLicenses(ctx, repo)
|
||||
if err != nil || len(licenses) == 0 {
|
||||
return Badge{Label: "license", Message: "none", Color: ColorGrey}, nil
|
||||
}
|
||||
return Badge{Label: "license", Message: "none", Color: ColorGrey}, nil
|
||||
return Badge{Label: "license", Message: licenses.StringList()[0], Color: ColorBlue}, nil
|
||||
}
|
||||
|
||||
func healthBadge(ctx context.Context, repo *repo_model.Repository) (Badge, error) {
|
||||
score := 0
|
||||
if repo.HasWiki() {
|
||||
score++
|
||||
}
|
||||
if len(repo.License) > 0 {
|
||||
|
||||
// Has license
|
||||
licenses, _ := repo_model.GetRepoLicenses(ctx, repo)
|
||||
if len(licenses) > 0 {
|
||||
score++
|
||||
}
|
||||
|
||||
// Has description
|
||||
if repo.Description != "" {
|
||||
score++
|
||||
}
|
||||
|
||||
// Has topics
|
||||
if len(repo.Topics) > 0 {
|
||||
score++
|
||||
}
|
||||
|
||||
var color string
|
||||
var msg string
|
||||
switch {
|
||||
|
||||
Reference in New Issue
Block a user