Skip to content

Simplify assign-to-agent flow to issue assignee REST APIs with canonical bot login resolution#41524

Merged
pelikhan merged 9 commits into
mainfrom
copilot/update-assign-to-agent-js
Jun 25, 2026
Merged

Simplify assign-to-agent flow to issue assignee REST APIs with canonical bot login resolution#41524
pelikhan merged 9 commits into
mainfrom
copilot/update-assign-to-agent-js

Conversation

Copilot AI commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

This updates assign_to_agent to resolve Copilot through canonical aliases in AGENT_LOGIN_NAMES (favoring [bot] logins) and to stop using agent task APIs. Assignment now uses issue-scoped REST checks and direct issue assignee mutation as requested.

  • Alias resolution and canonical bot login

    • Prioritizes [bot] aliases (notably copilot-swe-agent[bot]) in AGENT_LOGIN_NAMES.
    • Resolves and caches assignable login aliases directly, instead of resolving user IDs.
  • Issue-scoped assignability check

    • Uses issue-level REST assignability checks:
      • GET /repos/{owner}/{repo}/issues/{issue_number}/assignees/{assignee}
    • Removes repository-level assignee capability checks from this path.
    • Adds stricter/clearer issue number and client capability validation for this endpoint.
  • Direct issue assignment (no task API)

    • Replaces agent task creation with direct issue assignee mutation:
      • POST /repos/{owner}/{repo}/issues/{issue_number}/assignees
    • Sends canonical bot login in assignees[].
    • Updates assignment matching to login-based checks (including alias recognition), not user-ID-based checks.
  • Error guidance and behavior alignment

    • Updates permission/error guidance to reflect issue-assignee REST operations.
    • Removes task-API-specific handling and messaging from this flow.
  • Test updates

    • Adjusts helper and integration-style JS tests to validate:
      • [bot] alias preference,
      • issue-scoped assignability checks,
      • direct issue assignee POST behavior,
      • login-based caching/matching and revised expectations.
// Assignability check (issue-scoped)
await github.request(
  "GET /repos/{owner}/{repo}/issues/{issue_number}/assignees/{assignee}",
  { owner, repo, issue_number, assignee: "copilot-swe-agent[bot]" }
);

// Assignment (direct assignee mutation)
await github.request(
  "POST /repos/{owner}/{repo}/issues/{issue_number}/assignees",
  { owner, repo, issue_number, assignees: ["copilot-swe-agent[bot]"] }
);

Copilot AI and others added 4 commits June 25, 2026 19:52
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title Simplify assign-to-agent JS to use issue assignee REST APIs Simplify assign-to-agent flow to issue assignee REST APIs with canonical bot login resolution Jun 25, 2026
Copilot AI requested a review from pelikhan June 25, 2026 20:05
@pelikhan pelikhan marked this pull request as ready for review June 25, 2026 20:11
Copilot AI review requested due to automatic review settings June 25, 2026 20:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors the assign_to_agent workflow to stop using agent task APIs and instead assign Copilot by mutating issue assignees via issue-scoped REST endpoints, while also standardizing Copilot alias resolution to prefer canonical [bot] logins.

Changes:

  • Prefer canonical Copilot [bot] aliases (e.g., copilot-swe-agent[bot]) and switch caching/matching to login-based behavior.
  • Replace agent task creation with issue-scoped assignee checks and direct assignee mutation (GET .../assignees/{assignee} + POST .../assignees).
  • Update JS tests to validate the new REST routes, alias preference, and revised error behavior.
Show a summary per file
File Description
actions/setup/js/assign_to_agent.cjs Switches from agent-ID/task APIs to login-based assignment and alias-aware “already assigned” checks.
actions/setup/js/assign_to_agent.test.cjs Updates expectations for direct issue-assignee REST calls and revised 502 handling.
actions/setup/js/assign_agent_helpers.cjs Implements issue-scoped assignee validation and direct assignee mutation; updates alias ordering.
actions/setup/js/assign_agent_helpers.test.cjs Adjusts helper tests for login-based resolution and issue-scoped REST behavior.
.github/mcp.json Minor formatting/compaction of MCP server config.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (1)

