diff --git a/README.md b/README.md index ad576e4..59183f6 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ See it in action with the following live demos. - [Examples](docs/examples.md) - [Standard configuration](#standard-configuration) - [Advanced configuration](docs/advanced-configuration.md) +- [Updating to v2](docs/updating.md) ## Dispatching commands @@ -49,7 +50,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Slash Command Dispatch - uses: peter-evans/slash-command-dispatch@v1 + uses: peter-evans/slash-command-dispatch@v2 with: token: ${{ secrets.REPO_ACCESS_TOKEN }} commands: deploy, integration-test, build-docs @@ -90,7 +91,7 @@ You can use a [PAT](https://help.github.com/en/github/authenticating-to-github/c ```yml - name: Slash Command Dispatch - uses: peter-evans/slash-command-dispatch@v1 + uses: peter-evans/slash-command-dispatch@v2 with: token: ${{ secrets.REPO_ACCESS_TOKEN }} reaction-token: ${{ secrets.REPO_ACCESS_TOKEN }} @@ -172,7 +173,7 @@ These named arguments can be accessed in a workflow as follows. #### `github` and `pull_request` contexts -The payload contains the complete `github` context of the `issue_comment` event at path `github.event.client_payload.github`. +The payload contains the `github` context of the `issue_comment` event at path `github.event.client_payload.github`. Additionally, if the comment was made in a pull request, the action calls the [GitHub API to fetch the pull request detail](https://developer.github.com/v3/pulls/#get-a-single-pull-request) and attach it to the payload at path `github.event.client_payload.pull_request`. You can inspect the payload with the following step. @@ -183,6 +184,8 @@ You can inspect the payload with the following step. run: echo "$PAYLOAD_CONTEXT" ``` +Note that the `client_payload.github.payload.issue.body` and `client_payload.pull_request.body` context properties will be truncated if they exceed 1000 characters. + ### Responding to the comment on command completion Using [create-or-update-comment](https://github.com/peter-evans/create-or-update-comment) action there are a number of ways you can respond to the comment once the command has completed. diff --git a/__test__/command-helper.test.ts b/__test__/command-helper.test.ts index 5fc0c84..4b7f295 100644 --- a/__test__/command-helper.test.ts +++ b/__test__/command-helper.test.ts @@ -20,7 +20,7 @@ describe('command-helper tests', () => { permission: 'write', issueType: 'both', allowEdits: false, - // Should be process.env.GITHUB_REPOSITORY, but '' for tests + // Should be the value of github.repository, but '' for tests repository: '', eventTypeSuffix: '-command', namedArgs: false, diff --git a/dist/index.js b/dist/index.js index e55fb09..5bf3dc1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1202,9 +1202,16 @@ function run() { slash_command: {}, github: github.context }; + // Truncate the body to keep the size of the payload under the max + if (clientPayload.github.payload.issue && + clientPayload.github.payload.issue.body) { + clientPayload.github.payload.issue.body = clientPayload.github.payload.issue.body.slice(0, 1000); + } // Get the pull request context for the dispatch payload if (isPullRequest) { const { data: pullRequest } = yield octokit.pulls.get(Object.assign(Object.assign({}, github.context.repo), { pull_number: github.context.payload.issue.number })); + // Truncate the body to keep the size of the payload under the max + pullRequest.body = pullRequest.body.slice(0, 1000); clientPayload['pull_request'] = pullRequest; } // Dispatch for each matching configuration diff --git a/docs/advanced-configuration.md b/docs/advanced-configuration.md index 95e66d8..666344a 100644 --- a/docs/advanced-configuration.md +++ b/docs/advanced-configuration.md @@ -8,7 +8,7 @@ For example, the following basic configuration means that all commands must have ```yml - name: Slash Command Dispatch - uses: peter-evans/slash-command-dispatch@v1 + uses: peter-evans/slash-command-dispatch@v2 with: token: ${{ secrets.REPO_ACCESS_TOKEN }} commands: deploy, integration-test, build-docs @@ -35,7 +35,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Slash Command Dispatch - uses: peter-evans/slash-command-dispatch@v1 + uses: peter-evans/slash-command-dispatch@v2 with: token: ${{ secrets.REPO_ACCESS_TOKEN }} config: > @@ -77,7 +77,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Slash Command Dispatch - uses: peter-evans/slash-command-dispatch@v1 + uses: peter-evans/slash-command-dispatch@v2 with: token: ${{ secrets.REPO_ACCESS_TOKEN }} config-from-file: .github/slash-command-dispatch.json diff --git a/docs/getting-started.md b/docs/getting-started.md index 420a493..a4866f1 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -56,7 +56,7 @@ Command processing setup is complete! Now we need to setup command dispatch for runs-on: ubuntu-latest steps: - name: Slash Command Dispatch - uses: peter-evans/slash-command-dispatch@v1 + uses: peter-evans/slash-command-dispatch@v2 with: token: ${{ secrets.REPO_ACCESS_TOKEN }} commands: example diff --git a/docs/updating.md b/docs/updating.md new file mode 100644 index 0000000..80a559a --- /dev/null +++ b/docs/updating.md @@ -0,0 +1,9 @@ +## Updating from `v1` to `v2` + +### Breaking changes + +- The `client_payload.github.payload.issue.body` and `client_payload.pull_request.body` context properties will now be truncated if they exceed 1000 characters. + +### New features + +- diff --git a/src/main.ts b/src/main.ts index dabfccb..743abcb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -145,6 +145,16 @@ async function run(): Promise { slash_command: {}, github: github.context } + // Truncate the body to keep the size of the payload under the max + if ( + clientPayload.github.payload.issue && + clientPayload.github.payload.issue.body + ) { + clientPayload.github.payload.issue.body = clientPayload.github.payload.issue.body.slice( + 0, + 1000 + ) + } // Get the pull request context for the dispatch payload if (isPullRequest) { @@ -152,6 +162,8 @@ async function run(): Promise { ...github.context.repo, pull_number: github.context.payload.issue.number }) + // Truncate the body to keep the size of the payload under the max + pullRequest.body = pullRequest.body.slice(0, 1000) clientPayload['pull_request'] = pullRequest }