Skip to content

Commit

Permalink
Merge pull request Automattic#100 from Automattic/feature-sort-issue-…
Browse files Browse the repository at this point in the history
…comments

Add support for sorting according to severity
  • Loading branch information
gudmdharalds authored Jun 23, 2020
2 parents 62d619f + cf98ebe commit a2a9499
Show file tree
Hide file tree
Showing 4 changed files with 422 additions and 0 deletions.
16 changes: 16 additions & 0 deletions github-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -2215,6 +2215,22 @@ function vipgoci_github_pr_review_submit(
return;
}

/*
* Reverse results before starting processing,
* so that results are shown in correct order
* after posting.
*/

foreach (
array_keys(
$results['issues']
) as $pr_number
) {
$results['issues'][ $pr_number ] = array_reverse(
$results['issues'][ $pr_number ]
);
}

foreach (
// The $results array is keyed by Pull-Request number
array_keys(
Expand Down
68 changes: 68 additions & 0 deletions misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,74 @@ function vipgoci_issues_filter_duplicate( $file_issues_arr ) {
return $file_issues_arr_new;
}

/*
* Sort results to be submitted to GitHub according to
* severity of issues -- if configured to do so:
*/
function vipgoci_results_sort_by_severity(
$options,
&$results
) {

if ( true !== $options['results-comments-sort'] ) {
return;
}

vipgoci_log(
'Sorting issues in results according to severity before submission',
array(
)
);


foreach(
array_keys(
$results['issues']
) as $pr_number
) {
$current_pr_results = &$results['issues'][ $pr_number ];

/*
* Temporarily add severity
* column so we can sort using that.
*/
foreach(
array_keys( $current_pr_results ) as
$current_pr_result_item_key
) {
$current_pr_results[ $current_pr_result_item_key ][ 'severity'] =
$current_pr_results[ $current_pr_result_item_key ]['issue']['severity'];
}

/*
* Do the actual sorting.
*/
$severity_column = array_column(
$current_pr_results,
'severity'
);

array_multisort(
$severity_column,
SORT_DESC,
$current_pr_results
);

/*
* Remove severity column
* afterwards.
*/
foreach(
array_keys( $current_pr_results ) as
$current_pr_result_item_key
) {
unset(
$current_pr_results[ $current_pr_result_item_key ][ 'severity']
);
}
}
}


/*
* Add pagebreak to a Markdown-style comment
Expand Down
Loading

0 comments on commit a2a9499

Please sign in to comment.