mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-11 18:22:14 +00:00
[MIRROR] Use draft pull requests instead of the 'Work In Progress' and 'Needs Review' labels. (#2728)
* Use draft pull requests instead of the 'Work In Progress' and 'Needs Review' labels. (#56168) * Use draft pull requests instead of the 'Work In Progress' and 'Needs Review' labels. Co-authored-by: Jordan Brown <Cyberboss@users.noreply.github.com>
This commit is contained in:
@@ -262,8 +262,6 @@ function tag_pr($payload, $opened) {
|
||||
$tags[] = $tag;
|
||||
|
||||
check_tag_and_replace($payload, '[dnm]', 'Do Not Merge', $tags);
|
||||
if(!check_tag_and_replace($payload, '[wip]', 'Work In Progress', $tags) && check_tag_and_replace($payload, '[ready]', 'Work In Progress', $remove))
|
||||
$tags[] = 'Needs Review';
|
||||
|
||||
return array($tags, $remove);
|
||||
}
|
||||
@@ -287,81 +285,11 @@ function get_reviews($payload){
|
||||
return json_decode(github_apisend($payload['pull_request']['url'] . '/reviews'), true);
|
||||
}
|
||||
|
||||
function check_ready_for_review($payload, $labels = null, $remove = array()){
|
||||
$r4rlabel = 'Needs Review';
|
||||
$labels_which_should_not_be_ready = array('Do Not Merge', 'Work In Progress', 'Merge Conflict');
|
||||
$has_label_already = false;
|
||||
$should_not_have_label = false;
|
||||
if($labels == null)
|
||||
$labels = get_labels($payload);
|
||||
$returned = array($labels, $remove);
|
||||
//if the label is already there we may need to remove it
|
||||
foreach($labels as $L){
|
||||
if(in_array($L, $labels_which_should_not_be_ready))
|
||||
$should_not_have_label = true;
|
||||
if($L == $r4rlabel)
|
||||
$has_label_already = true;
|
||||
}
|
||||
|
||||
if($has_label_already && $should_not_have_label){
|
||||
$remove[] = $r4rlabel;
|
||||
return $returned;
|
||||
}
|
||||
|
||||
//find all reviews to see if changes were requested at some point
|
||||
$reviews = get_reviews($payload);
|
||||
|
||||
$reviews_ids_with_changes_requested = array();
|
||||
$dismissed_an_approved_review = false;
|
||||
|
||||
foreach($reviews as $R)
|
||||
if(is_maintainer($payload, $R['user']['login'])){
|
||||
$lower_state = 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'], 'Out of date review');
|
||||
$dismissed_an_approved_review = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$dismissed_an_approved_review && count($reviews_ids_with_changes_requested) == 0){
|
||||
if($has_label_already)
|
||||
$remove[] = $r4rlabel;
|
||||
return $returned; //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(github_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[] = $r4rlabel;
|
||||
return $returned; //no need to tag
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//finally, add it if necessary
|
||||
if(!$has_label_already){
|
||||
$labels[] = $r4rlabel;
|
||||
}
|
||||
return $returned;
|
||||
}
|
||||
|
||||
function check_dismiss_changelog_review($payload){
|
||||
global $require_changelog;
|
||||
global $require_changelogs;
|
||||
global $no_changelog;
|
||||
|
||||
if(!$require_changelog)
|
||||
if(!$require_changelogs)
|
||||
return;
|
||||
|
||||
if(!$no_changelog)
|
||||
@@ -406,8 +334,6 @@ function handle_pr($payload) {
|
||||
check_dismiss_changelog_review($payload);
|
||||
case 'synchronize':
|
||||
list($labels, $remove) = tag_pr($payload, false);
|
||||
if($payload['action'] == 'synchronize')
|
||||
list($labels, $remove) = check_ready_for_review($payload, $labels, $remove);
|
||||
set_labels($payload, $labels, $remove);
|
||||
return;
|
||||
case 'reopened':
|
||||
|
||||
Reference in New Issue
Block a user