diff options
author | Ethan Koenig <ethantkoenig@gmail.com> | 2017-08-17 00:22:08 -0700 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-08-17 15:22:08 +0800 |
commit | 7907786040100593831bce1d583bb5f6e34c1a16 (patch) | |
tree | 9f1615d398e2e54a9203e9c1c6adbc7d80c80e48 /models | |
parent | 951fb572a769acc965ec74b7152334e55b26de80 (diff) | |
download | gitea-7907786040100593831bce1d583bb5f6e34c1a16.tar.gz gitea-7907786040100593831bce1d583bb5f6e34c1a16.zip |
Trigger sync webhooks on UI commit (#2302)
* Trigger sync webhooks on UI commit
* Also fix UI upload/delete
Diffstat (limited to 'models')
-rw-r--r-- | models/repo_editor.go | 107 | ||||
-rw-r--r-- | models/update.go | 19 |
2 files changed, 79 insertions, 47 deletions
diff --git a/models/repo_editor.go b/models/repo_editor.go index 720e071625..692fe8c51b 100644 --- a/models/repo_editor.go +++ b/models/repo_editor.go @@ -155,27 +155,29 @@ func (repo *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) ( } // Simulate push event. - pushCommits := &PushCommits{ - Len: 1, - Commits: []*PushCommit{CommitToPushCommit(commit)}, - } oldCommitID := opts.LastCommitID if opts.NewBranch != opts.OldBranch { oldCommitID = git.EmptySHA } - if err := CommitRepoAction(CommitRepoActionOptions{ - PusherName: doer.Name, - RepoOwnerID: repo.MustOwner().ID, - RepoName: repo.Name, - RefFullName: git.BranchPrefix + opts.NewBranch, - OldCommitID: oldCommitID, - NewCommitID: commit.ID.String(), - Commits: pushCommits, - }); err != nil { - log.Error(4, "CommitRepoAction: %v", err) - return nil - } + if err = repo.GetOwner(); err != nil { + return fmt.Errorf("GetOwner: %v", err) + } + err = PushUpdate( + opts.NewBranch, + PushUpdateOptions{ + PusherID: doer.ID, + PusherName: doer.Name, + RepoUserName: repo.Owner.Name, + RepoName: repo.Name, + RefFullName: git.BranchPrefix + opts.NewBranch, + OldCommitID: oldCommitID, + NewCommitID: commit.ID.String(), + }, + ) + if err != nil { + return fmt.Errorf("PushUpdate: %v", err) + } return nil } @@ -295,23 +297,29 @@ func (repo *Repository) DeleteRepoFile(doer *User, opts DeleteRepoFileOptions) ( } // Simulate push event. - pushCommits := &PushCommits{ - Len: 1, - Commits: []*PushCommit{CommitToPushCommit(commit)}, - } - if err := CommitRepoAction(CommitRepoActionOptions{ - PusherName: doer.Name, - RepoOwnerID: repo.MustOwner().ID, - RepoName: repo.Name, - RefFullName: git.BranchPrefix + opts.NewBranch, - OldCommitID: opts.LastCommitID, - NewCommitID: commit.ID.String(), - Commits: pushCommits, - }); err != nil { - log.Error(4, "CommitRepoAction: %v", err) - return nil + oldCommitID := opts.LastCommitID + if opts.NewBranch != opts.OldBranch { + oldCommitID = git.EmptySHA } + if err = repo.GetOwner(); err != nil { + return fmt.Errorf("GetOwner: %v", err) + } + err = PushUpdate( + opts.NewBranch, + PushUpdateOptions{ + PusherID: doer.ID, + PusherName: doer.Name, + RepoUserName: repo.Owner.Name, + RepoName: repo.Name, + RefFullName: git.BranchPrefix + opts.NewBranch, + OldCommitID: oldCommitID, + NewCommitID: commit.ID.String(), + }, + ) + if err != nil { + return fmt.Errorf("PushUpdate: %v", err) + } return nil } @@ -534,21 +542,28 @@ func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions) } // Simulate push event. - pushCommits := &PushCommits{ - Len: 1, - Commits: []*PushCommit{CommitToPushCommit(commit)}, - } - if err := CommitRepoAction(CommitRepoActionOptions{ - PusherName: doer.Name, - RepoOwnerID: repo.MustOwner().ID, - RepoName: repo.Name, - RefFullName: git.BranchPrefix + opts.NewBranch, - OldCommitID: opts.LastCommitID, - NewCommitID: commit.ID.String(), - Commits: pushCommits, - }); err != nil { - log.Error(4, "CommitRepoAction: %v", err) - return nil + oldCommitID := opts.LastCommitID + if opts.NewBranch != opts.OldBranch { + oldCommitID = git.EmptySHA + } + + if err = repo.GetOwner(); err != nil { + return fmt.Errorf("GetOwner: %v", err) + } + err = PushUpdate( + opts.NewBranch, + PushUpdateOptions{ + PusherID: doer.ID, + PusherName: doer.Name, + RepoUserName: repo.Owner.Name, + RepoName: repo.Name, + RefFullName: git.BranchPrefix + opts.NewBranch, + OldCommitID: oldCommitID, + NewCommitID: commit.ID.String(), + }, + ) + if err != nil { + return fmt.Errorf("PushUpdate: %v", err) } return DeleteUploads(uploads...) diff --git a/models/update.go b/models/update.go index cd22189f6a..e6cbba64a5 100644 --- a/models/update.go +++ b/models/update.go @@ -64,7 +64,24 @@ type PushUpdateOptions struct { // PushUpdate must be called for any push actions in order to // generates necessary push action history feeds. -func PushUpdate(opts PushUpdateOptions) (repo *Repository, err error) { +func PushUpdate(branch string, opt PushUpdateOptions) error { + repo, err := pushUpdate(opt) + if err != nil { + return err + } + + pusher, err := GetUserByID(opt.PusherID) + if err != nil { + return err + } + + log.Trace("TriggerTask '%s/%s' by %s", repo.Name, branch, pusher.Name) + + go AddTestPullRequestTask(pusher, repo.ID, branch, true) + return nil +} + +func pushUpdate(opts PushUpdateOptions) (repo *Repository, err error) { isNewRef := opts.OldCommitID == git.EmptySHA isDelRef := opts.NewCommitID == git.EmptySHA if isNewRef && isDelRef { |