-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_issue.py
140 lines (119 loc) · 3.64 KB
/
git_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
github issue 파악
github API 참고 : https://developer.github.com/enterprise/2.13/v3/issues/#list-issues
"""
import requests
import json
import subprocess
import os
class color:
reset_color = "\033[0m"
black = "\033[0;30m"
red = "\033[0;31m"
green = "\033[0;32m"
yellow = "\033[0;33m"
blue = "\033[0;34m"
purple = "\033[0;35m"
cyan = "\033[0;36m"
white = "\033[0;37m"
user = ""
password = ""
baseURL = ""
owner = ""
repo = ""
def load_config(git_remote_url):
cfgFile = os.path.expanduser("~") + "/.git-credentials"
try:
f = open(cfgFile, "r")
except:
print("can't find ", cfgFile)
print(
cfgFile,
"""에 다음 예시 처럼 접근 관련 정보가 있어야 합니다.
https://ysoftman:[email protected]
https://ysoftman:[email protected]
""",
)
return False
cfgs = {}
while True:
line = f.readline()
if not line or line[0] == "\n":
break
line = line.strip() # remove \n
ele = line.split("@")
idpw = ele[0].split("//")[1].split(":")
cfgs[ele[0].split("//")[0] + "//" + ele[1]] = {
"user": idpw[0],
"password": idpw[1],
}
global user
global password
global baseURL
global owner
global repo
if git_remote_url[len(git_remote_url) - 1] == "/":
git_remote_url = git_remote_url[: len(git_remote_url) - 1]
findindex = git_remote_url.find(".git")
if findindex > 0:
git_remote_url = git_remote_url[:findindex]
baseURL = git_remote_url.rsplit("/", 2)[0]
owner = git_remote_url.rsplit("/", 2)[-2]
repo = git_remote_url.rsplit("/", 1)[-1]
for key, value in cfgs.items():
if key == baseURL:
user = value["user"]
password = value["password"]
break
f.close()
print(f"baseURL: {baseURL}")
print(f"owner: {owner}")
print(f"repo: {repo}")
print(f"user: {user}")
# print(f"password: {password}")
if (
len(user) == 0
or len(password) == 0
or len(baseURL) == 0
or len(owner) == 0
or len(repo) == 0
):
print("can't find the user/password about ->", git_remote_url)
return False
return True
def get_open_issue_url():
if baseURL == "https://github.com":
# print("[https://api.github.com]")
return "https://api.github.com/repos/{}/{}/issues?state=open".format(
owner, repo
)
# for github enterprise
return "{}/api/v3/repos/{}/{}/issues?state=open".format(baseURL, owner, repo)
def issue_list():
resp = requests.get(get_open_issue_url(), auth=(user, password))
result = json.loads(resp.content)
if type(result) != list:
print("issue not found!")
exit(0)
for item in result:
assignees = []
for i in item["assignees"]:
assignees.append(i["login"])
assignee_users = ",".join(assignees)
print(
color.cyan + item["created_at"] + color.reset_color,
color.yellow + item["state"] + color.reset_color,
color.purple + item["title"] + color.reset_color,
color.green + item["html_url"] + color.reset_color,
color.blue + assignee_users + color.reset_color,
)
if __name__ == "__main__":
# print(os.getcwd())
# print(os.path.expanduser('~'))
git_remote_url = subprocess.Popen(
"git remote -v | awk 'NR==1 {print $2}'", shell=True, stdout=subprocess.PIPE
).stdout.read()
if load_config(git_remote_url.decode().rstrip()) == True:
issue_list()