From 26b87561b6cd57475ba0c40dafb81c853af84ddd Mon Sep 17 00:00:00 2001 From: Jason Song Date: Tue, 6 Dec 2022 18:32:26 +0800 Subject: [PATCH] fix: deal with empty repo --- routers/web/repo/actions/actions.go | 32 +++++++++++++++++------------ 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/routers/web/repo/actions/actions.go b/routers/web/repo/actions/actions.go index 72f5759ffc..34ddaad99b 100644 --- a/routers/web/repo/actions/actions.go +++ b/routers/web/repo/actions/actions.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" ) @@ -46,21 +47,26 @@ func List(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.actions") ctx.Data["PageIsActions"] = true - defaultBranch, err := ctx.Repo.GitRepo.GetDefaultBranch() - if err != nil { - ctx.Error(http.StatusInternalServerError, err.Error()) - return - } - commit, err := ctx.Repo.GitRepo.GetBranchCommit(defaultBranch) - if err != nil { - ctx.Error(http.StatusInternalServerError, err.Error()) - return - } - - workflows, err := actions.ListWorkflows(commit) - if err != nil { + var workflows git.Entries + if empty, err := ctx.Repo.GitRepo.IsEmpty(); err != nil { ctx.Error(http.StatusInternalServerError, err.Error()) return + } else if !empty { + defaultBranch, err := ctx.Repo.GitRepo.GetDefaultBranch() + if err != nil { + ctx.Error(http.StatusInternalServerError, err.Error()) + return + } + commit, err := ctx.Repo.GitRepo.GetBranchCommit(defaultBranch) + if err != nil { + ctx.Error(http.StatusInternalServerError, err.Error()) + return + } + workflows, err = actions.ListWorkflows(commit) + if err != nil { + ctx.Error(http.StatusInternalServerError, err.Error()) + return + } } ctx.Data["workflows"] = workflows