diff --git a/coveralls/api.py b/coveralls/api.py index 73d51166..f6d54e89 100644 --- a/coveralls/api.py +++ b/coveralls/api.py @@ -2,7 +2,9 @@ import json import logging import os +import random import re +import sys import coverage import requests @@ -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()