@@ -533,32 +533,45 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit, bra
533
533
}
534
534
refMarked [key ] = true
535
535
536
- // only create comments for issues if user has permission for it
537
- if perm .IsAdmin () || perm .IsOwner () || perm .CanWrite (UnitTypeIssues ) {
538
- message := fmt .Sprintf (`<a href="%s/commit/%s">%s</a>` , repo .Link (), c .Sha1 , html .EscapeString (c .Message ))
539
- if err = CreateRefComment (doer , refRepo , refIssue , message , c .Sha1 ); err != nil {
540
- return err
541
- }
536
+ // FIXME: this kind of condition is all over the code, it should be consolidated in a single place
537
+ canclose := perm .IsAdmin () || perm .IsOwner () || perm .CanWrite (UnitTypeIssues ) || refIssue .PosterID == doer .ID
538
+ cancomment := canclose || perm .CanRead (UnitTypeIssues )
539
+
540
+ // Don't proceed if the user can't comment
541
+ if ! cancomment {
542
+ continue
542
543
}
543
544
544
- // Process closing/reopening keywords
545
- if ref .Action != references .XRefActionCloses && ref .Action != references .XRefActionReopens {
545
+ message := fmt .Sprintf (`<a href="%s/commit/%s">%s</a>` , repo .Link (), c .Sha1 , html .EscapeString (c .Message ))
546
+ if err = CreateRefComment (doer , refRepo , refIssue , message , c .Sha1 ); err != nil {
547
+ return err
548
+ }
549
+
550
+ // Only issues can be closed/reopened this way, and user needs the correct permissions
551
+ if refIssue .IsPull || ! canclose {
546
552
continue
547
553
}
548
554
549
- // Change issue status only if the commit has been pushed to the default branch.
550
- // and if the repo is configured to allow only that
551
- // FIXME: we should be using Issue.ref if set instead of repo.DefaultBranch
552
- if repo .DefaultBranch != branchName && ! repo .CloseIssuesViaCommitInAnyBranch {
555
+ // Only process closing/reopening keywords
556
+ if ref .Action != references .XRefActionCloses && ref .Action != references .XRefActionReopens {
553
557
continue
554
558
}
555
559
556
- // only close issues in another repo if user has push access
557
- if perm .IsAdmin () || perm .IsOwner () || perm .CanWrite (UnitTypeCode ) {
558
- if err := changeIssueStatus (refRepo , refIssue , doer , ref .Action == references .XRefActionCloses ); err != nil {
559
- return err
560
+ if ! repo .CloseIssuesViaCommitInAnyBranch {
561
+ // If the issue was specified to be in a particular branch, don't allow commits in other branches to close it
562
+ if refIssue .Ref != "" {
563
+ if branchName != refIssue .Ref {
564
+ continue
565
+ }
566
+ // Otherwise, only process commits to the default branch
567
+ } else if branchName != repo .DefaultBranch {
568
+ continue
560
569
}
561
570
}
571
+
572
+ if err := changeIssueStatus (refRepo , refIssue , doer , ref .Action == references .XRefActionCloses ); err != nil {
573
+ return err
574
+ }
562
575
}
563
576
}
564
577
return nil
0 commit comments