Skip to content

Commit bf091dc

Browse files
committed
check tag existence before trying to create new release
1 parent 56bc1b1 commit bf091dc

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tools/dorelease.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ def post_request(url, timeout, data, headers=[], proxy=None):
169169
raise MyError("server returned non-JSON output")
170170
except HTTPError as e:
171171
print e.code
172-
# XXX print string representation of the code
173172
raise MyError("got HTTP error: {} ({})".format(e.code, e.reason))
174173

175174
def upload_file(filepath, upload_url, headers, timeout, proxy=None):
@@ -235,8 +234,6 @@ def main():
235234
sys.exit(1)
236235
_files.append(file)
237236

238-
# TODO: Check if the tag is not already present in the repo.
239-
240237
try:
241238
password = os.environ["GITHUB_PASSWORD"]
242239
except:
@@ -250,6 +247,16 @@ def main():
250247
headers = {}
251248
headers['Authorization'] = _get_auth(user, password)
252249

250+
# Check if the tag is not already present in the repo.
251+
_url = "https://api.github.com"
252+
_path = '%s%s%s' % ("/repos/", repo, "/releases/tags/" + tag)
253+
url = '%s%s' % (_url, _path)
254+
output_json = post_request(url,
255+
arguments.timeout, None, headers, proxy)
256+
if output_json["tag_name"] == tag:
257+
print "tag '" + tag + "' already present in the releases"
258+
sys.exit(1)
259+
253260
prerelease = False
254261
if arguments.prerelease:
255262
prerelease = True

0 commit comments

Comments
 (0)