Skip to content

Fix add_comment to auto-detect discussion context and use GraphQL API#2001

Merged
pelikhan merged 4 commits intomainfrom
copilot/fix-add-comment-logic
Oct 19, 2025
Merged

Fix add_comment to auto-detect discussion context and use GraphQL API#2001
pelikhan merged 4 commits intomainfrom
copilot/fix-add-comment-logic

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 19, 2025

Problem

The add_comment safe-output job was failing when triggered from discussion or discussion_comment events, attempting to use the GitHub REST API (which only works for issues/PRs) instead of the GraphQL API (required for discussions).

Error from failed run: https://github.com/githubnext/gh-aw/actions/runs/18636565580/job/53128690343#step:5:1

Creating comment on discussions #1993
Comment content length: 1163
##[error]✗ Failed to create comment: Not Found
RequestError [HttpError]: Not Found
  ...
  url: 'https://api.github.com/repos/githubnext/gh-aw/issues/1993/comments',
  status: 404,

The code correctly detected it was in a discussion context and set commentEndpoint = "discussions", but then only checked the isDiscussion environment variable (set only when discussion: true is explicitly configured), causing it to fall through to the REST API code path.

Solution

Modified pkg/workflow/js/add_comment.cjs to use only the auto-detected commentEndpoint to determine whether to use GraphQL:

// Before: Only checked explicit flag
if (isDiscussion) {
  // Use GraphQL for discussions
}

// After: Only checks auto-detected endpoint
if (commentEndpoint === "discussions") {
  // Use GraphQL for discussions
}

This enables automatic detection of discussion contexts from events like discussion and discussion_comment. The backward compatible discussion: true configuration option has been removed.

Additional changes:

  • Removed GITHUB_AW_COMMENT_DISCUSSION environment variable and all related code
  • Removed isDiscussion variable from JavaScript code
  • Updated logic to use isDiscussionContext (derived from event type) for all endpoint determination
  • Moved context detection before staged mode check for proper flow

Testing

Added a comprehensive test case to pkg/workflow/js/add_comment.test.cjs:

  • Auto-detection test: Verifies that discussion_comment events automatically use GraphQL API

Test verifies:

  • GraphQL API is called with correct queries (fetch discussion ID, then create comment)
  • REST API is NOT called
  • Outputs are set correctly

Impact

Before:

  • Workflows triggered by discussion events would fail with 404 errors
  • Could use explicit discussion: true in safe-outputs configuration as a workaround

After:

  • Workflows automatically detect discussion context from event type
  • No configuration needed - works out of the box based on event
  • Breaking change: discussion: true configuration option is now ignored
  • Q workflow and other discussion-triggered workflows now work correctly

Affected workflows:

  • Q workflow (command trigger that can be invoked from discussions)
  • Any workflow triggered by discussion or discussion_comment events
  • Any workflow using add-comment safe-output in discussion contexts

Breaking Change:
If any workflows were explicitly using discussion: true configuration, this option is now ignored. These workflows should instead ensure they're triggered by appropriate discussion events (discussion or discussion_comment).

Original prompt

Fix the add_comment logic for discussions.

In this run, the code tried to add a comment to a discussion using the issue REST APIs.

See https://github.com/githubnext/gh-aw/actions/runs/18636565580/job/53128690343#step:5:1


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

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

@copilot remove backward compatible isDiscussion (The explicit isDiscussion environment variable flag (backward compatible)) and only use the endpoint info.

Copilot AI changed the title [WIP] Fix add_comment logic for discussions Fix add_comment to auto-detect discussion context and use GraphQL API Oct 19, 2025
Copilot AI requested a review from pelikhan October 19, 2025 22:27
…tion

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

Copilot AI commented Oct 19, 2025

@copilot remove backward compatible isDiscussion (The explicit isDiscussion environment variable flag (backward compatible)) and only use the endpoint info.

Removed the backward compatible isDiscussion flag. Now only uses endpoint detection from event context. Commit: da456db

@pelikhan pelikhan marked this pull request as ready for review October 19, 2025 22:50
@github-actions
Copy link
Copy Markdown
Contributor

Agentic Changeset Generator triggered by this pull request.

@pelikhan pelikhan merged commit b2a7d20 into main Oct 19, 2025
4 checks passed
@pelikhan pelikhan deleted the copilot/fix-add-comment-logic branch October 19, 2025 22:55
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