-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notify after deployment failure #595
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7caed85
notify after failure
AronNovak 1aa57dd
add to the template too
AronNovak 1161730
Apply suggestions from code review
AronNovak 68157d2
Update ci-scripts/notify_after_failure.sh
AronNovak 2cf79d3
use repo slug variable
AronNovak 95fddbf
Merge remote-tracking branch 'origin/585-gizra-notifier-after-failure…
AronNovak dcfb0a2
address pr review comment
AronNovak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
# Get the commit message from the environment variable or from git | ||
git_commit_message=${TRAVIS_COMMIT_MESSAGE:-$(git log -1 --pretty=%B)} | ||
|
||
# Initialize issue_number variable | ||
issue_number="" | ||
|
||
# Try to extract the issue number from the commit message. | ||
issue_matches=() | ||
if [[ $git_commit_message =~ from\ [a-zA-Z-_0-9]+/([0-9]+) ]]; then | ||
issue_matches=("${BASH_REMATCH[@]}") | ||
issue_number=${issue_matches[1]} | ||
else | ||
# Check for PR number in the format (#1234) | ||
if [[ $git_commit_message =~ \(\#([0-9]+)\) ]]; then | ||
pr_number=${BASH_REMATCH[1]} | ||
|
||
# Retrieve PR information from GitHub API | ||
pr_info=$(curl -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/$TRAVIS_REPO_SLUG/pulls/$pr_number") | ||
|
||
# Extract issue number from PR body | ||
if [[ $pr_info =~ \#([0-9]+) ]]; then | ||
issue_number=${BASH_REMATCH[1]} | ||
else | ||
echo "Could not determine the issue number from the PR description." | ||
exit 1 | ||
fi | ||
else | ||
echo "Could not determine the issue or PR number from the commit message: $git_commit_message" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
# Check if the script should notify | ||
if [ "$TRAVIS_BRANCH" == "main" ] && [ "$TRAVIS_EVENT_TYPE" == "push" ] && [ -z "$TRAVIS_TAG" ] && [ -n "$issue_number" ]; then | ||
message="Could not deploy the last PR to Pantheon properly." | ||
github_api_url="https://api.github.com/repos/$TRAVIS_REPO_SLUG/issues/$issue_number/comments" | ||
|
||
exit_code=$(curl -X POST -H "Authorization: token $GITHUB_TOKEN" -d "{\"body\": \"$message\"}" "$github_api_url" -o /dev/null -w '%{http_code}') | ||
|
||
if [ "$exit_code" -ne 200 ] && [ "$exit_code" -ne 201 ]; then | ||
echo "Failed to post the message to GitHub. HTTP response code: $exit_code" | ||
exit 1 | ||
fi | ||
else | ||
echo "Notification conditions not met or issue number not found. No action taken." | ||
fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AronNovak Should we include the PR number in this message?