Skip to content

Commit

Permalink
Merge pull request #30 from Automattic/feature-statistics-1
Browse files Browse the repository at this point in the history
More statistics, displaying message conditionally, whitespacing, splitting into multiple files
  • Loading branch information
gudmdharalds authored Dec 5, 2018
2 parents 60744e5 + 7857227 commit f988374
Show file tree
Hide file tree
Showing 9 changed files with 517 additions and 217 deletions.
22 changes: 2 additions & 20 deletions auto-approval.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function vipgoci_auto_approval_non_approval(
vipgoci_runtime_measure( VIPGOCI_RUNTIME_START, 'vipgoci_auto_approval_non_approval' );

vipgoci_counter_report(
'do',
VIPGOCI_COUNTERS_DO,
'github_pr_non_approval',
1
);
Expand Down Expand Up @@ -58,15 +58,6 @@ function vipgoci_auto_approval_non_approval(
true // Send to IRC
);

/*
* Temporary: Just while we test the
* approval-logic.
*/

vipgoci_runtime_measure( VIPGOCI_RUNTIME_STOP, 'vipgoci_auto_approval_non_approval' );

return;


if ( false === $pr_label ) {
vipgoci_log(
Expand Down Expand Up @@ -263,7 +254,7 @@ function vipgoci_autoapproval_do_approve(
vipgoci_runtime_measure( VIPGOCI_RUNTIME_START, 'vipgoci_autoapproval_do_approve' );

vipgoci_counter_report(
'do',
VIPGOCI_COUNTERS_DO,
'github_pr_approval',
1
);
Expand Down Expand Up @@ -311,15 +302,6 @@ function vipgoci_autoapproval_do_approve(
true // Send to IRC
);

/*
* Temporary: Just while we test the
* approval-logic.
*/

vipgoci_runtime_measure( VIPGOCI_RUNTIME_STOP, 'vipgoci_autoapproval_do_approve' );

return;


/*
* Actually approve, if not in dry-mode.
Expand Down
7 changes: 7 additions & 0 deletions defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,10 @@
define( 'VIPGOCI_RUNTIME_START', 'start' );
define( 'VIPGOCI_RUNTIME_STOP', 'stop' );
define( 'VIPGOCI_RUNTIME_DUMP', 'dump' );

/*
* Defines for vipgoci_counter_report()
*/

define( 'VIPGOCI_COUNTERS_DUMP', 'dump' );
define( 'VIPGOCI_COUNTERS_DO', 'do' );
103 changes: 87 additions & 16 deletions github-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,11 @@ function vipgoci_github_post_url(

vipgoci_runtime_measure( VIPGOCI_RUNTIME_START, 'github_api_post' );

vipgoci_counter_report( 'do', 'github_api_request_post', 1 );
vipgoci_counter_report(
VIPGOCI_COUNTERS_DO,
'github_api_request_post',
1
);

$resp_data = curl_exec( $ch );

Expand Down Expand Up @@ -655,7 +659,11 @@ function vipgoci_github_fetch_url(
*/
vipgoci_runtime_measure( VIPGOCI_RUNTIME_START, 'github_api_get' );

vipgoci_counter_report( 'do', 'github_api_request_get', 1 );
vipgoci_counter_report(
VIPGOCI_COUNTERS_DO,
'github_api_request_get',
1
);

$resp_data = curl_exec( $ch );

Expand Down Expand Up @@ -802,7 +810,11 @@ function vipgoci_github_put_url(

vipgoci_runtime_measure( VIPGOCI_RUNTIME_START, 'github_api_put' );

vipgoci_counter_report( 'do', 'github_api_request_put', 1 );
vipgoci_counter_report(
VIPGOCI_COUNTERS_DO,
'github_api_request_put',
1
);

$resp_data = curl_exec( $ch );

Expand Down Expand Up @@ -1186,15 +1198,15 @@ function vipgoci_github_pr_reviews_comments_get(

/*
* Get all review-comments submitted to a
* particular Pull-Request.
* particular Pull-Request.
* Supports filtering by:
* - User submitted (parameter: login)
* - Comment state (parameter: comments_active, true/false)
*
* Note that parameter login can be assigned a magic
* value, 'myself', in which case the actual username
* will be assumed to be that of the token-holder.
*/
function vipgoci_github_pr_reviews_comments_get_by_pr(
$options,
Expand All @@ -1220,7 +1232,7 @@ function vipgoci_github_pr_reviews_comments_get_by_pr(
$cached_data = vipgoci_cache( $cache_id );

vipgoci_log(
'Fetching all review comments submitted to a Pull-Request' .
'Fetching all review comments submitted to a Pull-Request' .
(( $cached_data !== false ) ? ' (cached)' : '' ),
array(
'repo_owner' => $options['repo-owner'],
Expand Down Expand Up @@ -1293,15 +1305,15 @@ function vipgoci_github_pr_reviews_comments_get_by_pr(
continue;
}
}

$all_comments[] = $comment;
}

$page++;
} while( count( $comments ) >= $per_page );

/*
* Cache the results and return
* Cache the results and return
*/
vipgoci_cache( $cache_id, $all_comments );

Expand Down Expand Up @@ -1513,7 +1525,11 @@ function vipgoci_github_pr_generic_comment_submit(
}

else {
$github_postfields['body'] .= "\n\r***\n\r";
$github_postfields['body'] .= "\n\r";

vipgoci_markdown_comment_add_pagebreak(
$github_postfields['body']
);
}


Expand Down Expand Up @@ -1581,7 +1597,11 @@ function vipgoci_github_pr_generic_comment_submit(
"tree/" .
rawurlencode( $commit_id ) .
"))." .
"\n\r***\n\r";
"\n\r";

vipgoci_markdown_comment_add_pagebreak(
$tmp_postfields_body
);

/*
* If we have informational URL, append that
Expand All @@ -1593,7 +1613,11 @@ function vipgoci_github_pr_generic_comment_submit(
VIPGOCI_INFORMATIONAL_MESSAGE,
$informational_url
) .
"\n\r***\n\r";
"\n\r";

vipgoci_markdown_comment_add_pagebreak(
$tmp_postfields_body
);
}

/*
Expand Down Expand Up @@ -1657,7 +1681,11 @@ function vipgoci_github_pr_comments_error_msg(

$message .
" (commit-ID: " . $commit_id . ")" .
"\n\r***\n\r";
"\n\r";

vipgoci_markdown_comment_add_pagebreak(
$github_postfields['body']
);

vipgoci_github_post_url(
$github_url,
Expand Down Expand Up @@ -2110,10 +2138,11 @@ function vipgoci_github_pr_review_submit(
* Add page-breaking, if needed.
*/
if ( ! empty( $github_postfields['body'] ) ) {
$github_postfields['body'] .= '***' . "\n\r";
vipgoci_markdown_comment_add_pagebreak(
$github_postfields['body']
);
}


/*
* Check if this type of scanning
* was skipped, and if so, note it.
Expand All @@ -2132,6 +2161,37 @@ function vipgoci_github_pr_review_submit(
continue;
}


/*
* If the current stat-type has no items
* to report, do not print out anything for
* it saying we found something to report on.
*/

$found_stats_to_ignore = true;

foreach(
$results
['stats']
[ strtolower( $stats_type ) ]
[ $pr_number ] as

$commit_issue_stat_key =>
$commit_issue_stat_value
) {
if ( $commit_issue_stat_value > 0 ) {
$found_stats_to_ignore = false;
}
}

if ( true === $found_stats_to_ignore ) {
// Skipped
continue;
}

unset( $found_stats_to_ignore );


$github_postfields['body'] .=
'**' . $stats_type . '**' .
" scanning turned up:\n\r";
Expand Down Expand Up @@ -2178,7 +2238,14 @@ function vipgoci_github_pr_review_submit(
*/
if ( null !== $informational_url ) {
$github_postfields['body'] .=
"\n\r***\n\r" .
"\n\r";

vipgoci_markdown_comment_add_pagebreak(
$github_postfields['body']
);


$github_postfields['body'] .=
sprintf(
VIPGOCI_INFORMATIONAL_MESSAGE,
$informational_url
Expand Down Expand Up @@ -2367,7 +2434,7 @@ function vipgoci_github_pr_reviews_dismiss_non_active_comments(
/*
* Get all comments to a the current Pull-Request.
*
* Note that we must bypass cache here,
* Note that we must bypass cache here,
*/
$all_comments = vipgoci_github_pr_reviews_comments_get_by_pr(
$options,
Expand Down Expand Up @@ -2456,6 +2523,10 @@ function vipgoci_github_pr_reviews_dismiss_non_active_comments(
/*
* Loop through each review we
* found matching the specific criteria.
*
* Note that implicit in this logic is that
* there must be some comments attached to a
* review so it becomes dismissable at all.
*/
foreach( $pr_reviews as $pr_review ) {
/*
Expand Down
10 changes: 10 additions & 0 deletions lint-scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ function vipgoci_lint_scan_commit(
$file_contents
);

/*
* Keep statistics of what we do.
*/

vipgoci_stats_per_file(
$options,
$filename,
'linted'
);

/*
* Actually lint the file
*/
Expand Down
Loading

0 comments on commit f988374

Please sign in to comment.