forked from fmtlib/fmt
Replace requests with urllib
This commit is contained in:
@ -12,9 +12,10 @@ obtained from https://github.com/settings/tokens.
|
|||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import datetime, docopt, errno, fileinput, json, os
|
import datetime, docopt, errno, fileinput, json, os
|
||||||
import re, requests, shutil, sys
|
import re, shutil, sys
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from subprocess import check_call
|
from subprocess import check_call
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
|
|
||||||
class Git:
|
class Git:
|
||||||
@ -191,22 +192,30 @@ def release(args):
|
|||||||
# Create a release on GitHub.
|
# Create a release on GitHub.
|
||||||
fmt_repo.push('origin', 'release')
|
fmt_repo.push('origin', 'release')
|
||||||
auth_headers = {'Authorization': 'token ' + os.getenv('FMT_TOKEN')}
|
auth_headers = {'Authorization': 'token ' + os.getenv('FMT_TOKEN')}
|
||||||
r = requests.post('https://api.github.com/repos/fmtlib/fmt/releases',
|
req = urllib.request.Request(
|
||||||
headers=auth_headers,
|
'https://api.github.com/repos/fmtlib/fmt/releases',
|
||||||
data=json.dumps({'tag_name': version,
|
data=json.dumps({'tag_name': version,
|
||||||
'target_commitish': 'release',
|
'target_commitish': 'release',
|
||||||
'body': changes, 'draft': True}))
|
'body': changes, 'draft': True}).encode('utf-8'),
|
||||||
if r.status_code != 201:
|
headers=auth_headers, method='POST')
|
||||||
raise Exception('Failed to create a release ' + str(r))
|
with urllib.request.urlopen(req) as response:
|
||||||
id = r.json()['id']
|
if response.status != 201:
|
||||||
|
raise Exception(f'Failed to create a release ' +
|
||||||
|
'{response.status} {response.reason}')
|
||||||
|
response_data = json.loads(response.read().decode('utf-8'))
|
||||||
|
id = response_data['id']
|
||||||
|
|
||||||
|
# Upload the package.
|
||||||
uploads_url = 'https://uploads.github.com/repos/fmtlib/fmt/releases'
|
uploads_url = 'https://uploads.github.com/repos/fmtlib/fmt/releases'
|
||||||
package = 'fmt-{}.zip'.format(version)
|
package = 'fmt-{}.zip'.format(version)
|
||||||
r = requests.post(
|
req = urllib.request.Request(
|
||||||
'{}/{}/assets?name={}'.format(uploads_url, id, package),
|
f'{uploads_url}/{id}/assets?name={package}',
|
||||||
headers={'Content-Type': 'application/zip'} | auth_headers,
|
headers={'Content-Type': 'application/zip'} | auth_headers,
|
||||||
data=open('build/fmt/' + package, 'rb'))
|
data=open('build/fmt/' + package, 'rb'), method='POST')
|
||||||
if r.status_code != 201:
|
with urllib.request.urlopen(req) as response:
|
||||||
raise Exception('Failed to upload an asset ' + str(r))
|
if response.status != 201:
|
||||||
|
raise Exception(f'Failed to upload an asset '
|
||||||
|
'{response.status} {response.reason}')
|
||||||
|
|
||||||
update_site(env)
|
update_site(env)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user