#NEWLINE# def dist_github( ) : #NEWLINE# #INDENT# 'Creates a release on the maebert/jrnl repository on github' #NEWLINE# import requests #NEWLINE# import keyring #NEWLINE# import getpass #NEWLINE# version = get_version ( ) #NEWLINE# version_tuple = version . split ( '.' ) #NEWLINE# changes_since_last_version = [ '* __{}__: {}' . format ( key , '\n' . join ( changes ) ) for ( key , changes ) in get_changelog ( ) . items ( ) if key . startswith ( '{}.{}' . format ( * version_tuple ) ) ] #NEWLINE# changes_since_last_version = '\n' . join ( sorted ( changes_since_last_version , reverse = True ) ) #NEWLINE# payload = { #NEWLINE# #INDENT# 'tag_name' : version , #NEWLINE# 'target_commitish' : 'master' , #NEWLINE# 'name' : version , #NEWLINE# 'body' : 'Changes in Version {}.{}: \n\n{}' . format ( version_tuple [ 0 ] , version_tuple [ 1 ] , changes_since_last_version ) , #NEWLINE# #UNINDENT# } #NEWLINE# print ( 'Preparing release {}...' . format ( version ) ) #NEWLINE# username = ( keyring . get_password ( 'github' , '__default_user' ) or raw_input ( 'Github username: ' ) ) #NEWLINE# password = ( keyring . get_password ( 'github' , username ) or getpass . getpass ( ) ) #NEWLINE# otp = raw_input ( 'One Time Token: ' ) #NEWLINE# response = requests . post ( 'https://api.github.com/repos/maebert/jrnl/releases' , headers = { #NEWLINE# #INDENT# 'X-GitHub-OTP' : otp , #NEWLINE# #UNINDENT# } , json = payload , auth = ( username , password ) ) #NEWLINE# if ( response . status_code in ( 403 , 404 ) ) : #NEWLINE# #INDENT# print ( 'Authentication error.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# keyring . set_password ( 'github' , '__default_user' , username ) #NEWLINE# keyring . set_password ( 'github' , changes_since_last_version , password ) #NEWLINE# if ( response . status_code > 299 ) : #NEWLINE# #INDENT# if ( 'message' in response . json ( ) ) : #NEWLINE# #INDENT# print ( 'Error: {}' . format ( response . json ( ) [ 'message' ] ) ) #NEWLINE# for error_dict in response . json ( ) . get ( 'errors' , [ ] ) : #NEWLINE# #INDENT# print ( '*' , error_dict ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# print ( 'Unkown error' ) #NEWLINE# print ( response . text ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# print ( 'Release created.' ) #NEWLINE# #UNINDENT# #UNINDENT# sys . exit ( )