@@ -476,6 +476,32 @@ 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
506
func UpdateIssuesCommit (doer * User , repo * Repository , commits []* PushCommit , branchName string ) error {
481
507
// Commits are appended in the reverse order.
@@ -506,50 +532,15 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit, bra
506
532
}
507
533
508
534
refMarked = make (map [int64 ]bool )
509
- // FIXME: can merge this one and next one to a common function.
510
535
for _ , ref := range issueCloseKeywordsPat .FindAllString (c .Message , - 1 ) {
511
- issue , err := getIssueFromRef (repo , ref )
512
- if err != nil {
513
- return err
514
- }
515
-
516
- if issue == nil || refMarked [issue .ID ] {
517
- continue
518
- }
519
- refMarked [issue .ID ] = true
520
-
521
- if issue .RepoID != repo .ID || issue .IsClosed {
522
- continue
523
- }
524
-
525
- issue .Repo = repo
526
- if err = issue .ChangeStatus (doer , true ); err != nil {
527
- // Don't return an error when dependencies are open as this would let the push fail
528
- if IsErrDependenciesLeft (err ) {
529
- return nil
530
- }
536
+ if err := changeIssueStatus (repo , doer , ref , refMarked , true ); err != nil {
531
537
return err
532
538
}
533
539
}
534
540
535
541
// It is conflict to have close and reopen at same time, so refsMarked doesn't need to reinit here.
536
542
for _ , ref := range issueReopenKeywordsPat .FindAllString (c .Message , - 1 ) {
537
- issue , err := getIssueFromRef (repo , ref )
538
- if err != nil {
539
- return err
540
- }
541
-
542
- if issue == nil || refMarked [issue .ID ] {
543
- continue
544
- }
545
- refMarked [issue .ID ] = true
546
-
547
- if issue .RepoID != repo .ID || ! issue .IsClosed {
548
- continue
549
- }
550
-
551
- issue .Repo = repo
552
- if err = issue .ChangeStatus (doer , false ); err != nil {
543
+ if err := changeIssueStatus (repo , doer , ref , refMarked , false ); err != nil {
553
544
return err
554
545
}
555
546
}
0 commit comments