-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
[#1065] Fixed failing GitHub notifications. #1361
Merged
+186
−23
Merged
Changes from all commits
Commits
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
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 |
---|---|---|
|
@@ -118,7 +118,7 @@ load _helper.bash | |
declare -a STEPS=( | ||
"Started dispatching notifications." | ||
"Started GitHub notification for pre_deployment event." | ||
"@curl -X POST -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments -d {\"ref\":\"mybranch\", \"environment\": \"PR\", \"auto_merge\": false} # {\"id\": \"${app_id}\", \"othervar\": \"54321\"}" | ||
"@curl -X POST -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments -d {\"ref\":\"existingbranch\", \"environment\": \"PR\", \"auto_merge\": false} # {\"id\": \"${app_id}\", \"othervar\": \"54321\"}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replacing to use |
||
"Marked deployment as started." | ||
"Finished GitHub notification for pre_deployment event." | ||
"Finished dispatching notifications." | ||
|
@@ -130,7 +130,7 @@ load _helper.bash | |
export DREVOPS_NOTIFY_EVENT="pre_deployment" | ||
export DREVOPS_NOTIFY_GITHUB_TOKEN="token12345" | ||
export DREVOPS_NOTIFY_REPOSITORY="myorg/myrepo" | ||
export DREVOPS_NOTIFY_REF="mybranch" | ||
export DREVOPS_NOTIFY_BRANCH="existingbranch" | ||
run ./scripts/drevops/notify.sh | ||
assert_success | ||
|
||
|
@@ -139,6 +139,62 @@ load _helper.bash | |
popd >/dev/null || exit 1 | ||
} | ||
|
||
@test "Notify: github, pre_deployment, longer ID" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
|
||
app_id="12345678987" | ||
|
||
declare -a STEPS=( | ||
"Started dispatching notifications." | ||
"Started GitHub notification for pre_deployment event." | ||
"@curl -X POST -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments -d {\"ref\":\"existingbranch\", \"environment\": \"PR\", \"auto_merge\": false} # {\"id\": \"${app_id}\", \"othervar\": \"54321\"}" | ||
"Marked deployment as started." | ||
"Finished GitHub notification for pre_deployment event." | ||
"Finished dispatching notifications." | ||
) | ||
|
||
mocks="$(run_steps "setup")" | ||
|
||
export DREVOPS_NOTIFY_CHANNELS="github" | ||
export DREVOPS_NOTIFY_EVENT="pre_deployment" | ||
export DREVOPS_NOTIFY_GITHUB_TOKEN="token12345" | ||
export DREVOPS_NOTIFY_REPOSITORY="myorg/myrepo" | ||
export DREVOPS_NOTIFY_BRANCH="existingbranch" | ||
run ./scripts/drevops/notify.sh | ||
assert_success | ||
|
||
run_steps "assert" "${mocks[@]}" | ||
|
||
popd >/dev/null || exit 1 | ||
} | ||
|
||
@test "Notify: github, pre_deployment, failure" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
|
||
declare -a STEPS=( | ||
"Started dispatching notifications." | ||
"Started GitHub notification for pre_deployment event." | ||
"@curl -X POST -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments -d {\"ref\":\"nonexistingbranch\", \"environment\": \"PR\", \"auto_merge\": false} # {\"message\": \"No ref found for: nonexistingbranch\",\"documentation_url\": \"https://docs.github.com/rest/deployments/deployments#create-a-deployment\",\"status\": \"422\"}" | ||
"Failed to get a deployment ID for a pre_deployment operation. Payload:" | ||
"Wait for GitHub checks to finish and try again." | ||
"-Marked deployment as finished." | ||
) | ||
|
||
mocks="$(run_steps "setup")" | ||
|
||
export DREVOPS_NOTIFY_CHANNELS="github" | ||
export DREVOPS_NOTIFY_EVENT="pre_deployment" | ||
export DREVOPS_NOTIFY_GITHUB_TOKEN="token12345" | ||
export DREVOPS_NOTIFY_REPOSITORY="myorg/myrepo" | ||
export DREVOPS_NOTIFY_BRANCH="nonexistingbranch" | ||
run ./scripts/drevops/notify.sh | ||
assert_failure | ||
|
||
run_steps "assert" "${mocks[@]}" | ||
|
||
popd >/dev/null || exit 1 | ||
} | ||
|
||
@test "Notify: github, post_deployment" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
|
||
|
@@ -148,8 +204,39 @@ load _helper.bash | |
declare -a STEPS=( | ||
"Started dispatching notifications." | ||
"Started GitHub notification for post_deployment event." | ||
"@curl -X GET -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments?ref=mybranch # [{\"id\": \"${app_id}\", \"othervar\": \"54321\"},{\"id\": \"98765432101\", \"othervar\": \"12345\"}]" | ||
"@curl -X POST -H Accept: application/vnd.github.v3+json -H Authorization: token token12345 https://api.github.com/repos/myorg/myrepo/deployments/123456789/statuses -s -d {\"state\":\"success\", \"environment_url\": \"https://develop.testproject.com\"} # {\"state\": \"success\", \"othervar\": \"54321\"}" | ||
"@curl -X GET -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments?ref=existingbranch # [{\"id\": \"${app_id}\", \"othervar\": \"54321\"},{\"id\": \"98765432101\", \"othervar\": \"12345\"}]" | ||
"@curl -X POST -H Accept: application/vnd.github.v3+json -H Authorization: token token12345 https://api.github.com/repos/myorg/myrepo/deployments/${app_id}/statuses -s -d {\"state\":\"success\", \"environment_url\": \"https://develop.testproject.com\"} # {\"state\": \"success\", \"othervar\": \"54321\"}" | ||
"Marked deployment as finished." | ||
"Finished GitHub notification for post_deployment event." | ||
"Finished dispatching notifications." | ||
) | ||
mocks="$(run_steps "setup")" | ||
|
||
export DREVOPS_NOTIFY_CHANNELS="github" | ||
export DREVOPS_NOTIFY_EVENT="post_deployment" | ||
export DREVOPS_NOTIFY_GITHUB_TOKEN="token12345" | ||
export DREVOPS_NOTIFY_REPOSITORY="myorg/myrepo" | ||
export DREVOPS_NOTIFY_BRANCH="existingbranch" | ||
export DREVOPS_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" | ||
run ./scripts/drevops/notify.sh | ||
assert_success | ||
|
||
run_steps "assert" "${mocks[@]}" | ||
|
||
popd >/dev/null || exit 1 | ||
} | ||
|
||
@test "Notify: github, post_deployment, longer ID" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
|
||
app_id="12345678987" | ||
mock_curl=$(mock_command "curl") | ||
|
||
declare -a STEPS=( | ||
"Started dispatching notifications." | ||
"Started GitHub notification for post_deployment event." | ||
"@curl -X GET -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments?ref=existingbranch # [{\"id\": \"${app_id}\", \"othervar\": \"54321\"},{\"id\": \"98765432101\", \"othervar\": \"12345\"}]" | ||
"@curl -X POST -H Accept: application/vnd.github.v3+json -H Authorization: token token12345 https://api.github.com/repos/myorg/myrepo/deployments/${app_id}/statuses -s -d {\"state\":\"success\", \"environment_url\": \"https://develop.testproject.com\"} # {\"state\": \"success\", \"othervar\": \"54321\"}" | ||
"Marked deployment as finished." | ||
"Finished GitHub notification for post_deployment event." | ||
"Finished dispatching notifications." | ||
|
@@ -160,7 +247,7 @@ load _helper.bash | |
export DREVOPS_NOTIFY_EVENT="post_deployment" | ||
export DREVOPS_NOTIFY_GITHUB_TOKEN="token12345" | ||
export DREVOPS_NOTIFY_REPOSITORY="myorg/myrepo" | ||
export DREVOPS_NOTIFY_REF="mybranch" | ||
export DREVOPS_NOTIFY_BRANCH="existingbranch" | ||
export DREVOPS_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" | ||
run ./scripts/drevops/notify.sh | ||
assert_success | ||
|
@@ -170,6 +257,65 @@ load _helper.bash | |
popd >/dev/null || exit 1 | ||
} | ||
|
||
@test "Notify: github, post_deployment, failure to get id" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
|
||
mock_curl=$(mock_command "curl") | ||
|
||
declare -a STEPS=( | ||
"Started dispatching notifications." | ||
"Started GitHub notification for post_deployment event." | ||
"@curl -X GET -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments?ref=nonexistingbranch # []" | ||
"Failed to get a deployment ID for a post_deployment operation. Payload:" | ||
"Check that a pre_deployment notification was dispatched." | ||
"-Marked deployment as finished." | ||
) | ||
mocks="$(run_steps "setup")" | ||
|
||
export DREVOPS_NOTIFY_CHANNELS="github" | ||
export DREVOPS_NOTIFY_EVENT="post_deployment" | ||
export DREVOPS_NOTIFY_GITHUB_TOKEN="token12345" | ||
export DREVOPS_NOTIFY_REPOSITORY="myorg/myrepo" | ||
export DREVOPS_NOTIFY_BRANCH="nonexistingbranch" | ||
export DREVOPS_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" | ||
run ./scripts/drevops/notify.sh | ||
assert_failure | ||
|
||
run_steps "assert" "${mocks[@]}" | ||
|
||
popd >/dev/null || exit 1 | ||
} | ||
|
||
@test "Notify: github, post_deployment, failure to set status" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
|
||
app_id="12345678987" | ||
mock_curl=$(mock_command "curl") | ||
|
||
declare -a STEPS=( | ||
"Started dispatching notifications." | ||
"Started GitHub notification for post_deployment event." | ||
"@curl -X GET -H Authorization: token token12345 -H Accept: application/vnd.github.v3+json -s https://api.github.com/repos/myorg/myrepo/deployments?ref=existingbranch # [{\"id\": \"${app_id}\", \"othervar\": \"54321\"},{\"id\": \"98765432101\", \"othervar\": \"12345\"}]" | ||
"@curl -X POST -H Accept: application/vnd.github.v3+json -H Authorization: token token12345 https://api.github.com/repos/myorg/myrepo/deployments/${app_id}/statuses -s -d {\"state\":\"success\", \"environment_url\": \"https://develop.testproject.com\"} # {\"state\": \"notsuccess\", \"othervar\": \"54321\"}" | ||
"Previous deployment was found, but was unable to update the deployment status. Payload:" | ||
"-Marked deployment as finished." | ||
) | ||
mocks="$(run_steps "setup")" | ||
|
||
export DREVOPS_NOTIFY_CHANNELS="github" | ||
export DREVOPS_NOTIFY_EVENT="post_deployment" | ||
export DREVOPS_NOTIFY_GITHUB_TOKEN="token12345" | ||
export DREVOPS_NOTIFY_REPOSITORY="myorg/myrepo" | ||
export DREVOPS_NOTIFY_BRANCH="existingbranch" | ||
export DREVOPS_NOTIFY_ENVIRONMENT_URL="https://develop.testproject.com" | ||
run ./scripts/drevops/notify.sh | ||
assert_failure | ||
|
||
run_steps "assert" "${mocks[@]}" | ||
|
||
popd >/dev/null || exit 1 | ||
} | ||
|
||
@test "Notify: jira" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
|
||
|
@@ -215,7 +361,7 @@ load _helper.bash | |
popd >/dev/null || exit 1 | ||
} | ||
|
||
@test "Notify: webhook success" { | ||
@test "Notify: webhook" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
|
||
mock_curl=$(mock_command "curl") | ||
|
@@ -245,7 +391,7 @@ load _helper.bash | |
popd >/dev/null || exit 1 | ||
} | ||
|
||
@test "Notify: webhook failure" { | ||
@test "Notify: webhook, failure" { | ||
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 | ||
|
||
mock_curl=$(mock_command "curl") | ||
|
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
Oops, something went wrong.
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.
do not fail the deployment if the notifications fail