-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_release_notes.py
61 lines (43 loc) · 1.58 KB
/
get_release_notes.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
import sys
import time
import argparse
import os
import random
import requests
import string
from datetime import datetime
def random_letters(length):
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for _ in range(length))
def get_release_notes(date: str, token: str | None = None) -> (str, str):
target_date = time.mktime(datetime.strptime(date, "%Y/%m/%d").timetuple())
headers = {
"Accept": "application/vnd.github+json"
}
if token is not None:
headers["Authorization"] = "Bearer " + token
r = requests.get('https://api.github.com/repos/TheStarport/ChaosMod/releases', headers=headers)
print("Status Code: " + str(r.status_code))
releases = r.json()
body = ""
url = ""
# Iterate over releases in reverse order
for release in releases[::-1]:
created_at = release["created_at"]
if time.mktime(time.strptime(created_at, '%Y-%m-%dT%H:%M:%SZ')) < target_date:
continue
url = release["html_url"]
body = body + release["body"]
if len(body) == 0:
raise ValueError("Invalid date passed in or no releases have been created in the specified time frame.")
env_file = os.getenv('GITHUB_ENV')
if env_file is not None:
with open(env_file, "a") as env:
eof = random_letters(12)
env.write(f"URL<<{eof}\n")
env.write(f"{url}\n{eof}\n")
with open(env_file, "a") as env:
eof = random_letters(12)
env.write(f"BODY<<{eof}\n")
env.write(f"{body}\n{eof}\n")
return url, body