Skip to content

Instantly share code, notes, and snippets.

@jameswritescode
Created January 7, 2014 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jameswritescode/8292377 to your computer and use it in GitHub Desktop.
Save jameswritescode/8292377 to your computer and use it in GitHub Desktop.
import re
from util import hook, http
github_repo = (r'((gist\.)?github.com/((\S+)(/(\S+))?))', re.I)
def get_repo_info(repo):
try:
j = http.get_json('https://api.github.com/repos/%s' % repo)
except:
return 'GitHub: ' + repo + ' does not exist'
out = ('\x02%s:\x02 %s \x02Author:\x02 %s \x02Lang:\x02 %s \x02Link:\x02 %s' %
(j['name'], j['description'], j['owner']['login'], j['language'],
j['html_url']))
if j['fork'] == True:
out += (' - \x034FORK\x02')
return 'GitHub: ' + out
def get_user_info(user):
try:
j = http.get_json('https://api.github.com/users/%s' % user)
except:
return 'GitHub: user ' + user + ' does not exist'
out = ('\x02%(login)s\x02 - ' % j)
if 'name' in j:
out += ('\x02Name:\x02 %(name)s ' % j)
if 'location' in j:
out += ('\x02Location:\x02 %(location)s ' % j)
out += ('\x02Repos:\x02 %(public_repos)s \x02Gists:\x02 %(public_gists)s '
'\x02Following:\x02 %(following)s \x02Followers:\x02 %(followers)s ' % j)
if 'blog' in j :
out += ('\x02Blog:\x02 %(blog)s ' % j)
out += ('\x02URL:\x02 %(html_url)s ' % j)
if 'hireable' in j:
out += ('- \x034HIREABLE\x02')
return 'GitHub: ' + out
def get_gist_info(gist):
try:
j = http.get_json('https://api.github.com/gists/%s' % gist)
except:
return 'GitHub: gist ' + gist + ' does not exist'
out = '\x02Gist:\x02'
if len(j['description']) > 0:
out += ' \x02Description:\x02 %(description)s' % j
out += ' \x02Files:\x02 %s' % len(j['files'])
out += ' \x02Revisions:\x02 %s' % len(j['history'])
out += ' \x02Forks:\x02 %s' % len(j['forks'])
out += ' \x02Author:\x02 %s' % j['user']['login']
if j['public'] == False:
out += ' - \x034PRIVATE\x02'
return 'GitHub: ' + out
def search_github(search):
search = search.split()
search = '+'.join(search)
j = http.get_json('https://api.github.com/legacy/repos/search/%s' % search)
j = j['repositories']
r = len(j) if len(j) < 5 else 5
out = 'GitHub Top results: '
for i in range(0, r):
out += j[i]['owner'] + '/' + j[i]['name'] + ' '
return out
@hook.command('gh')
@hook.command
def github(inp, say=None):
".gh user/repo -- information about repo"
say(get_repo_info(inp))
@hook.regex(*github_repo)
def github_repo_url(match, say=None):
u = match.group(3)
if match.group(2) == 'gist.':
say(get_gist_info(u))
else:
say(get_repo_info(u))
@hook.command
def ghs(inp, say=None):
".ghs text -- search github.com"
say(search_github(inp))
@hook.command
def ghu(inp, say=None):
".ghu username -- get info on github user"
say(get_user_info(inp))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment