Skip to content

Commit

Permalink
feat(api): add workaround allowing job resubmission (#241)
Browse files Browse the repository at this point in the history
As the commit/other information doesn't change when performing a
rebuild, resubmissions will fail with an HTTP 422 error. This adds a
workaround for such cases, appending a random value to the id and
attempting a resubmission with that.
  • Loading branch information
r0ps3c committed Nov 19, 2020
1 parent 6c8639c commit 0de0c01
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions coveralls/api.py
Expand Up @@ -2,7 +2,9 @@
import json
import logging
import os
import random
import re
import sys

import coverage
import requests
Expand Down Expand Up @@ -202,6 +204,21 @@ def wear(self, dry_run=False):
verify = not bool(os.environ.get('COVERALLS_SKIP_SSL_VERIFY'))
response = requests.post(endpoint, files={'json_file': json_string},
verify=verify)

# check and adjust/resubmit if submission looks like it
# failed due to resubmission (non-unique)
if response.status_code == 422:
self.config['service_job_id'] = '{}-{}'.format(
self.config['service_job_id'], random.randint(0, sys.maxsize))

# ensure create_report uses updated data
self._data = None

print('resubmitting with id {}'.format(
self.config['service_job_id']))
response = requests.post(endpoint, files={'json_file': self.create_report()},
verify=verify)

try:
response.raise_for_status()
return response.json()
Expand Down

0 comments on commit 0de0c01

Please sign in to comment.