Skip to content

Commit 178c073

Browse files
committed
Add create-github-release command.
1 parent c8692c9 commit 178c073

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
v7.1.0
2+
======
3+
4+
* Add create-github-release routine.
5+
16
v7.0.0
27
======
38

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
import sys
3+
import subprocess
4+
import getpass
5+
import urllib.parse
6+
7+
import keyring
8+
import autocommand
9+
from requests_toolbelt import sessions
10+
11+
12+
session = sessions.BaseUrlSession('https://api.github.com/repos/')
13+
14+
15+
def load_token():
16+
token = os.environ.get("GITHUB_TOKEN") or keyring.get_password(
17+
'Github', getpass.getuser()
18+
)
19+
assert token, "Token not available"
20+
return token
21+
22+
23+
@autocommand.autocommand(__name__)
24+
def run():
25+
session.headers = dict(
26+
Accept='application/vnd.github.v3+json',
27+
Authorization=f'token {load_token()}',
28+
)
29+
url, version = subprocess.run(
30+
[sys.executable, 'setup.py', '--url', '--version'],
31+
check=True,
32+
stdout=subprocess.PIPE,
33+
text=True,
34+
).stdout.split()
35+
tag = 'v' + version
36+
project = urllib.parse.urlparse(url).path.strip('/')
37+
releases = f'{project}/releases'
38+
session.post(releases, json=dict(tag_name=tag, name=tag)).raise_for_status()

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ install_requires =
2121
jaraco.ui
2222
keyring
2323
autocommand
24+
requests-toolbelt
2425
setup_requires = setuptools_scm[toml] >= 3.4.1
2526

2627
[options.extras_require]

0 commit comments

Comments
 (0)