@@ -10,9 +10,7 @@ import (
1010 "strings"
1111 "time"
1212
13- "code.gitea.io/gitea/modules/cache"
1413 "code.gitea.io/gitea/modules/git"
15- "code.gitea.io/gitea/modules/log"
1614 "code.gitea.io/gitea/modules/util"
1715)
1816
@@ -64,26 +62,8 @@ type PushUpdateOptions struct {
6462 NewCommitID string
6563}
6664
67- // PushUpdate must be called for any push actions in order to
68- // generates necessary push action history feeds.
69- func PushUpdate (branch string , opt PushUpdateOptions ) error {
70- repo , err := pushUpdate (opt )
71- if err != nil {
72- return err
73- }
74-
75- pusher , err := GetUserByID (opt .PusherID )
76- if err != nil {
77- return err
78- }
79-
80- log .Trace ("TriggerTask '%s/%s' by %s" , repo .Name , branch , pusher .Name )
81-
82- go AddTestPullRequestTask (pusher , repo .ID , branch , true )
83- return nil
84- }
85-
86- func pushUpdateDeleteTag (repo * Repository , tagName string ) error {
65+ // PushUpdateDeleteTag must be called for any push actions to delete tag
66+ func PushUpdateDeleteTag (repo * Repository , tagName string ) error {
8767 rel , err := GetRelease (repo .ID , tagName )
8868 if err != nil {
8969 if IsErrReleaseNotExist (err ) {
@@ -107,7 +87,8 @@ func pushUpdateDeleteTag(repo *Repository, tagName string) error {
10787 return nil
10888}
10989
110- func pushUpdateAddTag (repo * Repository , gitRepo * git.Repository , tagName string ) error {
90+ // PushUpdateAddTag must be called for any push actions to add tag
91+ func PushUpdateAddTag (repo * Repository , gitRepo * git.Repository , tagName string ) error {
11192 rel , err := GetRelease (repo .ID , tagName )
11293 if err != nil && ! IsErrReleaseNotExist (err ) {
11394 return fmt .Errorf ("GetRelease: %v" , err )
@@ -182,95 +163,3 @@ func pushUpdateAddTag(repo *Repository, gitRepo *git.Repository, tagName string)
182163 }
183164 return nil
184165}
185-
186- func pushUpdate (opts PushUpdateOptions ) (repo * Repository , err error ) {
187- isNewRef := opts .OldCommitID == git .EmptySHA
188- isDelRef := opts .NewCommitID == git .EmptySHA
189- if isNewRef && isDelRef {
190- return nil , fmt .Errorf ("Old and new revisions are both %s" , git .EmptySHA )
191- }
192-
193- repoPath := RepoPath (opts .RepoUserName , opts .RepoName )
194-
195- _ , err = git .NewCommand ("update-server-info" ).RunInDir (repoPath )
196- if err != nil {
197- return nil , fmt .Errorf ("Failed to call 'git update-server-info': %v" , err )
198- }
199-
200- owner , err := GetUserByName (opts .RepoUserName )
201- if err != nil {
202- return nil , fmt .Errorf ("GetUserByName: %v" , err )
203- }
204-
205- repo , err = GetRepositoryByName (owner .ID , opts .RepoName )
206- if err != nil {
207- return nil , fmt .Errorf ("GetRepositoryByName: %v" , err )
208- }
209-
210- gitRepo , err := git .OpenRepository (repoPath )
211- if err != nil {
212- return nil , fmt .Errorf ("OpenRepository: %v" , err )
213- }
214-
215- if err = repo .UpdateSize (); err != nil {
216- log .Error ("Failed to update size for repository: %v" , err )
217- }
218-
219- var commits = & PushCommits {}
220- if strings .HasPrefix (opts .RefFullName , git .TagPrefix ) {
221- // If is tag reference
222- tagName := opts .RefFullName [len (git .TagPrefix ):]
223- if isDelRef {
224- err = pushUpdateDeleteTag (repo , tagName )
225- if err != nil {
226- return nil , fmt .Errorf ("pushUpdateDeleteTag: %v" , err )
227- }
228- } else {
229- // Clear cache for tag commit count
230- cache .Remove (repo .GetCommitsCountCacheKey (tagName , true ))
231- err = pushUpdateAddTag (repo , gitRepo , tagName )
232- if err != nil {
233- return nil , fmt .Errorf ("pushUpdateAddTag: %v" , err )
234- }
235- }
236- } else if ! isDelRef {
237- // If is branch reference
238-
239- // Clear cache for branch commit count
240- cache .Remove (repo .GetCommitsCountCacheKey (opts .RefFullName [len (git .BranchPrefix ):], true ))
241-
242- newCommit , err := gitRepo .GetCommit (opts .NewCommitID )
243- if err != nil {
244- return nil , fmt .Errorf ("gitRepo.GetCommit: %v" , err )
245- }
246-
247- // Push new branch.
248- var l * list.List
249- if isNewRef {
250- l , err = newCommit .CommitsBeforeLimit (10 )
251- if err != nil {
252- return nil , fmt .Errorf ("newCommit.CommitsBeforeLimit: %v" , err )
253- }
254- } else {
255- l , err = newCommit .CommitsBeforeUntil (opts .OldCommitID )
256- if err != nil {
257- return nil , fmt .Errorf ("newCommit.CommitsBeforeUntil: %v" , err )
258- }
259- }
260-
261- commits = ListToPushCommits (l )
262- }
263-
264- if err := CommitRepoAction (CommitRepoActionOptions {
265- PusherName : opts .PusherName ,
266- RepoOwnerID : owner .ID ,
267- RepoName : repo .Name ,
268- RefFullName : opts .RefFullName ,
269- OldCommitID : opts .OldCommitID ,
270- NewCommitID : opts .NewCommitID ,
271- Commits : commits ,
272- }); err != nil {
273- return nil , fmt .Errorf ("CommitRepoAction: %v" , err )
274- }
275- return repo , nil
276- }
0 commit comments