|
| 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() |
0 commit comments