FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pytorch/.github/scripts/process_commit.py at master · annotifyapp/pytorch · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
annotifyapp
/
pytorch
Public
forked from
pytorch/pytorch
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pytorch
/
.github
/
scripts
/
process_commit.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
106 lines (89 loc) · 4.07 KB
Breadcrumbs
pytorch
/
.github
/
scripts
/
process_commit.py
Copy path
File metadata and controls
106 lines (89 loc) · 4.07 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!/usr/bin/env python3
"""
This script finds the user/pr creator responsible for labeling a PR by a commit SHA. It is used by the workflow in
'.github/workflows/pr-labels.yml'. If there exists no PR associated with the commit or the PR is properly labeled,
this script is a no-op.
Note: we ping the user only, not the reviewers, as the reviewers can sometimes be external to pytorch
with no labeling responsibility, so we don't want to bother them.
This script is based on: https://github.com/pytorch/vision/blob/main/.github/process_commit.py
"""
import
sys
from
typing
import
Any
,
Set
,
Tuple
,
List
import
re
import
os
import
json
import
requests
# For a PR to be properly labeled it should have release notes label and one topic label
PULL_REQUEST_EXP
=
"Pull Request resolved:.*pull/(.*)"
PRIMARY_LABEL_FILTER
=
"release notes:"
SECONDARY_LABELS
=
{
"topic: bc_breaking"
,
"topic: deprecation"
,
"topic: new feature"
,
"topic: improvements"
,
"topic: bug fixes"
,
"topic: performance"
,
"topic: documentation"
,
"topic: developer feature"
,
"topic: not user facing"
,
}
# This secondary does not require a primary
ALLOWED_ONLY_SECONDARY
=
{
"topic: not user facing"
}
PYTORCH_REPO
=
"https://api.github.com/repos/pytorch/pytorch"
GITHUB_TOKEN
=
os
.
environ
.
get
(
'GITHUB_TOKEN'
)
REQUEST_HEADERS
=
{
'Accept'
:
'application/vnd.github.v3+json'
,
'Authorization'
:
f'token
{
GITHUB_TOKEN
}
'
}
def
query_pytorch
(
cmd
:
str
)
->
Any
:
response
=
requests
.
get
(
f"
{
PYTORCH_REPO
}
/
{
cmd
}
"
,
headers
=
REQUEST_HEADERS
)
return
response
.
json
()
def
get_pr_number
(
commit_hash
:
str
)
->
Any
:
data
=
query_pytorch
(
f"commits/
{
commit_hash
}
"
)
if
not
data
or
(
not
data
[
"commit"
][
"message"
]):
return
None
message
=
data
[
"commit"
][
"message"
]
p
=
re
.
compile
(
PULL_REQUEST_EXP
)
result
=
p
.
search
(
message
)
if
not
result
:
return
None
return
result
.
group
(
1
)
def
get_pr_author_and_labels
(
pr_number
:
int
)
->
Tuple
[
str
,
Set
[
str
]]:
# See https://docs.github.com/en/rest/reference/pulls#get-a-pull-request
data
=
query_pytorch
(
f"pulls/
{
pr_number
}
"
)
user
=
data
[
"user"
][
"login"
]
labels
=
{
label
[
"name"
]
for
label
in
data
[
"labels"
]}
return
user
,
labels
def
get_repo_labels
()
->
List
[
str
]:
collected_labels
:
List
[
str
]
=
list
()
for
page
in
range
(
0
,
10
):
response
=
query_pytorch
(
f"labels?per_page=100&page=
{
page
}
"
)
page_labels
=
list
(
map
(
lambda
x
:
str
(
x
[
"name"
]),
response
))
if
not
page_labels
:
break
collected_labels
+=
page_labels
return
collected_labels
def
post_pytorch_comment
(
pr_number
:
int
,
merger
:
str
)
->
Any
:
message
=
{
'body'
:
f"Hey @
{
merger
}
."
+
"""
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label.
\
Please add one of each to the PR. The 'release notes: ...' label should represent the part of
\
PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should
\
represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc).
\
The list of valid labels can be found [here](https://github.com/pytorch/pytorch/labels?q=release+notes)
\
for the 'release notes: ...' and [here](https://github.com/pytorch/pytorch/labels?q=topic) for the
\
'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label."""
}
response
=
requests
.
post
(
f"
{
PYTORCH_REPO
}
/issues/
{
pr_number
}
/comments"
,
json
.
dumps
(
message
),
headers
=
REQUEST_HEADERS
)
return
response
.
json
()
if
__name__
==
"__main__"
:
commit_hash
=
sys
.
argv
[
1
]
pr_number
=
get_pr_number
(
commit_hash
)
if
not
pr_number
:
sys
.
exit
(
0
)
user
,
labels
=
get_pr_author_and_labels
(
pr_number
)
repo_labels
=
get_repo_labels
()
primary_labels
=
set
(
filter
(
lambda
x
:
x
.
startswith
(
PRIMARY_LABEL_FILTER
),
repo_labels
))
has_both_labels
=
bool
(
primary_labels
.
intersection
(
labels
)
and
SECONDARY_LABELS
.
intersection
(
labels
))
is_properly_labeled
=
has_both_labels
or
bool
(
ALLOWED_ONLY_SECONDARY
.
intersection
(
labels
))
if
not
is_properly_labeled
:
post_pytorch_comment
(
pr_number
,
user
)
Back
|
FazBrowse Home
|
New Git URL