Skip to content

Instantly share code, notes, and snippets.

@thomaspoignant
Last active December 2, 2020 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomaspoignant/7d75d4cf0d71b4b3dff9bdcb2e4b4ca1 to your computer and use it in GitHub Desktop.
Save thomaspoignant/7d75d4cf0d71b4b3dff9bdcb2e4b4ca1 to your computer and use it in GitHub Desktop.
function open_pull_requests() {
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
STAGES=( dev pre pro )
for STAGE in "${STAGES[@]}"; do
# Run CDK diff
cdk diff -c stage=${STAGE} | tee cdk_diff_${STAGE}.txt
# Prepare PR message
read -r -d '' MESSAGE <<-EOM
> :warning: **Please review this changes before merging.**
**This PR will apply these changes(\`cdk diff\`):**
\`\`\`console
$(cat cdk_diff_${STAGE}.txt)
\`\`\`
EOM
set +e
CMD_MESSAGE_OUTPUT=$(gh pr create --title "Update $STAGE environment." --body "$MESSAGE" --base "$STAGE" --head "$TRAVIS_BRANCH" 2>&1)
CMD_RES=$?
set -e
if [ $CMD_RES -ne 0 ]; then
if [[ "$CMD_MESSAGE_OUTPUT" == *"already exists"* ]]; then
echo "A PR is already opened. Skip opening a new one."
else
travis_terminate 1
fi
fi
done
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment