Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
openEuler-Advisor
提交
b9727131
O
openEuler-Advisor
项目概览
openeuler
/
openEuler-Advisor
通知
36
Star
4
Fork
4
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
openEuler-Advisor
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b9727131
编写于
6月 12, 2020
作者:
O
openeuler-ci-bot
提交者:
Gitee
6月 12, 2020
浏览文件
操作
浏览文件
下载
差异文件
!18 Improve tc_reminder
Merge pull request !18 from Shinwell_Hu/improve_tc_reminder
上级
748ba2da
44e9fe07
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
52 addition
and
14 deletion
+52
-14
tc_reminder.py
tc_reminder.py
+52
-14
未找到文件。
tc_reminder.py
浏览文件 @
b9727131
...
...
@@ -14,17 +14,21 @@ import yaml
from
pprint
import
pprint
from
datetime
import
datetime
class
Advisor
:
class
Advisor
(
object
):
"""
This is a object abstract TC robot
"""
def
__init__
(
self
):
self
.
secret
=
open
(
os
.
path
.
expanduser
(
"~/.gitee_token.json"
),
"r"
)
self
.
secret
=
open
(
os
.
path
.
expanduser
(
"~/.gitee_
personal_
token.json"
),
"r"
)
self
.
token
=
json
.
load
(
self
.
secret
)
# self.req = urllib.request.Request('https://gitee.com/api/v5/repos/#{owner}/issues')
self
.
header
=
{
"User-Agent"
:
"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0"
}
self
.
tc_members
=
None
self
.
time_format
=
"%Y-%m-%dT%H:%M:%S%z"
def
get_json
(
self
,
url
):
"""
Return object parsed from remote json
"""
headers
=
self
.
header
.
copy
()
headers
[
"Content-Type"
]
=
"application/json;charset=UTF-8"
req
=
urllib
.
request
.
Request
(
url
=
url
,
...
...
@@ -35,8 +39,10 @@ class Advisor:
resp
=
json
.
loads
(
u
.
read
().
decode
(
"utf-8"
))
return
resp
def
get_file
(
self
,
repo
,
path
):
"""
Get remote raw file
"""
url
=
"https://gitee.com/{repo}/raw/master/{path}"
.
format
(
repo
=
repo
,
path
=
path
)
req
=
urllib
.
request
.
Request
(
url
=
url
,
headers
=
self
.
header
,
...
...
@@ -48,21 +54,35 @@ class Advisor:
return
resp
def
get_prs
(
self
):
list_url
=
"https://gitee.com/api/v5/repos/openeuler/community/pulls?access_token={token}&state=open&sort=created&direction=desc&page=1&per_page=100"
"""
Get list of PRs
"""
pulls_url
=
"https://gitee.com/api/v5/repos/openeuler/community/pulls"
list_url
=
pulls_url
+
"?access_token={token}&state=open&sort=created&direction=desc&page=1&per_page=100"
url
=
list_url
.
format
(
token
=
self
.
token
[
"access_token"
])
return
self
.
get_json
(
url
)
def
get_pr_comments
(
self
,
number
):
desc_url
=
"https://gitee.com/api/v5/repos/openeuler/community/pulls/{number}/comments?access_token={token}&page=1&per_page=100"
"""
Get Comments for a specific PR
"""
pulls_url
=
"https://gitee.com/api/v5/repos/openeuler/community/pulls"
desc_url
=
pulls_url
+
"/{number}/comments?access_token={token}&page=1&per_page=100"
url
=
desc_url
.
format
(
number
=
number
,
token
=
self
.
token
[
"access_token"
])
return
self
.
get_json
(
url
)
def
get_tc_members
(
self
):
"""
Get list of current TC members
"""
m
=
yaml
.
load
(
adv
.
get_file
(
"openeuler/community"
,
"sig/TC/OWNERS"
),
Loader
=
yaml
.
Loader
)
self
.
tc_members
=
m
[
"maintainers"
]
return
m
[
"maintainers"
]
def
filter_out_tc
(
self
,
users
):
"""
Pick TC members from users
"""
if
not
self
.
tc_members
:
self
.
get_tc_members
()
return
[
x
for
x
in
self
.
tc_members
if
x
in
users
]
...
...
@@ -75,18 +95,36 @@ if __name__ == "__main__":
adv
=
Advisor
()
PRs
=
adv
.
get_prs
()
PRs
.
reverse
()
for
pr
in
PRs
:
commenters
=
[]
commenters
.
append
(
pr
[
"user"
][
"login"
])
last_update
=
pr
[
"updated_at"
]
print
(
"URL: https://gitee.com/openeuler/community/pulls/{number}"
.
format
(
number
=
pr
[
"number"
]))
print
(
"Title: "
+
pr
[
"title"
])
comm
=
adv
.
get_pr_comments
(
pr
[
"number"
])
for
c
in
comm
:
#print("comment updated at:")
#pprint(datetime.strptime(c["updated_at"], adv.time_format))
commenters
.
append
(
c
[
"user"
][
"login"
])
print
(
"Title: "
+
pr
[
"title"
])
comments
=
adv
.
get_pr_comments
(
pr
[
"number"
])
last_update
=
datetime
.
strptime
(
comments
[
0
][
"updated_at"
],
adv
.
time_format
)
comments
.
reverse
()
current_lgtm
=
0
current_approve
=
False
for
comment
in
comments
:
commenters
.
append
(
comment
[
"user"
][
"login"
])
if
comment
[
"body"
].
startswith
(
"new changes are detected"
):
last_update
=
datetime
.
strptime
(
comment
[
"updated_at"
],
adv
.
time_format
)
break
# older comments are ignored
elif
comment
[
"body"
].
startswith
(
"***lgtm*** is added in this pull request"
):
current_lgtm
=
current_lgtm
+
1
elif
comment
[
"body"
].
startswith
(
"***approved*** is added in this pull request"
):
current_approve
=
True
tc
=
adv
.
filter_out_tc
(
commenters
)
print
(
"Currently involved TC members: "
+
", "
.
join
(
tc
)
+
"
\n
"
)
age
=
datetime
.
now
()
-
last_update
.
replace
(
tzinfo
=
None
)
age_days
=
max
(
age
.
days
,
0
)
print
(
"Currently {num} days old"
.
format
(
num
=
age_days
))
print
(
"Currently involved TC members: "
+
", "
.
join
(
tc
))
print
(
"Currently has {num} /lgtm"
.
format
(
num
=
current_lgtm
))
if
current_approve
:
print
(
"Currently /approve"
)
print
(
""
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录