Skip to content

Commit

Permalink
style: Improve logging associated with release, assets and references
Browse files Browse the repository at this point in the history
Here are few examples of output:

```
$ githubrelease release jcfr/sandbox list

release 'nightly' info
  Tag name      : nightly
  Name          : nightly (updated on 20170212)
  ID            : 5427736
  Created       : 2017-02-01T07:31:19Z
  URL           : https://github.com/jcfr/sandbox/releases/tag/nightly
  Author        : jcfr
  Is published  : True
  Is prerelease : True

  Asset #0
    name      : sandbox-4.12.0.dev20170212-cp27-cp27m-win32.whl
    size      : 52
    uploader  : jcfr
    URL       : https://github.com/jcfr/sandbox/releases/download/nightly/sandbox-4.12.0.dev20170212-cp27-cp27m-win32.whl
    Downloads : 0

  Asset #1
    name      : sandbox-4.12.0.dev20170212-cp27-cp27m-win_amd64.whl
    size      : 56
    uploader  : jcfr
    URL       : https://github.com/jcfr/sandbox/releases/download/nightly/sandbox-4.12.0.dev20170212-cp27-cp27m-win_amd64.whl
    Downloads : 0

  Asset #2
    name      : sandbox-4.12.0.dev20170212-cp34-cp34m-win32.whl
    size      : 52
    uploader  : jcfr
    URL       : https://github.com/jcfr/sandbox/releases/download/nightly/sandbox-4.12.0.dev20170212-cp34-cp34m-win32.whl
    Downloads : 0

  Asset #3
    name      : sandbox-4.12.0.dev20170212-cp34-cp34m-win_amd64.whl
    size      : 56
    uploader  : jcfr
    URL       : https://github.com/jcfr/sandbox/releases/download/nightly/sandbox-4.12.0.dev20170212-cp34-cp34m-win_amd64.whl
    Downloads : 0

  Asset #4
    name      : sandbox-4.12.0.dev20170212-cp35-cp35m-win32.whl
    size      : 52
    uploader  : jcfr
    URL       : https://github.com/jcfr/sandbox/releases/download/nightly/sandbox-4.12.0.dev20170212-cp35-cp35m-win32.whl
    Downloads : 0

  Asset #5
    name      : sandbox-4.12.0.dev20170212-cp35-cp35m-win_amd64.whl
    size      : 56
    uploader  : jcfr
    URL       : https://github.com/jcfr/sandbox/releases/download/nightly/sandbox-4.12.0.dev20170212-cp35-cp35m-win_amd64.whl
    Downloads : 0

  Asset #6
    name      : sandbox-4.12.0.dev20170212-cp36-cp36m-win32.whl
    size      : 52
    uploader  : jcfr
    URL       : https://github.com/jcfr/sandbox/releases/download/nightly/sandbox-4.12.0.dev20170212-cp36-cp36m-win32.whl
    Downloads : 0

  Asset #7
    name      : sandbox-4.12.0.dev20170212-cp36-cp36m-win_amd64.whl
    size      : 56
    uploader  : jcfr
    URL       : https://github.com/jcfr/sandbox/releases/download/nightly/sandbox-4.12.0.dev20170212-cp36-cp36m-win_amd64.whl
    Downloads : 0
```

```
$ githubrelease ref jcfr/sandbox list --verbose
Reference 'refs/heads/master'
  Object
    type : commit
    sha  : 0616014562f225a86469fffe39219536a53b56b1

Reference 'refs/tags/nightly'
  Object
    type : commit
    sha  : 0616014562f225a86469fffe39219536a53b56b1


```

```
$ githubrelease release jcfr/sandbox create my-tag
created 'my-tag' release
  Tag name      : my-tag
  ID            : 5427757
  Created       : 2017-02-11T06:23:39Z
  URL           : https://github.com/jcfr/sandbox/releases/tag/untagged-cfccf5564b71b4d4a2a0
  Author        : jcfr
  Is published  : False
  Is prerelease : False
```
  • Loading branch information
jcfr committed Feb 11, 2017
1 parent 17578b2 commit f838d4c
Showing 1 changed file with 45 additions and 32 deletions.
77 changes: 45 additions & 32 deletions github_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,26 @@ def _request(*args, **kwargs):
# Releases
#

