-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
70 lines (56 loc) · 1.74 KB
/
main.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
import os
import re
import requests
def main():
"""
Function to validate the Issue present over the Pull Request body.
"""
pattern = "((?:Fixes|Resolves) #\d+)"
# Get the PR body and the PR URL
body = os.getenv("INPUT_PRBODY")
url = os.getenv("INPUT_PRURL")
print(body)
print(url)
# Get the Issue number
try:
issue_num = re.search(pattern, body)[0]
if "Resolves" in issue_num:
issue_num = issue_num.replace("Resolves #", "")
if "Fixes" in issue_num:
issue_num = issue_num.replace("Fixes #", "")
issue_num = issue_num.strip()
print(issue_num)
except:
issue_num = "No issue number"
# URL List will match: ['https:', '', 'api.github.com', 'repos', 'owner', 'repo-name']
url = url.split("/")[:-2]
url[2] = url[2].replace("api.", "")
# Get rid of the repos record
url.pop(3)
# Reattach the URL pieces
url = "/".join(url)
# Add the issue number to the URL
url += "/issues/{}".format(issue_num)
print(url)
# Check if its valid code
valid_code = 0
response = requests.get(url)
if response.status_code == 200:
if response.url == url:
# Check if issue is open or closed
text = response.text
pattern_issue = "Status:\s(\w+)"
if re.search(pattern_issue, text)[1] == "Open":
valid_code = 1
else:
print("Issue is closed")
else:
print(
"Invalid Response Code obtained - error code: {}".format(
response.status_code
)
)
print("Valid flag is:", valid_code)
print(f"valid={valid_code} >> $GITHUB_OUTPUT")
if __name__ == "__main__":
main()