Commit e8aebd11 authored by Jason R. Coombs's avatar Jason R. Coombs

Use requests for updating milestone and version

parent 70dc35dc
...@@ -16,10 +16,7 @@ import collections ...@@ -16,10 +16,7 @@ import collections
import itertools import itertools
import re import re
try: import requests
import urllib.request as urllib_request
except ImportError:
import urllib2 as urllib_request
try: try:
input = raw_input input = raw_input
...@@ -79,7 +76,7 @@ def get_repo_name(): ...@@ -79,7 +76,7 @@ def get_repo_name():
""" """
Get the repo name from the hgrc default path. Get the repo name from the hgrc default path.
""" """
default = subprocess.check_output('hg paths default').strip() default = subprocess.check_output('hg paths default').strip().decode('utf-8')
parts = default.split('/') parts = default.split('/')
if parts[-1] == '': if parts[-1] == '':
parts.pop() parts.pop()
...@@ -105,20 +102,13 @@ def get_mercurial_creds(system='https://bitbucket.org', username=None): ...@@ -105,20 +102,13 @@ def get_mercurial_creds(system='https://bitbucket.org', username=None):
return Credential(username, password) return Credential(username, password)
def add_milestone_and_version(version): def add_milestone_and_version(version):
auth = 'Basic ' + ':'.join(get_mercurial_creds()).encode('base64').strip()
headers = {
'Authorization': auth,
}
base = 'https://api.bitbucket.org' base = 'https://api.bitbucket.org'
for type in 'milestones', 'versions': for type in 'milestones', 'versions':
url = (base + '/1.0/repositories/{repo}/issues/{type}' url = (base + '/1.0/repositories/{repo}/issues/{type}'
.format(repo = get_repo_name(), type=type)) .format(repo = get_repo_name(), type=type))
req = urllib_request.Request(url = url, headers = headers, resp = requests.post(url=url,
data='name='+version) data='name='+version, auth=get_mercurial_creds())
try: resp.raise_for_status()
urllib_request.urlopen(req)
except urllib_request.HTTPError as e:
print(e.fp.read())
def bump_versions(target_ver): def bump_versions(target_ver):
for filename in files_with_versions: for filename in files_with_versions:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment