feat: support discussion_comment event#119
Merged
Merged
Conversation
Extend `command-action` to handle `discussion_comment` events alongside
`issue_comment` so IssueOps commands can be triggered from comments on
GitHub Discussions.
- Add a `resolveCommentContext()` helper in `src/main.ts` that normalizes
both event types into `{ kind, number, commentId, actor }` and returns
`null` for unsupported events. `isValidContext()` now takes
`kind: CommentKind` and validates uniformly via
`allowedContexts.includes(kind)` (no `length === 1` special-casing).
- Extend `validContexts` and the `allowed_contexts` default vocabulary
with `"discussion"` (`action.yaml` default becomes
`issue,pull_request,discussion`). Update the input description, the
`context` output description, and the `number` output description to
list all three values.
- For `discussion_comment`, emit `number = payload.discussion.number` and
`context = "discussion"`; `issue_number` is intentionally not emitted.
For `issue_comment` (issue or PR), behavior is unchanged.
- Update the unsupported-event warning to list both accepted events.
- Add `src/main.test.ts` cases covering: discussion accept (default),
`allowed_contexts="issue"` filter mismatch on a discussion comment,
`allowed_contexts="discussion"` single-context accept, and
`allowed_contexts="discussion"` rejecting a heterogeneous
`issue_comment`. Expand the existing unsupported-event test to assert
the warning lists both `issue_comment` and `discussion_comment`.
- README: regenerate the Inputs/Outputs tables, add a `### Triggering
from GitHub Discussions` Tips subsection with a hardened workflow
example, and harden the existing Getting Started example to pass
IssueOps params through `env:` instead of interpolating them directly
into a `run:` shell script. A warning callout cites GitHub Actions
security guidance for expression-injection.
- Regenerate `dist/`.
Closes #101
|
🎉 This PR is included in version 2.2.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extend
command-actionto handlediscussion_commentevents alongsideissue_commentso IssueOps commands can be triggered from comments on GitHub Discussions, reusing thenumber/contextoutput redesign introduced by #100.Implementation:
resolveCommentContext()insrc/main.tsthat normalizes both event types into{ kind: 'issue' | 'pull_request' | 'discussion', number, commentId, actor }and returnsnullfor unsupported events.isValidContext()now receiveskind: CommentKindand validates uniformly viaallowedContexts.includes(kind)— the previouslength === 1switch is gone.validContextsand theallowed_contextsdefault with"discussion"(default becomesissue,pull_request,discussion). Update theallowed_contextsinput description, thecontextoutput description, and thenumberoutput description to list all three values.discussion_comment: emitnumber = payload.discussion.number,context = "discussion", pluscomment_id/actor.issue_numberis intentionally not emitted for discussions. Forissue_comment(issue or PR), behavior is unchanged from feat(output): addnumberandcontextoutputs, soft-deprecateissue_number#100.issue_commentanddiscussion_comment).Tests (
src/main.test.ts, 54 → 58 cases):allowed_contexts)allowed_contexts="issue"rejects a discussion comment via the filterallowed_contexts="discussion"accepts a discussion comment (single-context positive)allowed_contexts="discussion"rejects anissue_comment(heterogeneous)Docs:
### Triggering from GitHub DiscussionsTips subsection with a hardened workflow example and a security callout linking to GitHub Actions security hardening.env:rather than interpolating${{ ... }}directly into arun:script. Discussion / Issue / PR comment content is attacker-controlled, so interpolating it into a shell command is an expression-injection sink.pnpm generate.Generated:
dist/index.jsanddist/index.js.mapregenerated viapnpm build.Migration
For existing v1 consumers, no migration is required. Workflows that only listen to
issue_commentare unaffected. Workflows that want to support discussions:on: discussion_comment: types: [created].outputs.issue_numbertooutputs.number(already recommended by feat(output): addnumberandcontextoutputs, soft-deprecateissue_number#100).permissions: discussions: writeif your follow-up step writes back to the discussion (e.g. reactions via GraphQL).References
discussion_commentevent #101numberandcontextoutputs, soft-deprecateissue_number#100 (number/contextoutput redesign)discussion_commentTest plan
pnpm typecheckexits 0pnpm lint(oxlint --max-warnings=0) exits 0 with 0 warnings / 0 errorspnpm testpasses 58/58 (was 54; +4 new tests + 1 expansion)pnpm format:checkcleanpnpm generateandpnpm buildare idempotent (md5sum determinism check)