From 8e6786f6a42d1225b602e69154caf5afaca93e5f Mon Sep 17 00:00:00 2001 From: r0ps3c <15878019+r0ps3c@users.noreply.github.com> Date: Thu, 19 Nov 2020 17:47:41 -0500 Subject: [PATCH] feat(api): add workaround allowing job resubmission (#241) 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. --- coveralls/api.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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()