From 22fa3d16bf0ddcf8fbcfa10fc86a19b431acce08 Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Wed, 20 May 2026 20:16:25 -0500 Subject: [PATCH] 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) --- modules/badge/presets.go | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/modules/badge/presets.go b/modules/badge/presets.go index 8a24454234..87f694e112 100644 --- a/modules/badge/presets.go +++ b/modules/badge/presets.go @@ -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 {