Skip to content

Commit 83af0ff

Browse files
authored
Merge pull request #30 from j0057/improve-get_refs
get_refs: Gather tags consolidating both "refs" and "refs/tags"
2 parents b7bdea4 + 2b1164b commit 83af0ff

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

CHANGES.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
Next release
2+
============
3+
4+
Features (CLI and Python API)
5+
-----------------------------
6+
7+
* ``ref`` command:
8+
9+
* ``list``: Consolidate tags listing using [refs and refs/tags](https://developer.github.com/v3/git/refs/#get-all-references)
10+
endpoints. In practice, we observed that tags can be listed with one or the other.
11+
12+
113
1.5.3
214
=====
315

github_release.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,10 +877,25 @@ def get_refs(repo_name, tags=None, pattern=None):
877877
# If "tags" is True, keep only "refs/tags/*"
878878
data = response.json()
879879
if tags:
880+
tag_names = []
880881
data = []
881882
for ref in response.json():
882883
if ref['ref'].startswith("refs/tags"):
883884
data.append(ref)
885+
tag_names.append(ref["ref"])
886+
887+
try:
888+
response = _request(
889+
'GET',
890+
GITHUB_API + '/repos/{0}/git/refs/tags'.format(repo_name))
891+
response.raise_for_status()
892+
for ref in response.json():
893+
if ref["ref"] not in tag_names:
894+
data.append(ref)
895+
except requests.exceptions.HTTPError as exc_info:
896+
response = exc_info.response
897+
if response.status_code != 404:
898+
raise
884899

885900
# If "pattern" is not None, select only matching references
886901
filtered_data = data

0 commit comments

Comments
 (0)