From 4fc99fa825a6a01a94e93fde969ed20589ed5a6a Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Mon, 12 Feb 2024 17:47:59 +0000 Subject: [PATCH 1/2] Show commit status for releases. --- routers/web/repo/release.go | 29 +++++- services/actions/commit_status.go | 3 + templates/repo/commit_statuses.tmpl | 4 +- templates/repo/release/list.tmpl | 152 ++++++++++++++-------------- 4 files changed, 109 insertions(+), 79 deletions(-) diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go index fdb247d413835..e3fa948a6d4b5 100644 --- a/routers/web/repo/release.go +++ b/routers/web/repo/release.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + git_model "code.gitea.io/gitea/models/git" repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" @@ -121,6 +122,15 @@ func Releases(ctx *context.Context) { } var ok bool + type ReleaseInfo struct { + Release *repo_model.Release + CommitStatus *git_model.CommitStatus + CommitStatuses []*git_model.CommitStatus + } + + canReadActions := ctx.Repo.CanRead(unit.TypeActions) + + releaseInfos := make([]*ReleaseInfo, 0, len(releases)) for _, r := range releases { if r.Publisher, ok = cacheUsers[r.PublisherID]; !ok { r.Publisher, err = user_model.GetUserByID(ctx, r.PublisherID) @@ -148,6 +158,23 @@ func Releases(ctx *context.Context) { return } + info := &ReleaseInfo{ + Release: r, + } + + if canReadActions { + statuses, _, err := git_model.GetLatestCommitStatus(ctx, r.Repo.ID, r.Sha1, db.ListOptions{ListAll: true}) + if err != nil { + ctx.ServerError("GetLatestCommitStatus", err) + return + } + + info.CommitStatus = git_model.CalcCommitStatus(statuses) + info.CommitStatuses = statuses + } + + releaseInfos = append(releaseInfos, info) + if r.IsDraft { continue } @@ -158,7 +185,7 @@ func Releases(ctx *context.Context) { } } - ctx.Data["Releases"] = releases + ctx.Data["Releases"] = releaseInfos numReleases := ctx.Data["NumReleases"].(int64) pager := context.NewPagination(int(numReleases), opts.PageSize, opts.Page, 5) diff --git a/services/actions/commit_status.go b/services/actions/commit_status.go index 72a3ab7ac60e2..edd1fd1568754 100644 --- a/services/actions/commit_status.go +++ b/services/actions/commit_status.go @@ -64,6 +64,9 @@ func createCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er return fmt.Errorf("head of pull request is missing in event payload") } sha = payload.PullRequest.Head.Sha + case webhook_module.HookEventRelease: + event = string(run.Event) + sha = run.CommitSHA default: return nil } diff --git a/templates/repo/commit_statuses.tmpl b/templates/repo/commit_statuses.tmpl index ec2be6c38d5af..74c20a6a2c1e4 100644 --- a/templates/repo/commit_statuses.tmpl +++ b/templates/repo/commit_statuses.tmpl @@ -1,10 +1,10 @@ {{if .Statuses}} {{if and (eq (len .Statuses) 1) .Status.TargetURL}} - + {{template "repo/commit_status" .Status}} {{else}} - + {{template "repo/commit_status" .Status}} {{end}} diff --git a/templates/repo/release/list.tmpl b/templates/repo/release/list.tmpl index fb2fce2950dc8..6dbeb741db0e2 100644 --- a/templates/repo/release/list.tmpl +++ b/templates/repo/release/list.tmpl @@ -5,90 +5,90 @@ {{template "base/alert" .}} {{template "repo/release_tag_header" .}}