Skip to content
This repository has been archived by the owner on Nov 11, 2019. It is now read-only.

Commit

Permalink
shipit_uplift: Use .format instead of % (#868)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-v authored and marco-c committed Feb 28, 2018
1 parent 036c473 commit a56c2a4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
24 changes: 12 additions & 12 deletions src/shipit_uplift/shipit_uplift/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@lru_cache(maxsize=2048)
def get_github_commit(mercurial_commit):
r = requests.get('https://api.pub.build.mozilla.org/mapper/gecko-dev/rev/hg/%s' % mercurial_commit)
r = requests.get('https://api.pub.build.mozilla.org/mapper/gecko-dev/rev/hg/{}'.format(mercurial_commit))
return r.text.split(' ')[0]


Expand Down Expand Up @@ -50,7 +50,7 @@ class CoverallsCoverage(Coverage):
@staticmethod
@lru_cache(maxsize=2048)
def get_coverage(changeset):
r = requests.get(CoverallsCoverage.URL + '/builds/%s.json' % get_github_commit(changeset))
r = requests.get(CoverallsCoverage.URL + '/builds/{}.json'.format(get_github_commit(changeset)))

if r.status_code != requests.codes.ok:
raise CoverageException('Error while loading coverage data.')
Expand All @@ -64,7 +64,7 @@ def get_coverage(changeset):

@staticmethod
def get_file_coverage(changeset, filename):
r = requests.get(CoverallsCoverage.URL + '/builds/%s/source.json' % get_github_commit(changeset), params={
r = requests.get(CoverallsCoverage.URL + '/builds/{}/source.json'.format(get_github_commit(changeset)), params={
'filename': filename,
})

Expand Down Expand Up @@ -100,12 +100,12 @@ def get_directory_coverage(changeset, prev_changeset, directory):
class CodecovCoverage(Coverage):
@staticmethod
def _get(url=''):
return requests.get('https://codecov.io/api/gh/marco-c/gecko-dev%s?access_token=%s' % (url, secrets.CODECOV_ACCESS_TOKEN))
return requests.get('https://codecov.io/api/gh/marco-c/gecko-dev{}?access_token={}'.format(url, secrets.CODECOV_ACCESS_TOKEN))

@staticmethod
@lru_cache(maxsize=2048)
def get_coverage(changeset):
r = CodecovCoverage._get('/commit/%s' % get_github_commit(changeset))
r = CodecovCoverage._get('/commit/{}'.format(get_github_commit(changeset)))

if r.status_code != requests.codes.ok:
raise CoverageException('Error while loading coverage data.')
Expand All @@ -119,18 +119,18 @@ def get_coverage(changeset):

@staticmethod
def get_file_coverage(changeset, filename):
r = CodecovCoverage._get('/src/%s/%s' % (get_github_commit(changeset), filename))
r = CodecovCoverage._get('/src/{}/{}'.format(get_github_commit(changeset), filename))

try:
data = r.json()
except Exception as e:
raise CoverageException('Can\'t parse codecov.io report for %s@%s (response: %s)' % (filename, changeset, r.text))
raise CoverageException('Can\'t parse codecov.io report for {}@{} (response: {})'.format(filename, changeset, r.text))

if r.status_code != requests.codes.ok:
if data['error']['reason'] == 'File not found in report':
return None

raise CoverageException('Can\'t load codecov.io report for %s@%s (response: %s)' % (filename, changeset, r.text))
raise CoverageException('Can\'t load codecov.io report for {}@{} (response: {})'.format(filename, changeset, r.text))

return dict([(int(l), v) for l, v in data['commit']['report']['files'][filename]['l'].items()])

Expand All @@ -144,14 +144,14 @@ def get_latest_build():
@staticmethod
@lru_cache(maxsize=2048)
def get_directory_coverage(changeset, prev_changeset, directory):
r = CodecovCoverage._get('/tree/%s/%s' % (get_github_commit(changeset), directory))
r = CodecovCoverage._get('/tree/{}/{}'.format(get_github_commit(changeset), directory))

if r.status_code != requests.codes.ok:
raise CoverageException('Error while loading coverage data.')

cur_result = r.json()

r = CodecovCoverage._get('/tree/%s/%s' % (get_github_commit(prev_changeset), directory))
r = CodecovCoverage._get('/tree/{}/{}'.format(get_github_commit(prev_changeset), directory))

if r.status_code != requests.codes.ok:
raise CoverageException('Error while loading coverage data.')
Expand Down Expand Up @@ -225,7 +225,7 @@ def get_directory_coverage(changeset, prev_changeset, directory):


def get_pushes(push_id):
r = requests.get('https://hg.mozilla.org/mozilla-central/json-pushes?version=2&full=1&startID=%s&endID=%s' % (push_id - 1, push_id + 7))
r = requests.get('https://hg.mozilla.org/mozilla-central/json-pushes?version=2&full=1&startID={}&endID={}'.format(push_id - 1, push_id + 7))
data = r.json()

for pushid, pushdata in data['pushes'].items():
Expand Down Expand Up @@ -261,7 +261,7 @@ def get_pushes_changesets(push_id, push_id_end):

def get_changeset_data(changeset):
if changeset[:12] not in changeset_cache:
r = requests.get('https://hg.mozilla.org/mozilla-central/json-rev/%s' % changeset)
r = requests.get('https://hg.mozilla.org/mozilla-central/json-rev/{}'.format(changeset))
rev = r.json()
push_id = int(rev['pushid'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def retrieve_coverage(path):

# Use hg annotate to report lines in their correct positions and to avoid
# reporting lines that have been modified by a successive patch in the same push.
r = requests.get('https://hg.mozilla.org/mozilla-central/json-annotate/%s/%s' % (build_changeset, path))
r = requests.get('https://hg.mozilla.org/mozilla-central/json-annotate/{}/{}'.format(build_changeset, path))
data = r.json()
if 'not found in manifest' in data:
# The file was removed.
Expand Down
4 changes: 2 additions & 2 deletions src/shipit_uplift/shipit_uplift/coverage_by_dir_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@


def get_mercurial_commit(github_commit):
url = 'https://api.pub.build.mozilla.org/mapper/gecko-dev/rev/git/%s'
r = requests.get(url % github_commit)
url = 'https://api.pub.build.mozilla.org/mapper/gecko-dev/rev/git/{}'
r = requests.get(url.format(github_commit))

return r.text.split(' ')[1]

Expand Down

0 comments on commit a56c2a4

Please sign in to comment.