diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-10-16 17:56:59 +0800 |
---|---|---|
committer | zeripath <art27@cantab.net> | 2019-10-16 10:56:59 +0100 |
commit | 8edf3d58048fce20cdde776c3deb2ca1d94ad8e7 (patch) | |
tree | 21b576bb8269b2c1081c80f5d241f50565026804 /models/action.go | |
parent | 1d9a1a0d456887a458fd17fef417ff9c6bdd58da (diff) | |
download | gitea-8edf3d58048fce20cdde776c3deb2ca1d94ad8e7.tar.gz gitea-8edf3d58048fce20cdde776c3deb2ca1d94ad8e7.zip |
Move sync mirror actions to mirror service package (#8518)
* move sync mirror actions to mirror service
* fix go.mod
* fix lint
* fix lint
Diffstat (limited to 'models/action.go')
-rw-r--r-- | models/action.go | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/models/action.go b/models/action.go index 2d2999f880..b651c658d5 100644 --- a/models/action.go +++ b/models/action.go @@ -6,7 +6,6 @@ package models import ( - "encoding/json" "fmt" "html" "path" @@ -610,79 +609,6 @@ func MergePullRequestAction(actUser *User, repo *Repository, pull *Issue) error return mergePullRequestAction(x, actUser, repo, pull) } -func mirrorSyncAction(e Engine, opType ActionType, repo *Repository, refName string, data []byte) error { - if err := notifyWatchers(e, &Action{ - ActUserID: repo.OwnerID, - ActUser: repo.MustOwner(), - OpType: opType, - RepoID: repo.ID, - Repo: repo, - IsPrivate: repo.IsPrivate, - RefName: refName, - Content: string(data), - }); err != nil { - return fmt.Errorf("notifyWatchers: %v", err) - } - - defer func() { - go HookQueue.Add(repo.ID) - }() - - return nil -} - -// MirrorSyncPushActionOptions mirror synchronization action options. -type MirrorSyncPushActionOptions struct { - RefName string - OldCommitID string - NewCommitID string - Commits *PushCommits -} - -// MirrorSyncPushAction adds new action for mirror synchronization of pushed commits. -func MirrorSyncPushAction(repo *Repository, opts MirrorSyncPushActionOptions) error { - if len(opts.Commits.Commits) > setting.UI.FeedMaxCommitNum { - opts.Commits.Commits = opts.Commits.Commits[:setting.UI.FeedMaxCommitNum] - } - - apiCommits, err := opts.Commits.ToAPIPayloadCommits(repo.RepoPath(), repo.HTMLURL()) - if err != nil { - return err - } - - opts.Commits.CompareURL = repo.ComposeCompareURL(opts.OldCommitID, opts.NewCommitID) - apiPusher := repo.MustOwner().APIFormat() - if err := PrepareWebhooks(repo, HookEventPush, &api.PushPayload{ - Ref: opts.RefName, - Before: opts.OldCommitID, - After: opts.NewCommitID, - CompareURL: setting.AppURL + opts.Commits.CompareURL, - Commits: apiCommits, - Repo: repo.APIFormat(AccessModeOwner), - Pusher: apiPusher, - Sender: apiPusher, - }); err != nil { - return fmt.Errorf("PrepareWebhooks: %v", err) - } - - data, err := json.Marshal(opts.Commits) - if err != nil { - return err - } - - return mirrorSyncAction(x, ActionMirrorSyncPush, repo, opts.RefName, data) -} - -// MirrorSyncCreateAction adds new action for mirror synchronization of new reference. -func MirrorSyncCreateAction(repo *Repository, refName string) error { - return mirrorSyncAction(x, ActionMirrorSyncCreate, repo, refName, nil) -} - -// MirrorSyncDeleteAction adds new action for mirror synchronization of delete reference. -func MirrorSyncDeleteAction(repo *Repository, refName string) error { - return mirrorSyncAction(x, ActionMirrorSyncDelete, repo, refName, nil) -} - // GetFeedsOptions options for retrieving feeds type GetFeedsOptions struct { RequestedUser *User |