Trigger sync webhooks on UI commit (#2302)
* Trigger sync webhooks on UI commit * Also fix UI upload/deleterelease/v1.15
parent
951fb572a7
commit
7907786040
|
@ -155,27 +155,29 @@ func (repo *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) (
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simulate push event.
|
// Simulate push event.
|
||||||
pushCommits := &PushCommits{
|
|
||||||
Len: 1,
|
|
||||||
Commits: []*PushCommit{CommitToPushCommit(commit)},
|
|
||||||
}
|
|
||||||
oldCommitID := opts.LastCommitID
|
oldCommitID := opts.LastCommitID
|
||||||
if opts.NewBranch != opts.OldBranch {
|
if opts.NewBranch != opts.OldBranch {
|
||||||
oldCommitID = git.EmptySHA
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,23 +297,29 @@ func (repo *Repository) DeleteRepoFile(doer *User, opts DeleteRepoFileOptions) (
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simulate push event.
|
// Simulate push event.
|
||||||
pushCommits := &PushCommits{
|
oldCommitID := opts.LastCommitID
|
||||||
Len: 1,
|
if opts.NewBranch != opts.OldBranch {
|
||||||
Commits: []*PushCommit{CommitToPushCommit(commit)},
|
oldCommitID = git.EmptySHA
|
||||||
}
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,21 +542,28 @@ func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simulate push event.
|
// Simulate push event.
|
||||||
pushCommits := &PushCommits{
|
oldCommitID := opts.LastCommitID
|
||||||
Len: 1,
|
if opts.NewBranch != opts.OldBranch {
|
||||||
Commits: []*PushCommit{CommitToPushCommit(commit)},
|
oldCommitID = git.EmptySHA
|
||||||
}
|
}
|
||||||
if err := CommitRepoAction(CommitRepoActionOptions{
|
|
||||||
PusherName: doer.Name,
|
if err = repo.GetOwner(); err != nil {
|
||||||
RepoOwnerID: repo.MustOwner().ID,
|
return fmt.Errorf("GetOwner: %v", err)
|
||||||
RepoName: repo.Name,
|
}
|
||||||
RefFullName: git.BranchPrefix + opts.NewBranch,
|
err = PushUpdate(
|
||||||
OldCommitID: opts.LastCommitID,
|
opts.NewBranch,
|
||||||
NewCommitID: commit.ID.String(),
|
PushUpdateOptions{
|
||||||
Commits: pushCommits,
|
PusherID: doer.ID,
|
||||||
}); err != nil {
|
PusherName: doer.Name,
|
||||||
log.Error(4, "CommitRepoAction: %v", err)
|
RepoUserName: repo.Owner.Name,
|
||||||
return nil
|
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...)
|
return DeleteUploads(uploads...)
|
||||||
|
|
|
@ -64,7 +64,24 @@ type PushUpdateOptions struct {
|
||||||
|
|
||||||
// PushUpdate must be called for any push actions in order to
|
// PushUpdate must be called for any push actions in order to
|
||||||
// generates necessary push action history feeds.
|
// 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
|
isNewRef := opts.OldCommitID == git.EmptySHA
|
||||||
isDelRef := opts.NewCommitID == git.EmptySHA
|
isDelRef := opts.NewCommitID == git.EmptySHA
|
||||||
if isNewRef && isDelRef {
|
if isNewRef && isDelRef {
|
||||||
|
|
|
@ -32,15 +32,7 @@ func PushUpdate(ctx *macaron.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := models.PushUpdate(opt)
|
err := models.PushUpdate(branch, opt)
|
||||||
if err != nil {
|
|
||||||
ctx.JSON(500, map[string]interface{}{
|
|
||||||
"err": err.Error(),
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
pusher, err := models.GetUserByID(opt.PusherID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrUserNotExist(err) {
|
if models.IsErrUserNotExist(err) {
|
||||||
ctx.Error(404)
|
ctx.Error(404)
|
||||||
|
@ -51,10 +43,5 @@ func PushUpdate(ctx *macaron.Context) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Trace("TriggerTask '%s/%s' by %s", repo.Name, branch, pusher.Name)
|
|
||||||
|
|
||||||
go models.HookQueue.Add(repo.ID)
|
|
||||||
go models.AddTestPullRequestTask(pusher, repo.ID, branch, true)
|
|
||||||
ctx.Status(202)
|
ctx.Status(202)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue