-
Notifications
You must be signed in to change notification settings - Fork 20
Add logic to skip files with more than 15000 lines #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a05aceb
Add logic to skip files with more than 15000 lines
ariskataoka a519b8f
Add option skip-large-files
ariskataoka 25de796
Apply automattic indent in the modified test files
ariskataoka 04df222
Add option skip-large-files-limit
ariskataoka 2357612
Add helper for new parameters skip-large-file and limit
ariskataoka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,128 @@ | ||
| <?php | ||
| declare( strict_types=1 ); | ||
|
|
||
| /** | ||
| * Validation applied to verify wether the bot should scan or skip the file specified | ||
| */ | ||
|
|
||
| /** | ||
| * @param string $temp_file_name | ||
| * @param string $file_name | ||
| * @param string $commit_id | ||
| * @param int $max_lines | ||
| * | ||
| * Validates if the file is valid to be scanned by vip-go-ci | ||
| * | ||
| * @return array | ||
| * [ | ||
| * 'issues' => | ||
| * [ | ||
| * 'max-lines' => [$file_name], | ||
| * ], | ||
| * 'total' => 1 | ||
| * ] | ||
| * In a oop we could simply inject a service for caching | ||
| * Vars and set values in the constructor | ||
| */ | ||
| function vipgoci_validate( string $temp_file_name, string $file_name, string $commit_id, int $max_lines ): array { | ||
| $validation_result = array( 'total' => 0 ); | ||
|
|
||
| if ( false === vipgoci_is_number_of_lines_valid( $temp_file_name, $file_name, $commit_id, $max_lines ) ) { | ||
| $validation_result['issues'][ VIPGOCI_VALIDATION_MAXIMUM_LINES ] = [ $file_name ]; | ||
| $validation_result['total'] = count( $validation_result['issues'] ); | ||
| } | ||
|
|
||
| return $validation_result; | ||
| } | ||
|
|
||
| /** | ||
| * @param string $temp_file_name | ||
| * @param string $file_name | ||
| * @param string $commit_id | ||
| * @param int $max_lines | ||
| * | ||
| * @return bool | ||
| */ | ||
| function vipgoci_is_number_of_lines_valid( string $temp_file_name, string $file_name, string $commit_id, int $max_lines ): bool { | ||
| /** | ||
| * Verifies if number of lines validation are in the cache | ||
| * If so, returns the value | ||
| */ | ||
|
|
||
| $cache_key = vipgoci_cache_get_is_number_of_lines_valid_key( $file_name, $commit_id ); | ||
| $is_number_of_lines_valid = vipgoci_cache_get_is_number_of_lines_valid( $cache_key ); | ||
| if ( ! is_null( $is_number_of_lines_valid ) ) { | ||
| return $is_number_of_lines_valid; | ||
| } | ||
|
|
||
| /** | ||
| * Calculates the file number of lines | ||
| * if it is > than the default limit (defined at defined) | ||
| * the bot won't scan it | ||
| */ | ||
| $cmd = sprintf( 'wc -l %s | awk \'{print $1;}\' 2>&1', escapeshellcmd( $temp_file_name ) ); | ||
| vipgoci_log( 'Validating number of lines', array( 'file_name' => $file_name ) ); | ||
|
|
||
| $output = vipgoci_sanitize_string( | ||
| vipgoci_runtime_measure_shell_exec( $cmd, 'file_validation' ) | ||
| ); | ||
|
|
||
| vipgoci_log( | ||
| 'Validation number of lines ', | ||
| array( 'file_name' => $file_name, 'cmd' => $cmd, 'output' => $output ) | ||
| ); | ||
|
|
||
| $is_number_of_lines_valid = vipgoci_verify_number_of_lines_output( $output, $max_lines ); | ||
|
|
||
| vipgoci_cache_set_is_number_of_lines_valid( $cache_key, $is_number_of_lines_valid ); | ||
|
|
||
| return $is_number_of_lines_valid; | ||
| } | ||
|
|
||
| /** | ||
| * @param array $cache_key | ||
| * @param bool $is_number_of_lines_valid | ||
| * | ||
| * Sets cache for converted is_number_of_lines_valid | ||
| */ | ||
| function vipgoci_cache_set_is_number_of_lines_valid( array $cache_key, bool $is_number_of_lines_valid ): void { | ||
| vipgoci_cache( | ||
| $cache_key, | ||
| $is_number_of_lines_valid === true ? 'true' : 'false' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @param string $output | ||
| * @param int $max_lines | ||
| * | ||
| * @return bool | ||
| */ | ||
| function vipgoci_verify_number_of_lines_output( string $output, int $max_lines ): bool { | ||
| return is_numeric( $output ) && $output < $max_lines; | ||
| } | ||
|
|
||
| /** | ||
| * @param array $cache_key | ||
| * | ||
| * Verifies if there's cached validation result available | ||
| * returns it if it does, else returns null | ||
| * | ||
| * @return bool|null | ||
| */ | ||
| function vipgoci_cache_get_is_number_of_lines_valid( array $cache_key ): ?bool { | ||
| $cached_value = vipgoci_cache( $cache_key ); | ||
|
|
||
| return false !== $cached_value ? 'true' === $cached_value : null; | ||
| } | ||
|
|
||
| /** | ||
| * @param string $file_name | ||
| * @param string $commit_id | ||
| * Builds the cache key for the number of lines validation | ||
| * | ||
| * @return array | ||
| */ | ||
| function vipgoci_cache_get_is_number_of_lines_valid_key( string $file_name, string $commit_id ): array { | ||
| return array( __FUNCTION__, $file_name, $commit_id ); | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.