Skip to content
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

Hide the "Details" link of commit status when the user cannot access actions #30156

Merged
merged 5 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion models/git/commit_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,17 @@ func GetNextCommitStatusIndex(ctx context.Context, repoID int64, sha string) (in
return newIdx, nil
}

func (status *CommitStatus) loadAttributes(ctx context.Context) (err error) {
func (status *CommitStatus) loadRepository(ctx context.Context) (err error) {
if status.Repo == nil {
status.Repo, err = repo_model.GetRepositoryByID(ctx, status.RepoID)
if err != nil {
return fmt.Errorf("getRepositoryByID [%d]: %w", status.RepoID, err)
}
}
return nil
}

func (status *CommitStatus) loadCreator(ctx context.Context) (err error) {
if status.Creator == nil && status.CreatorID > 0 {
status.Creator, err = user_model.GetUserByID(ctx, status.CreatorID)
if err != nil {
Expand All @@ -187,6 +191,13 @@ func (status *CommitStatus) loadAttributes(ctx context.Context) (err error) {
return nil
}

func (status *CommitStatus) loadAttributes(ctx context.Context) (err error) {
if err := status.loadRepository(ctx); err != nil {
return err
}
return status.loadCreator(ctx)
}

// APIURL returns the absolute APIURL to this commit-status.
func (status *CommitStatus) APIURL(ctx context.Context) string {
_ = status.loadAttributes(ctx)
Expand All @@ -198,6 +209,21 @@ func (status *CommitStatus) LocaleString(lang translation.Locale) string {
return lang.TrString("repo.commitstatus." + status.State.String())
}

// HideActionsURL set `TargetURL` to an empty string if the status comes from Gitea Actions
func (status *CommitStatus) HideActionsURL(ctx context.Context) {
if status.Repo == nil {
if err := status.loadRepository(ctx); err != nil {
log.Error("loadRepository: %v", err)
return
}
}

prefix := fmt.Sprintf("%s/actions", status.Repo.Link())
if strings.HasPrefix(status.TargetURL, prefix) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is TargetURL a relative path or a URL?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on the source of the commit status.

  • If the commit status comes from Gitea Actions, the TargetURL will be a relative path like /{owner}/{repo}/actions/runs/1/jobs/2.
  • If the commit status comes from an external service like Drone, the TargetURL will be a URL.

status.TargetURL = ""
}
}

// CalcCommitStatus returns commit status state via some status, the commit statues should order by id desc
func CalcCommitStatus(statuses []*CommitStatus) *CommitStatus {
var lastStatus *CommitStatus
Expand Down Expand Up @@ -506,3 +532,15 @@ func ConvertFromGitCommit(ctx context.Context, commits []*git.Commit, repo *repo
repo,
)
}

// CommitStatusesHideActionsURL hide Gitea Actions urls
func CommitStatusesHideActionsURL(ctx context.Context, statuses []*CommitStatus) {
idToRepos := make(map[int64]*repo_model.Repository)
for _, status := range statuses {
if status.Repo == nil {
status.Repo = idToRepos[status.RepoID]
}
status.HideActionsURL(ctx)
idToRepos[status.RepoID] = status.Repo
}
}
25 changes: 25 additions & 0 deletions models/git/commit_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
package git_test

import (
"fmt"
"testing"
"time"

actions_model "code.gitea.io/gitea/models/actions"
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
repo_model "code.gitea.io/gitea/models/repo"
Expand Down Expand Up @@ -231,3 +233,26 @@ func TestFindRepoRecentCommitStatusContexts(t *testing.T) {
assert.Equal(t, "compliance/lint-backend", contexts[0])
}
}

func TestCommitStatusesHideActionsURL(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())

repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
run := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{ID: 791, RepoID: repo.ID})
assert.NoError(t, run.LoadAttributes(db.DefaultContext))

statuses := []*git_model.CommitStatus{
{
RepoID: repo.ID,
TargetURL: fmt.Sprintf("%s/jobs/%d", run.Link(), run.Index),
},
{
RepoID: repo.ID,
TargetURL: "https://mycicd.org/1",
},
}

git_model.CommitStatusesHideActionsURL(db.DefaultContext, statuses)
assert.Empty(t, statuses[0].TargetURL)
assert.Equal(t, "https://mycicd.org/1", statuses[1].TargetURL)
}
5 changes: 5 additions & 0 deletions routers/web/repo/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ func Branches(ctx *context.Context) {
ctx.ServerError("LoadBranches", err)
return
}
if !ctx.Repo.CanRead(unit.TypeActions) {
for key := range commitStatuses {
git_model.CommitStatusesHideActionsURL(ctx, commitStatuses[key])
}
}

commitStatus := make(map[string]*git_model.CommitStatus)
for commitID, cs := range commitStatuses {
Expand Down
21 changes: 18 additions & 3 deletions routers/web/repo/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
repo_model "code.gitea.io/gitea/models/repo"
unit_model "code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/charset"
Expand Down Expand Up @@ -81,7 +82,7 @@ func Commits(ctx *context.Context) {
ctx.ServerError("CommitsByRange", err)
return
}
ctx.Data["Commits"] = git_model.ConvertFromGitCommit(ctx, commits, ctx.Repo.Repository)
ctx.Data["Commits"] = processGitCommits(ctx, commits)

ctx.Data["Username"] = ctx.Repo.Owner.Name
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
Expand Down Expand Up @@ -199,7 +200,7 @@ func SearchCommits(ctx *context.Context) {
return
}
ctx.Data["CommitCount"] = len(commits)
ctx.Data["Commits"] = git_model.ConvertFromGitCommit(ctx, commits, ctx.Repo.Repository)
ctx.Data["Commits"] = processGitCommits(ctx, commits)

ctx.Data["Keyword"] = query
if all {
Expand Down Expand Up @@ -242,7 +243,7 @@ func FileHistory(ctx *context.Context) {
ctx.ServerError("CommitsByFileAndRange", err)
return
}
ctx.Data["Commits"] = git_model.ConvertFromGitCommit(ctx, commits, ctx.Repo.Repository)
ctx.Data["Commits"] = processGitCommits(ctx, commits)

ctx.Data["Username"] = ctx.Repo.Owner.Name
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
Expand Down Expand Up @@ -353,6 +354,9 @@ func Diff(ctx *context.Context) {
if err != nil {
log.Error("GetLatestCommitStatus: %v", err)
}
if !ctx.Repo.CanRead(unit_model.TypeActions) {
git_model.CommitStatusesHideActionsURL(ctx, statuses)
}

ctx.Data["CommitStatus"] = git_model.CalcCommitStatus(statuses)
ctx.Data["CommitStatuses"] = statuses
Expand Down Expand Up @@ -433,3 +437,14 @@ func RawDiff(ctx *context.Context) {
return
}
}

func processGitCommits(ctx *context.Context, gitCommits []*git.Commit) []*git_model.SignCommitWithStatuses {
commits := git_model.ConvertFromGitCommit(ctx, gitCommits, ctx.Repo.Repository)
if !ctx.Repo.CanRead(unit_model.TypeActions) {
for _, commit := range commits {
commit.Status.HideActionsURL(ctx)
git_model.CommitStatusesHideActionsURL(ctx, commit.Statuses)
}
}
return commits
}
2 changes: 1 addition & 1 deletion routers/web/repo/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ func PrepareCompareDiff(
return false
}

commits := git_model.ConvertFromGitCommit(ctx, ci.CompareInfo.Commits, ci.HeadRepo)
commits := processGitCommits(ctx, ci.CompareInfo.Commits)
ctx.Data["Commits"] = commits
ctx.Data["CommitCount"] = len(commits)

Expand Down
11 changes: 11 additions & 0 deletions routers/web/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
ctx.ServerError("GetIssuesAllCommitStatus", err)
return
}
if !ctx.Repo.CanRead(unit.TypeActions) {
for key := range commitStatuses {
git_model.CommitStatusesHideActionsURL(ctx, commitStatuses[key])
}
}

if err := issues.LoadAttributes(ctx); err != nil {
ctx.ServerError("issues.LoadAttributes", err)
Expand Down Expand Up @@ -1757,6 +1762,12 @@ func ViewIssue(ctx *context.Context) {
ctx.ServerError("LoadPushCommits", err)
return
}
if !ctx.Repo.CanRead(unit.TypeActions) {
for _, commit := range comment.Commits {
commit.Status.HideActionsURL(ctx)
git_model.CommitStatusesHideActionsURL(ctx, commit.Statuses)
}
}
} else if comment.Type == issues_model.CommentTypeAddTimeManual ||
comment.Type == issues_model.CommentTypeStopTracking ||
comment.Type == issues_model.CommentTypeDeleteTimeManual {
Expand Down
14 changes: 13 additions & 1 deletion routers/web/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *issues_model.Issue)
ctx.ServerError("GetLatestCommitStatus", err)
return nil
}
if !ctx.Repo.CanRead(unit.TypeActions) {
git_model.CommitStatusesHideActionsURL(ctx, commitStatuses)
}

if len(commitStatuses) != 0 {
ctx.Data["LatestCommitStatuses"] = commitStatuses
ctx.Data["LatestCommitStatus"] = git_model.CalcCommitStatus(commitStatuses)
Expand Down Expand Up @@ -345,6 +349,10 @@ func PrepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C
ctx.ServerError("GetLatestCommitStatus", err)
return nil
}
if !ctx.Repo.CanRead(unit.TypeActions) {
git_model.CommitStatusesHideActionsURL(ctx, commitStatuses)
}

if len(commitStatuses) > 0 {
ctx.Data["LatestCommitStatuses"] = commitStatuses
ctx.Data["LatestCommitStatus"] = git_model.CalcCommitStatus(commitStatuses)
Expand Down Expand Up @@ -437,6 +445,10 @@ func PrepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C
ctx.ServerError("GetLatestCommitStatus", err)
return nil
}
if !ctx.Repo.CanRead(unit.TypeActions) {
git_model.CommitStatusesHideActionsURL(ctx, commitStatuses)
}

if len(commitStatuses) > 0 {
ctx.Data["LatestCommitStatuses"] = commitStatuses
ctx.Data["LatestCommitStatus"] = git_model.CalcCommitStatus(commitStatuses)
Expand Down Expand Up @@ -603,7 +615,7 @@ func ViewPullCommits(ctx *context.Context) {
ctx.Data["Username"] = ctx.Repo.Owner.Name
ctx.Data["Reponame"] = ctx.Repo.Repository.Name

commits := git_model.ConvertFromGitCommit(ctx, prInfo.Commits, ctx.Repo.Repository)
commits := processGitCommits(ctx, prInfo.Commits)
ctx.Data["Commits"] = commits
ctx.Data["CommitCount"] = len(commits)

Expand Down
3 changes: 3 additions & 0 deletions routers/web/repo/repo.go
Copy link

@badhezi badhezi Jul 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Zettat123
This invocation throws nil pointer dereference on my local setup.

2024/07/29 16:09:18 ...rs/common/errpage.go:26:RenderPanicErrorPage() [E] PANIC: runtime error: invalid memory address or nil pointer dereference
/usr/local/go/src/runtime/panic.go:770 (0x104ea8c43)
        gopanic: fn()
/Users/hezi/Documents/repos/hub/modules/web/routing/logger_manager.go:116 (0x106574deb)
        (*requestRecordsManager).handler-fm.(*requestRecordsManager).handler.func1.1: panic(localPanicErr)
/usr/local/go/src/runtime/panic.go:770 (0x104ea8c43)
        gopanic: fn()
/usr/local/go/src/runtime/panic.go:261 (0x104ec3d27)
        panicmem: panic(memoryError)
/usr/local/go/src/runtime/signal_unix.go:881 (0x104ec3cf4)
        sigpanic: panicmem()
/Users/hezi/Documents/repos/hub/models/git/commit_status.go:544 (0x105f40444)
        CommitStatusesHideActionsURL: if status.Repo == nil {
/Users/hezi/Documents/repos/hub/routers/web/repo/repo.go:669 (0x106e44397)
        SearchRepo: git_model.CommitStatusesHideActionsURL(ctx, latestCommitStatuses)
/usr/local/go/src/reflect/value.go:596 (0x104f629ef)
        Value.call: call(frametype, fn, stackArgs, uint32(frametype.Size()), uint32(abid.retOffset), uint32(frameSize), &regArgs)
/usr/local/go/src/reflect/value.go:380 (0x104f61e93)
        Value.Call: return v.call("Call", in)
/Users/hezi/Documents/repos/hub/modules/web/handler.go:172 (0x10657dd67)
        toHandlerProvider.func1.1: ret := fn.Call(argsIn)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/Documents/repos/hub/modules/web/handler.go:182 (0x10657ddd7)
        toHandlerProvider.func1.1: next.ServeHTTP(resp, req)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/go/pkg/mod/github.com/go-chi/chi/[email protected]/chain.go:31 (0x1065758bf)
        (*ChainHandler).ServeHTTP: c.chain.ServeHTTP(w, r)
/Users/hezi/go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:459 (0x106578607)
        (*Mux).routeHTTP: h.ServeHTTP(w, r)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/Documents/repos/hub/modules/web/handler.go:182 (0x10657ddd7)
        toHandlerProvider.func1.1: next.ServeHTTP(resp, req)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/Documents/repos/hub/modules/web/handler.go:182 (0x10657ddd7)
        toHandlerProvider.func1.1: next.ServeHTTP(resp, req)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/Documents/repos/hub/modules/web/handler.go:182 (0x10657ddd7)
        toHandlerProvider.func1.1: next.ServeHTTP(resp, req)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/go/pkg/mod/github.com/go-chi/chi/[email protected]/middleware/get_head.go:37 (0x106dafb3b)
        GetHead.func1: next.ServeHTTP(w, r)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/Documents/repos/hub/modules/web/handler.go:136 (0x10657e1a7)
        toHandlerProvider.wrapHandlerProvider[...].func2.1: h.ServeHTTP(resp, req)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/Documents/repos/hub/modules/web/handler.go:182 (0x10657ddd7)
        toHandlerProvider.func1.1: next.ServeHTTP(resp, req)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/Documents/repos/hub/services/context/context.go:218 (0x106612b6b)
        Contexter.func1.1: next.ServeHTTP(ctx.Resp, ctx.Req)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/Documents/repos/hub/modules/web/handler.go:136 (0x10657e1a7)
        toHandlerProvider.wrapHandlerProvider[...].func2.1: h.ServeHTTP(resp, req)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/go/pkg/mod/gitea.com/go-chi/[email protected]/session.go:257 (0x1065265a3)
        Sessioner.func1.1: next.ServeHTTP(w, req)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/Documents/repos/hub/modules/web/handler.go:136 (0x10657e1a7)
        toHandlerProvider.wrapHandlerProvider[...].func2.1: h.ServeHTTP(resp, req)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:73 (0x106576413)
        (*Mux).ServeHTTP: mx.handler.ServeHTTP(w, r)
/Users/hezi/go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:327 (0x106577c5f)
        (*Mux).Mount.func1: handler.ServeHTTP(w, r)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:459 (0x106578607)
        (*Mux).routeHTTP: h.ServeHTTP(w, r)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:73 (0x106576413)
        (*Mux).ServeHTTP: mx.handler.ServeHTTP(w, r)
/Users/hezi/go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:327 (0x106577c5f)
        (*Mux).Mount.func1: handler.ServeHTTP(w, r)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:459 (0x106578607)
        (*Mux).routeHTTP: h.ServeHTTP(w, r)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/Documents/repos/hub/modules/web/routing/logger_manager.go:122 (0x106574c87)
        (*requestRecordsManager).handler-fm.(*requestRecordsManager).handler.func1: next.ServeHTTP(w, req)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/Documents/repos/hub/modules/web/handler.go:136 (0x10657e1a7)
        toHandlerProvider.wrapHandlerProvider[...].func2.1: h.ServeHTTP(resp, req)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/go/pkg/mod/github.com/chi-middleware/[email protected]/middleware.go:37 (0x106cf6cd7)
        ProtocolMiddlewares.ForwardedHeaders.func4.1: h.ServeHTTP(w, r)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/Documents/repos/hub/modules/web/handler.go:136 (0x10657e1a7)
        toHandlerProvider.wrapHandlerProvider[...].func2.1: h.ServeHTTP(resp, req)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/Documents/repos/hub/routers/common/middleware.go:59 (0x106cf7ccb)
        ProtocolMiddlewares.func3.1: next.ServeHTTP(context.WrapResponseWriter(resp), req.WithContext(cache.WithCacheContext(ctx)))
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/Documents/repos/hub/modules/web/handler.go:136 (0x10657e1a7)
        toHandlerProvider.wrapHandlerProvider[...].func2.1: h.ServeHTTP(resp, req)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/Documents/repos/hub/routers/common/middleware.go:50 (0x106cf78e3)
        ProtocolMiddlewares.func2.1: next.ServeHTTP(resp, req)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/Documents/repos/hub/modules/web/handler.go:136 (0x10657e1a7)
        toHandlerProvider.wrapHandlerProvider[...].func2.1: h.ServeHTTP(resp, req)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/Documents/repos/hub/routers/common/middleware.go:36 (0x106cf75ab)
        ProtocolMiddlewares.func1.1: next.ServeHTTP(resp, req)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/Documents/repos/hub/modules/web/handler.go:136 (0x10657e1a7)
        toHandlerProvider.wrapHandlerProvider[...].func2.1: h.ServeHTTP(resp, req)
/usr/local/go/src/net/http/server.go:2166 (0x1053089b7)
        HandlerFunc.ServeHTTP: f(w, r)
/Users/hezi/go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:90 (0x1065763cf)
        (*Mux).ServeHTTP: mx.handler.ServeHTTP(w, r)
/Users/hezi/Documents/repos/hub/modules/web/route.go:225 (0x10657f937)
        (*Router).normalizeRequestPath: next.ServeHTTP(resp, req)
/Users/hezi/Documents/repos/hub/modules/web/route.go:165 (0x10657f4ff)
        (*Router).ServeHTTP: r.normalizeRequestPath(w, req, r.chiRouter)
/usr/local/go/src/net/http/server.go:3137 (0x10530bdcb)
        serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
/usr/local/go/src/net/http/server.go:2039 (0x105307587)
        (*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
/usr/local/go/src/runtime/asm_arm64.s:1222 (0x104ee67a3)
        goexit: MOVD    R0, R0  // NOP

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we are getting nil elements in the latestCommitStatuses slice (i.e. because of this call).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nil needs to be cache which means there is no commit status.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,9 @@ func SearchRepo(ctx *context.Context) {
ctx.JSON(http.StatusInternalServerError, nil)
return
}
if !ctx.Repo.CanRead(unit.TypeActions) {
git_model.CommitStatusesHideActionsURL(ctx, latestCommitStatuses)
}

results := make([]*repo_service.WebSearchRepository, len(repos))
for i, repo := range repos {
Expand Down
3 changes: 3 additions & 0 deletions routers/web/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ func loadLatestCommitData(ctx *context.Context, latestCommit *git.Commit) bool {
if err != nil {
log.Error("GetLatestCommitStatus: %v", err)
}
if !ctx.Repo.CanRead(unit_model.TypeActions) {
git_model.CommitStatusesHideActionsURL(ctx, statuses)
}

ctx.Data["LatestCommitStatus"] = git_model.CalcCommitStatus(statuses)
ctx.Data["LatestCommitStatuses"] = statuses
Expand Down
6 changes: 6 additions & 0 deletions routers/web/user/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
activities_model "code.gitea.io/gitea/models/activities"
asymkey_model "code.gitea.io/gitea/models/asymkey"
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/organization"
repo_model "code.gitea.io/gitea/models/repo"
Expand Down Expand Up @@ -568,6 +569,11 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
ctx.ServerError("GetIssuesLastCommitStatus", err)
return
}
if !ctx.Repo.CanRead(unit.TypeActions) {
for key := range commitStatuses {
git_model.CommitStatusesHideActionsURL(ctx, commitStatuses[key])
}
}

// -------------------------------
// Fill stats to post to ctx.Data.
Expand Down
7 changes: 7 additions & 0 deletions routers/web/user/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import (

activities_model "code.gitea.io/gitea/models/activities"
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
Expand Down Expand Up @@ -303,6 +305,11 @@ func NotificationSubscriptions(ctx *context.Context) {
ctx.ServerError("GetIssuesAllCommitStatus", err)
return
}
if !ctx.Repo.CanRead(unit.TypeActions) {
for key := range commitStatuses {
git_model.CommitStatusesHideActionsURL(ctx, commitStatuses[key])
}
}
ctx.Data["CommitLastStatus"] = lastStatus
ctx.Data["CommitStatuses"] = commitStatuses
ctx.Data["Issues"] = issues
Expand Down