def print_release_info(release):
print('Tag name : {tag_name}'.format(**release))
def print_release_info(release, title=None, indent=""):
if title is None:
title = "release '{0}' info".format(release["tag_name"])
print(indent + title)
indent = " " + indent
print(indent + 'Tag name : {tag_name}'.format(**release))
if release['name']:
print('Name : {name}'.format(**release))
print('ID : {id}'.format(**release))
print('Created : {created_at}'.format(**release))
print('URL : {html_url}'.format(**release))
print('Author : {login}'.format(**release['author']))
print('Is published : {0}'.format(not release['draft']))
print('Is prerelease : {0}'.format(release['prerelease']))
print(indent + 'Name : {name}'.format(**release))
print(indent + 'ID : {id}'.format(**release))
print(indent + 'Created : {created_at}'.format(**release))
print(indent + 'URL : {html_url}'.format(**release))
print(indent + 'Author : {login}'.format(**release['author']))
print(indent + 'Is published : {0}'.format(not release['draft']))
print(indent + 'Is prerelease : {0}'.format(release['prerelease']))
if release['body']:
print('Release notes :')
print(release['body'])
print(indent + 'Release notes :')
print(indent + release['body'])
print('')
for (i, asset) in enumerate(release['assets']):
print_asset_info(i, asset)
print_asset_info(i, asset, indent=indent)


def get_releases(repo_name):
Expand Down Expand Up @@ -134,8 +138,9 @@ def patch_release(repo_name, current_tag_name, **values):
if key in values and data[key] != values[key]:
updated.append("%s: '%s' -> '%s'" % (key, data[key], values[key]))
if updated:
print("updating release [%s]: \n %s" % (
print("updating '%s' release: \n %s" % (
current_tag_name, "\n ".join(updated)))
print("")

data.update(values)

Expand Down Expand Up @@ -206,7 +211,7 @@ def gh_release_create(repo_name, tag_name,
data=json.dumps(data),
headers={'Content-Type': 'application/json'})
response.raise_for_status()
print_release_info(response.json())
print_release_info(response.json(), title="created '%s' release" % tag_name)


gh_release_create.description = {
Expand Down Expand Up @@ -343,13 +348,15 @@ def gh_release_debug(repo_name, tag_name):
# Assets
#

def print_asset_info(i, asset):
print(' Asset #{i} name : {name}'.format(i=i, **asset))
print(' Asset #{i} size : {size}'.format(i=i, **asset))
print(' Asset #{i} uploader : {login}'.format(i=i, **asset['uploader']))
print(' Asset #{i} URL : {browser_download_url}'.format(i=i, **asset))
print(' Asset #{i} Downloads : {download_count}'.format(i=i, **asset))
print('')
def print_asset_info(i, asset, indent=""):
print(indent + "Asset #{i}".format(i=i))
indent = " " + indent
print(indent + "name : {name}".format(i=i, **asset))
print(indent + "size : {size}".format(i=i, **asset))
print(indent + "uploader : {login}".format(i=i, **asset['uploader']))
print(indent + "URL : {browser_download_url}".format(i=i, **asset))
print(indent + "Downloads : {download_count}".format(i=i, **asset))
print("")


def gh_asset_upload(repo_name, tag_name, pattern, dry_run=False, verbose=False):
Expand All @@ -367,23 +374,29 @@ def gh_asset_upload(repo_name, tag_name, pattern, dry_run=False, verbose=False):
else:
filenames = glob.glob(pattern)

prefix = "uploading '{0}' release assets: ".format(tag_name)
if len(filenames) > 1:
print(prefix)
prefix = " "

for filename in filenames:
print('release {0}: uploading {1}'.format(tag_name, filename))
print(prefix + 'uploading ' + filename)
if dry_run:
uploaded = True
continue
with open(filename, 'rb') as f:
basename = os.path.basename(filename)
url = '{0}?name={1}'.format(upload_url, basename)
if verbose:
print('url:', url)
print(prefix + 'upload_url: ' + url)
response = _request(
'POST', url,
headers={'Content-Type': 'application/octet-stream'},
data=f.read())
response.raise_for_status()
asset = response.json()
print('browser_download_url:', asset["browser_download_url"])
print(prefix + 'download_url: ' + asset["browser_download_url"])
print("")
uploaded = True
if not uploaded:
print("release {0}: skipping upload: "
Expand Down Expand Up @@ -467,16 +480,16 @@ def gh_asset_download(repo_name, tag_name=None, pattern=None):
# References
#

def print_object_info(ref_object):
print('Object:')
print(' type : {type}'.format(**ref_object))
print(' sha : {sha}'.format(**ref_object))
def print_object_info(ref_object, indent=""):
print(indent + 'Object')
print(indent + ' type : {type}'.format(**ref_object))
print(indent + ' sha : {sha}'.format(**ref_object))


def print_ref_info(ref):
print('-' * 80)
print('Reference : {ref}'.format(**ref))
print_object_info(ref['object'])
def print_ref_info(ref, indent=""):
print(indent + "Reference '{ref}'".format(**ref))
print_object_info(ref['object'], indent=" " + indent)
print("")


def get_refs(repo_name, tags=False, pattern=None):
Expand Down

0 comments on commit f838d4c

Please sign in to comment.