-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_issue.py
executable file
·56 lines (40 loc) · 1.14 KB
/
new_issue.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
56
#!/bin/python3
from os import environ as env
from os import system as sh
from os import popen
from time import sleep
repos = {
'admin': ('school', 'db-admin'),
'contact': ('external', 'contact'),
'jobs': ('external', 'jobs'),
'mgmt': ('school', 'db-mgmt'),
'syntax': ('school/s2022', 'syntax')
}
default_browser = env.get("WEB", "firefox")
gitlab_browser = env.get("GITLAB_WEB", default_browser)
base = env.get("GITLAB_URL", "gitlab.com")
suffix = '/-/issues'
new = '/new'
def build_url(repo_id):
return base + repo_id + suffix + new
def format (d):
return '\n'.join(d.keys())
def join (item):
if (type(item) is tuple):
ns, repo = item
return f"{ns}/{repo}"
else:
return item
def rofi_select ():
# todo: fall back to dmenu if rofi is not installed
selection = popen(f'echo "{format(repos)}" | rofi -dmenu').read().strip()
return join(repos[selection]) \
if selection in repos \
else selection
def open_and_go (url, browser):
sh(browser + " " + url)
sel = rofi_select()
if sel:
url = build_url(sel)
print(url)
open_and_go(url, gitlab_browser)