diff --git a/modules/repofiles/update.go b/modules/repofiles/update.go index a9dadf816504..569c89ac51d5 100644 --- a/modules/repofiles/update.go +++ b/modules/repofiles/update.go @@ -18,7 +18,6 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/structs" ) @@ -424,11 +423,16 @@ func CreateOrUpdateRepoFile(repo *models.Repository, doer *models.User, opts *Up return file, nil } -// PushUpdate push updates -func PushUpdate(repo *models.Repository, branch string, opt models.PushUpdateOptions) error { - if err := models.PushUpdate(branch, opt); err != nil { - return err +// PushUpdate must be called for any push actions in order to +// generates necessary push action history feeds and other operations +func PushUpdate(repo *models.Repository, branch string, opts models.PushUpdateOptions) error { + err := models.PushUpdate(branch, opts) + if err != nil { + return fmt.Errorf("PushUpdate: %v", err) + } + + if opts.RefFullName == git.BranchPrefix+repo.DefaultBranch { + models.UpdateRepoIndexer(repo) } - notification.NotifyPushCommits(repo, branch, opt) return nil } diff --git a/routers/private/hook.go b/routers/private/hook.go index 700c8bf33279..a5985f161e71 100644 --- a/routers/private/hook.go +++ b/routers/private/hook.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/private" + "code.gitea.io/gitea/modules/repofiles" "code.gitea.io/gitea/modules/util" macaron "gopkg.in/macaron.v1" @@ -117,7 +118,15 @@ func HookPostReceive(ctx *macaron.Context) { // or other less-standard refs spaces are ignored since there // may be a very large number of them). if strings.HasPrefix(refFullName, git.BranchPrefix) || strings.HasPrefix(refFullName, git.TagPrefix) { - if err := models.PushUpdate(branch, models.PushUpdateOptions{ + repo, err := models.GetRepositoryByOwnerAndName(ownerName, repoName) + if err != nil { + log.Error("Failed to get repository: %s/%s Error: %v", ownerName, repoName, err) + ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ + "err": fmt.Sprintf("Failed to get repository: %s/%s Error: %v", ownerName, repoName, err), + }) + return + } + if err := repofiles.PushUpdate(repo, branch, models.PushUpdateOptions{ RefFullName: refFullName, OldCommitID: oldCommitID, NewCommitID: newCommitID, diff --git a/routers/private/push_update.go b/routers/private/push_update.go index d1247f099033..733490ce1cd7 100644 --- a/routers/private/push_update.go +++ b/routers/private/push_update.go @@ -26,6 +26,13 @@ func PushUpdate(ctx *macaron.Context) { return } + branch := strings.TrimPrefix(opt.RefFullName, git.BranchPrefix) + if len(branch) == 0 || opt.PusherID <= 0 { + ctx.Error(404) + log.Trace("PushUpdate: branch or secret is empty, or pusher ID is not valid") + return + } + repo, err := models.GetRepositoryByOwnerAndName(opt.RepoUserName, opt.RepoName) if err != nil { ctx.JSON(500, map[string]interface{}{ @@ -34,13 +41,6 @@ func PushUpdate(ctx *macaron.Context) { return } - branch := strings.TrimPrefix(opt.RefFullName, git.BranchPrefix) - if len(branch) == 0 || opt.PusherID <= 0 { - ctx.Error(404) - log.Trace("PushUpdate: branch or secret is empty, or pusher ID is not valid") - return - } - err = repofiles.PushUpdate(repo, branch, opt) if err != nil { if models.IsErrUserNotExist(err) {