-
Notifications
You must be signed in to change notification settings - Fork 264
Fix "Copilot is not a user" error in compute_text.cjs for app-created PRs #18592
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,17 +17,38 @@ async function main() { | |
| const actor = context.actor; | ||
| const { owner, repo } = context.repo; | ||
|
|
||
| // Check if the actor has repository access (admin, maintain permissions) | ||
| const repoPermission = await github.rest.repos.getCollaboratorPermissionLevel({ | ||
| owner: owner, | ||
| repo: repo, | ||
| username: actor, | ||
| }); | ||
|
|
||
| const permission = repoPermission.data.permission; | ||
| core.info(`Repository permission level: ${permission}`); | ||
| // Check if the actor has repository access (admin, maintain, write permissions) | ||
| // Non-user actors (bots, GitHub Apps like "Copilot") may not have a user record, | ||
| // causing the API to throw an error (e.g., "Copilot is not a user"). | ||
| // In that case, check the allowed bots list before returning empty outputs. | ||
| let permission; | ||
| try { | ||
| const repoPermission = await github.rest.repos.getCollaboratorPermissionLevel({ | ||
| owner: owner, | ||
| repo: repo, | ||
| username: actor, | ||
| }); | ||
| permission = repoPermission.data.permission; | ||
| core.info(`Repository permission level: ${permission}`); | ||
| } catch (permError) { | ||
| core.warning(`Permission check failed for actor '${actor}': ${getErrorMessage(permError)}`); | ||
| // Check if actor is in the allowed bots list (configured via on.bots in frontmatter) | ||
| const allowedBots = | ||
| process.env.GH_AW_ALLOWED_BOTS?.split(",") | ||
| .map(b => b.trim()) | ||
| .filter(b => b) ?? []; | ||
|
Comment on lines
+36
to
+39
|
||
| if (allowedBots.includes(actor)) { | ||
| core.info(`Actor '${actor}' is in the allowed bots list, treating as 'write' access`); | ||
| permission = "write"; | ||
| } else { | ||
| core.setOutput("text", ""); | ||
| core.setOutput("title", ""); | ||
| core.setOutput("body", ""); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| if (permission !== "admin" && permission !== "maintain") { | ||
| if (permission !== "admin" && permission !== "maintain" && permission !== "write") { | ||
| core.setOutput("text", ""); | ||
| core.setOutput("title", ""); | ||
| core.setOutput("body", ""); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot read the list of trusted bots from the front matter and treat them as "write" access.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in d231e93. When the permission check fails for a non-user actor,
compute_text.cjsnow readsGH_AW_ALLOWED_BOTS(passed from theon.botsfrontmatter) and treats listed bots as having "write" access, allowing them to proceed with text extraction.