gitea源码

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. commitID, err := git.NewIDFromString(opts.OldCommitID)
  20. return err == nil && commitID.IsZero()
  21. }
  22. // IsDelRef return true if it's a deletion to a branch or tag
  23. func (opts *PushUpdateOptions) IsDelRef() bool {
  24. commitID, err := git.NewIDFromString(opts.NewCommitID)
  25. return err == nil && commitID.IsZero()
  26. }
  27. // IsUpdateRef return true if it's an update operation
  28. func (opts *PushUpdateOptions) IsUpdateRef() bool {
  29. return !opts.IsNewRef() && !opts.IsDelRef()
  30. }
  31. // IsNewTag return true if it's a creation to a tag
  32. func (opts *PushUpdateOptions) IsNewTag() bool {
  33. return opts.RefFullName.IsTag() && opts.IsNewRef()
  34. }
  35. // IsDelTag return true if it's a deletion to a tag
  36. func (opts *PushUpdateOptions) IsDelTag() bool {
  37. return opts.RefFullName.IsTag() && opts.IsDelRef()
  38. }
  39. // IsNewBranch return true if it's the first-time push to a branch
  40. func (opts *PushUpdateOptions) IsNewBranch() bool {
  41. return opts.RefFullName.IsBranch() && opts.IsNewRef()
  42. }
  43. // IsUpdateBranch return true if it's not the first push to a branch
  44. func (opts *PushUpdateOptions) IsUpdateBranch() bool {
  45. return opts.RefFullName.IsBranch() && opts.IsUpdateRef()
  46. }
  47. // IsDelBranch return true if it's a deletion to a branch
  48. func (opts *PushUpdateOptions) IsDelBranch() bool {
  49. return opts.RefFullName.IsBranch() && opts.IsDelRef()
  50. }
  51. // RefName returns simple name for ref
  52. func (opts *PushUpdateOptions) RefName() string {
  53. return opts.RefFullName.ShortName()
  54. }
  55. // RepoFullName returns repo full name
  56. func (opts *PushUpdateOptions) RepoFullName() string {
  57. return opts.RepoUserName + "/" + opts.RepoName
  58. }