mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Add flat-square action badge style (#34062)
Adds the `flat-square` style to action badges. Styles can be selected by adding `?style=<style>` to the badge endpoint. If no style query is given, or if the query is invalid, the style defaults to `flat`. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -5,35 +5,38 @@ package actions
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
"code.gitea.io/gitea/modules/badge"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
)
|
||||
|
||||
func GetWorkflowBadge(ctx *context.Context) {
|
||||
workflowFile := ctx.PathParam("workflow_name")
|
||||
branch := ctx.Req.URL.Query().Get("branch")
|
||||
if branch == "" {
|
||||
branch = ctx.Repo.Repository.DefaultBranch
|
||||
}
|
||||
branchRef := fmt.Sprintf("refs/heads/%s", branch)
|
||||
event := ctx.Req.URL.Query().Get("event")
|
||||
branch := ctx.FormString("branch", ctx.Repo.Repository.DefaultBranch)
|
||||
event := ctx.FormString("event")
|
||||
style := ctx.FormString("style")
|
||||
|
||||
badge, err := getWorkflowBadge(ctx, workflowFile, branchRef, event)
|
||||
branchRef := git.RefNameFromBranch(branch)
|
||||
b, err := getWorkflowBadge(ctx, workflowFile, branchRef.String(), event)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetWorkflowBadge", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Badge"] = badge
|
||||
ctx.Data["Badge"] = b
|
||||
ctx.RespHeader().Set("Content-Type", "image/svg+xml")
|
||||
ctx.HTML(http.StatusOK, "shared/actions/runner_badge")
|
||||
switch style {
|
||||
case badge.StyleFlatSquare:
|
||||
ctx.HTML(http.StatusOK, "shared/actions/runner_badge_flat-square")
|
||||
default: // defaults to badge.StyleFlat
|
||||
ctx.HTML(http.StatusOK, "shared/actions/runner_badge_flat")
|
||||
}
|
||||
}
|
||||
|
||||
func getWorkflowBadge(ctx *context.Context, workflowFile, branchName, event string) (badge.Badge, error) {
|
||||
@@ -48,7 +51,7 @@ func getWorkflowBadge(ctx *context.Context, workflowFile, branchName, event stri
|
||||
return badge.Badge{}, err
|
||||
}
|
||||
|
||||
color, ok := badge.StatusColorMap[run.Status]
|
||||
color, ok := badge.GlobalVars().StatusColorMap[run.Status]
|
||||
if !ok {
|
||||
return badge.GenerateBadge(workflowName, "unknown status", badge.DefaultColor), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user