diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2025-04-02 18:16:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-02 18:16:41 +0800 |
commit | 8f75f61b64bdf70824a54021be43c579239bdcc5 (patch) | |
tree | ae9dc8d0f36386906eb1f0bb0664fe73848ca8e5 /routers | |
parent | 25e409e025a125a5a8012f9f015089e93927d08c (diff) | |
download | gitea-release/v1.23.tar.gz gitea-release/v1.23.zip |
Do not show 500 error when default branch doesn't exist (#34096) (#34097)release/v1.23
Backport #34096
Diffstat (limited to 'routers')
-rw-r--r-- | routers/web/repo/actions/actions.go | 7 | ||||
-rw-r--r-- | routers/web/repo/activity.go | 19 |
2 files changed, 23 insertions, 3 deletions
diff --git a/routers/web/repo/actions/actions.go b/routers/web/repo/actions/actions.go index 1de1835936..46b7461883 100644 --- a/routers/web/repo/actions/actions.go +++ b/routers/web/repo/actions/actions.go @@ -6,6 +6,7 @@ package actions import ( "bytes" stdCtx "context" + "errors" "fmt" "net/http" "slices" @@ -77,7 +78,11 @@ func List(ctx *context.Context) { return } else if !empty { commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch) - if err != nil { + if errors.Is(err, util.ErrNotExist) { + ctx.Data["NotFoundPrompt"] = ctx.Tr("repo.branch.default_branch_not_exist", ctx.Repo.Repository.DefaultBranch) + ctx.NotFound("GetBranchCommit", err) + return + } else if err != nil { ctx.ServerError("GetBranchCommit", err) return } diff --git a/routers/web/repo/activity.go b/routers/web/repo/activity.go index 65dd9e392f..65fd379406 100644 --- a/routers/web/repo/activity.go +++ b/routers/web/repo/activity.go @@ -8,6 +8,7 @@ import ( "time" activities_model "code.gitea.io/gitea/models/activities" + "code.gitea.io/gitea/models/git" "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/services/context" @@ -52,12 +53,26 @@ func Activity(ctx *context.Context) { ctx.Data["DateUntil"] = timeUntil ctx.Data["PeriodText"] = ctx.Tr("repo.activity.period." + ctx.Data["Period"].(string)) + canReadCode := ctx.Repo.CanRead(unit.TypeCode) + if canReadCode { + // GetActivityStats needs to read the default branch to get some information + branchExist, _ := git.IsBranchExist(ctx, ctx.Repo.Repository.ID, ctx.Repo.Repository.DefaultBranch) + if !branchExist { + ctx.Data["NotFoundPrompt"] = ctx.Tr("repo.branch.default_branch_not_exist", ctx.Repo.Repository.DefaultBranch) + ctx.NotFound("", nil) + return + } + } + var err error - if ctx.Data["Activity"], err = activities_model.GetActivityStats(ctx, ctx.Repo.Repository, timeFrom, + // TODO: refactor these arguments to a struct + ctx.Data["Activity"], err = activities_model.GetActivityStats(ctx, ctx.Repo.Repository, timeFrom, ctx.Repo.CanRead(unit.TypeReleases), ctx.Repo.CanRead(unit.TypeIssues), ctx.Repo.CanRead(unit.TypePullRequests), - ctx.Repo.CanRead(unit.TypeCode)); err != nil { + canReadCode, + ) + if err != nil { ctx.ServerError("GetActivityStats", err) return } |