Skip to content

Commit

Permalink
Add create-github-release command.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Aug 30, 2020
1 parent c8692c9 commit 178c073
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v7.1.0
======

* Add create-github-release routine.

v7.0.0
======

Expand Down
38 changes: 38 additions & 0 deletions jaraco/develop/create-github-release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os
import sys
import subprocess
import getpass
import urllib.parse

import keyring
import autocommand
from requests_toolbelt import sessions


session = sessions.BaseUrlSession('https://api.github.com/repos/')


def load_token():
token = os.environ.get("GITHUB_TOKEN") or keyring.get_password(
'Github', getpass.getuser()
)
assert token, "Token not available"
return token


@autocommand.autocommand(__name__)
def run():
session.headers = dict(
Accept='application/vnd.github.v3+json',
Authorization=f'token {load_token()}',
)
url, version = subprocess.run(
[sys.executable, 'setup.py', '--url', '--version'],
check=True,
stdout=subprocess.PIPE,
text=True,
).stdout.split()
tag = 'v' + version
project = urllib.parse.urlparse(url).path.strip('/')
releases = f'{project}/releases'
session.post(releases, json=dict(tag_name=tag, name=tag)).raise_for_status()
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ install_requires =
jaraco.ui
keyring
autocommand
requests-toolbelt
setup_requires = setuptools_scm[toml] >= 3.4.1

[options.extras_require]
Expand Down

0 comments on commit 178c073

Please sign in to comment.