-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: badge support tag #32451
base: main
Are you sure you want to change the base?
feat: badge support tag #32451
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,13 +19,33 @@ import ( | |
func GetWorkflowBadge(ctx *context.Context) { | ||
workflowFile := ctx.PathParam("workflow_name") | ||
branch := ctx.Req.URL.Query().Get("branch") | ||
if branch == "" { | ||
tag := ctx.Req.URL.Query().Get("tag") | ||
useLatestTag := ctx.Req.URL.Query().Has("latest_tag") | ||
var ref string | ||
switch { | ||
case useLatestTag: | ||
tags, _, err := ctx.Repo.GitRepo.GetTagInfos(0, 1) | ||
if err != nil { | ||
ctx.ServerError("GetTagInfos", err) | ||
return | ||
} | ||
if len(tags) != 0 { | ||
tag = tags[0].Name | ||
} else { | ||
tag = "" // return empty result on no tag | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's empty, we should return error. |
||
} | ||
ref = fmt.Sprintf("refs/tags/%s", tag) | ||
BoYanZh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case tag != "": | ||
ref = fmt.Sprintf("refs/tags/%s", tag) | ||
case branch != "": | ||
ref = fmt.Sprintf("refs/heads/%s", branch) | ||
default: | ||
branch = ctx.Repo.Repository.DefaultBranch | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assign statement is unnecessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I
or add a |
||
ref = fmt.Sprintf("refs/heads/%s", branch) | ||
} | ||
branchRef := fmt.Sprintf("refs/heads/%s", branch) | ||
event := ctx.Req.URL.Query().Get("event") | ||
|
||
badge, err := getWorkflowBadge(ctx, workflowFile, branchRef, event) | ||
badge, err := getWorkflowBadge(ctx, workflowFile, ref, event) | ||
if err != nil { | ||
ctx.ServerError("GetWorkflowBadge", err) | ||
return | ||
|
@@ -36,11 +56,11 @@ func GetWorkflowBadge(ctx *context.Context) { | |
ctx.HTML(http.StatusOK, "shared/actions/runner_badge") | ||
} | ||
|
||
func getWorkflowBadge(ctx *context.Context, workflowFile, branchName, event string) (badge.Badge, error) { | ||
func getWorkflowBadge(ctx *context.Context, workflowFile, ref, event string) (badge.Badge, error) { | ||
extension := filepath.Ext(workflowFile) | ||
workflowName := strings.TrimSuffix(workflowFile, extension) | ||
|
||
run, err := actions_model.GetWorkflowLatestRun(ctx, ctx.Repo.Repository.ID, workflowFile, branchName, event) | ||
run, err := actions_model.GetWorkflowLatestRun(ctx, ctx.Repo.Repository.ID, workflowFile, ref, event) | ||
if err != nil { | ||
if errors.Is(err, util.ErrNotExist) { | ||
return badge.GenerateBadge(workflowName, "no status", badge.DefaultColor), nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should use a function like
GetLatestReleaseByRepoID
to do that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we need the tag of the latest release here? Do we need to rename it to
latest_release_tag
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. All tags have been synced into databases. They shared the same table with releases.