|
6 | 6 | package models |
7 | 7 |
|
8 | 8 | import ( |
9 | | - "encoding/json" |
10 | 9 | "fmt" |
11 | 10 | "html" |
12 | 11 | "path" |
@@ -610,79 +609,6 @@ func MergePullRequestAction(actUser *User, repo *Repository, pull *Issue) error |
610 | 609 | return mergePullRequestAction(x, actUser, repo, pull) |
611 | 610 | } |
612 | 611 |
|
613 | | -func mirrorSyncAction(e Engine, opType ActionType, repo *Repository, refName string, data []byte) error { |
614 | | - if err := notifyWatchers(e, &Action{ |
615 | | - ActUserID: repo.OwnerID, |
616 | | - ActUser: repo.MustOwner(), |
617 | | - OpType: opType, |
618 | | - RepoID: repo.ID, |
619 | | - Repo: repo, |
620 | | - IsPrivate: repo.IsPrivate, |
621 | | - RefName: refName, |
622 | | - Content: string(data), |
623 | | - }); err != nil { |
624 | | - return fmt.Errorf("notifyWatchers: %v", err) |
625 | | - } |
626 | | - |
627 | | - defer func() { |
628 | | - go HookQueue.Add(repo.ID) |
629 | | - }() |
630 | | - |
631 | | - return nil |
632 | | -} |
633 | | - |
634 | | -// MirrorSyncPushActionOptions mirror synchronization action options. |
635 | | -type MirrorSyncPushActionOptions struct { |
636 | | - RefName string |
637 | | - OldCommitID string |
638 | | - NewCommitID string |
639 | | - Commits *PushCommits |
640 | | -} |
641 | | - |
642 | | -// MirrorSyncPushAction adds new action for mirror synchronization of pushed commits. |
643 | | -func MirrorSyncPushAction(repo *Repository, opts MirrorSyncPushActionOptions) error { |
644 | | - if len(opts.Commits.Commits) > setting.UI.FeedMaxCommitNum { |
645 | | - opts.Commits.Commits = opts.Commits.Commits[:setting.UI.FeedMaxCommitNum] |
646 | | - } |
647 | | - |
648 | | - apiCommits, err := opts.Commits.ToAPIPayloadCommits(repo.RepoPath(), repo.HTMLURL()) |
649 | | - if err != nil { |
650 | | - return err |
651 | | - } |
652 | | - |
653 | | - opts.Commits.CompareURL = repo.ComposeCompareURL(opts.OldCommitID, opts.NewCommitID) |
654 | | - apiPusher := repo.MustOwner().APIFormat() |
655 | | - if err := PrepareWebhooks(repo, HookEventPush, &api.PushPayload{ |
656 | | - Ref: opts.RefName, |
657 | | - Before: opts.OldCommitID, |
658 | | - After: opts.NewCommitID, |
659 | | - CompareURL: setting.AppURL + opts.Commits.CompareURL, |
660 | | - Commits: apiCommits, |
661 | | - Repo: repo.APIFormat(AccessModeOwner), |
662 | | - Pusher: apiPusher, |
663 | | - Sender: apiPusher, |
664 | | - }); err != nil { |
665 | | - return fmt.Errorf("PrepareWebhooks: %v", err) |
666 | | - } |
667 | | - |
668 | | - data, err := json.Marshal(opts.Commits) |
669 | | - if err != nil { |
670 | | - return err |
671 | | - } |
672 | | - |
673 | | - return mirrorSyncAction(x, ActionMirrorSyncPush, repo, opts.RefName, data) |
674 | | -} |
675 | | - |
676 | | -// MirrorSyncCreateAction adds new action for mirror synchronization of new reference. |
677 | | -func MirrorSyncCreateAction(repo *Repository, refName string) error { |
678 | | - return mirrorSyncAction(x, ActionMirrorSyncCreate, repo, refName, nil) |
679 | | -} |
680 | | - |
681 | | -// MirrorSyncDeleteAction adds new action for mirror synchronization of delete reference. |
682 | | -func MirrorSyncDeleteAction(repo *Repository, refName string) error { |
683 | | - return mirrorSyncAction(x, ActionMirrorSyncDelete, repo, refName, nil) |
684 | | -} |
685 | | - |
686 | 612 | // GetFeedsOptions options for retrieving feeds |
687 | 613 | type GetFeedsOptions struct { |
688 | 614 | RequestedUser *User |
|
0 commit comments