@@ -476,8 +476,34 @@ func getIssueFromRef(repo *Repository, ref string) (*Issue, error) {
476
476
return issue , nil
477
477
}
478
478
479
+ func changeIssueStatus (repo * Repository , doer * User , ref string , refMarked map [int64 ]bool , status bool ) error {
480
+ issue , err := getIssueFromRef (repo , ref )
481
+ if err != nil {
482
+ return err
483
+ }
484
+
485
+ if issue == nil || refMarked [issue .ID ] {
486
+ return nil
487
+ }
488
+ refMarked [issue .ID ] = true
489
+
490
+ if issue .RepoID != repo .ID || issue .IsClosed == status {
491
+ return nil
492
+ }
493
+
494
+ issue .Repo = repo
495
+ if err = issue .ChangeStatus (doer , status ); err != nil {
496
+ // Don't return an error when dependencies are open as this would let the push fail
497
+ if IsErrDependenciesLeft (err ) {
498
+ return nil
499
+ }
500
+ return err
501
+ }
502
+ return nil
503
+ }
504
+
479
505
// UpdateIssuesCommit checks if issues are manipulated by commit message.
480
- func UpdateIssuesCommit (doer * User , repo * Repository , commits []* PushCommit ) error {
506
+ func UpdateIssuesCommit (doer * User , repo * Repository , commits []* PushCommit , branchName string ) error {
481
507
// Commits are appended in the reverse order.
482
508
for i := len (commits ) - 1 ; i >= 0 ; i -- {
483
509
c := commits [i ]
@@ -500,51 +526,21 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit) err
500
526
}
501
527
}
502
528
529
+ // Change issue status only if the commit has been pushed to the default branch.
530
+ if repo .DefaultBranch != branchName {
531
+ continue
532
+ }
533
+
503
534
refMarked = make (map [int64 ]bool )
504
- // FIXME: can merge this one and next one to a common function.
505
535
for _ , ref := range issueCloseKeywordsPat .FindAllString (c .Message , - 1 ) {
506
- issue , err := getIssueFromRef (repo , ref )
507
- if err != nil {
508
- return err
509
- }
510
-
511
- if issue == nil || refMarked [issue .ID ] {
512
- continue
513
- }
514
- refMarked [issue .ID ] = true
515
-
516
- if issue .RepoID != repo .ID || issue .IsClosed {
517
- continue
518
- }
519
-
520
- issue .Repo = repo
521
- if err = issue .ChangeStatus (doer , true ); err != nil {
522
- // Don't return an error when dependencies are open as this would let the push fail
523
- if IsErrDependenciesLeft (err ) {
524
- return nil
525
- }
536
+ if err := changeIssueStatus (repo , doer , ref , refMarked , true ); err != nil {
526
537
return err
527
538
}
528
539
}
529
540
530
541
// It is conflict to have close and reopen at same time, so refsMarked doesn't need to reinit here.
531
542
for _ , ref := range issueReopenKeywordsPat .FindAllString (c .Message , - 1 ) {
532
- issue , err := getIssueFromRef (repo , ref )
533
- if err != nil {
534
- return err
535
- }
536
-
537
- if issue == nil || refMarked [issue .ID ] {
538
- continue
539
- }
540
- refMarked [issue .ID ] = true
541
-
542
- if issue .RepoID != repo .ID || ! issue .IsClosed {
543
- continue
544
- }
545
-
546
- issue .Repo = repo
547
- if err = issue .ChangeStatus (doer , false ); err != nil {
543
+ if err := changeIssueStatus (repo , doer , ref , refMarked , false ); err != nil {
548
544
return err
549
545
}
550
546
}
@@ -609,7 +605,7 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
609
605
opts .Commits .CompareURL = repo .ComposeCompareURL (opts .OldCommitID , opts .NewCommitID )
610
606
}
611
607
612
- if err = UpdateIssuesCommit (pusher , repo , opts .Commits .Commits ); err != nil {
608
+ if err = UpdateIssuesCommit (pusher , repo , opts .Commits .Commits , refName ); err != nil {
613
609
log .Error (4 , "updateIssuesCommit: %v" , err )
614
610
}
615
611
}
0 commit comments