Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn about old PRs #22986

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/old_pr_notifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os
import requests
from datetime import datetime

REPO = "microsoft/vscode-python"
# TOKEN = os.environ["GH_TOKEN"]
# HEADERS = {"Authorization": f"token {TOKEN}"}
STALE_DAYS = 30 # Number of days to consider a PR stale. Set for a month.


def get_last_comment_date(pr_object):
# pr_number = # We need to iterate through all PR we have open in the repo
url = f"https://api.github.com/repos/{REPO}/issues/{pr_object['number']}/comments"
response = requests.get(url)
if response.status_code == 200:
comments = response.json()
print(comments)
if comments:
# Find maximum by comment creation date value.
last_comment = max(comments, key=lambda c: c["created_at"])
# Convert to datetime object and remove "Z" at end of string.
# Z is part of ISO 8601 standard that represent zero UTC offset,
# but datetime.fromisoformat does not support it.
# print("what are we returning")
# print(datetime.fromisoformat(last_comment["created_at"].rstrip("Z")))
return datetime.fromisoformat(last_comment["created_at"].rstrip("Z"))
# return None
# In case there are no comments, create date when the PR was created
return datetime.fromisoformat(pr_object["created_at"].rstrip("Z"))


# Fetch all open PR in repository
def get_open_pull_requests(owner, repo):
url = f"https://api.github.com/repos/{owner}/{repo}/pulls?state=open"
response = requests.get(url)
if response.status_code == 200:
# print(type(response.json()))
return response.json()
else:
print("Failed to fetch PRs:", response.content)
return []


def main():
# print(get_last_comment_date(22741))
all_pr = get_open_pull_requests("microsoft", "vscode-python")
# Itarate through all PRs, and check if the latest comment in the PR is older than 30 days.
for pr in all_pr:
today = datetime.now()
latest_comment_date = get_last_comment_date(pr)
# print(type(latest_comment_date))
age_of_pr = today - latest_comment_date
if age_of_pr.days > 30:
print("Older than one month!!!")
print(pr["number"])
else:
print("pretty new")


if __name__ == "__main__":
main()
Loading