MirrorSyncPush creates an action for mirror synchronization of pushed commits.
(ctx context.Context, opts MirrorSyncPushOptions)
| 212 | // MirrorSyncPush creates an action for mirror synchronization of pushed |
| 213 | // commits. |
| 214 | func (s *ActionsStore) MirrorSyncPush(ctx context.Context, opts MirrorSyncPushOptions) error { |
| 215 | if conf.UI.FeedMaxCommitNum > 0 && len(opts.Commits.Commits) > conf.UI.FeedMaxCommitNum { |
| 216 | opts.Commits.Commits = opts.Commits.Commits[:conf.UI.FeedMaxCommitNum] |
| 217 | } |
| 218 | |
| 219 | apiCommits, err := opts.Commits.APIFormat(ctx, |
| 220 | newUsersStore(s.db), |
| 221 | repoutil.RepositoryPath(opts.Owner.Name, opts.Repo.Name), |
| 222 | repoutil.HTMLURL(opts.Owner.Name, opts.Repo.Name), |
| 223 | ) |
| 224 | if err != nil { |
| 225 | return errors.Wrap(err, "convert commits to API format") |
| 226 | } |
| 227 | |
| 228 | opts.Commits.CompareURL = repoutil.CompareCommitsPath(opts.Owner.Name, opts.Repo.Name, opts.OldCommitID, opts.NewCommitID) |
| 229 | apiPusher := opts.Owner.APIFormat() |
| 230 | err = PrepareWebhooks( |
| 231 | opts.Repo, |
| 232 | HookEventTypePush, |
| 233 | &api.PushPayload{ |
| 234 | Ref: opts.RefName, |
| 235 | Before: opts.OldCommitID, |
| 236 | After: opts.NewCommitID, |
| 237 | CompareURL: conf.Server.ExternalURL + opts.Commits.CompareURL, |
| 238 | Commits: apiCommits, |
| 239 | Repo: opts.Repo.APIFormat(opts.Owner), |
| 240 | Pusher: apiPusher, |
| 241 | Sender: apiPusher, |
| 242 | }, |
| 243 | ) |
| 244 | if err != nil { |
| 245 | return errors.Wrap(err, "prepare webhooks") |
| 246 | } |
| 247 | |
| 248 | data, err := jsoniter.Marshal(opts.Commits) |
| 249 | if err != nil { |
| 250 | return errors.Wrap(err, "marshal JSON") |
| 251 | } |
| 252 | |
| 253 | return s.mirrorSyncAction(ctx, ActionMirrorSyncPush, opts.Owner, opts.Repo, opts.RefName, data) |
| 254 | } |
| 255 | |
| 256 | // MirrorSyncCreate creates an action for mirror synchronization of a new |
| 257 | // reference. |