forked from v-yarotsky/alfred-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.py
executable file
·56 lines (44 loc) · 1.85 KB
/
github.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
import itertools
import alfred
import github_api
from argparse import ArgumentParser
from util import *
from fuzzy_matching import fuzzy_match
from keychain import Keychain
import gui
parser = ArgumentParser()
parser.add_argument('-l', '--lazy', help='get repos only from cache', action='store_true')
parser.add_argument('--debug', help='show debug messages', action='store_true')
parser.add_argument('query', help='get repos only from cache', nargs='?')
args = parser.parse_args()
keychain = Keychain('Alfred Github')
token = keychain.get_password('Alfred Github')
if not token:
print("Authorizing")
github_username = gui.input_box("Github username")
github_password = gui.input_box("Github password")
token = github_api.authorize(username=github_username,
password=github_password,
client_id=alfred.preferences['github_api']['client_id'],
client_secret=alfred.preferences['github_api']['client_secret'],
scopes=['repo'],
note='Alfred Github extension')
keychain.store_password('Alfred Github', token)
gh = github_api.AuthenticatedGithub(token, lazy=args.lazy, debug=args.debug)
def get_all_repos():
orgs = gh.get_orgs()
org_names = pluck(orgs, 'login')
org_repos = flatten(gh.get_org_repos(org) for org in org_names)
own_repos = gh.get_own_repos()
return itertools.chain(org_repos, own_repos)
all_repos = get_all_repos()
feedback = alfred.Feedback()
for repo in all_repos:
title = repo.get('owner').get('login') + '/' + repo.get('name')
if not args.query or fuzzy_match(args.query, title):
feedback.append_item(uid=str(repo.get('id')),
arg=repo.get('html_url'),
valid='yes',
title=title)
print(feedback.xml())