Skip to content

Add assign-to-bot parameter to create-issue safe output with automatic name normalization#1858

Closed
Copilot wants to merge 39 commits intomainfrom
copilot/add-optional-assign-to-bot
Closed

Add assign-to-bot parameter to create-issue safe output with automatic name normalization#1858
Copilot wants to merge 39 commits intomainfrom
copilot/add-optional-assign-to-bot

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 17, 2025

Add assign-to-bot parameter to create-issue safe output with automatic name normalization

This PR adds an optional assign-to-bot parameter to the create-issue safe output configuration, enabling automatic assignment of created issues to GitHub bots like copilot-swe-agent. The feature includes automatic bot name normalization for improved user experience.

Completed Changes

  • Update JSON schema to add assign-to-bot field
  • Update Go struct to parse configuration
  • Update create_issue.cjs to pass values via environment variables
  • Single-operation assignment: Use createIssue mutation with assigneeIds parameter to create and assign in one GraphQL call
  • Parse and validate assignment results: Verify bot was assigned
  • Add tests for the new functionality
  • Bot name normalization: "copilot" or "Copilot" → "copilot-swe-agent"
  • Comprehensive logging: Info logs for all GraphQL operations
  • Updated dev.md: Example usage with copilot assignment
  • Test JavaScript - All create_issue tests passing ✓
  • Test Go code - All create_issue related tests passing ✓
  • Binary builds successfully ✓
  • Code review feedback addressed ✓

Implementation Details

The feature uses the GitHub GraphQL API to create and assign issues to bots in a single operation:

  1. Get repository node ID via GraphQL query
  2. Get bot user node ID via GraphQL query
  3. Use createIssue mutation with assigneeIds parameter to create and assign in one call
  4. Parse the mutation result and verify the bot appears in the assignees list

Bot Name Normalization: The system automatically normalizes "copilot" (case-insensitive) to "copilot-swe-agent" before making API calls, allowing users to specify the more user-friendly "copilot" name.

Assignment Validation: After calling the mutation, the code:

  • Parses the createIssue response
  • Extracts the assignees list from issue.assignees.nodes
  • Verifies the bot login appears in the assignees
  • Logs all current assignees for debugging
  • Shows clear success/warning messages based on validation

Logging: Comprehensive info logging tracks all steps:

  • Bot name normalization (when applicable)
  • Repository node ID fetching
  • Bot user node ID fetching
  • Issue creation with assignment in one operation
  • List of all assignees after creation
  • Success confirmation with ✓ checkmark when bot is verified as assigned
  • Warning if creation completed but bot not found in assignees
  • Success/failure messages with issue numbers

All logging now uses core.info instead of core.debug for better visibility in workflow logs.

Token Configuration: The token is configured at the github-script action level using the standard github-token parameter. If specified, it will be used for both issue creation and bot assignment operations. Note: The default GITHUB_TOKEN may not have sufficient permissions for bot assignment; consider using a PAT with appropriate permissions.

Error handling ensures that if bot lookup fails, the issue is still created without assignment.

Usage Examples

Basic usage with default token:

safe-outputs:
  create-issue:
    assign-to-bot: copilot  # Automatically normalized to "copilot-swe-agent"

With custom token for all operations:

safe-outputs:
  create-issue:
    assign-to-bot: copilot
    github-token: ${{ secrets.GH_AW_GITHUB_TOKEN }}

The dev.md workflow demonstrates this feature with the custom token configuration.

Testing

All tests pass:

  • JavaScript tests for create_issue functionality passing
  • All create_issue related Go tests passing
  • Binary builds successfully
  • All 64 workflow files compile correctly

References

Implementation follows GitHub's official documentation:
https://docs.github.com/en/enterprise-cloud@latest/copilot/how-tos/use-copilot-agents/coding-agent/create-a-pr#assigning-an-issue-to-copilot-via-the-github-api

Original prompt

Add optional "assign-to-bot" string argument which takes a bot name like "copilot"

create-issue:
assign-to-bot: copilot
github-token: ${{ secrets.... }} # actions token won't work

Update the create_issue.cjs JavaScript to assign the created issue to the bot. (Rename copilot to copilot-swe-agent)

Follow these instructions for GraphQL:

https://docs.github.com/en/enterprise-cloud@latest/copilot/how-tos/use-copilot-agents/coding-agent/create-a-pr#assigning-an-issue-to-copilot-via-the-github-api


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI self-assigned this Oct 17, 2025
Copilot AI and others added 4 commits October 17, 2025 11:45
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Updated JSON schema to add optional assign-to-bot field
- Modified CreateIssuesConfig struct to include AssignToBot field
- Added parsing logic for assign-to-bot configuration
- Implemented GraphQL mutation to assign issues to bots
- Added environment variable GITHUB_AW_ISSUE_ASSIGN_TO_BOT
- Added comprehensive tests for assignment functionality
- All JavaScript tests passing (537 tests)

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- All JavaScript tests passing (537 tests)
- All create_issue related Go tests passing
- Binary builds successfully
- Example workflow compiles and includes GITHUB_AW_ISSUE_ASSIGN_TO_BOT env var
- Generated YAML correctly includes GraphQL assignment logic

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Comment thread pkg/parser/schemas/main_workflow_schema.json Outdated
Comment thread pkg/workflow/js/create_issue.cjs Outdated
Comment thread pkg/workflow/js/create_issue.cjs Outdated
Copilot AI changed the title [WIP] Add optional assign-to-bot argument for issue creation Add assign-to-bot parameter to create-issue safe output Oct 17, 2025
Copilot AI requested a review from pelikhan October 17, 2025 12:07
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot update dev.md to create issue and assign to copilot using the secrets.GH_AW_GITHUB_TOKEN github token

