From 294f0362610d2dd10ff9b9114ec3e42364bd4d73 Mon Sep 17 00:00:00 2001 From: Drew De Ponte Date: Thu, 19 Oct 2023 00:23:40 -0400 Subject: [PATCH] Improve example request_review_post_sync hook Improve example request_review_post_sync hook so that it handles a failure case better and so that it lets the user know more about what is going on. Signed-off-by: Drew De Ponte --- .../request_review_post_sync-github-cli-example | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/example_hooks/request_review_post_sync-github-cli-example b/example_hooks/request_review_post_sync-github-cli-example index 99008cf..c344163 100755 --- a/example_hooks/request_review_post_sync-github-cli-example +++ b/example_hooks/request_review_post_sync-github-cli-example @@ -21,9 +21,16 @@ patch_stack_upstream_remote_url=$4 # string of the patch stack's remote url gh pr -R "$patch_stack_upstream_remote_url" view $patch_upstream_branch_name if [ $? -eq 0 ]; then + echo "gh pr -R \"$patch_stack_upstream_remote_url\" view $patch_upstream_branch_name succeded" + closed=$(gh pr -R "$patch_stack_upstream_remote_url" view $patch_upstream_branch_name --json closed --jq '.closed') - if [ $closed != "true" ]; then - exit 0 + if [ $? -eq 0 ]; then + echo "gh pr -R \"$patch_stack_upstream_remote_url\" view $patch_upstream_branch_name --json closed --jq '.closed' succeded" + echo "closed=$closed" + if [ $closed != "true" ]; then + echo "An open PR was found for the branch, so exiting to prevent duplicate PR creation." + exit 0 + fi fi fi