You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

push.go 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package repository
  4. import (
  5. "code.gitea.io/gitea/modules/git"
  6. )
  7. // PushUpdateOptions defines the push update options
  8. type PushUpdateOptions struct {
  9. PusherID int64
  10. PusherName string
  11. RepoUserName string
  12. RepoName string
  13. RefFullName git.RefName // branch, tag or other name to push
  14. OldCommitID string
  15. NewCommitID string
  16. }
  17. // IsNewRef return true if it's a first-time push to a branch, tag or etc.
  18. func (opts *PushUpdateOptions) IsNewRef() bool {
  19. return opts.OldCommitID == git.EmptySHA
  20. }
  21. // IsDelRef return true if it's a deletion to a branch or tag
  22. func (opts *PushUpdateOptions) IsDelRef() bool {
  23. return opts.NewCommitID == git.EmptySHA
  24. }
  25. // IsUpdateRef return true if it's an update operation
  26. func (opts *PushUpdateOptions) IsUpdateRef() bool {
  27. return !opts.IsNewRef() && !opts.IsDelRef()
  28. }
  29. // IsNewTag return true if it's a creation to a tag
  30. func (opts *PushUpdateOptions) IsNewTag() bool {
  31. return opts.RefFullName.IsTag() && opts.IsNewRef()
  32. }
  33. // IsDelTag return true if it's a deletion to a tag
  34. func (opts *PushUpdateOptions) IsDelTag() bool {
  35. return opts.RefFullName.IsTag() && opts.IsDelRef()
  36. }
  37. // IsNewBranch return true if it's the first-time push to a branch
  38. func (opts *PushUpdateOptions) IsNewBranch() bool {
  39. return opts.RefFullName.IsBranch() && opts.IsNewRef()
  40. }
  41. // IsUpdateBranch return true if it's not the first push to a branch
  42. func (opts *PushUpdateOptions) IsUpdateBranch() bool {
  43. return opts.RefFullName.IsBranch() && opts.IsUpdateRef()
  44. }
  45. // IsDelBranch return true if it's a deletion to a branch
  46. func (opts *PushUpdateOptions) IsDelBranch() bool {
  47. return opts.RefFullName.IsBranch() && opts.IsDelRef()
  48. }
  49. // RefName returns simple name for ref
  50. func (opts *PushUpdateOptions) RefName() string {
  51. return opts.RefFullName.ShortName()
  52. }
  53. // RepoFullName returns repo full name
  54. func (opts *PushUpdateOptions) RepoFullName() string {
  55. return opts.RepoUserName + "/" + opts.RepoName
  56. }