mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-11 18:22:14 +00:00
Merge pull request #30659 from Cyberboss/AlsoOnComment
Update Ready for Review when a review comment is created by a maintainer
This commit is contained in:
@@ -95,6 +95,11 @@ switch (strtolower($_SERVER['HTTP_X_GITHUB_EVENT'])) {
|
||||
case 'pull_request':
|
||||
handle_pr($payload);
|
||||
break;
|
||||
case 'pull_request_review':
|
||||
$lower_state = strtolower($payload['review']['state']);
|
||||
if(($lower_state == 'approved' || $lower_state == 'changes_requested') && is_maintainer($payload, $payload['review']['user']['login']))
|
||||
remove_ready_for_review($payload);
|
||||
break;
|
||||
default:
|
||||
header('HTTP/1.0 404 Not Found');
|
||||
echo "Event:$_SERVER[HTTP_X_GITHUB_EVENT] Payload:\n";
|
||||
@@ -145,6 +150,12 @@ function validate_user($payload) {
|
||||
return $res['total_count'] >= (int)$validation_count;
|
||||
|
||||
}
|
||||
|
||||
function get_labels($payload){
|
||||
$url = $payload['pull_request']['issue_url'] . '/labels';
|
||||
return json_decode(apisend($url), true);
|
||||
}
|
||||
|
||||
//rip bs-12
|
||||
function tag_pr($payload, $opened) {
|
||||
//get the mergeable state
|
||||
@@ -196,7 +207,7 @@ function tag_pr($payload, $opened) {
|
||||
|
||||
$url = $payload['pull_request']['issue_url'] . '/labels';
|
||||
|
||||
$existing_labels = json_decode(apisend($url), true);
|
||||
$existing_labels = get_labels($payload);
|
||||
|
||||
$existing = array();
|
||||
foreach($existing_labels as $label)
|
||||
@@ -215,17 +226,26 @@ function tag_pr($payload, $opened) {
|
||||
return $final;
|
||||
}
|
||||
|
||||
function remove_ready_for_review($payload, $labels, $r4rlabel){
|
||||
$index = array_search($r4rlabel, $labels);
|
||||
function remove_ready_for_review($payload, $labels = null){
|
||||
if($labels == null)
|
||||
$labels = get_labels($payload);
|
||||
$index = array_search('Ready for Review', $labels);
|
||||
if($index !== FALSE)
|
||||
unset($labels[$index]);
|
||||
$url = $payload['pull_request']['issue_url'] . '/labels';
|
||||
apisend($url, 'PUT', $labels);
|
||||
}
|
||||
|
||||
function check_ready_for_review($payload, $labels){
|
||||
$r4rlabel = 'Ready for Review';
|
||||
function dismiss_review($payload, $id){
|
||||
$content = array('message' => 'Out of date review');
|
||||
apisend($payload['pull_request']['url'] . '/reviews/' . $id . '/dismissals', 'PUT', $content);
|
||||
}
|
||||
|
||||
function check_ready_for_review($payload, $labels = null){
|
||||
$r4rlabel = 'Ready for Review';
|
||||
$has_label_already = false;
|
||||
if($labels == null)
|
||||
$labels = get_labels($payload);
|
||||
//if the label is already there we may need to remove it
|
||||
foreach($labels as $L)
|
||||
if($L == $r4rlabel){
|
||||
@@ -237,40 +257,54 @@ function check_ready_for_review($payload, $labels){
|
||||
$reviews = json_decode(apisend($payload['pull_request']['url'] . '/reviews'), true);
|
||||
|
||||
$reviews_ids_with_changes_requested = array();
|
||||
$dismissed_an_approved_review = false;
|
||||
|
||||
foreach($reviews as $R){
|
||||
if($R['state'] == 'CHANGES_REQUESTED' && isset($R['author_association']) && ($R['author_association'] == 'MEMBER' || $R['author_association'] == 'CONTRIBUTOR' || $R['author_association'] == 'OWNER'))
|
||||
$reviews_ids_with_changes_requested[] = $R['id'];
|
||||
}
|
||||
|
||||
if(count($reviews_ids_with_changes_requested) == 0){
|
||||
if($has_label_already)
|
||||
remove_ready_for_review($payload, $labels, $r4rlabel);
|
||||
return; //no need to be here
|
||||
}
|
||||
|
||||
echo count($reviews_ids_with_changes_requested) . ' offending reviews';
|
||||
|
||||
//now get the review comments for the offending reviews
|
||||
|
||||
$review_comments = json_decode(apisend($payload['pull_request']['review_comments_url']), true);
|
||||
|
||||
foreach($review_comments as $C){
|
||||
//make sure they are part of an offending review
|
||||
if(!in_array($C['pull_request_review_id'], $reviews_ids_with_changes_requested))
|
||||
continue;
|
||||
|
||||
//review comments which are outdated have a null position
|
||||
if($C['position'] !== null){
|
||||
if($has_label_already)
|
||||
remove_ready_for_review($payload, $labels, $r4rlabel);
|
||||
return; //no need to tag
|
||||
if(isset($R['author_association'])){
|
||||
$lower_association = strtolower($R['author_association']);
|
||||
if($lower_association == 'member' || $lower_association == 'contributor' || $lower_association == 'owner'){
|
||||
$lowerstate = strtolower($R['state']);
|
||||
if($lower_state == 'changes_requested')
|
||||
$reviews_ids_with_changes_requested[] = $R['id'];
|
||||
else if ($lower_state == 'approved'){
|
||||
dismiss_review($payload, $R['id']);
|
||||
$dismissed_an_approved_review = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$labels[] = $r4rlabel;
|
||||
$url = $payload['pull_request']['issue_url'] . '/labels';
|
||||
apisend($url, 'PUT', $labels);
|
||||
if(!$dismissed_an_approved_review && count($reviews_ids_with_changes_requested) == 0){
|
||||
if($has_label_already)
|
||||
remove_ready_for_review($payload, $labels);
|
||||
return; //no need to be here
|
||||
}
|
||||
|
||||
if(count($reviews_ids_with_changes_requested) > 0){
|
||||
//now get the review comments for the offending reviews
|
||||
|
||||
$review_comments = json_decode(apisend($payload['pull_request']['review_comments_url']), true);
|
||||
|
||||
foreach($review_comments as $C){
|
||||
//make sure they are part of an offending review
|
||||
if(!in_array($C['pull_request_review_id'], $reviews_ids_with_changes_requested))
|
||||
continue;
|
||||
|
||||
//review comments which are outdated have a null position
|
||||
if($C['position'] !== null){
|
||||
if($has_label_already)
|
||||
remove_ready_for_review($payload, $labels);
|
||||
return; //no need to tag
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//finally, add it if necessary
|
||||
if(!$has_label_already){
|
||||
$labels[] = $r4rlabel;
|
||||
$url = $payload['pull_request']['issue_url'] . '/labels';
|
||||
apisend($url, 'PUT', $labels);
|
||||
}
|
||||
}
|
||||
|
||||
function handle_pr($payload) {
|
||||
|
||||
Reference in New Issue
Block a user