Skip to content

Commit 237b83f

Browse files
committed
feat: badge support tag
1 parent 35bcd66 commit 237b83f

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

models/actions/run.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,10 @@ func GetLatestRun(ctx context.Context, repoID int64) (*ActionRun, error) {
374374
return run, nil
375375
}
376376

377-
func GetWorkflowLatestRun(ctx context.Context, repoID int64, workflowFile, branch, event string) (*ActionRun, error) {
377+
func GetWorkflowLatestRun(ctx context.Context, repoID int64, workflowFile, ref, event string) (*ActionRun, error) {
378378
var run ActionRun
379379
q := db.GetEngine(ctx).Where("repo_id=?", repoID).
380-
And("ref = ?", branch).
380+
And("ref = ?", ref).
381381
And("workflow_id = ?", workflowFile)
382382
if event != "" {
383383
q.And("event = ?", event)
@@ -386,7 +386,7 @@ func GetWorkflowLatestRun(ctx context.Context, repoID int64, workflowFile, branc
386386
if err != nil {
387387
return nil, err
388388
} else if !has {
389-
return nil, util.NewNotExistErrorf("run with repo_id %d, ref %s, workflow_id %s", repoID, branch, workflowFile)
389+
return nil, util.NewNotExistErrorf("run with repo_id %d, ref %s, workflow_id %s", repoID, ref, workflowFile)
390390
}
391391
return &run, nil
392392
}

routers/web/repo/actions/badge.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ import (
1919
func 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+
if branch == "" && tag == "" {
2324
branch = ctx.Repo.Repository.DefaultBranch
2425
}
25-
branchRef := fmt.Sprintf("refs/heads/%s", branch)
26+
ref := fmt.Sprintf("refs/heads/%s", branch)
27+
if branch == "" && tag != "" {
28+
ref = fmt.Sprintf("refs/tags/%s", tag)
29+
}
2630
event := ctx.Req.URL.Query().Get("event")
2731

28-
badge, err := getWorkflowBadge(ctx, workflowFile, branchRef, event)
32+
badge, err := getWorkflowBadge(ctx, workflowFile, ref, event)
2933
if err != nil {
3034
ctx.ServerError("GetWorkflowBadge", err)
3135
return

0 commit comments

Comments
 (0)