File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,15 @@ public function onIssueComment(GitHubEvent $event)
5050 // Second subpattern = first status character
5151 $ newStatus = static ::$ triggerWordToStatus [strtolower (end ($ matches [1 ]))];
5252
53+ if (Status::REVIEWED === $ newStatus && false === $ this ->checkUserIsAllowedToReview ($ data )) {
54+ $ event ->setResponseData (array (
55+ 'issue ' => $ issueNumber ,
56+ 'status_change ' => null ,
57+ ));
58+
59+ return ;
60+ }
61+
5362 $ this ->logger ->debug (sprintf ('Setting issue number %s to status %s ' , $ issueNumber , $ newStatus ));
5463 $ this ->statusApi ->setIssueStatus ($ issueNumber , $ newStatus , $ repository );
5564 }
@@ -66,4 +75,9 @@ public static function getSubscribedEvents()
6675 GitHubEvents::ISSUE_COMMENT => 'onIssueComment ' ,
6776 );
6877 }
78+
79+ private function checkUserIsAllowedToReview (array $ data )
80+ {
81+ return $ data ['issue ' ]['user ' ]['login ' ] !== $ data ['comment ' ]['user ' ]['login ' ];
82+ }
6983}
Original file line number Diff line number Diff line change @@ -98,4 +98,35 @@ public function getCommentsForStatusChange()
9898 array ('Before the ticket was in state "Status: reviewed", but then the status was changed ' , null ),
9999 );
100100 }
101+
102+ /**
103+ * @dataProvider getCommentsForStatusChange
104+ */
105+ public function testOnIssueCommentAuthorSelfReview ()
106+ {
107+ $ this ->statusApi ->expects ($ this ->never ())
108+ ->method ('setIssueStatus ' )
109+ ;
110+
111+ $ user = array ('login ' => 'weaverryan ' );
112+
113+ $ event = new GitHubEvent (array (
114+ 'issue ' => array (
115+ 'number ' => 1234 ,
116+ 'user ' => $ user ,
117+ ),
118+ 'comment ' => array (
119+ 'body ' => 'Status: reviewed ' ,
120+ 'user ' => $ user ,
121+ ),
122+ ), $ this ->repository );
123+
124+ self ::$ dispatcher ->dispatch (GitHubEvents::ISSUE_COMMENT , $ event );
125+
126+ $ responseData = $ event ->getResponseData ();
127+
128+ $ this ->assertCount (2 , $ responseData );
129+ $ this ->assertSame (1234 , $ responseData ['issue ' ]);
130+ $ this ->assertNull ($ responseData ['status_change ' ]);
131+ }
101132}
You can’t perform that action at this time.
0 commit comments