|
54 | 54 | resolve_discussions, |
55 | 55 | ) |
56 | 56 | from github_cli import TransientGhError |
| 57 | +from pull_request_author import effective_author |
57 | 58 | from pull_request_source import ( |
58 | 59 | Actor, |
59 | 60 | IssueComment, |
|
86 | 87 | ) |
87 | 88 |
|
88 | 89 |
|
89 | | -# Copilot appears under two slugs: `gh pr view`'s `author` field reports |
90 | | -# `app/copilot-swe-agent`, while the Pulls/commits endpoint's `committer.login` |
91 | | -# field can report the bare `copilot` slug. Either slug can name Copilot as the |
92 | | -# author, so the author set carries both while the committer set carries only |
93 | | -# the bare slug. These sets hold the identities `normalize_author_identity` |
94 | | -# returns, without the `app/` prefix or the `[bot]` suffix. Do not treat either |
95 | | -# slug as the human author behind a Copilot-authored PR. |
96 | | -_COPILOT_COMMITTER_IDENTITIES = {"copilot"} |
97 | | -_COPILOT_PR_AUTHOR_IDENTITIES = {"copilot-swe-agent", "copilot"} |
98 | 90 | _MAINTENANCE_APP_IDENTITIES = {"dependabot", "otelbot", "renovate"} |
99 | 91 |
|
100 | 92 |
|
@@ -144,45 +136,6 @@ def __post_init__(self) -> None: |
144 | 136 | raise ValueError("pull request number must be positive") |
145 | 137 |
|
146 | 138 |
|
147 | | -def _human_author_for_copilot_pr(source: PullRequestSource) -> str: |
148 | | - assignees = [ |
149 | | - assignee.login |
150 | | - for assignee in source.pull_request.assignees |
151 | | - ] |
152 | | - for login in assignees: |
153 | | - identity = normalize_author_identity(login) |
154 | | - if ( |
155 | | - login |
156 | | - and identity not in _COPILOT_PR_AUTHOR_IDENTITIES |
157 | | - and not is_unattended_author_login(login) |
158 | | - ): |
159 | | - return login |
160 | | - |
161 | | - commits = source.commits |
162 | | - if not commits: |
163 | | - return "" |
164 | | - committer = commits[0].committer |
165 | | - login = committer.login |
166 | | - if ( |
167 | | - not login |
168 | | - or normalize_author_identity(login) in _COPILOT_COMMITTER_IDENTITIES |
169 | | - or is_unattended_author_login(login) |
170 | | - or committer.is_bot |
171 | | - or committer.is_copilot_reviewer |
172 | | - ): |
173 | | - return "" |
174 | | - return login |
175 | | - |
176 | | - |
177 | | -def _effective_author(source: PullRequestSource) -> str: |
178 | | - author = source.pull_request.author.login |
179 | | - if normalize_author_identity(author) in _COPILOT_PR_AUTHOR_IDENTITIES: |
180 | | - human_author = _human_author_for_copilot_pr(source) |
181 | | - if human_author: |
182 | | - return human_author |
183 | | - return author |
184 | | - |
185 | | - |
186 | 139 | def _compute_facts( |
187 | 140 | source: PullRequestSource, |
188 | 141 | author: str, |
@@ -472,7 +425,7 @@ async def evaluate_pull_request( |
472 | 425 | pr_title=pr.title, |
473 | 426 | pr_url=pr.url, |
474 | 427 | ) |
475 | | - author = _effective_author(pr_source) |
| 428 | + author = effective_author(pr_source.pull_request, pr_source.commits) |
476 | 429 | activity = build_activity_timeline( |
477 | 430 | ActivityInput(pr_source, author, config.approver_logins) |
478 | 431 | ) |
|
0 commit comments