0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-12-05 03:08:45 +01:00

fix: clearer logic on getting ref

This commit is contained in:
BoYanZh 2024-11-10 19:26:52 -05:00
parent cbd4fb8a52
commit 3dea5ee2fb
No known key found for this signature in database
GPG key ID: CA088E6D9284F870

View file

@ -21,12 +21,9 @@ func GetWorkflowBadge(ctx *context.Context) {
branch := ctx.Req.URL.Query().Get("branch") branch := ctx.Req.URL.Query().Get("branch")
tag := ctx.Req.URL.Query().Get("tag") tag := ctx.Req.URL.Query().Get("tag")
useLatestTag := ctx.Req.URL.Query().Has("latest_tag") useLatestTag := ctx.Req.URL.Query().Has("latest_tag")
if branch == "" && tag == "" && !useLatestTag { var ref string
branch = ctx.Repo.Repository.DefaultBranch switch {
} case useLatestTag:
ref := fmt.Sprintf("refs/heads/%s", branch)
if branch == "" && tag != "" {
if useLatestTag {
tags, _, err := ctx.Repo.GitRepo.GetTagInfos(0, 1) tags, _, err := ctx.Repo.GitRepo.GetTagInfos(0, 1)
if err != nil { if err != nil {
ctx.ServerError("GetTagInfos", err) ctx.ServerError("GetTagInfos", err)
@ -35,8 +32,14 @@ func GetWorkflowBadge(ctx *context.Context) {
if len(tags) != 0 { if len(tags) != 0 {
tag = tags[0].Name tag = tags[0].Name
} }
}
ref = fmt.Sprintf("refs/tags/%s", tag) ref = fmt.Sprintf("refs/tags/%s", tag)
case tag != "":
ref = fmt.Sprintf("refs/tags/%s", tag)
case branch != "":
ref = fmt.Sprintf("refs/heads/%s", branch)
default:
branch = ctx.Repo.Repository.DefaultBranch
ref = fmt.Sprintf("refs/heads/%s", branch)
} }
event := ctx.Req.URL.Query().Get("event") event := ctx.Req.URL.Query().Get("event")