PushTag creates an action for pushing tags to the repository. An action with the type ActionDeleteTag is created if the push deletes a tag. Otherwise, an action with the type ActionPushTag is created for a regular push.
(ctx context.Context, opts PushTagOptions)
| 608 | // the type ActionDeleteTag is created if the push deletes a tag. Otherwise, an |
| 609 | // action with the type ActionPushTag is created for a regular push. |
| 610 | func (s *ActionsStore) PushTag(ctx context.Context, opts PushTagOptions) error { |
| 611 | err := newReposStore(s.db).Touch(ctx, opts.Repo.ID) |
| 612 | if err != nil { |
| 613 | return errors.Wrap(err, "touch repository") |
| 614 | } |
| 615 | |
| 616 | pusher, err := newUsersStore(s.db).GetByUsername(ctx, opts.PusherName) |
| 617 | if err != nil { |
| 618 | return errors.Wrapf(err, "get pusher [name: %s]", opts.PusherName) |
| 619 | } |
| 620 | |
| 621 | refName := git.RefShortName(opts.RefFullName) |
| 622 | action := &Action{ |
| 623 | ActUserID: pusher.ID, |
| 624 | ActUserName: pusher.Name, |
| 625 | RepoID: opts.Repo.ID, |
| 626 | RepoUserName: opts.Owner.Name, |
| 627 | RepoName: opts.Repo.Name, |
| 628 | RefName: refName, |
| 629 | IsPrivate: opts.Repo.IsPrivate || opts.Repo.IsUnlisted, |
| 630 | } |
| 631 | |
| 632 | apiRepo := opts.Repo.APIFormat(opts.Owner) |
| 633 | apiPusher := pusher.APIFormat() |
| 634 | if opts.NewCommitID == git.EmptyID { |
| 635 | err = PrepareWebhooks( |
| 636 | opts.Repo, |
| 637 | HookEventTypeDelete, |
| 638 | &api.DeletePayload{ |
| 639 | Ref: refName, |
| 640 | RefType: "tag", |
| 641 | PusherType: api.PUSHER_TYPE_USER, |
| 642 | Repo: apiRepo, |
| 643 | Sender: apiPusher, |
| 644 | }, |
| 645 | ) |
| 646 | if err != nil { |
| 647 | return errors.Wrap(err, "prepare webhooks for delete tag") |
| 648 | } |
| 649 | |
| 650 | action.OpType = ActionDeleteTag |
| 651 | err = s.notifyWatchers(ctx, action) |
| 652 | if err != nil { |
| 653 | return errors.Wrap(err, "notify watchers") |
| 654 | } |
| 655 | return nil |
| 656 | } |
| 657 | |
| 658 | err = PrepareWebhooks( |
| 659 | opts.Repo, |
| 660 | HookEventTypeCreate, |
| 661 | &api.CreatePayload{ |
| 662 | Ref: refName, |
| 663 | RefType: "tag", |
| 664 | Sha: opts.NewCommitID, |
| 665 | DefaultBranch: opts.Repo.DefaultBranch, |
| 666 | Repo: apiRepo, |
| 667 | Sender: apiPusher, |