mirror of
https://github.com/yogstation13/Yogstation.git
synced 2025-02-26 09:04:50 +00:00
Update Ready for Review when a review comment is created
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,21 @@ 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){
|
||||
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){
|
||||
@@ -239,13 +254,16 @@ function check_ready_for_review($payload, $labels){
|
||||
$reviews_ids_with_changes_requested = array();
|
||||
|
||||
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(strtolower($R['state']) == 'changes_requested' && isset($R['author_association'])){
|
||||
$lower_association = strtolower($R['author_association']);
|
||||
if($lower_association == 'member' || $lower_association == 'contributor' || $lower_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);
|
||||
remove_ready_for_review($payload, $labels);
|
||||
return; //no need to be here
|
||||
}
|
||||
|
||||
@@ -263,7 +281,7 @@ function check_ready_for_review($payload, $labels){
|
||||
//review comments which are outdated have a null position
|
||||
if($C['position'] !== null){
|
||||
if($has_label_already)
|
||||
remove_ready_for_review($payload, $labels, $r4rlabel);
|
||||
remove_ready_for_review($payload, $labels);
|
||||
return; //no need to tag
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user