From 2b1164bf43ef0f3e5006af42bfdc48255fff8390 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Tue, 11 Apr 2017 06:16:41 -0400 Subject: [PATCH] get_refs: Gather tags consolidating both "refs" and "refs/tags" In practice, we observed that tags can be listed with "refs", "refs/tags" or both. --- CHANGES.md | 12 ++++++++++++ github_release.py | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 2f355ae..ed2d057 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,15 @@ +Next release +============ + +Features (CLI and Python API) +----------------------------- + +* ``ref`` command: + + * ``list``: Consolidate tags listing using [refs and refs/tags](https://developer.github.com/v3/git/refs/#get-all-references) + endpoints. In practice, we observed that tags can be listed with one or the other. + + 1.5.3 ===== diff --git a/github_release.py b/github_release.py index c0eb4c8..ee9aa55 100755 --- a/github_release.py +++ b/github_release.py @@ -877,10 +877,25 @@ def get_refs(repo_name, tags=None, pattern=None): # If "tags" is True, keep only "refs/tags/*" data = response.json() if tags: + tag_names = [] data = [] for ref in response.json(): if ref['ref'].startswith("refs/tags"): data.append(ref) + tag_names.append(ref["ref"]) + + try: + response = _request( + 'GET', + GITHUB_API + '/repos/{0}/git/refs/tags'.format(repo_name)) + response.raise_for_status() + for ref in response.json(): + if ref["ref"] not in tag_names: + data.append(ref) + except requests.exceptions.HTTPError as exc_info: + response = exc_info.response + if response.status_code != 404: + raise # If "pattern" is not None, select only matching references filtered_data = data