Skip to content

Commit 323a9e8

Browse files
authored
Create pending_user_response.py (#13881)
Python script for Workflow automation for pending_user_response.yml based on the following: - If an issue or PR has 'needs-user-input' label, and it has been 30 days since the last comment, comment and tag the user asking them to take a look. - And 30 days after this comment from the workflow, if no response, close the issue with a comment stating the user did not respond and they can re-open if needed. - If the user responds, remove the 'needs-user-input' label.
1 parent 48ebe3b commit 323a9e8

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import datetime
2+
import os
3+
4+
from github import Github
5+
6+
REPO_NAME = "pytorch/executorch"
7+
LABEL = "need-user-input"
8+
REMINDER_MARKER = "<!-- executorch-auto-reminder -->"
9+
REMINDER_COMMENT = (
10+
f"{REMINDER_MARKER}\nHi @{0}, this issue/PR has been marked as 'need-user-input'. "
11+
"Please respond or provide input. If we don't hear back in 30 days, this will be closed."
12+
)
13+
CLOSE_COMMENT = (
14+
f"{REMINDER_MARKER}\nClosing due to no response after 30 days. "
15+
"If you still need help, feel free to re-open or comment again!"
16+
)
17+
DAYS_BEFORE_REMINDER = 30
18+
DAYS_BEFORE_CLOSE = 30
19+
REMINDER_COOLDOWN_DAYS = 7 # Don't post another reminder within 7 days
20+
21+
22+
def main():
23+
g = Github(os.environ["GH_TOKEN"])
24+
repo = g.get_repo(REPO_NAME)
25+
26+
print("[VALIDATION] Would connect to Github and fetch repo:", REPO_NAME)
27+
issues = repo.get_issues(state="open", labels=[LABEL])
28+
print(f"[VALIDATION] Would fetch open issues with label '{LABEL}'.")
29+
30+
now = datetime.datetime.utcnow()
31+
32+
for issue in issues:
33+
print(f"[VALIDATION] Would fetch comments for issue/PR #{issue.number}.")
34+
comments = [] # Replace with mock comments if needed
35+
last_comment = comments[-1] if comments else None
36+
37+
# Find automation comments
38+
auto_comments = [c for c in comments if REMINDER_MARKER in c.body]
39+
user_comments = [c for c in comments if REMINDER_MARKER not in c.body]
40+
41+
# ---- REMINDER LOGIC ----
42+
# Only remind if NO reminder in last 7 days
43+
recent_auto_reminder = any(
44+
(now - c.created_at).days < REMINDER_COOLDOWN_DAYS for c in auto_comments
45+
)
46+
47+
if not auto_comments:
48+
if (
49+
last_comment
50+
and (now - last_comment.created_at).days >= DAYS_BEFORE_REMINDER
51+
):
52+
user = issue.user.login
53+
print(f"[VALIDATION] Would remind {user} on issue/PR #{issue.number}")
54+
elif auto_comments and not recent_auto_reminder:
55+
# Only post new reminder if last was > REMINDER_COOLDOWN_DAYS ago
56+
last_auto = auto_comments[-1]
57+
user = issue.user.login
58+
if (now - last_auto.created_at).days >= REMINDER_COOLDOWN_DAYS:
59+
print(
60+
f"[VALIDATION] Would remind {user} again on issue/PR #{issue.number}"
61+
)
62+
63+
# ---- EXISTING CLOSE/REMOVE LABEL LOGIC ----
64+
if auto_comments:
65+
last_auto = auto_comments[-1]
66+
user_responded = any(
67+
c.created_at > last_auto.created_at and c.user.login == issue.user.login
68+
for c in user_comments
69+
)
70+
if not user_responded:
71+
if (now - last_auto.created_at).days >= DAYS_BEFORE_CLOSE:
72+
print(
73+
f"[VALIDATION] Would close issue/PR #{issue.number} due to inactivity."
74+
)
75+
else:
76+
print(
77+
f"[VALIDATION] Would remove label from issue/PR #{issue.number} after user response."
78+
)
79+
80+
81+
if __name__ == "__main__":
82+
main()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Needs User Input Automation
2+
3+
on:
4+
schedule:
5+
- cron: '0 8 * * 1' # runs every Monday at 8:00 UTC
6+
workflow_dispatch:
7+
8+
jobs:
9+
needs-user-input:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repo
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: '3.11'
19+
20+
- name: Install dependencies
21+
run: pip install PyGithub
22+
23+
- name: Run needs-user-input script
24+
env:
25+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
run: python .github/scripts/pending_user_response.py

0 commit comments

Comments
 (0)