<s> import os <EOL> import sys <EOL> try : <EOL> import requests <EOL> except ImportError : <EOL> requests = None <EOL> import urlparse <EOL> import textwrap <EOL> PROJECT_DIRECTORY = os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT:..>" ) <EOL> new_path = [ PROJECT_DIRECTORY ] <EOL> new_path . extend ( sys . path [ <NUM_LIT:1> : ] ) <EOL> sys . path = new_path <EOL> import pulsar as project <EOL> PROJECT_OWNER = project . PROJECT_OWNER <EOL> PROJECT_NAME = project . PROJECT_NAME <EOL> PROJECT_URL = "<STR_LIT>" % ( PROJECT_OWNER , PROJECT_NAME ) <EOL> PROJECT_API = "<STR_LIT>" % ( PROJECT_OWNER , PROJECT_NAME ) <EOL> def main ( argv ) : <EOL> history_path = os . path . join ( PROJECT_DIRECTORY , "<STR_LIT>" ) <EOL> history = open ( history_path , "<STR_LIT:r>" ) . read ( ) . decode ( "<STR_LIT:utf-8>" ) <EOL> def extend ( from_str , line ) : <EOL> from_str += "<STR_LIT:\n>" <EOL> return history . replace ( from_str , from_str + line + "<STR_LIT:\n>" ) <EOL> ident = argv [ <NUM_LIT:1> ] <EOL> message = "<STR_LIT>" <EOL> if len ( argv ) > <NUM_LIT:2> : <EOL> message = argv [ <NUM_LIT:2> ] <EOL> elif not ( ident . startswith ( "<STR_LIT>" ) or ident . startswith ( "<STR_LIT>" ) ) : <EOL> api_url = urlparse . urljoin ( PROJECT_API , "<STR_LIT>" % ident ) <EOL> req = requests . get ( api_url ) . json ( ) <EOL> commit = req [ "<STR_LIT>" ] <EOL> message = commit [ "<STR_LIT:message>" ] <EOL> message = get_first_sentence ( message ) <EOL> elif requests is not None and ident . startswith ( "<STR_LIT>" ) : <EOL> pull_request = ident [ len ( "<STR_LIT>" ) : ] <EOL> api_url = urlparse . urljoin ( PROJECT_API , "<STR_LIT>" % pull_request ) <EOL> req = requests . get ( api_url ) . json ( ) <EOL> message = req [ "<STR_LIT:title>" ] <EOL> elif requests is not None and ident . startswith ( "<STR_LIT>" ) : <EOL> issue = ident [ len ( "<STR_LIT>" ) : ] <EOL> api_url = urlparse . urljoin ( PROJECT_API , "<STR_LIT>" % issue ) <EOL> req = requests . get ( api_url ) . json ( ) <EOL> message = req [ "<STR_LIT:title>" ] <EOL> else : <EOL> message = "<STR_LIT>" <EOL> to_doc = message + "<STR_LIT:U+0020>" <EOL> if ident . startswith ( "<STR_LIT>" ) : <EOL> pull_request = ident [ len ( "<STR_LIT>" ) : ] <EOL> text = "<STR_LIT>" . format ( pull_request , PROJECT_URL ) <EOL> history = extend ( "<STR_LIT>" , text ) <EOL> to_doc += "<STR_LIT>" . format ( pull_request ) <EOL> elif ident . startswith ( "<STR_LIT>" ) : <EOL> issue = ident [ len ( "<STR_LIT>" ) : ] <EOL> text = "<STR_LIT>" . format ( issue , PROJECT_URL ) <EOL> history = extend ( "<STR_LIT>" , text ) <EOL> to_doc += "<STR_LIT>" . format ( issue ) <EOL> else : <EOL> short_rev = ident [ : <NUM_LIT:7> ] <EOL> text = "<STR_LIT>" . format ( short_rev , PROJECT_URL ) <EOL> history = extend ( "<STR_LIT>" , text ) <EOL> to_doc += "<STR_LIT>" . format ( short_rev ) <EOL> to_doc = wrap ( to_doc ) <EOL> history = extend ( "<STR_LIT>" , to_doc ) <EOL> open ( history_path , "<STR_LIT:w>" ) . write ( history . encode ( "<STR_LIT:utf-8>" ) ) <EOL> def get_first_sentence ( message ) : <EOL> first_line = message . split ( "<STR_LIT:\n>" ) [ <NUM_LIT:0> ] <EOL> return first_line <EOL> def wrap ( message ) : <EOL> wrapper = textwrap . TextWrapper ( initial_indent = "<STR_LIT>" ) <EOL> wrapper . subsequent_indent = '<STR_LIT:U+0020>' <EOL> wrapper . width = <NUM_LIT> <EOL> return "<STR_LIT:\n>" . join ( wrapper . wrap ( message ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( sys . argv ) </s>
