forked from Automattic/vip-go-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ap-file-types.php
90 lines (80 loc) · 2.16 KB
/
ap-file-types.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* Auto-approve based on file-types.
*
* @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 files that
* fit the criteria of having certain file-endings.
* The allowable file-endings are specifiable
* via the command-line.
*
* @param array $options Options needed.
* @param array $auto_approved_files_arr Array of auto-approved files.
*/
function vipgoci_ap_file_types(
array $options,
array &$auto_approved_files_arr
) :void {
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'],
)
);
$commit_skipped_files = array();
$pr_item_files_changed = vipgoci_github_files_affected_by_commit(
$options,
$options['commit'],
$commit_skipped_files,
true, // Renamed files included.
true, // Removed files included.
true, // Permission changes included.
null
);
/*
* Loop through files renamed, removed, had
* permissions changed, or content modified
* -- and auto-approve them if their file-type
* is auto-approvable.
*/
foreach ( $pr_item_files_changed['all'] as $pr_diff_file_name ) {
/*
* 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_get(
$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';
}
}
vipgoci_runtime_measure( VIPGOCI_RUNTIME_STOP, 'ap_file_types' );
}