Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/github-actions-a1c…
Browse files Browse the repository at this point in the history
…ff6d793
  • Loading branch information
GrantBirki authored Dec 12, 2024
2 parents 160bd60 + 36e621c commit 6e22056
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 33 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ jobs:
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
Expand Down Expand Up @@ -139,7 +140,7 @@ jobs:
runs-on: ubuntu-latest
steps:
# Checkout your projects repository
- uses: actions/checkout@v3
- uses: actions/checkout@v4
```

Sets up your `demo` job, uses an ubuntu runner, and checks out your repo - Just some standard setup for a general Action. We also add an `if:` statement here to only run this workflow on pull request comments to make it a little more specific (if necessary)
Expand Down Expand Up @@ -185,6 +186,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 Expand Up @@ -213,6 +216,8 @@ As seen above, we have a single example step. Perhaps you would actually use a r
| `fork_label` | The API label field returned for the fork |
| `fork_checkout` | The console command presented in the GitHub UI to checkout a given fork locally |
| `fork_full_name` | The full name of the fork in "org/repo" format |
| `sha` | The commit sha if being used in the context of a pull request |
| `ref` | The ref if being used in the context of a pull request |

## Allowlist 👩‍🔬

Expand Down
28 changes: 28 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 Expand Up @@ -218,6 +238,14 @@ outputs:
description:
type: string
required: true
ref:
description:
type: string
required: true
sha:
description:
type: string
required: true
initial_reaction_id:
description:
type: string
Expand Down
12 changes: 12 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 Expand Up @@ -87,6 +95,10 @@ outputs:
description: 'The console command presented in the GitHub UI to checkout a given fork locally'
fork_full_name:
description: 'The full name of the fork in "org/repo" format'
sha:
description: 'The commit sha if being used in the context of a pull request'
ref:
description: 'The ref if being used in the context of a pull request'
runs:
using: "node20"
main: "dist/index.js"
Expand Down
35 changes: 22 additions & 13 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.

8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.25.9",
"@babel/preset-env": "^7.26.0",
"@types/node": "^22.10.0",
"@types/node": "^22.10.1",
"@vercel/ncc": "^0.38.3",
"@babel/core": "^7.26.0",
"babel-jest": "^29.7.0",
Expand Down
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
15 changes: 11 additions & 4 deletions src/functions/prechecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ export async function prechecks(
// CI checks are set to be bypassed and the PR has not been reviewed
} else if (
commitStatus === 'skip_ci' &&
reviewDecision === 'REVIEW_REQUIRED'
(reviewDecision === 'REVIEW_REQUIRED' ||
reviewDecision === 'CHANGES_REQUESTED')
) {
message = `### ⚠️ Cannot proceed with operation\n\n> CI checks are not required for this operation but the PR has not been reviewed`
return {message: message, status: false}
Expand All @@ -257,7 +258,8 @@ export async function prechecks(

// If CI is passing but the PR has not been reviewed
} else if (
reviewDecision === 'REVIEW_REQUIRED' &&
(reviewDecision === 'REVIEW_REQUIRED' ||
reviewDecision === 'CHANGES_REQUESTED') &&
commitStatus === 'SUCCESS'
) {
message = `### ⚠️ Cannot proceed with operation\n\n> CI checks are passing but the PR has not been reviewed`
Expand All @@ -270,7 +272,8 @@ export async function prechecks(

// If CI is pending and the PR has not been reviewed
} else if (
reviewDecision === 'REVIEW_REQUIRED' &&
(reviewDecision === 'REVIEW_REQUIRED' ||
reviewDecision === 'CHANGES_REQUESTED') &&
commitStatus === 'PENDING'
) {
message = `### ⚠️ Cannot proceed with operation\n\n- reviewDecision: \`${reviewDecision}\`\n- commitStatus: \`${commitStatus}\`\n\n> CI is still in a pending state and reviews are also required for this operation`
Expand All @@ -282,7 +285,11 @@ export async function prechecks(
return {message: message, status: false}

// If CI is undefined and the PR has not been reviewed
} else if (reviewDecision === 'REVIEW_REQUIRED' && commitStatus === null) {
} else if (
(reviewDecision === 'REVIEW_REQUIRED' ||
reviewDecision === 'CHANGES_REQUESTED') &&
commitStatus === null
) {
message = `### ⚠️ Cannot proceed with operation\n\n- reviewDecision: \`${reviewDecision}\`\n- commitStatus: \`${commitStatus}\`\n\n> CI checks have not been defined but reviews are required for this operation`
return {message: message, status: false}

Expand Down

0 comments on commit 6e22056

Please sign in to comment.