-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Automattic/feature-vip-hashes-api
hashes-to-hashes database API integration
- Loading branch information
Showing
14 changed files
with
3,935 additions
and
449 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
/* | ||
* Process all files in the PRs | ||
* involved with the commit specified. | ||
* | ||
* This function will add to an array | ||
* of auto-approvable files any files that | ||
* fit the criteria of having certain file-endings. | ||
* The allowable file-endings are specifiable | ||
* via the command-line. | ||
* | ||
* Note that the --skip-folders argument is ignored | ||
* in this function. | ||
*/ | ||
|
||
function vipgoci_ap_file_types( | ||
$options, | ||
&$auto_approved_files_arr | ||
) { | ||
|
||
vipgoci_runtime_measure( VIPGOCI_RUNTIME_START, 'ap_file_types' ); | ||
|
||
vipgoci_log( | ||
'Doing auto-approval scanning based on file-types', | ||
array( | ||
'repo_owner' => $options['repo-owner'], | ||
'repo_name' => $options['repo-name'], | ||
'commit_id' => $options['commit'], | ||
'autoapprove' => $options['autoapprove'], | ||
|
||
'autoapprove-filetypes' => | ||
$options['autoapprove-filetypes'], | ||
) | ||
); | ||
|
||
|
||
$prs_implicated = vipgoci_github_prs_implicated( | ||
$options['repo-owner'], | ||
$options['repo-name'], | ||
$options['commit'], | ||
$options['token'], | ||
$options['branches-ignore'] | ||
); | ||
|
||
|
||
foreach ( $prs_implicated as $pr_item ) { | ||
$pr_diff = vipgoci_github_diffs_fetch( | ||
$options['repo-owner'], | ||
$options['repo-name'], | ||
$options['token'], | ||
$pr_item->base->sha, | ||
$options['commit'], | ||
true | ||
); | ||
|
||
|
||
foreach ( $pr_diff as | ||
$pr_diff_file_name => $pr_diff_contents | ||
) { | ||
/* | ||
* If the file is already in the array | ||
* of approved files, do not do anything. | ||
*/ | ||
if ( isset( | ||
$auto_approved_files_arr[ | ||
$pr_diff_file_name | ||
] | ||
) ) { | ||
continue; | ||
} | ||
|
||
$pr_diff_file_extension = vipgoci_file_extension( | ||
$pr_diff_file_name | ||
); | ||
|
||
/* | ||
* Check if the extension of the file | ||
* is in a list of auto-approvable | ||
* file extensions. | ||
*/ | ||
if ( in_array( | ||
$pr_diff_file_extension, | ||
$options['autoapprove-filetypes'], | ||
true | ||
) ) { | ||
$auto_approved_files_arr[ | ||
$pr_diff_file_name | ||
] = 'autoapprove-filetypes'; | ||
} | ||
} | ||
} | ||
|
||
/* | ||
* Reduce memory-usage as possible | ||
*/ | ||
unset( $prs_implicated ); | ||
unset( $pr_diff ); | ||
unset( $pr_item ); | ||
unset( $pr_diff_file_extension ); | ||
unset( $pr_diff_file_name ); | ||
|
||
gc_collect_cycles(); | ||
|
||
vipgoci_runtime_measure( VIPGOCI_RUNTIME_STOP, 'ap_file_types' ); | ||
} | ||
|
Oops, something went wrong.