Skip to content

Commit

Permalink
Merge pull request #20 from Automattic/feature-vip-hashes-api
Browse files Browse the repository at this point in the history
hashes-to-hashes database API integration
  • Loading branch information
gudmdharalds authored Nov 20, 2018
2 parents fd52987 + f8124a1 commit 60744e5
Show file tree
Hide file tree
Showing 14 changed files with 3,935 additions and 449 deletions.
107 changes: 107 additions & 0 deletions ap-file-types.php
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' );
}

Loading

0 comments on commit 60744e5

Please sign in to comment.