Skip to content

Add GitHub Actions workflow for auto-answering issues#5836

Open
trwalke wants to merge 8 commits intomainfrom
trwalke/addGhActionForIssues
Open

Add GitHub Actions workflow for auto-answering issues#5836
trwalke wants to merge 8 commits intomainfrom
trwalke/addGhActionForIssues

Conversation

@trwalke
Copy link
Member

@trwalke trwalke commented Mar 11, 2026

This pull request introduces a new GitHub Actions workflow to automatically respond to issues opened or labeled by trusted contributors. The workflow leverages Azure OpenAI to generate a friendly, informative reply and posts it as a comment on the issue. The automation is restricted to members, owners, collaborators, and contributors to prevent misuse.

Automated issue triage and response:

  • Added .github/workflows/auto-answer-issues.yml to enable automatic responses to issues using Azure OpenAI, triggered when issues are opened or labeled by trusted contributors.
  • Implemented environment variable checks and error handling to ensure required secrets and context are available before generating a response.
  • Integrated the @octokit/rest and openai Node.js packages to interact with GitHub and Azure OpenAI APIs for generating and posting replies.

Security and access control:

  • Restricted workflow execution to issues created by members, owners, collaborators, or contributors, preventing untrusted users from consuming API tokens.

This action will attempt to answer questions customers have when posted on the repo.
@trwalke trwalke requested a review from a team as a code owner March 11, 2026 18:04
Copilot AI review requested due to automatic review settings March 11, 2026 18:04
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new GitHub Actions workflow intended to automatically generate and post responses to newly opened/labeled GitHub issues by running a Node.js script (with OpenAI + Octokit dependencies).

Changes:

  • Introduces .github/workflows/main.yml to trigger on issues events (opened, labeled).
  • Sets up Node.js 20, installs @octokit/rest and openai, then executes a repo script to generate/post a response.

Copy link
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5837, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5838, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5839, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5840, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5841, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits March 11, 2026 13:52
…hor_association (#5841)

* Initial plan

* Guard workflow against untrusted triggering using author_association

Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>

* Add COLLABORATOR and CONTRIBUTOR to author_association guard

Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 11, 2026 20:55
@trwalke
Copy link
Member Author

trwalke commented Mar 11, 2026

@copilot rename the file to auto-answer-issues.yml

Copy link
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5842, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 5 comments.

…issues.yml (#5842)

* Initial plan

* Rename main.yml to auto-answer-issues.yml

Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>
Copy link
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5843, to work on those changes. Once the pull request is ready, I'll request review from you.

…5843)

* Initial plan

* Switch auto-answer-issues workflow from OpenAI.com to Azure OpenAI

Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 11, 2026 21:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Copy link
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5844, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5845, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5846, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits March 11, 2026 15:25
…workflow (#5846)

* Initial plan

* Fix ESM/CJS issue: use dynamic import() for openai and @octokit/rest in workflow

Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>
…s workflow (#5845)

* Initial plan

* Remove CONTRIBUTOR from author_association check in auto-answer-issues workflow

Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 11, 2026 22:27
* Initial plan

* Add duplicate comment detection to auto-answer-issues workflow

Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.

Comment on lines +7 to +9
permissions:
issues: write
contents: read
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

The job requests contents: read, but this workflow doesn’t appear to need repository contents (it only installs npm packages and calls GitHub/Azure OpenAI). For least-privilege, consider removing contents: read unless a later step truly requires it.

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +25
- name: Checkout repository
uses: actions/checkout@v4

Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

The actions/checkout step is not used by subsequent steps (the script is inline and dependencies are installed from the registry). Removing checkout reduces runtime and avoids granting/using repository content access unnecessarily.

Suggested change
- name: Checkout repository
uses: actions/checkout@v4

Copilot uses AI. Check for mistakes.
Comment on lines +94 to +96
});
const botAlreadyCommented = comments.some(
(comment) => comment.user?.login === "github-actions[bot]"
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

This prompt hard-codes “An issue has been opened…”, but the workflow also runs on the labeled event. Consider adjusting the prompt text based on github.event.action so the model has accurate context (e.g., “opened” vs “labeled for auto-answer”).

Copilot uses AI. Check for mistakes.
Comment on lines +123 to +128
- Uses markdown formatting suitable for a GitHub issue comment.
`;

const completion = await openai.chat.completions.create({
model: AZURE_OPENAI_DEPLOYMENT,
messages: [
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

This workflow always posts a new comment for every eligible opened/labeled event. There’s currently no guard for a specific label name and no check for whether the bot has already commented, so repeated labeling (or reopening) can spam issues and burn Azure OpenAI tokens. Consider (a) gating on a dedicated label (e.g. only when action == 'labeled' && label.name == 'auto-answer'), and/or (b) listing existing issue comments via Octokit and exiting early if a prior auto-answer marker/comment from the bot is already present.

Copilot uses AI. Check for mistakes.
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.

4 participants