mirror of
https://github.com/SPLURT-Station/S.P.L.U.R.T-Station-13.git
synced 2025-12-10 01:49:19 +00:00
Contributors can add the ready tag to their own prs (#32062)
* Contributors can add the ready tag * Webhook synchronize case pushes update at the end * Fixes pr not getting tagged when opened
This commit is contained in:
committed by
CitadelStationBot
parent
56c534fa62
commit
a7cd317dae
@@ -172,6 +172,23 @@ function check_tag_and_replace($payload, $title_tag, $label, &$array_to_add_labe
|
||||
return false;
|
||||
}
|
||||
|
||||
function set_labels($payload, $labels, $remove) {
|
||||
$existing = get_labels($payload);
|
||||
|
||||
$tags = array();
|
||||
|
||||
$tags = array_merge($labels, $existing);
|
||||
$tags = array_unique($tags);
|
||||
$tags = array_diff($tags, $remove);
|
||||
|
||||
$final = array();
|
||||
foreach($tags as $t)
|
||||
$final[] = $t;
|
||||
|
||||
$url = $payload['pull_request']['issue_url'] . '/labels';
|
||||
echo apisend($url, 'PUT', $final);
|
||||
}
|
||||
|
||||
//rip bs-12
|
||||
function tag_pr($payload, $opened) {
|
||||
//get the mergeable state
|
||||
@@ -215,31 +232,16 @@ 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);
|
||||
if(!check_tag_and_replace($payload, '[wip]', 'Work In Progress', $tags) && check_tag_and_replace($payload, '[ready]', 'Work In Progress', $remove))
|
||||
$tags[] = 'Needs Review';
|
||||
|
||||
$url = $payload['pull_request']['issue_url'] . '/labels';
|
||||
|
||||
$existing = get_labels($payload);
|
||||
|
||||
$tags = array_merge($tags, $existing);
|
||||
$tags = array_unique($tags);
|
||||
$tags = array_diff($tags, $remove);
|
||||
|
||||
$final = array();
|
||||
foreach($tags as $t)
|
||||
$final[] = $t;
|
||||
|
||||
|
||||
echo apisend($url, 'PUT', $final);
|
||||
|
||||
return $final;
|
||||
return array($tags, $remove);
|
||||
}
|
||||
|
||||
function remove_ready_for_review($payload, $labels = null){
|
||||
if($labels == null)
|
||||
$labels = get_labels($payload);
|
||||
$index = array_search('Review Again', $labels);
|
||||
$index = array_search('Needs Review', $labels);
|
||||
if($index !== FALSE)
|
||||
unset($labels[$index]);
|
||||
$url = $payload['pull_request']['issue_url'] . '/labels';
|
||||
@@ -255,13 +257,14 @@ function get_reviews($payload){
|
||||
return json_decode(apisend($payload['pull_request']['url'] . '/reviews'), true);
|
||||
}
|
||||
|
||||
function check_ready_for_review($payload, $labels = null){
|
||||
$r4rlabel = 'Review Again';
|
||||
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))
|
||||
@@ -271,8 +274,8 @@ function check_ready_for_review($payload, $labels = null){
|
||||
}
|
||||
|
||||
if($has_label_already && $should_not_have_label){
|
||||
remove_ready_for_review($payload, $labels, $r4rlabel);
|
||||
return;
|
||||
$remove[] = $r4rlabel;
|
||||
return $returned;
|
||||
}
|
||||
|
||||
//find all reviews to see if changes were requested at some point
|
||||
@@ -294,8 +297,8 @@ function check_ready_for_review($payload, $labels = null){
|
||||
|
||||
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
|
||||
$remove[] = $r4rlabel;
|
||||
return $returned; //no need to be here
|
||||
}
|
||||
|
||||
if(count($reviews_ids_with_changes_requested) > 0){
|
||||
@@ -311,8 +314,8 @@ function check_ready_for_review($payload, $labels = null){
|
||||
//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
|
||||
$remove[] = $r4rlabel;
|
||||
return $returned; //no need to tag
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -320,9 +323,8 @@ function check_ready_for_review($payload, $labels = null){
|
||||
//finally, add it if necessary
|
||||
if(!$has_label_already){
|
||||
$labels[] = $r4rlabel;
|
||||
$url = $payload['pull_request']['issue_url'] . '/labels';
|
||||
apisend($url, 'PUT', $labels);
|
||||
}
|
||||
return $returned;
|
||||
}
|
||||
|
||||
function check_dismiss_changelog_review($payload){
|
||||
@@ -359,7 +361,8 @@ function handle_pr($payload) {
|
||||
$validated = validate_user($payload);
|
||||
switch ($payload["action"]) {
|
||||
case 'opened':
|
||||
tag_pr($payload, true);
|
||||
list($labels, $remove) = tag_pr($payload, true);
|
||||
set_labels($payload, $labels, $remove);
|
||||
if($no_changelog)
|
||||
check_dismiss_changelog_review($payload);
|
||||
if(get_pr_code_friendliness($payload) < 0){
|
||||
@@ -372,9 +375,10 @@ function handle_pr($payload) {
|
||||
case 'edited':
|
||||
check_dismiss_changelog_review($payload);
|
||||
case 'synchronize':
|
||||
$labels = tag_pr($payload, false);
|
||||
list($labels, $remove) = tag_pr($payload, false);
|
||||
if($payload['action'] == 'synchronize')
|
||||
check_ready_for_review($payload, $labels);
|
||||
list($labels, $remove) = check_ready_for_review($payload, $labels, $remove);
|
||||
set_labels($payload, $labels, $remove);
|
||||
return;
|
||||
case 'reopened':
|
||||
$action = $payload['action'];
|
||||
|
||||
Reference in New Issue
Block a user