Skip to content

Commit

Permalink
Merge pull request #54 from github/reaction-fixes
Browse files Browse the repository at this point in the history
Reaction fixes
  • Loading branch information
GrantBirki authored Dec 12, 2024
2 parents 07212c2 + 34f94d8 commit 8880fcc
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 19 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ As seen above, we have a single example step. Perhaps you would actually use a r
| `github_token` | `true` | `${{ github.token }}` | The GitHub token used to create an authenticated client - Provided for you by default! |
| `status` | `true` | `${{ job.status }}` | The status of the GitHub Actions - For use in the post run workflow - Provided for you by default! |
| `reaction` | `true` | `eyes` | If set, the specified emoji "reaction" is put on the comment to indicate that the trigger was detected. For example, "rocket" or "eyes" |
| `success_reaction` | `true` | `+1` | The reaction to add to the comment that triggered the Action if its execution was successful |
| `failure_reaction` | `true` | `-1` | The reaction to add to the comment that triggered the Action if its execution failed |
| `allowed_contexts` | `true` | `pull_request` | A comma separated list of comment contexts that are allowed to trigger this IssueOps command. Pull requests and issues are the only currently supported contexts. To allow IssueOps commands to be invoked from both PRs and issues, set this option to the following: `"pull_request,issue"`. By default, the only place this Action will allow IssueOps commands from is pull requests |
| `permissions` | `true` | `"write,maintain,admin"` | The allowed GitHub permissions an actor can have to invoke IssueOps commands |
| `allow_drafts` | `true` | `"false"` | Whether or not to allow this IssueOps command to be run on draft pull requests |
Expand Down
20 changes: 20 additions & 0 deletions __tests__/schemas/action.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,26 @@ inputs:
default:
type: string
required: true
success_reaction:
description:
type: string
required: true
required:
type: boolean
required: true
default:
type: string
required: true
failure_reaction:
description:
type: string
required: true
required:
type: boolean
required: true
default:
type: string
required: true
allowed_contexts:
description:
type: string
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ inputs:
description: 'If set, the specified emoji "reaction" is put on the comment to indicate that the trigger was detected. For example, "rocket" or "eyes"'
required: true
default: "eyes"
success_reaction:
description: 'The reaction to add to the comment that triggered the Action if its execution was successful'
required: true
default: "+1"
failure_reaction:
description: 'The reaction to add to the comment that triggered the Action if its execution failed'
required: true
default: "-1"
allowed_contexts:
description: 'A comma separated list of comment contexts that are allowed to trigger this IssueOps command. Pull requests and issues are the only currently supported contexts'
required: true
Expand Down
20 changes: 11 additions & 9 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/functions/post-reactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
// :param reaction: The reaction to add to the issue_comment
// :param reaction_id: The reaction_id of the initial reaction on the issue_comment
export async function postReactions(octokit, context, reaction, reaction_id) {
// Update the action status to indicate the result of the action as a reaction
// add a reaction to the issue_comment to indicate success or failure
await octokit.rest.reactions.createForIssueComment({
// remove the initial reaction on the IssueOp comment that triggered this action
await octokit.rest.reactions.deleteForIssueComment({
...context.repo,
comment_id: context.payload.comment.id,
content: reaction
reaction_id: parseInt(reaction_id)
})

// remove the initial reaction on the IssueOp comment that triggered this action
await octokit.rest.reactions.deleteForIssueComment({
// Update the action status to indicate the result of the action as a reaction
// add a reaction to the issue_comment to indicate success or failure
await octokit.rest.reactions.createForIssueComment({
...context.repo,
comment_id: context.payload.comment.id,
reaction_id: parseInt(reaction_id)
content: reaction
})
}
6 changes: 4 additions & 2 deletions src/functions/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ export async function post() {
}

// Select the reaction to add to the issue_comment
// If it is a success, use the user defined reaction
// Otherwise, add a thumbs down reaction
var reaction
if (success) {
reaction = thumbsUp
reaction = core.getInput('success_reaction') || thumbsUp
} else {
reaction = thumbsDown
reaction = core.getInput('failed_reaction') || thumbsDown
}

// Update the reactions on the command comment
Expand Down

0 comments on commit 8880fcc

Please sign in to comment.