From 4db8eff7a8dcd902d9700ffc7f2711769451eea5 Mon Sep 17 00:00:00 2001 From: r0ps3c Date: Fri, 13 Nov 2020 08:48:50 -0500 Subject: [PATCH 1/2] Add workaround allowing resubmission 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 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/coveralls/api.py b/coveralls/api.py index 73d51166..77db8226 100644 --- a/coveralls/api.py +++ b/coveralls/api.py @@ -3,6 +3,8 @@ import logging import os import re +import random +import sys import coverage import requests @@ -202,6 +204,19 @@ 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() From a10246262f907a23b4dbfe614dbb01efc5bc02a3 Mon Sep 17 00:00:00 2001 From: r0ps3c Date: Sun, 15 Nov 2020 11:22:46 -0500 Subject: [PATCH 2/2] Lint changes --- coveralls/api.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/coveralls/api.py b/coveralls/api.py index 77db8226..f6d54e89 100644 --- a/coveralls/api.py +++ b/coveralls/api.py @@ -2,8 +2,8 @@ import json import logging import os -import re import random +import re import sys import coverage @@ -208,14 +208,16 @@ def wear(self, dry_run=False): # 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)) + 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'])) + print('resubmitting with id {}'.format( + self.config['service_job_id'])) response = requests.post(endpoint, files={'json_file': self.create_report()}, - verify=verify) + verify=verify) try: response.raise_for_status()