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)
50
50
// Second subpattern = first status character
51
51
$ newStatus = static ::$ triggerWordToStatus [strtolower (end ($ matches [1 ]))];
52
52
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
+
53
62
$ this ->logger ->debug (sprintf ('Setting issue number %s to status %s ' , $ issueNumber , $ newStatus ));
54
63
$ this ->statusApi ->setIssueStatus ($ issueNumber , $ newStatus , $ repository );
55
64
}
@@ -66,4 +75,9 @@ public static function getSubscribedEvents()
66
75
GitHubEvents::ISSUE_COMMENT => 'onIssueComment ' ,
67
76
);
68
77
}
78
+
79
+ private function checkUserIsAllowedToReview (array $ data )
80
+ {
81
+ return $ data ['issue ' ]['user ' ]['login ' ] !== $ data ['comment ' ]['user ' ]['login ' ];
82
+ }
69
83
}
Original file line number Diff line number Diff line change @@ -98,4 +98,35 @@ public function getCommentsForStatusChange()
98
98
array ('Before the ticket was in state "Status: reviewed", but then the status was changed ' , null ),
99
99
);
100
100
}
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
+ }
101
132
}
You can’t perform that action at this time.
0 commit comments