@@ -19,13 +19,28 @@ import (
1919func GetWorkflowBadge (ctx * context.Context ) {
2020 workflowFile := ctx .PathParam ("workflow_name" )
2121 branch := ctx .Req .URL .Query ().Get ("branch" )
22- if branch == "" {
22+ tag := ctx .Req .URL .Query ().Get ("tag" )
23+ useLatestTag := ctx .Req .URL .Query ().Has ("latest_tag" )
24+ if branch == "" && tag == "" && ! useLatestTag {
2325 branch = ctx .Repo .Repository .DefaultBranch
2426 }
25- branchRef := fmt .Sprintf ("refs/heads/%s" , branch )
27+ ref := fmt .Sprintf ("refs/heads/%s" , branch )
28+ if branch == "" && tag != "" {
29+ if useLatestTag {
30+ tags , _ , err := ctx .Repo .GitRepo .GetTagInfos (0 , 1 )
31+ if err != nil {
32+ ctx .ServerError ("GetTagInfos" , err )
33+ return
34+ }
35+ if len (tags ) != 0 {
36+ tag = tags [0 ].Name
37+ }
38+ }
39+ ref = fmt .Sprintf ("refs/tags/%s" , tag )
40+ }
2641 event := ctx .Req .URL .Query ().Get ("event" )
2742
28- badge , err := getWorkflowBadge (ctx , workflowFile , branchRef , event )
43+ badge , err := getWorkflowBadge (ctx , workflowFile , ref , event )
2944 if err != nil {
3045 ctx .ServerError ("GetWorkflowBadge" , err )
3146 return
@@ -36,11 +51,11 @@ func GetWorkflowBadge(ctx *context.Context) {
3651 ctx .HTML (http .StatusOK , "shared/actions/runner_badge" )
3752}
3853
39- func getWorkflowBadge (ctx * context.Context , workflowFile , branchName , event string ) (badge.Badge , error ) {
54+ func getWorkflowBadge (ctx * context.Context , workflowFile , ref , event string ) (badge.Badge , error ) {
4055 extension := filepath .Ext (workflowFile )
4156 workflowName := strings .TrimSuffix (workflowFile , extension )
4257
43- run , err := actions_model .GetWorkflowLatestRun (ctx , ctx .Repo .Repository .ID , workflowFile , branchName , event )
58+ run , err := actions_model .GetWorkflowLatestRun (ctx , ctx .Repo .Repository .ID , workflowFile , ref , event )
4459 if err != nil {
4560 if errors .Is (err , util .ErrNotExist ) {
4661 return badge .GenerateBadge (workflowName , "no status" , badge .DefaultColor ), nil
0 commit comments