Skip to content

Commit

Permalink
Merge branch 'main' into changelog-v1.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
gudmdharalds authored Apr 4, 2022
2 parents 8fb1a82 + 2e693ae commit 66374f4
Show file tree
Hide file tree
Showing 55 changed files with 3,620 additions and 2,155 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ commands:
# Move to project directory
- run: cd ~/project
# Run unit tests
- run: ./vendor/bin/phpunit --testsuite=unit-tests -vv
- run: VIPGOCI_TESTING_DEBUG_MODE=true ./vendor/bin/phpunit --testsuite=unit-tests
# Run integration tests
- run: ./vendor/bin/phpunit --testsuite=integration-tests -vv
- run: VIPGOCI_TESTING_DEBUG_MODE=true ./vendor/bin/phpunit --testsuite=integration-tests
# Run PHPCS, check for PHP compatibility issues
- run: ~/vip-go-ci-tools/phpcs/bin/phpcs --runtime-set 'testVersion' '8.1-' --standard=PHPCompatibility,PHPCompatibilityParagonieRandomCompat,PHPCompatibilityParagonieSodiumCompat --ignore="vendor/*" ~/project

Expand Down
8 changes: 4 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Pull-Requests should have a TODO included. Here are three drafts. Please select
Draft for a patch:

TODO:
- [ ] Add/update unit-tests (if needed)
- [ ] Check automated unit-tests
- [ ] Add/update tests -- unit and/or integrated (if needed)
- [ ] Check status of automated tests
- [ ] Add or update `PHPDoc` comments for new or updated functions (main code only; for VIP)
- [ ] Changelog entry (for VIP)

Expand All @@ -24,12 +24,12 @@ TODO:
- [ ] Specify a parameter to make [feature] configurable
- [ ] Update `--help` message
- [ ] Implement [new feature / logic]
- [ ] Add/update unit-tests
- [ ] Add/update tests -- unit and/or integrated
- [ ] Add or update `PHPDoc` comments for new or updated functions (main code only)
- [ ] Update README
- [ ] Changelog entry
- [ ] Public documentation changes
- [ ] Check automated unit-tests
- [ ] Check status of automated tests

***

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,8 @@ This feature can be used in this fashion:
At this time, only certain messages are posted to IRC, all indicated by a special parameter to the `vipgoci_log()` function. See the code for implementation details.

Using the `VIPGOCI_IRC_IGNORE_STRING_START` and `VIPGOCI_IRC_IGNORE_STRING_END` constants, it is possible to designate parts of strings that should not be logged to the IRC API. Simply place any string not to be logged to IRC between these two constants and it will be filtered away before submisssion. Multiple constants can be used in one log message.


## Updating tools-init.sh with new versions

Expand Down Expand Up @@ -777,15 +779,15 @@ This file is not included, and needs to be configured manually.

The unit test suite can be run using the following command:

> phpunit --testsuite=unit-tests -vv
> VIPGOCI_TESTING_DEBUG_MODE=true phpunit --testsuite=unit-tests
By running this command, you will run the tests that do not depend on external calls.

### Integration test suite

The integration tests can be run using the following command:

> phpunit --testsuite=integration-tests -vv
> VIPGOCI_TESTING_DEBUG_MODE=true phpunit --testsuite=integration-tests
Integration tests will execute the scanning utilities — PHPCS, SVG scanner and PHP Lint — and so paths to these, and a PHP interpreter, need to be configured. See the `unittests.ini` file.

