From baf7515fcdfd2006f4c43fadb6560ca85f203816 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Thu, 29 Feb 2024 15:53:09 +0800 Subject: [PATCH 01/12] feat: check branch commit --- routers/web/repo/view.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index e89739e2fb6d1..dafd1710d27e7 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -768,6 +768,7 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) { } } + // Home render repository home page func Home(ctx *context.Context) { if setting.Other.EnableFeed { @@ -1006,6 +1007,8 @@ func renderHomeCode(ctx *context.Context) { return } + checkOutdatedBranch(ctx) + checkCitationFile(ctx, entry) if ctx.Written() { return @@ -1072,6 +1075,31 @@ func renderHomeCode(ctx *context.Context) { ctx.HTML(http.StatusOK, tplRepoHome) } +func checkOutdatedBranch(ctx *context.Context) { + // get the head commit of the branch since ctx.Repo.CommitID is not always the head commit of `ctx.Repo.BranchName` + commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.BranchName) + if err != nil { + log.Error("GetBranchCommitID: %v", err) + // Don't return an error page, as it can be rechecked the next time the user opens the page. + return + } + + + dbBranch, err := git_model.GetBranch(ctx, ctx.Repo.Repository.ID, ctx.Repo.BranchName) + if err != nil { + log.Error("GetBranch: %v", err) + // Don't return an error page, as it can be rechecked the next time the user opens the page. + return + } + + if commit.ID.String() != dbBranch.CommitID && + time.Since(commit.) + { + + } +} + + // RenderUserCards render a page show users according the input template func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOptions) ([]*user_model.User, error), tpl base.TplName) { page := ctx.FormInt("page") @@ -1147,3 +1175,5 @@ func Forks(ctx *context.Context) { ctx.HTML(http.StatusOK, tplForks) } + + From ae44e3f06844f5b033152b72b1ee8f64026e2e5d Mon Sep 17 00:00:00 2001 From: Jason Song Date: Thu, 29 Feb 2024 15:53:55 +0800 Subject: [PATCH 02/12] Revert "feat: check branch commit" This reverts commit baf7515fcdfd2006f4c43fadb6560ca85f203816. --- routers/web/repo/view.go | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index dafd1710d27e7..e89739e2fb6d1 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -768,7 +768,6 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) { } } - // Home render repository home page func Home(ctx *context.Context) { if setting.Other.EnableFeed { @@ -1007,8 +1006,6 @@ func renderHomeCode(ctx *context.Context) { return } - checkOutdatedBranch(ctx) - checkCitationFile(ctx, entry) if ctx.Written() { return @@ -1075,31 +1072,6 @@ func renderHomeCode(ctx *context.Context) { ctx.HTML(http.StatusOK, tplRepoHome) } -func checkOutdatedBranch(ctx *context.Context) { - // get the head commit of the branch since ctx.Repo.CommitID is not always the head commit of `ctx.Repo.BranchName` - commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.BranchName) - if err != nil { - log.Error("GetBranchCommitID: %v", err) - // Don't return an error page, as it can be rechecked the next time the user opens the page. - return - } - - - dbBranch, err := git_model.GetBranch(ctx, ctx.Repo.Repository.ID, ctx.Repo.BranchName) - if err != nil { - log.Error("GetBranch: %v", err) - // Don't return an error page, as it can be rechecked the next time the user opens the page. - return - } - - if commit.ID.String() != dbBranch.CommitID && - time.Since(commit.) - { - - } -} - - // RenderUserCards render a page show users according the input template func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOptions) ([]*user_model.User, error), tpl base.TplName) { page := ctx.FormInt("page") @@ -1175,5 +1147,3 @@ func Forks(ctx *context.Context) { ctx.HTML(http.StatusOK, tplForks) } - - From 4a8bbde1436ea8ed491591b9b9e5535bfccb77f2 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Thu, 29 Feb 2024 17:43:09 +0800 Subject: [PATCH 03/12] feat: use RepoIndexerTypeHook --- models/repo/repo_indexer.go | 6 ++++++ options/locale/locale_en-US.ini | 1 + routers/private/default_branch.go | 15 +++++++++++++++ routers/private/hook_post_receive.go | 27 +++++++++++++++++++++++++++ routers/web/repo/view.go | 26 ++++++++++++++++++++++++++ services/repository/branch.go | 10 ++++++++++ 6 files changed, 85 insertions(+) diff --git a/models/repo/repo_indexer.go b/models/repo/repo_indexer.go index 6e19d8f937f18..ad2b1d2a30cab 100644 --- a/models/repo/repo_indexer.go +++ b/models/repo/repo_indexer.go @@ -20,6 +20,8 @@ const ( RepoIndexerTypeCode RepoIndexerType = iota // 0 // RepoIndexerTypeStats repository stats indexer RepoIndexerTypeStats // 1 + // RepoIndexerTypeHook doesn't index anything, it's a health check for git hooks. + RepoIndexerTypeHook // 2 ) // RepoIndexerStatus status of a repo's entry in the repo indexer @@ -73,6 +75,8 @@ func GetIndexerStatus(ctx context.Context, repo *Repository, indexerType RepoInd if repo.StatsIndexerStatus != nil { return repo.StatsIndexerStatus, nil } + default: + // Do nothing since other types do not need to be patched to `repo`. } status := &RepoIndexerStatus{RepoID: repo.ID} if has, err := db.GetEngine(ctx).Where("`indexer_type` = ?", indexerType).Get(status); err != nil { @@ -86,6 +90,8 @@ func GetIndexerStatus(ctx context.Context, repo *Repository, indexerType RepoInd repo.CodeIndexerStatus = status case RepoIndexerTypeStats: repo.StatsIndexerStatus = status + default: + // Do nothing since other types do not need to be patched to `repo`. } return status, nil } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 6d4e109e1dc66..d15a68787d03e 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2591,6 +2591,7 @@ find_file.no_matching = No matching file found error.csv.too_large = Can't render this file because it is too large. error.csv.unexpected = Can't render this file because it contains an unexpected character in line %d and column %d. error.csv.invalid_field_count = Can't render this file because it has a wrong number of fields in line %d. +error.broken_git_hook = Git hooks of this repository seem to be broken. Please follow the documentation to fix them, then push/merge to the default branch to refresh the status. [graphs] component_loading = Loading %s... diff --git a/routers/private/default_branch.go b/routers/private/default_branch.go index 2e323129ef028..6b41c3bd4795a 100644 --- a/routers/private/default_branch.go +++ b/routers/private/default_branch.go @@ -35,5 +35,20 @@ func SetDefaultBranch(ctx *gitea_context.PrivateContext) { }) return } + + commitID, err := ctx.Repo.GitRepo.GetBranchCommitID(ctx.Repo.Repository.DefaultBranch) + if err != nil { + ctx.JSON(http.StatusInternalServerError, private.Response{ + Err: fmt.Sprintf("Unable to get commit ID for new default branch on repository: %s/%s Error: %v", ownerName, repoName, err), + }) + return + } + if err := repo_model.UpdateIndexerStatus(ctx, ctx.Repo.Repository, repo_model.RepoIndexerTypeHook, commitID); err != nil { + ctx.JSON(http.StatusInternalServerError, private.Response{ + Err: fmt.Sprintf("Unable to update hook status for new default branch on repository: %s/%s Error: %v", ownerName, repoName, err), + }) + return + } + ctx.PlainText(http.StatusOK, "success") } diff --git a/routers/private/hook_post_receive.go b/routers/private/hook_post_receive.go index 4eafe3923dfb8..56a508c57a8f0 100644 --- a/routers/private/hook_post_receive.go +++ b/routers/private/hook_post_receive.go @@ -89,6 +89,33 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { } } + // Update the hook status + hookStatus := + for i, update := range updates { + if !update.RefFullName.IsBranch() { + continue + } + if repo == nil { + repo = loadRepository(ctx, ownerName, repoName) + if ctx.Written() { + return + } + } + if repo.IsEmpty { + + } + if ref.BranchName() != repo.DefaultBranch { + continue + } + if err := repo_model.UpdateIndexerStatus(ctx, repo, repo_model.RepoIndexerTypeHook, opts.NewCommitIDs[i]); err != nil { + log.Error("Failed to update hook status: %s/%s Error: %v", ownerName, repoName, err) + ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{ + Err: fmt.Sprintf("Failed to update hook status: %s/%s Error: %v", ownerName, repoName, err), + }) + return + } + } + // Handle Push Options if len(opts.GitPushOptions) > 0 { // load the repository diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index e89739e2fb6d1..f190db976b52e 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -940,6 +940,30 @@ func prepareOpenWithEditorApps(ctx *context.Context) { ctx.Data["OpenWithEditorApps"] = tmplApps } +func checkGitHookStatus(ctx *context.Context) { + if ctx.Repo.Repository.IsEmpty { + return + } + status, err := repo_model.GetIndexerStatus(ctx, ctx.Repo.Repository, repo_model.RepoIndexerTypeHook) + if err != nil { + log.Error("GetIndexerStatus: %v", err) + // Don't return an error page, as it can be rechecked the next time the user opens the page. + return + } + + // get the head commit of the branch since ctx.Repo.CommitID is not always the head commit of the default branch + commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch) + if err != nil { + log.Error("GetBranchCommitID: %v", err) + // Don't return an error page, as it can be rechecked the next time the user opens the page. + return + } + + if status.CommitSha != commit.ID.String() { + ctx.Flash.Warning(ctx.Tr("repo.error.broken_git_hook"), true) + } +} + func renderHomeCode(ctx *context.Context) { ctx.Data["PageIsViewCode"] = true ctx.Data["RepositoryUploadEnabled"] = setting.Repository.Upload.Enabled @@ -1016,6 +1040,8 @@ func renderHomeCode(ctx *context.Context) { return } + checkGitHookStatus(ctx) + if entry.IsDir() { renderDirectory(ctx) } else { diff --git a/services/repository/branch.go b/services/repository/branch.go index ec41173da8c4f..fe560f677945f 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -473,6 +473,11 @@ func SetRepoDefaultBranch(ctx context.Context, repo *repo_model.Repository, gitR } } + commitID, err := gitRepo.GetBranchCommitID(newBranchName) + if err != nil { + return err + } + oldDefaultBranchName := repo.DefaultBranch repo.DefaultBranch = newBranchName if err := db.WithTx(ctx, func(ctx context.Context) error { @@ -480,6 +485,10 @@ func SetRepoDefaultBranch(ctx context.Context, repo *repo_model.Repository, gitR return err } + if err := repo_model.UpdateIndexerStatus(ctx, repo, repo_model.RepoIndexerTypeHook, commitID); err != nil { + return err + } + if err := actions_model.DeleteScheduleTaskByRepo(ctx, repo.ID); err != nil { log.Error("DeleteCronTaskByRepo: %v", err) } @@ -499,6 +508,7 @@ func SetRepoDefaultBranch(ctx context.Context, repo *repo_model.Repository, gitR return err } } + return nil }); err != nil { return err From 0a028973a9e11aae87b832d0cf53d1ba31f403c8 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Thu, 29 Feb 2024 18:28:25 +0800 Subject: [PATCH 04/12] Revert "feat: use RepoIndexerTypeHook" This reverts commit 4a8bbde1436ea8ed491591b9b9e5535bfccb77f2. --- models/repo/repo_indexer.go | 6 ------ options/locale/locale_en-US.ini | 1 - routers/private/default_branch.go | 15 --------------- routers/private/hook_post_receive.go | 27 --------------------------- routers/web/repo/view.go | 26 -------------------------- services/repository/branch.go | 10 ---------- 6 files changed, 85 deletions(-) diff --git a/models/repo/repo_indexer.go b/models/repo/repo_indexer.go index ad2b1d2a30cab..6e19d8f937f18 100644 --- a/models/repo/repo_indexer.go +++ b/models/repo/repo_indexer.go @@ -20,8 +20,6 @@ const ( RepoIndexerTypeCode RepoIndexerType = iota // 0 // RepoIndexerTypeStats repository stats indexer RepoIndexerTypeStats // 1 - // RepoIndexerTypeHook doesn't index anything, it's a health check for git hooks. - RepoIndexerTypeHook // 2 ) // RepoIndexerStatus status of a repo's entry in the repo indexer @@ -75,8 +73,6 @@ func GetIndexerStatus(ctx context.Context, repo *Repository, indexerType RepoInd if repo.StatsIndexerStatus != nil { return repo.StatsIndexerStatus, nil } - default: - // Do nothing since other types do not need to be patched to `repo`. } status := &RepoIndexerStatus{RepoID: repo.ID} if has, err := db.GetEngine(ctx).Where("`indexer_type` = ?", indexerType).Get(status); err != nil { @@ -90,8 +86,6 @@ func GetIndexerStatus(ctx context.Context, repo *Repository, indexerType RepoInd repo.CodeIndexerStatus = status case RepoIndexerTypeStats: repo.StatsIndexerStatus = status - default: - // Do nothing since other types do not need to be patched to `repo`. } return status, nil } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index d15a68787d03e..6d4e109e1dc66 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2591,7 +2591,6 @@ find_file.no_matching = No matching file found error.csv.too_large = Can't render this file because it is too large. error.csv.unexpected = Can't render this file because it contains an unexpected character in line %d and column %d. error.csv.invalid_field_count = Can't render this file because it has a wrong number of fields in line %d. -error.broken_git_hook = Git hooks of this repository seem to be broken. Please follow the documentation to fix them, then push/merge to the default branch to refresh the status. [graphs] component_loading = Loading %s... diff --git a/routers/private/default_branch.go b/routers/private/default_branch.go index 6b41c3bd4795a..2e323129ef028 100644 --- a/routers/private/default_branch.go +++ b/routers/private/default_branch.go @@ -35,20 +35,5 @@ func SetDefaultBranch(ctx *gitea_context.PrivateContext) { }) return } - - commitID, err := ctx.Repo.GitRepo.GetBranchCommitID(ctx.Repo.Repository.DefaultBranch) - if err != nil { - ctx.JSON(http.StatusInternalServerError, private.Response{ - Err: fmt.Sprintf("Unable to get commit ID for new default branch on repository: %s/%s Error: %v", ownerName, repoName, err), - }) - return - } - if err := repo_model.UpdateIndexerStatus(ctx, ctx.Repo.Repository, repo_model.RepoIndexerTypeHook, commitID); err != nil { - ctx.JSON(http.StatusInternalServerError, private.Response{ - Err: fmt.Sprintf("Unable to update hook status for new default branch on repository: %s/%s Error: %v", ownerName, repoName, err), - }) - return - } - ctx.PlainText(http.StatusOK, "success") } diff --git a/routers/private/hook_post_receive.go b/routers/private/hook_post_receive.go index 56a508c57a8f0..4eafe3923dfb8 100644 --- a/routers/private/hook_post_receive.go +++ b/routers/private/hook_post_receive.go @@ -89,33 +89,6 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { } } - // Update the hook status - hookStatus := - for i, update := range updates { - if !update.RefFullName.IsBranch() { - continue - } - if repo == nil { - repo = loadRepository(ctx, ownerName, repoName) - if ctx.Written() { - return - } - } - if repo.IsEmpty { - - } - if ref.BranchName() != repo.DefaultBranch { - continue - } - if err := repo_model.UpdateIndexerStatus(ctx, repo, repo_model.RepoIndexerTypeHook, opts.NewCommitIDs[i]); err != nil { - log.Error("Failed to update hook status: %s/%s Error: %v", ownerName, repoName, err) - ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{ - Err: fmt.Sprintf("Failed to update hook status: %s/%s Error: %v", ownerName, repoName, err), - }) - return - } - } - // Handle Push Options if len(opts.GitPushOptions) > 0 { // load the repository diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index f190db976b52e..e89739e2fb6d1 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -940,30 +940,6 @@ func prepareOpenWithEditorApps(ctx *context.Context) { ctx.Data["OpenWithEditorApps"] = tmplApps } -func checkGitHookStatus(ctx *context.Context) { - if ctx.Repo.Repository.IsEmpty { - return - } - status, err := repo_model.GetIndexerStatus(ctx, ctx.Repo.Repository, repo_model.RepoIndexerTypeHook) - if err != nil { - log.Error("GetIndexerStatus: %v", err) - // Don't return an error page, as it can be rechecked the next time the user opens the page. - return - } - - // get the head commit of the branch since ctx.Repo.CommitID is not always the head commit of the default branch - commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch) - if err != nil { - log.Error("GetBranchCommitID: %v", err) - // Don't return an error page, as it can be rechecked the next time the user opens the page. - return - } - - if status.CommitSha != commit.ID.String() { - ctx.Flash.Warning(ctx.Tr("repo.error.broken_git_hook"), true) - } -} - func renderHomeCode(ctx *context.Context) { ctx.Data["PageIsViewCode"] = true ctx.Data["RepositoryUploadEnabled"] = setting.Repository.Upload.Enabled @@ -1040,8 +1016,6 @@ func renderHomeCode(ctx *context.Context) { return } - checkGitHookStatus(ctx) - if entry.IsDir() { renderDirectory(ctx) } else { diff --git a/services/repository/branch.go b/services/repository/branch.go index fe560f677945f..ec41173da8c4f 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -473,11 +473,6 @@ func SetRepoDefaultBranch(ctx context.Context, repo *repo_model.Repository, gitR } } - commitID, err := gitRepo.GetBranchCommitID(newBranchName) - if err != nil { - return err - } - oldDefaultBranchName := repo.DefaultBranch repo.DefaultBranch = newBranchName if err := db.WithTx(ctx, func(ctx context.Context) error { @@ -485,10 +480,6 @@ func SetRepoDefaultBranch(ctx context.Context, repo *repo_model.Repository, gitR return err } - if err := repo_model.UpdateIndexerStatus(ctx, repo, repo_model.RepoIndexerTypeHook, commitID); err != nil { - return err - } - if err := actions_model.DeleteScheduleTaskByRepo(ctx, repo.ID); err != nil { log.Error("DeleteCronTaskByRepo: %v", err) } @@ -508,7 +499,6 @@ func SetRepoDefaultBranch(ctx context.Context, repo *repo_model.Repository, gitR return err } } - return nil }); err != nil { return err From 5068c8a7eebe35957ddecdeeaf0138faba979055 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Thu, 29 Feb 2024 15:53:09 +0800 Subject: [PATCH 05/12] feat: check branch commit --- routers/web/repo/view.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index e89739e2fb6d1..dafd1710d27e7 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -768,6 +768,7 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) { } } + // Home render repository home page func Home(ctx *context.Context) { if setting.Other.EnableFeed { @@ -1006,6 +1007,8 @@ func renderHomeCode(ctx *context.Context) { return } + checkOutdatedBranch(ctx) + checkCitationFile(ctx, entry) if ctx.Written() { return @@ -1072,6 +1075,31 @@ func renderHomeCode(ctx *context.Context) { ctx.HTML(http.StatusOK, tplRepoHome) } +func checkOutdatedBranch(ctx *context.Context) { + // get the head commit of the branch since ctx.Repo.CommitID is not always the head commit of `ctx.Repo.BranchName` + commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.BranchName) + if err != nil { + log.Error("GetBranchCommitID: %v", err) + // Don't return an error page, as it can be rechecked the next time the user opens the page. + return + } + + + dbBranch, err := git_model.GetBranch(ctx, ctx.Repo.Repository.ID, ctx.Repo.BranchName) + if err != nil { + log.Error("GetBranch: %v", err) + // Don't return an error page, as it can be rechecked the next time the user opens the page. + return + } + + if commit.ID.String() != dbBranch.CommitID && + time.Since(commit.) + { + + } +} + + // RenderUserCards render a page show users according the input template func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOptions) ([]*user_model.User, error), tpl base.TplName) { page := ctx.FormInt("page") @@ -1147,3 +1175,5 @@ func Forks(ctx *context.Context) { ctx.HTML(http.StatusOK, tplForks) } + + From 0f04a6904650ce3c8388e7f98f3ff59ec5b3b9d6 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Thu, 29 Feb 2024 18:32:30 +0800 Subject: [PATCH 06/12] fix: show warning --- options/locale/locale_en-US.ini | 1 + routers/web/repo/view.go | 11 ++--------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 6d4e109e1dc66..d15a68787d03e 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2591,6 +2591,7 @@ find_file.no_matching = No matching file found error.csv.too_large = Can't render this file because it is too large. error.csv.unexpected = Can't render this file because it contains an unexpected character in line %d and column %d. error.csv.invalid_field_count = Can't render this file because it has a wrong number of fields in line %d. +error.broken_git_hook = Git hooks of this repository seem to be broken. Please follow the documentation to fix them, then push/merge to the default branch to refresh the status. [graphs] component_loading = Loading %s... diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index dafd1710d27e7..7987fff037fb2 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -768,7 +768,6 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) { } } - // Home render repository home page func Home(ctx *context.Context) { if setting.Other.EnableFeed { @@ -1084,7 +1083,6 @@ func checkOutdatedBranch(ctx *context.Context) { return } - dbBranch, err := git_model.GetBranch(ctx, ctx.Repo.Repository.ID, ctx.Repo.BranchName) if err != nil { log.Error("GetBranch: %v", err) @@ -1092,14 +1090,11 @@ func checkOutdatedBranch(ctx *context.Context) { return } - if commit.ID.String() != dbBranch.CommitID && - time.Since(commit.) - { - + if dbBranch.CommitID != commit.ID.String() { + ctx.Flash.Warning(ctx.Tr("repo.error.broken_git_hook"), true) } } - // RenderUserCards render a page show users according the input template func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOptions) ([]*user_model.User, error), tpl base.TplName) { page := ctx.FormInt("page") @@ -1175,5 +1170,3 @@ func Forks(ctx *context.Context) { ctx.HTML(http.StatusOK, tplForks) } - - From 0a1eb842f01b4fa7bdf72bfc8c08c83a7ed65051 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Thu, 29 Feb 2024 18:50:50 +0800 Subject: [PATCH 07/12] chore: udpate tip --- options/locale/locale_en-US.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index d15a68787d03e..43988c2630d32 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2591,7 +2591,7 @@ find_file.no_matching = No matching file found error.csv.too_large = Can't render this file because it is too large. error.csv.unexpected = Can't render this file because it contains an unexpected character in line %d and column %d. error.csv.invalid_field_count = Can't render this file because it has a wrong number of fields in line %d. -error.broken_git_hook = Git hooks of this repository seem to be broken. Please follow the documentation to fix them, then push/merge to the default branch to refresh the status. +error.broken_git_hook = Git hooks of this repository seem to be broken. Please follow the documentation to fix them, then push some commits to refresh the status. [graphs] component_loading = Loading %s... From e6652f4b28482faee25db2a063dfb77f09a38fda Mon Sep 17 00:00:00 2001 From: Jason Song Date: Fri, 1 Mar 2024 11:18:46 +0800 Subject: [PATCH 08/12] fix: owner or admin only --- routers/web/repo/view.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 7987fff037fb2..05405ccbbbdd9 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -1075,6 +1075,10 @@ func renderHomeCode(ctx *context.Context) { } func checkOutdatedBranch(ctx *context.Context) { + if !(ctx.Repo.IsAdmin() || ctx.Repo.IsOwner()) { + return + } + // get the head commit of the branch since ctx.Repo.CommitID is not always the head commit of `ctx.Repo.BranchName` commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.BranchName) if err != nil { From a92d3b847152db35053b4d8723f326cb24904669 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Fri, 1 Mar 2024 11:26:19 +0800 Subject: [PATCH 09/12] chore: update doc link --- options/locale/locale_en-US.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 43988c2630d32..4785183a60693 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2591,7 +2591,7 @@ find_file.no_matching = No matching file found error.csv.too_large = Can't render this file because it is too large. error.csv.unexpected = Can't render this file because it contains an unexpected character in line %d and column %d. error.csv.invalid_field_count = Can't render this file because it has a wrong number of fields in line %d. -error.broken_git_hook = Git hooks of this repository seem to be broken. Please follow the documentation to fix them, then push some commits to refresh the status. +error.broken_git_hook = Git hooks of this repository seem to be broken. Please follow the documentation to fix them, then push some commits to refresh the status. [graphs] component_loading = Loading %s... From ac3f6d0e7ec54d53461b8e9006d8cafd9e0fbc9c Mon Sep 17 00:00:00 2001 From: Jason Song Date: Fri, 1 Mar 2024 11:44:34 +0800 Subject: [PATCH 10/12] fix: typo --- options/locale/locale_en-US.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 4785183a60693..523d27d061ff9 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2591,7 +2591,7 @@ find_file.no_matching = No matching file found error.csv.too_large = Can't render this file because it is too large. error.csv.unexpected = Can't render this file because it contains an unexpected character in line %d and column %d. error.csv.invalid_field_count = Can't render this file because it has a wrong number of fields in line %d. -error.broken_git_hook = Git hooks of this repository seem to be broken. Please follow the documentation to fix them, then push some commits to refresh the status. +error.broken_git_hook = Git hooks of this repository seem to be broken. Please follow the documentation to fix them, then push some commits to refresh the status. [graphs] component_loading = Loading %s... From 452afc20bd6db791c3d7cfb84dae53431b290069 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Fri, 1 Mar 2024 12:04:27 +0800 Subject: [PATCH 11/12] fix: move link to code --- options/locale/locale_en-US.ini | 2 +- routers/web/repo/view.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 523d27d061ff9..bb3691e41742e 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2591,7 +2591,7 @@ find_file.no_matching = No matching file found error.csv.too_large = Can't render this file because it is too large. error.csv.unexpected = Can't render this file because it contains an unexpected character in line %d and column %d. error.csv.invalid_field_count = Can't render this file because it has a wrong number of fields in line %d. -error.broken_git_hook = Git hooks of this repository seem to be broken. Please follow the documentation to fix them, then push some commits to refresh the status. +error.broken_git_hook = Git hooks of this repository seem to be broken. Please follow the documentation to fix them, then push some commits to refresh the status. [graphs] component_loading = Loading %s... diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 05405ccbbbdd9..bbc8fedd359a2 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -1095,7 +1095,10 @@ func checkOutdatedBranch(ctx *context.Context) { } if dbBranch.CommitID != commit.ID.String() { - ctx.Flash.Warning(ctx.Tr("repo.error.broken_git_hook"), true) + ctx.Flash.Warning(ctx.Tr( + "repo.error.broken_git_hook", + "https://docs.gitea.com/help/faq#push-hook--webhook--actions-arent-running", + ), true) } } From 797302c428477c9b97008f499b7cffa759ecc32e Mon Sep 17 00:00:00 2001 From: Jason Song Date: Fri, 1 Mar 2024 13:45:18 +0800 Subject: [PATCH 12/12] Update routers/web/repo/view.go Co-authored-by: wxiaoguang --- routers/web/repo/view.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index bbc8fedd359a2..185e7d0d3e6d4 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -1095,10 +1095,7 @@ func checkOutdatedBranch(ctx *context.Context) { } if dbBranch.CommitID != commit.ID.String() { - ctx.Flash.Warning(ctx.Tr( - "repo.error.broken_git_hook", - "https://docs.gitea.com/help/faq#push-hook--webhook--actions-arent-running", - ), true) + ctx.Flash.Warning(ctx.Tr("repo.error.broken_git_hook", "https://docs.gitea.com/help/faq#push-hook--webhook--actions-arent-running"), true) } }