actions/setup/js/assign_agent_helpers.cjs:92

  • The doc comment says this helper "falls back to repository-scoped checks", but validateAssigneeAlias now only uses the issue-scoped assignee endpoint and will fail without a valid issue/PR number. Updating the comment avoids misleading future callers.
/**
 * Return list of coding agent bot login names that are currently available as assignable actors
 * in this repository, preferring issue-scoped checks when issue/PR context is available
 * and falling back to repository-scoped checks.
  • Files reviewed: 5/5 changed files
  • Comments generated: 2

Comment on lines 321 to 325
/**
* Start an agent task for issue or pull request context using REST
* @param {string} assignableId - Synthetic target ID in format owner/repo#issue:N or owner/repo#pull:N
* @param {string} agentId - Agent login name
* @param {string} agentLogin - Agent login name
* @param {Array<{id: string, login: string}>} currentAssignees - List of current assignees with id and login
Comment on lines 186 to 188
* @param {string} agentName - Agent name (copilot)
* @param {number|string|null} [issueNumber] - Optional issue/PR number for issue-scoped assignability check
* @param {Object} [githubClient] - Authenticated GitHub client (defaults to global github)
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot link to the official documentation from the docs and the core.info logs and the generated acction failure issue:

https://docs.github.com/en/copilot/how-tos/use-copilot-agents/cloud-agent/use-cloud-agent-via-the-api#using-the-issues-api

In particular, help about minting the token:

Note

If using a fine-grained personal access token, it needs the following permissions to assign Copilot to an issue:

Read access to metadata
Read and write access to actions, contents, issues and pull requests
If using a personal access token (classic), it needs the repo scope to assign Copilot to an issue.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot update the agent login list to start with copilot-swe-agent[bot] - agents are always bots and always end with [bot]

Copilot AI and others added 2 commits June 25, 2026 20:44
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot link to the official documentation from the docs and the core.info logs and the generated acction failure issue:

https://docs.github.com/en/copilot/how-tos/use-copilot-agents/cloud-agen...

Done. Updated in commits e9ff64b and 5551e63:

  • copilot-cloud-agent.mdx: Added link to https://docs.github.com/en/copilot/how-tos/use-copilot-agents/cloud-agent/use-cloud-agent-via-the-api#using-the-issues-api, updated PAT permissions to actions, contents, issues, pull requests (replacing the old agent_tasks requirement), added classic PAT repo scope guidance, and clarified the creation step to offer both PAT types.

  • assign_agent_helpers.cjs logPermissionError: updated to list fine-grained PAT (metadata read + actions/contents/issues/pull_requests read/write) and classic PAT (repo scope), with a link to the official docs.

  • assign_agent_helpers.cjs generatePermissionErrorSummary (failure issue body): same token permission details with the official docs link replacing the generic REST assignees reference.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot update the agent login list to start with copilot-swe-agent[bot] - agents are always bots and always end with [bot]

Done. AGENT_LOGIN_NAMES now orders all [bot] aliases first: ["copilot-swe-agent[bot]", "github-copilot-enterprise[bot]", "github-copilot[bot]", "copilot-swe-agent", "github-copilot-enterprise", "github-copilot"]. Tests updated accordingly.

@github-actions

Copy link
Copy Markdown
Contributor

@copilot review all comments and address unresolved review feedback. Please also summarize the remaining blockers in a brief progress update.

Generated by 👨‍🍳 PR Sous Chef · 88.4 AIC · ⌖ 0.943 AIC · ⊞ 17.1K ·

@pelikhan

Copy link
Copy Markdown
Collaborator

…nees REST routes

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix https://github.com/github/gh-aw/actions/runs/28199949836/job/83536601075

Recompile

Fixed in the latest commit. create_issue.test.cjs and create_pull_request.test.cjs had stale assertions expecting the old POST /agents/repos/.../tasks route — updated to POST /repos/{owner}/{repo}/issues/{issue_number}/assignees and adjusted mock setup to cover both the GET assignability check and POST assignment calls.

@pelikhan pelikhan merged commit e040019 into main Jun 25, 2026
36 of 37 checks passed
@pelikhan pelikhan deleted the copilot/update-assign-to-agent-js branch June 25, 2026 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants