2022-04-03 16:54:43 -04:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2023-07-12 02:50:39 -04:00
|
|
|
import requests
|
|
|
|
from datetime import datetime, timedelta, timezone
|
2023-07-11 03:51:22 -04:00
|
|
|
|
2023-07-12 02:50:39 -04:00
|
|
|
# Set up your personal access token and the repository details
|
|
|
|
token = os.environ.get('GH_TOKEN')
|
2024-01-10 03:13:43 -05:00
|
|
|
repo_owner = "portapack-mayhem"
|
|
|
|
repo_name = "mayhem-firmware"
|
2023-07-11 03:51:22 -04:00
|
|
|
|
|
|
|
|
2023-07-12 02:50:39 -04:00
|
|
|
def print_stable_changelog(previous_sha):
|
|
|
|
url = f"compare/{previous_sha}...next"
|
|
|
|
commits = handle_get_request(url)
|
|
|
|
for commit in commits["commits"]:
|
|
|
|
# Print the commit details
|
|
|
|
print(format_output(commit))
|
2023-07-11 03:51:22 -04:00
|
|
|
|
2022-04-03 16:54:43 -04:00
|
|
|
|
2023-07-12 02:50:39 -04:00
|
|
|
def print_nightly_changelog():
|
|
|
|
# Calculate the date and time 24 hours ago
|
|
|
|
since_time = (datetime.now(timezone.utc) - timedelta(hours=24)).isoformat() # Check that this is UTC
|
|
|
|
url = "commits"
|
|
|
|
commits = handle_get_request(url, since_time)
|
|
|
|
for commit in commits:
|
|
|
|
# Print the commit details
|
|
|
|
print(format_output(commit))
|
2022-04-03 16:54:43 -04:00
|
|
|
|
2023-07-11 03:51:22 -04:00
|
|
|
|
2023-07-12 02:50:39 -04:00
|
|
|
def handle_get_request(path, offset=None):
|
2023-07-26 22:53:56 -04:00
|
|
|
headers = {} if token == None else {"Authorization": f"Bearer {token}"}
|
2023-07-12 02:50:39 -04:00
|
|
|
params = {"since": offset}
|
|
|
|
url_base = f"https://api.github.com/repos/{repo_owner}/{repo_name}/"
|
|
|
|
response = requests.get(url_base + path, headers=headers, params=params)
|
2023-07-11 03:51:22 -04:00
|
|
|
|
2023-07-12 02:50:39 -04:00
|
|
|
# Check if the request was successful (status code 200)
|
|
|
|
if response.status_code == 200:
|
|
|
|
return response.json()
|
|
|
|
else:
|
|
|
|
print(f"Request failed with status code: {response.status_code}")
|
|
|
|
return None
|
2023-07-11 03:51:22 -04:00
|
|
|
|
|
|
|
|
2023-07-12 02:50:39 -04:00
|
|
|
def format_output(commit):
|
|
|
|
message_lines = commit["commit"]["message"].split("\n")
|
|
|
|
author = commit["author"]["login"] if commit["author"] and "login" in commit["author"] else commit["commit"]["author"]["name"]
|
|
|
|
return '- ' + commit["sha"][:8] + ' - @' + author + ': ' + message_lines[0]
|
2023-07-11 03:51:22 -04:00
|
|
|
|
|
|
|
|
2023-07-12 02:50:39 -04:00
|
|
|
if len(sys.argv) < 2:
|
|
|
|
print_nightly_changelog()
|
|
|
|
else:
|
|
|
|
past_version = sys.argv[1]
|
|
|
|
print_stable_changelog(past_version)
|