Add logging to the GH action for assigning a milestone to merged PRs

If the GH API call to assign the milestone to a merged PR returns an
error, the data returned from the call will be dumped to the console,
and thus will be readable by looking at the action execution log.
This commit is contained in:
Nestor Soriano 2021-07-28 15:20:16 +02:00 committed by And Finally
parent ddc767c81f
commit 53f66a2cb7
1 changed files with 15 additions and 4 deletions

View File

@ -99,7 +99,7 @@ if ( getenv( 'DRY_RUN' ) ) {
* Assign the milestone to the pull request.
*/
echo "Assigning the milestone to the pull request...\n";
echo 'Assigning the milestone to the pull request... ';
$milestone_id = $chosen_milestone['id'];
$mutation = "
@ -108,14 +108,25 @@ $mutation = "
}
";
do_graphql_api_request( $mutation, true );
$result = do_graphql_api_request( $mutation, true );
if ( is_array( $result ) ) {
if ( empty( $result['errors'] ) ) {
echo "Ok!\n";
} else {
echo "\n*** Errors found while assigning the milestone:\n";
echo var_dump( $result['errors'] );
}
} else {
echo "\n*** Error found while assigning the milestone: file_get_contents returned the following:\n";
echo var_dump( $result );
}
/**
* Function to query the GitHub GraphQL API.
*
* @param string $body The GraphQL-formatted request body, without "query" or "mutation" wrapper.
* @param bool $is_mutation True if the request is a mutation, false if it's a query.
* @return array The json-decoded response.
* @return mixed The json-decoded response if a response is received, 'false' (or whatever file_get_contents returns) otherwise.
*/
function do_graphql_api_request( $body, $is_mutation = false ) {
global $github_token, $graphql_api_url;
@ -138,7 +149,7 @@ function do_graphql_api_request( $body, $is_mutation = false ) {
);
$result = file_get_contents( $graphql_api_url, false, $context );
return json_decode( $result, true );
return is_string( $result ) ? json_decode( $result, true ) : $result;
}
// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.WP.AlternativeFunctions