Expand Down
2 changes: 1 addition & 1 deletion ap-hashes-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function vipgoci_ap_hashes_api_file_approved(
*/

$file_hashes_info =
vipgoci_github_fetch_url(
vipgoci_http_api_fetch_url(
$hashes_to_hashes_url,
array(
'oauth_consumer_key' => $options['hashes-oauth-consumer-key'],
Expand Down
24 changes: 22 additions & 2 deletions defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
define( 'VIPGOCI_GITHUB_BASE_URL', 'https://api.github.com' );
}

/*
* Timeout constant for HTTP APIs.
*/
define( 'VIPGOCI_HTTP_API_LONG_TIMEOUT', 20 );
define( 'VIPGOCI_HTTP_API_SHORT_TIMEOUT', 5 );

/*
* Various messages.
*/
Expand Down Expand Up @@ -119,6 +125,20 @@
'The error may be temporary. If the error persists, please contact a human'
);

/*
* Indicates which sections of log
* messages should not be logged to IRC.
*/
define(
'VIPGOCI_IRC_IGNORE_STRING_START',
'<!-- vip-go-ci-irc-ignore-start -->'
);

define(
'VIPGOCI_IRC_IGNORE_STRING_END',
'<!-- vip-go-ci-irc-ignore-end -->'
);

/*
* Define exit-codes
*/
Expand Down Expand Up @@ -169,9 +189,9 @@
define( 'VIPGOCI_CACHE_CLEAR', '--VIPGOCI-CACHE-CLEAR-0x321--' );

/*
* Define for vipgoci_github_wait() function.
* Define for vipgoci_http_api_wait() function.
*/
define( 'VIPGOCI_GITHUB_WAIT_TIME_SECONDS', 2 );
define( 'VIPGOCI_HTTP_API_WAIT_TIME_SECONDS', 2 );

/*
* Defines for files.
Expand Down
12 changes: 9 additions & 3 deletions file-validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,18 @@ function vipgoci_is_number_of_lines_valid( string $temp_file_name, string $file_
* 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 ) );
$cmd = sprintf( 'wc -l %s | awk \'{print $1;}\'', escapeshellcmd( $temp_file_name ) );

$output_2 = '';
$output_res_code = -255;

$output = vipgoci_runtime_measure_shell_exec_with_retry(
$output = vipgoci_runtime_measure_exec_with_retry(
$cmd,
'file_validation'
array( 0 ),
$output_2,
$output_res_code,
'file_validation',
true
);

vipgoci_log(
Expand Down
140 changes: 106 additions & 34 deletions git-repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function vipgoci_git_version(): ?string {
}

$git_version_cmd = sprintf(
'%s %s 2>&1',
'%s %s',
escapeshellcmd( 'git' ),
escapeshellarg( '--version' )
);
Expand All @@ -24,10 +24,19 @@ function vipgoci_git_version(): ?string {
)
);

/* Actually execute */
$git_version_results = vipgoci_runtime_measure_shell_exec_with_retry(
/*
* Actually execute
*/
$git_output = '';
$git_result_code = -255;

$git_version_results = vipgoci_runtime_measure_exec_with_retry(
$git_version_cmd,
'git_cli'
array( 0 ),
$git_output,
$git_result_code,
'git_cli',
false
);

if ( null === $git_version_results ) {
Expand Down Expand Up @@ -120,17 +129,26 @@ function vipgoci_gitrepo_get_head( $local_git_repo ) {
*/

$cmd = sprintf(
'%s -C %s log -n %s --pretty=format:"%s" 2>&1',
'%s -C %s log -n %s --pretty=format:"%s"',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
escapeshellarg( 1 ),
escapeshellarg( '%H' )
);

/* Actually execute */
$result = vipgoci_runtime_measure_shell_exec_with_retry(
/*
* Actually execute
*/
$result_output = '';
$result_code = -255;

$result = vipgoci_runtime_measure_exec_with_retry(
$cmd,
'git_cli'
array( 0 ),
$result_output,
$result_code,
'git_cli',
false
);

if ( null === $result ) {
Expand Down Expand Up @@ -167,15 +185,24 @@ function vipgoci_gitrepo_get_head( $local_git_repo ) {

function vipgoci_gitrepo_branch_current_get( $local_git_repo ) {
$cmd = sprintf(
'%s -C %s branch 2>&1',
'%s -C %s branch',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
);

/* Actually execute */
$results = vipgoci_runtime_measure_shell_exec_with_retry(
/*
* Actually execute
*/
$results_output = '';
$results_result_code = -255;

$results = vipgoci_runtime_measure_exec_with_retry(
$cmd,
'git_cli'
array( 0 ),
$results_output,
$results_result_code,
'git_cli',
true
);

if ( null === $results ) {
Expand Down Expand Up @@ -400,16 +427,25 @@ function vipgoci_gitrepo_blame_for_file(
*/

$cmd = sprintf(
'%s -C %s blame --line-porcelain %s 2>&1',
'%s -C %s blame --line-porcelain %s',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
escapeshellarg( $file_name )
);

/* Actually execute */
$result = vipgoci_runtime_measure_shell_exec_with_retry(
/*
* Actually execute
*/
$result_output = '';
$result_code = -255;

$result = vipgoci_runtime_measure_exec_with_retry(
$cmd,
'git_cli'
array( 0 ),
$result_output,
$result_code,
'git_cli',
true
);

if ( null === $result ) {
Expand Down Expand Up @@ -587,17 +623,26 @@ function vipgoci_gitrepo_get_file_at_commit(
*/

$cmd = sprintf(
'%s -C %s show %s:%s 2>&1',
'%s -C %s show %s:%s',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
escapeshellarg( $commit_id ),
escapeshellarg( $file_name )
);

/* Actually execute */
$result = vipgoci_runtime_measure_shell_exec_with_retry(
/*
* Actually execute
*/
$result_output = '';
$result_code = -255;

$result = vipgoci_runtime_measure_exec_with_retry(
$cmd,
'git_cli'
array( 0, 128 ),
$result_output,
$result_code,
'git_cli',
true
);

if ( null === $result ) {
Expand All @@ -618,8 +663,8 @@ function vipgoci_gitrepo_get_file_at_commit(
* this revision, return null.
*/
if ( strpos(
$result,
'fatal: Path '
strtolower( $result ),
'fatal: path '
) === 0 ) {
return null;
}
Expand All @@ -632,17 +677,26 @@ function vipgoci_gitrepo_get_file_at_commit(
*/
function vipgoci_gitrepo_submodules_setup( $local_git_repo ) {
$cmd = sprintf(
'%s -C %s submodule init && %s -C %s submodule update 2>&1',
'%s -C %s submodule init && %s -C %s submodule update',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo )
);

/* Actually execute */
$result = vipgoci_runtime_measure_shell_exec_with_retry(
/*
* Actually execute
*/
$result_output = '';
$result_code = -255;

$result = vipgoci_runtime_measure_exec_with_retry(
$cmd,
'git_cli'
array( 0 ),
$result_output,
$result_code,
'git_cli',
true
);

if ( null === $result ) {
Expand Down Expand Up @@ -681,15 +735,24 @@ function vipgoci_gitrepo_submodules_list( $local_git_repo ) {
*/

$cmd = sprintf(
'%s -C %s submodule 2>&1',
'%s -C %s submodule',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
);

/* Actually execute */
$result = vipgoci_runtime_measure_shell_exec_with_retry(
/*
* Actually execute
*/
$result_output = '';
$result_code = -255;

$result = vipgoci_runtime_measure_exec_with_retry(
$cmd,
'git_cli'
array( 0 ),
$result_output,
$result_code,
'git_cli',
true
);

if ( null === $result ) {
Expand Down Expand Up @@ -920,7 +983,7 @@ function vipgoci_gitrepo_diffs_fetch_unfiltered(
* as that is what GitHub uses: https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-comparing-branches-in-pull-requests#three-dot-and-two-dot-git-diff-comparisons
*/
$git_diff_cmd = sprintf(
'%s -C %s diff %s 2>&1',
'%s -C %s diff %s',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
escapeshellarg( $commit_id_a . '...'. $commit_id_b )
Expand All @@ -933,10 +996,19 @@ function vipgoci_gitrepo_diffs_fetch_unfiltered(
)
);

/* Actually execute */
$git_diff_results = vipgoci_runtime_measure_shell_exec_with_retry(
/*
* Actually execute.
*/
$git_diff_results_output = '';
$git_diff_results_code = -255;

$git_diff_results = vipgoci_runtime_measure_exec_with_retry(
$git_diff_cmd,
'git_cli'
array( 0 ),
$git_diff_results_output,
$git_diff_results_code,
'git_cli',
true
);

if ( null === $git_diff_results ) {
Expand Down
Loading

0 comments on commit 66374f4

Please sign in to comment.