Skip to content

Commit 9a72cd3

Browse files
authored
ci: don't remind on prs from admins, etc. (#13965)
* ci: don't remind on prs from admins, etc. * don't remind model authors about linking issues/.
1 parent 236e5dd commit 9a72cd3

3 files changed

Lines changed: 47 additions & 2 deletions

File tree

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Fixes # (issue)
2626
[documentation guidelines](https://github.com/huggingface/diffusers/tree/main/docs), and
2727
[here are tips on formatting docstrings](https://github.com/huggingface/diffusers/tree/main/docs#writing-source-documentation).
2828
- [ ] Did you write any new necessary tests?
29+
- [ ] Are you the author (or part of the team) of the model/pipeline (only applicable for model/pipeline related PRs)?
2930

3031

3132
## Who can review?

.github/workflows/pr_link_issue_reminder.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ on:
66
workflow_dispatch:
77

88
jobs:
9-
remind_or_close:
10-
name: Remind or close PRs without a linked issue
9+
remind:
10+
# Reminds external contributors to link an issue. PRs from maintainers, users
11+
# with write/admin access, and collaborators are skipped by the script.
12+
name: Remind external contributors to link an issue
1113
if: github.repository == 'huggingface/diffusers'
1214
runs-on: ubuntu-22.04
1315
permissions:

utils/remind_link_issue.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@
2121
- If a PR is not linked and no prior reminder is present, the script posts a single
2222
friendly reminder comment.
2323
- PRs labeled `no-issue-needed` and bot-authored PRs are skipped.
24+
- PRs authored by maintainers, users with write (or admin) access, and collaborators
25+
are skipped; the reminder only targets external contributors.
2426
"""
2527

2628
import logging
2729
import os
30+
import re
2831
from datetime import datetime, timedelta, timezone
2932

3033
import requests
@@ -37,6 +40,20 @@
3740
REMINDER_MARKER = "<!-- pr-link-issue-reminder -->"
3841
BYPASS_LABELS = {"no-issue-needed"}
3942
LOOKBACK_DAYS = 2
43+
# Collaborator permission levels that mark a PR author as a maintainer / writer /
44+
# collaborator. Authors with any of these are skipped (the reminder is only for
45+
# external contributors).
46+
PRIVILEGED_PERMISSIONS = {"admin", "write", "maintain", "triage"}
47+
48+
# `author_association` values that mark the author as a maintainer / collaborator.
49+
# These are available on the PR payload without needing extra token scopes.
50+
PRIVILEGED_ASSOCIATIONS = {"OWNER", "MEMBER", "COLLABORATOR"}
51+
52+
# A PR authored by the model/pipeline's own team does not need to link an issue.
53+
# Matches a checked task-list item for the corresponding PR template checkbox.
54+
AUTHOR_CHECKBOX_PATTERN = re.compile(
55+
r"-\s*\[\s*[xX]\s*\]\s*Are you the author \(or part of the team\) of the model/pipeline"
56+
)
4057
CONTRIBUTION_GUIDE_URL = "https://huggingface.co/docs/diffusers/main/en/conceptual/contribution#coding-with-ai-agents"
4158

4259
GRAPHQL_URL = "https://api.github.com/graphql"
@@ -68,10 +85,31 @@ def has_linked_issue(token, owner, name, number):
6885
return data["repository"]["pullRequest"]["closingIssuesReferences"]["totalCount"] > 0
6986

7087

88+
def author_checkbox_checked(pr):
89+
return bool(AUTHOR_CHECKBOX_PATTERN.search(pr.body or ""))
90+
91+
7192
def has_existing_reminder(pr):
7293
return any(REMINDER_MARKER in (c.body or "") for c in pr.get_issue_comments())
7394

7495

96+
def is_privileged_author(repo, pr, author):
97+
"""Return True if the author is a maintainer, has write/admin access, or is a collaborator."""
98+
# `author_association` is on the PR payload and needs no extra token scope.
99+
association = (pr.raw_data or {}).get("author_association")
100+
if association in PRIVILEGED_ASSOCIATIONS:
101+
return True
102+
# Fall back to the collaborator-permission API to catch writers/collaborators
103+
# whose association is reported as CONTRIBUTOR/NONE on this particular PR.
104+
try:
105+
permission = repo.get_collaborator_permission(author)
106+
except Exception as e:
107+
# A 404 here means the user is not a collaborator at all (external contributor).
108+
logger.info("Could not resolve permission for @%s, treating as external: %s", author, e)
109+
return False
110+
return permission in PRIVILEGED_PERMISSIONS
111+
112+
75113
def reminder_body(author):
76114
return (
77115
f"{REMINDER_MARKER}\n"
@@ -109,9 +147,13 @@ def main():
109147
author = pr.user.login
110148
if not author or author.endswith("[bot]") or pr.user.type == "Bot":
111149
continue
150+
if is_privileged_author(repo, pr, author):
151+
continue
112152
labels = {label.name for label in pr.labels}
113153
if labels & BYPASS_LABELS:
114154
continue
155+
if author_checkbox_checked(pr):
156+
continue
115157
if has_linked_issue(token, owner, name, pr.number):
116158
continue
117159
if has_existing_reminder(pr):

0 commit comments

Comments
 (0)