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