mirror of https://github.com/go-gitea/gitea.git
fix: clearer logic on getting ref
This commit is contained in:
parent
cbd4fb8a52
commit
3dea5ee2fb
|
@ -21,22 +21,25 @@ 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)
|
tags, _, err := ctx.Repo.GitRepo.GetTagInfos(0, 1)
|
||||||
if branch == "" && tag != "" {
|
if err != nil {
|
||||||
if useLatestTag {
|
ctx.ServerError("GetTagInfos", err)
|
||||||
tags, _, err := ctx.Repo.GitRepo.GetTagInfos(0, 1)
|
return
|
||||||
if err != nil {
|
}
|
||||||
ctx.ServerError("GetTagInfos", err)
|
if len(tags) != 0 {
|
||||||
return
|
tag = tags[0].Name
|
||||||
}
|
|
||||||
if len(tags) != 0 {
|
|
||||||
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")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue