-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to list unabeled PR's since latest release
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import os | ||
import requests | ||
from datetime import datetime | ||
|
||
# Configuration | ||
# Your GitHub Personal Access Token | ||
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") | ||
GITHUB_USERNAME = "projectmesa" | ||
GITHUB_REPO = "mesa" | ||
HEADERS = {"Authorization": f"token {GITHUB_TOKEN}"} | ||
|
||
|
||
def get_latest_release_date() -> str: | ||
"""Fetches the latest release date from the GitHub repository.""" | ||
url = ( | ||
f"https://api.github.com/repos/{GITHUB_USERNAME}/{GITHUB_REPO}/releases/latest" | ||
) | ||
response = requests.get(url, headers=HEADERS) | ||
response.raise_for_status() # Raises an exception for HTTP error codes | ||
return response.json()["published_at"] | ||
|
||
|
||
def get_closed_pull_requests_since_latest_release( | ||
latest_release_date, | ||
) -> list[dict[str, any]]: | ||
"""Fetches pull requests created or updated after the latest release date, then filters by merged date.""" | ||
pull_requests = [] | ||
page = 1 | ||
while True: | ||
# Fetch PRs that were created or updated after the latest release date | ||
url = f"https://api.github.com/repos/{GITHUB_USERNAME}/{GITHUB_REPO}/pulls?state=closed&base=main&sort=updated&direction=desc&page={page}" | ||
response = requests.get(url, headers=HEADERS) | ||
response.raise_for_status() | ||
prs = response.json() | ||
if not prs: | ||
break | ||
|
||
# Convert latest release date to datetime for comparison | ||
latest_release_datetime = datetime.strptime( | ||
latest_release_date, "%Y-%m-%dT%H:%M:%SZ" | ||
) | ||
|
||
for pr in prs: | ||
# Convert PR's `updated_at` to datetime for comparison | ||
pr_updated_at = datetime.strptime(pr["updated_at"], "%Y-%m-%dT%H:%M:%SZ") | ||
# Stop fetching if PR was updated before the latest release | ||
if pr_updated_at < latest_release_datetime: | ||
return pull_requests | ||
|
||
if pr["merged_at"]: | ||
pr_merged_at = datetime.strptime(pr["merged_at"], "%Y-%m-%dT%H:%M:%SZ") | ||
if pr_merged_at > latest_release_datetime and not pr["labels"]: | ||
pull_requests.append(pr) | ||
page += 1 | ||
return pull_requests | ||
|
||
|
||
def main() -> None: | ||
# Based on https://github.com/projectmesa/mesa/pull/1917#issuecomment-1871352058 | ||
latest_release_date = get_latest_release_date() | ||
pull_requests = get_closed_pull_requests_since_latest_release(latest_release_date) | ||
if len(pull_requests) <= 0: | ||
return | ||
print("These pull requests must be labeled:") | ||
for pr in pull_requests: | ||
print(f" PR #{pr['number']}: {pr['title']} - Merged at: {pr['merged_at']}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |