Skip to content

Commit

Permalink
Merge branch 'trunk' into update/vipgoci-run-file
Browse files Browse the repository at this point in the history
  • Loading branch information
gudmdharalds authored Jan 30, 2023
2 parents b8a35ed + ee323ae commit 7808985
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ TODO:
- [ ] Add to, or update, `Scan run detail` report as applicable
- [ ] Add/update tests -- unit and/or integrated
- [ ] Ensure `PHPDoc` comments are up to date for functions added or altered
- [ ] Update README
- [ ] Update repository documentation (README.md, RELEASING.md, TESTING.md, TOOLS-UPDATE.md)
- [ ] Changelog entry (for VIP)
- [ ] Public documentation changes
- [ ] Check status of automated tests
Expand Down
2 changes: 1 addition & 1 deletion TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export DISMISSED_REVIEWS_EXCLUDE_REVIEWS_FROM_TEAM=""

Ensure to populate the relevant fields with your own values.

3) Create the pull requests needed in the forked repository on GitHub. Re-create the same pull requests as found [here](https://github.com/gudmdharalds-a8c/vip-go-ci-manual-testing/pulls), refering to the same branch names.
3) Create the pull requests needed in the forked repository on GitHub. Use the [create-all-pull-requests.sh](tests/manual/create-all-pull-requests.sh) script to create all the pull requests needed. Note that the pull requests will need to be created by a user _different_ from the one that runs the tests in the next step. This is because GitHub does not allow [_changing_ reviews](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/reviewing-proposed-changes-in-a-pull-request#submitting-your-review) to be posted to one's own pull requests.

### Running tests

Expand Down
79 changes: 69 additions & 10 deletions cli-utils/create-pull-requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

define( 'VIPGOCI_INCLUDED', true );

// Extra long time to avoid secondary rate limits.
define( 'VIPGOCI_HTTP_API_WAIT_TIME_SECONDS', 10 );

/**
* Ask the GitHub HTTP API to create pull requests specified.
*
Expand All @@ -26,6 +29,34 @@ function crprs_create_pull_requests(
array &$pr_items_failed
) :void {
foreach ( $pr_items as $pr_item ) {
if ( ! isset(
$pr_item['title'],
$pr_item['body'],
$pr_item['head'],
$pr_item['base'],
) ) {
// phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
vipgoci_log(
'Missing field for pull request item, not creating',
array(
'title' => @$pr_item['title'],
'body' => @$pr_item['body'],
'head' => @$pr_item['head'],
'base' => @$pr_item['base'],
)
);
// phpcs:enable WordPress.PHP.NoSilencedErrors.Discouraged

continue;
}

vipgoci_log(
'Creating pull request',
array(
'pr_item' => $pr_item,
)
);

$ret = vipgoci_http_api_post_url(
'https://api.github.com/repos/' .
rawurlencode( $options['repo-owner'] ) . '/' .
Expand All @@ -47,12 +78,14 @@ function crprs_create_pull_requests(
'pr_item' => $pr_item,
)
);
}

$pr_items_failed[] = $pr_item;

// Try to avoid secondary rate limit errors.
sleep( 5 );
$pr_items_failed[] = $pr_item;
} else {
vipgoci_log(
'Creation successful',
array()
);
}
}
}

Expand Down Expand Up @@ -129,13 +162,12 @@ function crprs_main() {
"\t" . '--repo-owner=STRING Specify repository owner, can be an organization.' . PHP_EOL .
"\t" . '--repo-name=STRING Specify name of the repository.' . PHP_EOL .
"\t" . '--github-token=STRING The access-token to use to communicate with GitHub.' . PHP_EOL .
PHP_EOL .
"\t" . '--pull-requests=STRING Specify pull requests to create. Expects JSON format. For example:' . PHP_EOL .
"\t" . ' [{"title":"test branch","body":"Test pull request","head":"testing1","base":"main"},{...}]' . PHP_EOL .
PHP_EOL .
"\t" . '--env-options=STRING Specifies configuration options to be read from environmental' . PHP_EOL .
"\t" . ' variables -- any variable can be specified. For example:' . PHP_EOL .
"\t" . ' --env-options="repo-owner=U_ROWNER,output=U_FOUTPUT"' . PHP_EOL .
"\t" . ' --env-options="repo-owner=U_REPO_OWNER,repo-name=U_REPO_NAME"' . PHP_EOL .
PHP_EOL .
"\t" . '--help Prints this message.' . PHP_EOL .
PHP_EOL .
Expand All @@ -149,7 +181,15 @@ function crprs_main() {
true
);

$pr_items_failed = array();
if ( null === $options['pull-requests'] ) {
vipgoci_sysexit(
'Unable to JSON decode --pull-requests option value',
array()
);
}

$pr_items_failed = array();
$pr_items_failed2 = array();

crprs_create_pull_requests(
$options,
Expand All @@ -159,9 +199,14 @@ function crprs_main() {

// Try failed items again.
if ( ! empty( $pr_items_failed ) ) {
sleep( 10 );
vipgoci_log(
'Retrying creation of pull requests that could not be created earlier',
array(
'pr_items_failed' => $pr_items_failed,
)
);

$pr_items_failed2 = array();
sleep( 15 );

crprs_create_pull_requests(
$options,
Expand All @@ -170,6 +215,20 @@ function crprs_main() {
);
}

if ( ! empty( $pr_items_failed2 ) ) {
vipgoci_log(
'Failed creating pull requests, not retrying',
array(
'pr_items_failed' => $pr_items_failed2,
)
);
} else {
vipgoci_log(
'Completed processing',
array()
);
}

exit( 0 );
}

Expand Down
2 changes: 1 addition & 1 deletion wp-core-misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ function vipgoci_wpcore_misc_determine_local_slug(
);

/*
* Only return "local" slug including directory if there are one or more
* Only return "local" slug including directory if there are two or more
* directories in path, but not when last directory name includes certain
* names that will result in bogus results.
*/
Expand Down

0 comments on commit 7808985

Please sign in to comment.