CommitRepo creates actions for pushing commits to the repository. An action with the type ActionDeleteBranch is created if the push deletes a branch; an action with the type ActionCommitRepo is created for a regular push. If the regular push also creates a new branch, then another action with type A
(ctx context.Context, opts CommitRepoOptions)
| 461 | // regular push also creates a new branch, then another action with type |
| 462 | // ActionCreateBranch is created. |
| 463 | func (s *ActionsStore) CommitRepo(ctx context.Context, opts CommitRepoOptions) error { |
| 464 | err := newReposStore(s.db).Touch(ctx, opts.Repo.ID) |
| 465 | if err != nil { |
| 466 | return errors.Wrap(err, "touch repository") |
| 467 | } |
| 468 | |
| 469 | pusher, err := newUsersStore(s.db).GetByUsername(ctx, opts.PusherName) |
| 470 | if err != nil { |
| 471 | return errors.Wrapf(err, "get pusher [name: %s]", opts.PusherName) |
| 472 | } |
| 473 | |
| 474 | isNewRef := opts.OldCommitID == git.EmptyID |
| 475 | isDelRef := opts.NewCommitID == git.EmptyID |
| 476 | |
| 477 | // If not the first commit, set the compare URL. |
| 478 | if !isNewRef && !isDelRef { |
| 479 | opts.Commits.CompareURL = repoutil.CompareCommitsPath(opts.Owner.Name, opts.Repo.Name, opts.OldCommitID, opts.NewCommitID) |
| 480 | } |
| 481 | |
| 482 | refName := git.RefShortName(opts.RefFullName) |
| 483 | action := &Action{ |
| 484 | ActUserID: pusher.ID, |
| 485 | ActUserName: pusher.Name, |
| 486 | RepoID: opts.Repo.ID, |
| 487 | RepoUserName: opts.Owner.Name, |
| 488 | RepoName: opts.Repo.Name, |
| 489 | RefName: refName, |
| 490 | IsPrivate: opts.Repo.IsPrivate || opts.Repo.IsUnlisted, |
| 491 | } |
| 492 | |
| 493 | apiRepo := opts.Repo.APIFormat(opts.Owner) |
| 494 | apiPusher := pusher.APIFormat() |
| 495 | if isDelRef { |
| 496 | err = PrepareWebhooks( |
| 497 | opts.Repo, |
| 498 | HookEventTypeDelete, |
| 499 | &api.DeletePayload{ |
| 500 | Ref: refName, |
| 501 | RefType: "branch", |
| 502 | PusherType: api.PUSHER_TYPE_USER, |
| 503 | Repo: apiRepo, |
| 504 | Sender: apiPusher, |
| 505 | }, |
| 506 | ) |
| 507 | if err != nil { |
| 508 | return errors.Wrap(err, "prepare webhooks for delete branch") |
| 509 | } |
| 510 | |
| 511 | action.OpType = ActionDeleteBranch |
| 512 | err = s.notifyWatchers(ctx, action) |
| 513 | if err != nil { |
| 514 | return errors.Wrap(err, "notify watchers") |
| 515 | } |
| 516 | |
| 517 | // Delete branch doesn't have anything to push or compare |
| 518 | return nil |
| 519 | } |
| 520 |