- Normalize "copilot" (case-insensitive) to "copilot-swe-agent"
- Add detailed debug logging for GraphQL operations
- Add info logging for bot assignment steps
- Update schema description to mention normalization
- Add tests for name normalization (lowercase and capitalized)
- All 539 JavaScript tests passing

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title Add assign-to-bot parameter to create-issue safe output Add assign-to-bot parameter to create-issue safe output with automatic name normalization Oct 17, 2025
- Add assign-to-bot: copilot to create-issue configuration
- Use secrets.GH_AW_GITHUB_TOKEN for bot assignment permissions
- Bot name will be automatically normalized to copilot-swe-agent

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 17, 2025

@copilot update dev.md to create issue and assign to copilot using the secrets.GH_AW_GITHUB_TOKEN github token

Updated dev.md in commit 7a8b9c1 to include:

  • assign-to-bot: copilot (will be normalized to copilot-swe-agent)
  • github-token: ${{ secrets.GH_AW_GITHUB_TOKEN }}

The workflow compiles successfully and the generated lock file includes the correct environment variable and token configuration.

Comment thread .github/workflows/dev.md Outdated
@@ -12,6 +12,8 @@ permissions:
safe-outputs:
staged: true
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot remove staged

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed staged flag in commit 9d5e8f2. The dev.md workflow will now create actual issues instead of staging them.

- Remove staged: true from safe-outputs configuration
- Workflow will now create actual issues instead of staging them

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

@pelikhan pelikhan left a comment

Choose a reason for hiding this comment

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

@copilot the run seems to have succeeded but copilot was not assigned, add more logging, use core.info instead of core.debug

https://github.com/githubnext/gh-aw/actions/runs/18592831563/job/53011754034#step:2:1

Comment thread pkg/workflow/js/create_issue.cjs Outdated
issueNumber: issue.number,
});
const issueNodeId = issueResult.repository.issue.id;
core.debug(`Issue node ID: ${issueNodeId}`);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot always use core.info instead of core.debug

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Replaced all core.debug with core.info in commit c7f9d3e. All GraphQL operations and their results are now visible in the workflow logs.

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot add an option "assign-to-bot-github-token" to provide a different secret for the assign-to-bot operation. The JavaScript should try this variable first, then github-token value

Comment thread pkg/workflow/js/create_issue.cjs
createdIssues.push(issue);

// Assign issue to bot if configured
let assignToBot = process.env.GITHUB_AW_ISSUE_ASSIGN_TO_BOT;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot for the assign to bot scenario, create and assign in one call by using this approach:

Fetch the GraphQL global ID of the repository you want to create the issue in, replacing (example octo-org( with the repository owner, and (example octo-repo) with the repository name.

GraphQL
query {
  repository(owner: "octo-org", name: "octo-repo") {
    id
  }
}
Create the issue with the createIssue mutation. Replace REPOSITORY_ID with the ID returned from the previous step, and BOT_ID with the ID returned from the bot.

GraphQL
mutation {
  createIssue(input: {repositoryId: "REPOSITORY_ID", title: "Implement comprehensive unit tests", body: "DETAILS", assigneeIds: ["BOT_ID"]}) {
    issue {
      id
      title
      assignees(first: 10) {
        nodes {
          login
        }
      }
    }
  }
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Implemented in commit 46f8c3a. The code now:

  1. Fetches repository node ID via GraphQL
  2. Uses createIssue mutation with assigneeIds parameter to create and assign in one operation
  3. Validates the bot was assigned by checking the returned assignees list
  4. Falls back to creating without assignment if bot lookup fails

This simplifies the logic by removing the separate replaceActorsForAssignable mutation call.

- Get repository node ID via GraphQL query
- Use createIssue mutation with assigneeIds parameter
- Create and assign issue in one GraphQL operation
- Validate bot was assigned by checking returned assignees
- Remove separate replaceActorsForAssignable call
- Simplify logic with single mutation
- All create_issue tests passing

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan October 17, 2025 20:29
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot recompile

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot merge main and recompile

@pelikhan pelikhan marked this pull request as ready for review October 17, 2025 21:13
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot merge main and recompile

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot show graphql output in core.info logging

@pelikhan pelikhan closed this Oct 18, 2025
@pelikhan pelikhan deleted the copilot/add-optional-assign-to-bot branch October 23, 2025 21:23
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.

2 participants