Skip to content

Commit 4fc886f

Browse files
lunnyjeffliu27
authored andcommitted
Move PushUpdate dependency from models to repofiles (go-gitea#6763)
* remove push_update * move models.PushUpdate to repofiles.PushUpdate
1 parent 132995e commit 4fc886f

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

modules/repofiles/update.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"code.gitea.io/gitea/modules/git"
1919
"code.gitea.io/gitea/modules/lfs"
2020
"code.gitea.io/gitea/modules/log"
21-
"code.gitea.io/gitea/modules/notification"
2221
"code.gitea.io/gitea/modules/setting"
2322
"code.gitea.io/gitea/modules/structs"
2423
)
@@ -424,11 +423,16 @@ func CreateOrUpdateRepoFile(repo *models.Repository, doer *models.User, opts *Up
424423
return file, nil
425424
}
426425

427-
// PushUpdate push updates
428-
func PushUpdate(repo *models.Repository, branch string, opt models.PushUpdateOptions) error {
429-
if err := models.PushUpdate(branch, opt); err != nil {
430-
return err
426+
// PushUpdate must be called for any push actions in order to
427+
// generates necessary push action history feeds and other operations
428+
func PushUpdate(repo *models.Repository, branch string, opts models.PushUpdateOptions) error {
429+
err := models.PushUpdate(branch, opts)
430+
if err != nil {
431+
return fmt.Errorf("PushUpdate: %v", err)
432+
}
433+
434+
if opts.RefFullName == git.BranchPrefix+repo.DefaultBranch {
435+
models.UpdateRepoIndexer(repo)
431436
}
432-
notification.NotifyPushCommits(repo, branch, opt)
433437
return nil
434438
}

routers/private/hook.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"code.gitea.io/gitea/modules/git"
1616
"code.gitea.io/gitea/modules/log"
1717
"code.gitea.io/gitea/modules/private"
18+
"code.gitea.io/gitea/modules/repofiles"
1819
"code.gitea.io/gitea/modules/util"
1920

2021
macaron "gopkg.in/macaron.v1"
@@ -117,7 +118,15 @@ func HookPostReceive(ctx *macaron.Context) {
117118
// or other less-standard refs spaces are ignored since there
118119
// may be a very large number of them).
119120
if strings.HasPrefix(refFullName, git.BranchPrefix) || strings.HasPrefix(refFullName, git.TagPrefix) {
120-
if err := models.PushUpdate(branch, models.PushUpdateOptions{
121+
repo, err := models.GetRepositoryByOwnerAndName(ownerName, repoName)
122+
if err != nil {
123+
log.Error("Failed to get repository: %s/%s Error: %v", ownerName, repoName, err)
124+
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
125+
"err": fmt.Sprintf("Failed to get repository: %s/%s Error: %v", ownerName, repoName, err),
126+
})
127+
return
128+
}
129+
if err := repofiles.PushUpdate(repo, branch, models.PushUpdateOptions{
121130
RefFullName: refFullName,
122131
OldCommitID: oldCommitID,
123132
NewCommitID: newCommitID,

routers/private/push_update.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ func PushUpdate(ctx *macaron.Context) {
2626
return
2727
}
2828

29+
branch := strings.TrimPrefix(opt.RefFullName, git.BranchPrefix)
30+
if len(branch) == 0 || opt.PusherID <= 0 {
31+
ctx.Error(404)
32+
log.Trace("PushUpdate: branch or secret is empty, or pusher ID is not valid")
33+
return
34+
}
35+
2936
repo, err := models.GetRepositoryByOwnerAndName(opt.RepoUserName, opt.RepoName)
3037
if err != nil {
3138
ctx.JSON(500, map[string]interface{}{
@@ -34,13 +41,6 @@ func PushUpdate(ctx *macaron.Context) {
3441
return
3542
}
3643

37-
branch := strings.TrimPrefix(opt.RefFullName, git.BranchPrefix)
38-
if len(branch) == 0 || opt.PusherID <= 0 {
39-
ctx.Error(404)
40-
log.Trace("PushUpdate: branch or secret is empty, or pusher ID is not valid")
41-
return
42-
}
43-
4444
err = repofiles.PushUpdate(repo, branch, opt)
4545
if err != nil {
4646
if models.IsErrUserNotExist(err) {

0 commit comments

Comments
 (0)