### Run the entire test suite Source: https://github.com/github/command/blob/main/CONTRIBUTING.md Execute all tests in the project. Ensure `npm install` has been run prior to executing this command. ```bash npm run test ``` -------------------------------- ### Demo Workflow with Command Action Source: https://github.com/github/command/blob/main/README.md A complete workflow example demonstrating how to use the command action to trigger custom logic based on IssueOps commands. It includes necessary permissions and conditionally runs subsequent steps. ```yaml name: "command demo" # the workflow to execute on is comments that are newly created on: issue_comment: types: [created] # permissions needed for reacting to IssueOps commands on issues and PRs permissions: pull-requests: write issues: write checks: read contents: read # useful if your workflows call actions/checkout@vX.X.X jobs: demo: runs-on: ubuntu-latest steps: # execute IssueOps command logic, hooray! # this will be used to "gate" all future steps below - uses: github/command@vX.X.X id: command with: command: ".ping" allowed_contexts: issue,pull_request # run on issues AND pull requests # run your custom logic for your project here - example seen below # conditionally run some logic here - name: ping if: ${{ steps.command.outputs.continue == 'true' }} run: echo "I am going to ping some cool website now!" ``` -------------------------------- ### Checkout Repository in GitHub Actions Job Source: https://github.com/github/command/blob/main/README.md Standard setup for a GitHub Actions job, including running on an Ubuntu environment and checking out the repository. This step is essential for subsequent actions to access repository files. ```yaml jobs: demo: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 ``` -------------------------------- ### Configure Allowlist with Handles Source: https://github.com/github/command/blob/main/README.md Use this configuration to allow specific GitHub handles to invoke IssueOps commands. This example allows 'monalisa' and 'octocat'. ```yaml - uses: github/command@vX.X.X id: command with: allowlist: monalisa,octocat ``` -------------------------------- ### Detect Command in Comment Body Source: https://context7.com/github/command/llms.txt Use the `triggerCheck` function to determine if a comment body begins with a specified trigger phrase. This function is case-sensitive and requires the trigger to be at the start of the comment. ```javascript import {triggerCheck} from './src/functions/trigger-check' // Simulates a comment body containing the trigger phrase const commentBody = '.lint --fix' const trigger = '.lint' const triggered = await triggerCheck(commentBody, trigger) console.log(triggered) // true // A comment that does NOT start with the trigger const noMatch = await triggerCheck('Hey, can someone run .lint?', '.lint') console.log(noMatch) // false // Also sets GitHub Actions output: comment_body = 'Hey, can someone run .lint?' ``` -------------------------------- ### Basic Command Action Usage Source: https://github.com/github/command/blob/main/README.md Use this snippet for basic integration of the command action with default configurations. Specify the command name to be recognized. ```yaml name: command id: command uses: github/command@vX.X.X with: command: .lint # can be anything you want (example) ``` -------------------------------- ### Pass Arbitrary String Parameters to Command Source: https://github.com/github/command/blob/main/docs/assets/parameters.md This demonstrates passing a simple string as parameters, which can be parsed by subsequent steps as needed. The parameters are appended after the command, separated by a pipe. ```text .restart | server1 server2 server3 ``` -------------------------------- ### Pass Key-Value Parameters to Command Source: https://github.com/github/command/blob/main/docs/assets/parameters.md Use this to pass environment-like variables to subsequent steps. The parameters are appended after the command, separated by a pipe. ```text .restart | LOG_LEVEL=debug CPU_CORES=4 ``` -------------------------------- ### Configure GitHub Command Action Inputs Source: https://context7.com/github/command/llms.txt Configure the github/command action using `with:` inputs in your workflow YAML. Key parameters include command triggers, reaction types, permission levels, and various gating options like skipping CI or reviews. ```yaml name: "IssueOps Command Demo" on: issue_comment: types: [created] permissions: pull-requests: write # required for reacting to PR comments issues: write # required for reacting to issue comments checks: read # required for reading CI check status contents: read jobs: run-command: runs-on: ubuntu-latest steps: - uses: github/command@v2.0.3 id: command with: command: ".lint" # trigger phrase to detect in comments reaction: "eyes" # reaction added immediately on trigger detection success_reaction: "+1" # reaction added on workflow success (post step) failure_reaction: "-1" # reaction added on workflow failure (post step) allowed_contexts: "pull_request" # only fire on PR comments (use "pull_request,issue" for both) permissions: "write,admin" # which GitHub repo permission levels can invoke this allow_drafts: "false" # block commands on draft PRs allow_forks: "false" # block commands from forked PRs skip_ci: "false" # require passing CI before allowing command skip_reviews: "false" # require PR approval before allowing command param_separator: "|" # character that separates command from parameters allowlist: "monalisa,octocat" # optional: restrict to specific users/teams allowlist_pat: ${{ secrets.MY_PAT }} # required only if allowlist uses org/team entries skip_completing: "false" # set true to manage post-step reactions manually fork_review_bypass: "false" # dangerous: bypass review check for fork PRs # gate all further steps on the `continue` output - name: Run Linter if: ${{ steps.command.outputs.continue == 'true' }} run: npm run lint ``` -------------------------------- ### Complete End-to-End Workflow with github/command Source: https://context7.com/github/command/llms.txt This workflow demonstrates a full command detection and execution process. It uses the github/command action to parse issue comments, apply reactions, and gate subsequent steps based on permissions and checks. Configure 'command', 'reaction', and 'permissions' to match your workflow needs. ```yaml name: "IssueOps Restart Command" on: issue_comment: types: [created] permissions: pull-requests: write issues: write checks: read contents: read jobs: restart: runs-on: ubuntu-latest steps: - uses: github/command@v2.0.3 id: command with: command: ".restart" reaction: "eyes" success_reaction: "+1" failure_reaction: "-1" allowed_contexts: "pull_request,issue" permissions: "write,admin" allowlist: "monalisa,octocat,my-org/ops-team" allowlist_pat: ${{ secrets.ALLOWLIST_PAT }} param_separator: "|" skip_ci: "false" skip_reviews: "false" allow_drafts: "false" allow_forks: "false" # Step only runs if command was valid and all checks passed - name: Restart Service if: ${{ steps.command.outputs.continue == 'true' }} env: PARAMS: ${{ steps.command.outputs.params }} ACTOR: ${{ steps.command.outputs.actor }} ISSUE: ${{ steps.command.outputs.issue_number }} REF: ${{ steps.command.outputs.ref }} run: | echo "Command triggered by: $ACTOR on issue #$ISSUE" echo "Branch ref: $REF" echo "Extra params: $PARAMS" # e.g., comment was: .restart | server=prod timeout=30 # PARAMS = "server=prod timeout=30" ./scripts/restart.sh "$PARAMS" ``` -------------------------------- ### Execute github/command Action Source: https://github.com/github/command/blob/main/README.md The core step that triggers the github/command action. It checks for a specific command (e.g., `.ping`) in the comment, reacts to the message, and performs permission checks before exporting outputs. ```yaml - uses: github/command@vX.X.X id: command with: command: ".ping" ``` -------------------------------- ### post() Source: https://context7.com/github/command/llms.txt Post-run reaction cleanup handler that runs automatically after all workflow steps complete. ```APIDOC ## `post()` ### Description The post-step handler that runs automatically after all workflow steps complete. Reads persisted Action state (`reaction_id`, `actionsToken`, `bypass`, `status`) and updates the trigger comment's reactions to reflect final workflow outcome. If `skip_completing` is `true`, this step is a no-op, enabling fully custom completion handling. ### Usage Example (YAML) ```yaml # Workflow using skip_completing for custom post-step handling - uses: github/command@v2.0.3 id: command with: command: ".deploy" skip_completing: "true" # disable automatic post-step reaction management - name: Deploy if: steps.command.outputs.continue == 'true' run: ./deploy.sh # Manually add your own completion reaction/comment after custom logic - name: Mark success if: steps.command.outputs.continue == 'true' uses: peter-evans/create-or-update-comment@v3 with: issue-number: ${{ steps.command.outputs.issue_number }} body: "🚀 Deployment to production complete!" ``` ``` -------------------------------- ### Accessing Command Action Parameters Output Source: https://github.com/github/command/blob/main/docs/assets/parameters.md Shows how to access the 'params' output from the command Action in a subsequent step. This output contains the text following the parameter separator. ```yaml - name: command id: command uses: github/command@vX.X.X with: command: .restart param_separator: "|" - name: example if: steps.command.outputs.continue == 'true' run: | echo "params: ${{ steps.command.outputs.params }}" ``` -------------------------------- ### Advanced Command Action Configuration Source: https://github.com/github/command/blob/main/README.md Configure the command action with custom settings for command syntax, reactions, allowed contexts, required permissions, and allowlists. This provides more control over command execution. ```yaml name: command id: command uses: github/command@vX.X.X with: command: .restart # can be anything you want (example) reaction: "eyes" allowed_contexts: "pull_request,issue" permissions: "write,admin" allowlist: monalisa ``` -------------------------------- ### Configure Parameter Separator Source: https://github.com/github/command/blob/main/docs/assets/parameters.md Demonstrates how to use the `param_separator` input to define a custom delimiter for parameters. The default is '|'. ```yaml - name: command id: command uses: github/command@vX.X.X with: command: .restart param_separator: "|" ``` -------------------------------- ### Configure Allowlist with Handles and Teams Source: https://github.com/github/command/blob/main/README.md This configuration allows specific GitHub handles and members of a GitHub org team to invoke IssueOps commands. A PAT with 'read:org' scope is required for team allowlisting. ```yaml - uses: github/command@vX.X.X id: command with: allowlist: monalisa,octocat,octo-awesome-org/octo-awesome-team allowlist_pat: ${{ secrets.ALLOWLIST_PAT }} ``` -------------------------------- ### Configure Custom Post-Run Reaction Cleanup with skip_completing Source: https://context7.com/github/command/llms.txt Use `skip_completing: "true"` in your workflow to disable automatic post-step reaction management. This allows you to manually add custom completion reactions or comments after your own logic. ```yaml # Workflow using skip_completing for custom post-step handling - uses: github/command@v2.0.3 id: command with: command: ".deploy" skip_completing: "true" # disable automatic post-step reaction management - name: Deploy if: steps.command.outputs.continue == 'true' run: ./deploy.sh # Manually add your own completion reaction/comment after custom logic - name: Mark success if: steps.command.outputs.continue == 'true' uses: peter-evans/create-or-update-comment@v3 with: issue-number: ${{ steps.command.outputs.issue_number }} body: "🚀 Deployment to production complete!" ``` -------------------------------- ### Conditional Step Based on Command Output Source: https://github.com/github/command/blob/main/README.md A subsequent step that runs only if the `github/command` action successfully processed the command and set the `continue` output to `true`. This allows for custom logic to be executed only when the command is valid and authorized. ```yaml - name: ping if: "${{ steps.command.outputs.continue == 'true' }}" run: echo "Do your custom logic here to ping your site!" ``` -------------------------------- ### reactEmote(reaction, context, octokit) Source: https://context7.com/github/command/llms.txt Adds a GitHub emoji reaction to the triggering `issue_comment`. Valid presets are: `+1`, `-1`, `laugh`, `confused`, `heart`, `hooray`, `rocket`, `eyes`. Returns the reaction response object (containing the `id`) which is saved for later removal. Throws an error if an invalid reaction name is provided. ```APIDOC ## `reactEmote(reaction, context, octokit)` — Add Emoji Reaction to Comment Adds a GitHub emoji reaction to the triggering `issue_comment`. Valid presets are: `+1`, `-1`, `laugh`, `confused`, `heart`, `hooray`, `rocket`, `eyes`. Returns the reaction response object (containing the `id`) which is saved for later removal. Throws an error if an invalid reaction name is provided. ```javascript import {reactEmote} from './src/functions/react-emote' // Add "eyes" reaction immediately when a command is detected (signals "I see this") const reactRes = await reactEmote('eyes', context, octokit) console.log(reactRes.data.id) // e.g. 12345678 — saved to remove it later // Add a "rocket" reaction to signal success const rocketRes = await reactEmote('rocket', context, octokit) // Invalid reaction throws: try { await reactEmote('fire', context, octokit) } catch (e) { console.error(e.message) // 'Reaction "fire" is not a valid preset' } ``` ``` -------------------------------- ### parameters(body, param_separator) Source: https://context7.com/github/command/llms.txt Splits the comment body on the `param_separator` character (default `|`) and extracts everything after it as a raw parameter string. Sets the `params` GitHub Actions output. Returns the trimmed parameter string or `null` if no parameters were provided. ```APIDOC ## `parameters(body, param_separator)` — Parse Inline Command Parameters Splits the comment body on the `param_separator` character (default `|`) and extracts everything after it as a raw parameter string. Sets the `params` GitHub Actions output. Returns the trimmed parameter string or `null` if no parameters were provided. ```javascript import {parameters} from './src/functions/parameters' // Comment body: ".restart | LOG_LEVEL=debug CPU_CORES=4" const params = await parameters('.restart | LOG_LEVEL=debug CPU_CORES=4', '|') console.log(params) // "LOG_LEVEL=debug CPU_CORES=4" // Sets GitHub Actions output: params = "LOG_LEVEL=debug CPU_CORES=4" // Comment body: ".ping | server1 server2 server3" const serverList = await parameters('.ping | server1 server2 server3', '|') console.log(serverList) // "server1 server2 server3" // Comment body with no parameters: ".lint" const noParams = await parameters('.lint', '|') console.log(noParams) // null // Sets GitHub Actions output: params = "" // Consuming params in a downstream workflow step: // - name: Use params // if: steps.command.outputs.continue == 'true' // run: echo "Params received: ${{ steps.command.outputs.params }}" ``` ``` -------------------------------- ### isAllowed(context) Source: https://context7.com/github/command/llms.txt Checks whether the comment author is permitted to run the command based on the `allowlist` input. Supports individual GitHub handles (e.g., `monalisa,octocat`) and GitHub org/team slugs (e.g., `my-org/my-team`). If `allowlist` is unset or `"false"`, all users with sufficient permissions are allowed. ```APIDOC ## `isAllowed(context)` — Allowlist Check for Users and Org Teams Checks whether the comment author is permitted to run the command based on the `allowlist` input. Supports individual GitHub handles (e.g., `monalisa,octocat`) and GitHub org/team slugs (e.g., `my-org/my-team`). If `allowlist` is unset or `"false"`, all users with sufficient permissions are allowed. ```javascript import {isAllowed} from './src/functions/allowlist' // allowlist input: "monalisa,octocat,my-org/ops-team" // allowlist_pat input: ghp_xxxx (needed for org/team lookups) const allowed = await isAllowed(context) if (!allowed) { // context.actor is not in allowlist console.log(`${context.actor} is not an allowed operator`) // Action will post: "User alice is not an allowed operator" } else { console.log(`${context.actor} is allowed to proceed`) } // Org team example: if context.actor belongs to my-org/ops-team, // the function makes GitHub API calls to verify team membership using allowlist_pat. ``` ``` -------------------------------- ### Perform Full Pre-flight Validation with prechecks Source: https://context7.com/github/command/llms.txt This function performs comprehensive validation including permission checks, allowlist enforcement, PR state inspection, CI status, and review decisions. It returns a status, message, and Git ref/SHA. ```javascript import {prechecks} from './src/functions/prechecks' const result = await prechecks( context.issue.number, // e.g. 42 false, // allowForks: reject fork PRs false, // skipCi: require passing CI false, // skipReviews: require PR approval false, // allowDraftPRs: reject draft PRs false, // forkReviewBypass: never skip reviews for forks 'pull_request', // contextType from contextCheck() context, // GitHub Actions context octokit // authenticated Octokit instance ) if (!result.status) { console.error(result.message) // e.g.: "### ⚠️ Cannot proceed\n\n> CI checks are passing but the PR has not been reviewed" } else { console.log(result.message) // "✅ PR is approved and all CI checks passed" console.log(result.ref) // "my-feature-branch" (or SHA for forks) console.log(result.sha) // "abc123def456..." } // Issue context (skips all PR-specific checks): const issueResult = await prechecks(99, false, false, false, false, false, 'issue', context, octokit) // issueResult.status = true, issueResult.ref = null, issueResult.sha = null ``` -------------------------------- ### validPermissions(octokit, context) Source: https://context7.com/github/command/llms.txt Fetches the commenter's repository collaborator permission level via the GitHub API and checks it against the `permissions` input (a comma-separated list such as `"write,admin"`). Returns `true` if allowed, or an error message string if not. ```APIDOC ## `validPermissions(octokit, context)` — Check Repo Permission Level Fetches the commenter's repository collaborator permission level via the GitHub API and checks it against the `permissions` input (a comma-separated list such as `"write,admin"`). Returns `true` if allowed, or an error message string if not. ```javascript import {validPermissions} from './src/functions/valid-permissions' // Called during prechecks; permissions input is read from GitHub Actions inputs // e.g., permissions: "write,admin" → only collaborators with write or admin role proceed const result = await validPermissions(octokit, context) if (result !== true) { // result is a human-readable error string console.error(result) // e.g.: "👋 __monalisa__, seems as if you have not write/admin permissions in this repo, permissions: read" } else { console.log('User has valid permissions') // proceed } ``` ``` -------------------------------- ### Allowlist Check for Users and Teams with isAllowed Source: https://context7.com/github/command/llms.txt Determines if a comment author is permitted to run a command based on the `allowlist` input, which can include individual handles or org/team slugs. If `allowlist` is unset or `"false"`, all users with sufficient permissions are allowed. ```javascript import {isAllowed} from './src/functions/allowlist' // allowlist input: "monalisa,octocat,my-org/ops-team" // allowlist_pat input: ghp_xxxx (needed for org/team lookups) const allowed = await isAllowed(context) if (!allowed) { // context.actor is not in allowlist console.log(`${context.actor} is not an allowed operator`) // Action will post: "User alice is not an allowed operator" } else { console.log(`${context.actor} is allowed to proceed`) } // Org team example: if context.actor belongs to my-org/ops-team, // the function makes GitHub API calls to verify team membership using allowlist_pat. ``` -------------------------------- ### Parse Inline Command Parameters with parameters Source: https://context7.com/github/command/llms.txt Extracts parameters from a comment body by splitting on a separator character. Sets the `params` GitHub Actions output and returns the trimmed parameter string or `null` if no parameters are found. ```javascript import {parameters} from './src/functions/parameters' // Comment body: ".restart | LOG_LEVEL=debug CPU_CORES=4" const params = await parameters('.restart | LOG_LEVEL=debug CPU_CORES=4', '|') console.log(params) // "LOG_LEVEL=debug CPU_CORES=4" // Sets GitHub Actions output: params = "LOG_LEVEL=debug CPU_CORES=4" // Comment body: ".ping | server1 server2 server3" const serverList = await parameters('.ping | server1 server2 server3', '|') console.log(serverList) // "server1 server2 server3" // Comment body with no parameters: ".lint" const noParams = await parameters('.lint', '|') console.log(noParams) // null // Sets GitHub Actions output: params = "" // Consuming params in a downstream workflow step: // - name: Use params // if: steps.command.outputs.continue == 'true' // run: echo "Params received: ${{ steps.command.outputs.params }}" ``` -------------------------------- ### Check Repository Permissions with validPermissions Source: https://context7.com/github/command/llms.txt Verifies if the commenter has the required repository collaborator permission level based on the `permissions` input. Returns `true` if allowed, or an error string otherwise. ```javascript import {validPermissions} from './src/functions/valid-permissions' // Called during prechecks; permissions input is read from GitHub Actions inputs // e.g., permissions: "write,admin" → only collaborators with write or admin role proceed const result = await validPermissions(octokit, context) if (result !== true) { // result is a human-readable error string console.error(result) // e.g.: "👋 __monalisa__, seems as if you have not write/admin permissions in this repo, permissions: read" } else { console.log('User has valid permissions') // proceed } ``` -------------------------------- ### Final commit before pull request Source: https://github.com/github/command/blob/main/CONTRIBUTING.md Run this command as your final commit before submitting a pull request to ensure all tests and checks pass. ```bash npm run all ``` -------------------------------- ### Parse Comma-Separated Input Strings with stringToArray Source: https://context7.com/github/command/llms.txt This utility function parses comma-separated GitHub Actions inputs into trimmed string arrays, filtering out empty entries. It's used internally for inputs like `permissions` and `allowed_contexts`. ```javascript import {stringToArray} from './src/functions/string-to-array' const perms = await stringToArray('write,admin') console.log(perms) // ['write', 'admin'] const contexts = await stringToArray('pull_request, issue') console.log(contexts) // ['pull_request', 'issue'] const empty = await stringToArray(' ') console.log(empty) // [] // Used internally when parsing the `permissions` input: // core.getInput('permissions') → "write,admin" → ['write', 'admin'] // Actor's permission 'write' is checked against this array with .includes() ``` -------------------------------- ### prechecks Source: https://context7.com/github/command/llms.txt Performs full pre-flight validation, including permission checks, allowlist enforcement, PR state inspection, CI status, and review decisions. ```APIDOC ## `prechecks(issue_number, allowForks, skipCi, skipReviews, allowDraftPRs, forkReviewBypass, contextType, context, octokit)` ### Description The central validation function. Combines permission checks, allowlist enforcement, PR state inspection (draft, fork), CI status (via GraphQL `statusCheckRollup`), and review decision (via GraphQL `reviewDecision`). Returns `{ status: boolean, message: string, ref: string|null, sha: string|null }`. ### Parameters - **issue_number**: The issue or PR number. - **allowForks**: Boolean to allow or reject fork PRs. - **skipCi**: Boolean to skip or require passing CI checks. - **skipReviews**: Boolean to skip or require PR approval. - **allowDraftPRs**: Boolean to allow or reject draft PRs. - **forkReviewBypass**: Boolean to bypass review checks for forks. - **contextType**: The type of context ('pull_request', 'issue'). - **context**: GitHub Actions context. - **octokit**: Authenticated Octokit instance. ### Returns - **status**: Boolean indicating if prechecks passed. - **message**: A message describing the result. - **ref**: The branch name or SHA for forks. - **sha**: The SHA of the commit. ### Usage Example ```javascript import {prechecks} from './src/functions/prechecks' const result = await prechecks( context.issue.number, // e.g. 42 false, // allowForks: reject fork PRs false, // skipCi: require passing CI false, // skipReviews: require PR approval false, // allowDraftPRs: reject draft PRs false, // forkReviewBypass: never skip reviews for forks 'pull_request', // contextType from contextCheck() context, // GitHub Actions context octokit // authenticated Octokit instance ) if (!result.status) { console.error(result.message) // e.g.: "### ⚠️ Cannot proceed\n\n> CI checks are passing but the PR has not been reviewed" } else { console.log(result.message) // "✅ PR is approved and all CI checks passed" console.log(result.ref) // "my-feature-branch" (or SHA for forks) console.log(result.sha) // "abc123def456..." } // Issue context (skips all PR-specific checks): const issueResult = await prechecks(99, false, false, false, false, false, 'issue', context, octokit) // issueResult.status = true, issueResult.ref = null, issueResult.sha = null ``` ``` -------------------------------- ### Set Permissions for GitHub Actions Source: https://github.com/github/command/blob/main/README.md Specifies the minimum required permissions for the workflow to interact with pull requests and issues. This is crucial for the action to perform its operations, such as adding reactions or checking statuses. ```yaml permissions: pull-requests: write issues: write checks: read ``` -------------------------------- ### actionStatus Source: https://context7.com/github/command/llms.txt Posts a comment on the issue/PR with the result message, adds a success or failure reaction to the trigger comment, and removes the original "in-progress" reaction. ```APIDOC ## `actionStatus(context, octokit, reactionId, message, success, altSuccessReaction)` ### Description Posts a comment on the issue/PR with the result message, adds a success (`rocket` or `+1`) or failure (`-1`) reaction to the trigger comment, and removes the original "in-progress" reaction (identified by `reactionId`). Used to communicate final operation status when prechecks fail or when `skip_completing` is `false`. ### Parameters - **context**: GitHub Actions context object. - **octokit**: Authenticated Octokit instance. - **reactionId**: The ID of the reaction to update. - **message**: The message to post as a comment. - **success**: Boolean indicating if the operation was successful. - **altSuccessReaction**: Boolean to use `+1` reaction instead of `rocket` when `success` is true. ### Usage Example ```javascript import {actionStatus} from './src/functions/action-status' const reactionId = 12345678 // from reactEmote().data.id // On precheck failure — posts message as a PR comment and adds thumbs-down reaction await actionStatus( context, octokit, reactionId, '### ⚠️ Cannot proceed\n\n> CI checks are failing', false // success = false → adds "-1" reaction ) // On custom success — posts message and adds "rocket" reaction await actionStatus( context, octokit, reactionId, '✅ Operation completed successfully', true, // success = true → adds "rocket" reaction false // altSuccessReaction = false (use rocket, not +1) ) // altSuccessReaction = true uses "+1" instead of "rocket" await actionStatus(context, octokit, reactionId, 'Done!', true, true) ``` ``` -------------------------------- ### Post Status Comment and Update Reactions with actionStatus Source: https://context7.com/github/command/llms.txt Use this function to post a status message as a comment on an issue or PR and update reactions on the trigger comment. It handles success and failure states, allowing for custom success reactions. ```javascript import {actionStatus} from './src/functions/action-status' const reactionId = 12345678 // from reactEmote().data.id // On precheck failure — posts message as a PR comment and adds thumbs-down reaction await actionStatus( context, octokit, reactionId, '### ⚠️ Cannot proceed\n\n> CI checks are failing', false // success = false → adds "-1" reaction ) // On custom success — posts message and adds "rocket" reaction await actionStatus( context, octokit, reactionId, '✅ Operation completed successfully', true, // success = true → adds "rocket" reaction false // altSuccessReaction = false (use rocket, not +1) ) // altSuccessReaction = true uses "+1" instead of "rocket" await actionStatus(context, octokit, reactionId, 'Done!', true, true) ``` -------------------------------- ### Define GitHub Actions Workflow Trigger Source: https://github.com/github/command/blob/main/README.md Configures the workflow to trigger on new issue comments. This ensures the action only runs when a comment is created, not on edits or other events. ```yaml name: "IssueOps github/command demo" on: issue_comment: types: [created] ``` -------------------------------- ### Validate Event Context with contextCheck Source: https://context7.com/github/command/llms.txt Ensures the workflow runs on an `issue_comment` event and the comment originates from an allowed context (`pull_request`, `issue`). Returns validation status and the effective context. ```javascript import {contextCheck} from './src/functions/context-check' // context is the @actions/github context object // Example: comment on a PR (issue_comment event where issue has a pull_request field) const result = await contextCheck(context) if (!result.valid) { // e.g., fired from a push event or an issue when only PR context is allowed console.log(`Invalid context: ${result.context}`) // 'push' or the event name return } // result.context will be 'pull_request' or 'issue' console.log(`Valid context: ${result.context}`) // 'pull_request' ``` -------------------------------- ### stringToArray Source: https://context7.com/github/command/llms.txt Utility function to parse comma-separated input strings into trimmed string arrays. ```APIDOC ## `stringToArray(string)` ### Description Utility used internally to parse comma-separated GitHub Actions inputs (e.g., `permissions`, `allowed_contexts`) into trimmed string arrays with empty-entry filtering. ### Parameters - **string**: The comma-separated input string. ### Returns - An array of strings. ### Usage Example ```javascript import {stringToArray} from './src/functions/string-to-array' const perms = await stringToArray('write,admin') console.log(perms) // ['write', 'admin'] const contexts = await stringToArray('pull_request, issue') console.log(contexts) // ['pull_request', 'issue'] const empty = await stringToArray(' ') console.log(empty) // [] // Used internally when parsing the `permissions` input: // core.getInput('permissions') → "write,admin" → ['write', 'admin'] // Actor's permission 'write' is checked against this array with .includes() ``` ``` -------------------------------- ### contextCheck(context) Source: https://context7.com/github/command/llms.txt Validates that the workflow is running in an `issue_comment` event and that the comment originates from an allowed context (`pull_request`, `issue`, or both) as defined by the `allowed_contexts` input. Returns `{ valid: boolean, context: 'pull_request' | 'issue' | eventName }`. ```APIDOC ## `contextCheck(context)` — Validate Event Context Validates that the workflow is running in an `issue_comment` event and that the comment originates from an allowed context (`pull_request`, `issue`, or both) as defined by the `allowed_contexts` input. Returns `{ valid: boolean, context: 'pull_request' | 'issue' | eventName }`. ```javascript import {contextCheck} from './src/functions/context-check' // context is the @actions/github context object // Example: comment on a PR (issue_comment event where issue has a pull_request field) const result = await contextCheck(context) if (!result.valid) { // e.g., fired from a push event or an issue when only PR context is allowed console.log(`Invalid context: ${result.context}`) return } // result.context will be 'pull_request' or 'issue' console.log(`Valid context: ${result.context}`) ``` ``` -------------------------------- ### Add Emoji Reaction to Comment with reactEmote Source: https://context7.com/github/command/llms.txt Applies a specified emoji reaction to the triggering `issue_comment`. Supports predefined reactions and returns the reaction ID for potential later removal. Throws an error for invalid reaction names. ```javascript import {reactEmote} from './src/functions/react-emote' // Add "eyes" reaction immediately when a command is detected (signals "I see this") const reactRes = await reactEmote('eyes', context, octokit) console.log(reactRes.data.id) // e.g. 12345678 — saved to remove it later // Add a "rocket" reaction to signal success const rocketRes = await reactEmote('rocket', context, octokit) // Invalid reaction throws: try { await reactEmote('fire', context, octokit) } catch (e) { console.error(e.message) // 'Reaction "fire" is not a valid preset' } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.