Skip to content

Commit

Permalink
Merge pull request #153 from Automattic/use-git-diffs
Browse files Browse the repository at this point in the history
Use local git repository to get git diffs
  • Loading branch information
gudmdharalds authored Apr 23, 2021
2 parents 20ba591 + 6d7b58d commit 61f087f
Show file tree
Hide file tree
Showing 24 changed files with 1,774 additions and 300 deletions.
1 change: 1 addition & 0 deletions .vipgoci_options
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"phpcs-severity":1,"skip-draft-prs":false,"phpcs-sniffs-include":["Generic.PHP.DisallowShortOpenTag", "Squiz.PHP.DiscouragedFunctions", "Squiz.PHP.CommentedOutCode"]}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This program comes with a small utility, `tools-init.sh`, that will install PHPC

* `vip-go-ci` requires PHP 7.3 or later. PHP 7.4 is preferred.
* Linux is recommended as a platform for `vip-go-ci`.
* git version 2.10 or later.

### On the console, standalone

Expand Down
8 changes: 3 additions & 5 deletions ap-file-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ function vipgoci_ap_file_types(


foreach ( $prs_implicated as $pr_item ) {
$pr_diff = vipgoci_github_diffs_fetch(
$options['repo-owner'],
$options['repo-name'],
$options['token'],
$pr_diff = vipgoci_gitrepo_diffs_fetch(
$options['local-git-repo'],
$pr_item->base->sha,
$options['commit'],
true, // renamed files included
Expand All @@ -63,7 +61,7 @@ function vipgoci_ap_file_types(
* them (if their file-type is auto-approvable).
*/

foreach ( $pr_diff as
foreach ( $pr_diff['files'] as
$pr_diff_file_name => $pr_diff_contents
) {
/*
Expand Down
8 changes: 3 additions & 5 deletions ap-hashes-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,8 @@ function vipgoci_ap_hashes_api_scan_commit(
* stability, there could be removal of vital
* files, and permission changes might be dangerous.
*/
$pr_diff = vipgoci_github_diffs_fetch(
$options['repo-owner'],
$options['repo-name'],
$options['token'],
$pr_diff = vipgoci_gitrepo_diffs_fetch(
$options['local-git-repo'],
$pr_item->base->sha,
$options['commit'],
false, // exclude renamed files
Expand All @@ -311,7 +309,7 @@ function vipgoci_ap_hashes_api_scan_commit(
);


foreach( $pr_diff as
foreach( $pr_diff['files'] as
$pr_diff_file_name => $pr_diff_contents
) {
/*
Expand Down
8 changes: 3 additions & 5 deletions ap-nonfunctional-changes.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ function vipgoci_ap_nonfunctional_changes(


foreach ( $prs_implicated as $pr_item ) {
$pr_diff = vipgoci_github_diffs_fetch(
$options['repo-owner'],
$options['repo-name'],
$options['token'],
$pr_diff = vipgoci_gitrepo_diffs_fetch(
$options['local-git-repo'],
$pr_item->base->sha,
$options['commit'],
true, // renamed files included
Expand All @@ -58,7 +56,7 @@ function vipgoci_ap_nonfunctional_changes(
* modified.
*/

foreach ( $pr_diff as
foreach ( $pr_diff['files'] as
$pr_diff_file_name => $pr_diff_contents
) {
/*
Expand Down
8 changes: 3 additions & 5 deletions ap-svg-files.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ function vipgoci_ap_svg_files(


foreach ( $prs_implicated as $pr_item ) {
$pr_diff = vipgoci_github_diffs_fetch(
$options['repo-owner'],
$options['repo-name'],
$options['token'],
$pr_diff = vipgoci_gitrepo_diffs_fetch(
$options['local-git-repo'],
$pr_item->base->sha,
$options['commit'],
true, // include renamed files
Expand All @@ -51,7 +49,7 @@ function vipgoci_ap_svg_files(
);


foreach ( $pr_diff as
foreach ( $pr_diff['files'] as
$pr_diff_file_name => $pr_diff_contents
) {
$pr_diff_file_extension = vipgoci_file_extension_get(
Expand Down
10 changes: 4 additions & 6 deletions auto-approval.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,8 @@ function vipgoci_auto_approval_scan_commit(


foreach ( $prs_implicated as $pr_item ) {
$pr_diff = vipgoci_github_diffs_fetch(
$options['repo-owner'],
$options['repo-name'],
$options['token'],
$pr_diff = vipgoci_gitrepo_diffs_fetch(
$options['local-git-repo'],
$pr_item->base->sha,
$options['commit'],
true, // include renamed files
Expand All @@ -557,7 +555,7 @@ function vipgoci_auto_approval_scan_commit(
* altered by the Pull-Request, look for
* files that can be auto-approved.
*/
foreach( $pr_diff as
foreach( $pr_diff['files'] as
$pr_diff_file_name => $pr_diff_contents
) {

Expand Down Expand Up @@ -630,7 +628,7 @@ function vipgoci_auto_approval_scan_commit(
$pr_label,
$auto_approved_files_arr,
$files_seen,
array_keys( $pr_diff )
array_keys( $pr_diff['files'] )
);
}

Expand Down
15 changes: 15 additions & 0 deletions defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

define( 'VIPGOCI_VERSION', '0.50' );

/*
* Define minimum version requirements.
*/
define( 'VIPGOCI_GIT_VERSION_MINIMUM', '2.10' );

/*
* Client-ID for curl-requests, etc.
*/
Expand All @@ -20,6 +25,10 @@
define( 'VIPGOCI_GITHUB_BASE_URL', 'https://api.github.com' );
}

/*
* Various messages.
*/

define( 'VIPGOCI_INFORMATIONAL_MESSAGE',
'This bot provides automated ' .
'PHP Linting and PHPCS scanning, ' .
Expand Down Expand Up @@ -121,3 +130,9 @@
*/

define( 'VIPGOCI_OPTIONS_FILE_NAME', '.vipgoci_options' );

/*
* Define for vipgoci_gitrepo_diffs_fetch()
*/

define( 'VIPGOCI_GIT_DIFF_CALC_CHANGES', array ('+' => 'additions', '-' => 'deletions') );
Loading

0 comments on commit 61f087f

Please sign in to comment.