Skip to content

Commit

Permalink
Apply WP CS
Browse files Browse the repository at this point in the history
  • Loading branch information
gudmdharalds committed Feb 16, 2022
1 parent 5cd657b commit 8b16a30
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions ap-nonfunctional-changes.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
<?php
/**
* Auto-approve PHP files that
* only have non-functional changes.
*
* @package Automattic/vip-go-ci
*/

declare(strict_types=1);

/*
/**
* Process all files in the PRs
* involved with the commit specified.
*
* This function will add to an array
* of auto-approvable files any PHP files that
* contain no material, functional changes -- only
* changes in whitespacing, comments, etc.
*
* @param array $options Options needed.
* @param array $auto_approved_files_arr Auto approved files array.
*
* @return void
*/

function vipgoci_ap_nonfunctional_changes(
$options,
&$auto_approved_files_arr
) {
array $options,
array &$auto_approved_files_arr
) :void {

vipgoci_runtime_measure( VIPGOCI_RUNTIME_START, 'ap_nonfunctional_changes' );

vipgoci_log(
'Doing auto-approval of PHP files with non-functional changes',
array(
'repo_owner' => $options['repo-owner'],
'repo_name' => $options['repo-name'],
'commit_id' => $options['commit'],
'autoapprove' => $options['autoapprove'],
'repo_owner' => $options['repo-owner'],
'repo_name' => $options['repo-name'],
'commit_id' => $options['commit'],
'autoapprove' => $options['autoapprove'],
)
);


$prs_implicated = vipgoci_github_prs_implicated(
$options['repo-owner'],
$options['repo-name'],
Expand All @@ -37,7 +48,6 @@ function vipgoci_ap_nonfunctional_changes(
$options['skip-draft-prs']
);


foreach ( $prs_implicated as $pr_item ) {
$pr_diff = vipgoci_git_diffs_fetch(
$options['local-git-repo'],
Expand All @@ -46,9 +56,9 @@ function vipgoci_ap_nonfunctional_changes(
$options['token'],
$pr_item->base->sha,
$options['commit'],
true, // renamed files included
true, // removed files included
true, // permission changes included
true, // Renamed files included.
true, // Removed files included.
true, // Permission changes included.
null
);

Expand All @@ -67,9 +77,7 @@ function vipgoci_ap_nonfunctional_changes(
* of approved files, do not do anything.
*/
if ( isset(
$auto_approved_files_arr[
$pr_diff_file_name
]
$auto_approved_files_arr[ $pr_diff_file_name ]
) ) {
continue;
}
Expand Down Expand Up @@ -114,9 +122,9 @@ function vipgoci_ap_nonfunctional_changes(
vipgoci_log(
'Skipping PHP file ("old version"), as it could not be fetched from git-repository',
array(
'pr_base_sha' => $pr_item->base->sha,
'pr_diff_file_name' => $pr_diff_file_name,
'local_git_repo' => $options['local-git-repo'],
'pr_base_sha' => $pr_item->base->sha,
'pr_diff_file_name' => $pr_diff_file_name,
'local_git_repo' => $options['local-git-repo'],
)
);

Expand Down Expand Up @@ -155,16 +163,15 @@ function vipgoci_ap_nonfunctional_changes(
vipgoci_log(
'Skipping PHP file ("new version"), as it could not be fetched from git-repository',
array(
'commit' => $options['commit'],
'pr_diff_file_name' => $pr_diff_file_name,
'local_git_repo' => $options['local-git-repo'],
'commit' => $options['commit'],
'pr_diff_file_name' => $pr_diff_file_name,
'local_git_repo' => $options['local-git-repo'],
)
);

continue;
}


$tmp_file_new = vipgoci_save_temp_file(
$pr_diff_file_name,
null,
Expand All @@ -182,33 +189,26 @@ function vipgoci_ap_nonfunctional_changes(
* all whitespacing changes.
*/
if (
sha1( php_strip_whitespace(
$tmp_file_old
) )
sha1( php_strip_whitespace( $tmp_file_old ) )
===
sha1( php_strip_whitespace(
$tmp_file_new
) )
sha1( php_strip_whitespace( $tmp_file_new ) )
) {
$log_msg = 'File is indeed functionally the same, autoapproving';

$auto_approved_files_arr[
$pr_diff_file_name
] = 'autoapprove-nonfunctional-changes';
}

else {
$auto_approved_files_arr[ $pr_diff_file_name ]
= 'autoapprove-nonfunctional-changes';
} else {
$log_msg = 'File is not functionally the same, not autoapproving';
}

vipgoci_log(
$log_msg,
array(
'repo_owner' => $options['repo-owner'],
'repo_name' => $options['repo-name'],
'autoapprove' => $options['autoapprove'],
'commit_id' => $options['commit'],
'file_name' => $pr_diff_file_name,
'repo_owner' => $options['repo-owner'],
'repo_name' => $options['repo-name'],
'autoapprove' => $options['autoapprove'],
'commit_id' => $options['commit'],
'file_name' => $pr_diff_file_name,
)
);

Expand Down

0 comments on commit 8b16a30

Please sign in to comment.