diff options
author | Teddy Wing | 2018-04-19 00:13:25 +0200 |
---|---|---|
committer | Teddy Wing | 2018-04-19 00:18:59 +0200 |
commit | c1d64dc4e0a1328107c05bb952133c0ca70b6e1c (patch) | |
tree | 83cab4298b4f9a64caf6d25e4a5cccc74cbc63fe | |
parent | ca360a1ea65f6e01de2f99a279ecd8d312c412ab (diff) | |
download | redprine-c1d64dc4e0a1328107c05bb952133c0ca70b6e1c.tar.bz2 |
update_redmine_status(): Print error if Redmine request fails
We want the program to error if the update fails, because that's kind of
the whole point.
Thanks to 'pvandenberk' for the explanation of how to get the HTTP
status code from Curl:
https://superuser.com/questions/272265/getting-curl-to-output-http-status-code/442395#442395
$ curl -s -o /dev/null -w "%{http_code}" http://www.example.org/
$ curl -s -o /dev/null -I -w "%{http_code}" http://www.example.org/
The error information isn't really enough (we only print the status
code, not a real error message from Redmine), but I'm letting it slide
for laziness.
Now that we're exiting from the program on a Redmine error, it means the
cache won't get updated with successful Redmine updated PRs. We need a
way to only store successfully updated issue PRs to the cache file at
the end of the run.
-rwxr-xr-x | redprine | 27 |
1 files changed, 15 insertions, 12 deletions
@@ -146,18 +146,21 @@ function update_redmine_status () { } }" - curl \ - --verbose \ - --header 'Content-Type: application/json' \ - --header "X-Redmine-API-Key: $REDMINE_TOKEN" \ - --request PUT \ - --data "$json" \ - --location "${REDMINE_BASE_URL}/issues/${issue_id}.json" - - # Output an error message if the request fails - # https://superuser.com/questions/272265/getting-curl-to-output-http-status-code/442395#442395 - # curl -s -o /dev/null -w "%{http_code}" http://www.example.org/ - # curl -s -o /dev/null -I -w "%{http_code}" http://www.example.org/ + local status_code=$( + curl \ + --output /dev/null \ + --head \ + --write-out '%{http_code}' \ + --header 'Content-Type: application/json' \ + --header "X-Redmine-API-Key: $REDMINE_TOKEN" \ + --request PUT \ + --data "$json" \ + --location "${REDMINE_BASE_URL}/issues/${issue_id}.json" + ) + + if [ "$status_code" != '200' ]; then + exit_with_error "Redmine API error, status code $status_code" + fi } # Updates the cache file appending new pull requests in our JSON format. |