Truncate body context properties

This commit is contained in:
Peter Evans
2020-07-20 17:24:08 +09:00
parent ad9cf8de57
commit dde66842e8
7 changed files with 39 additions and 8 deletions
+6 -3
View File
@@ -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.
+1 -1
View File
@@ -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,
+7
View File
@@ -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
+3 -3
View File
@@ -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
+1 -1
View File
@@ -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
+9
View File
@@ -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
-
+12
View File
@@ -145,6 +145,16 @@ async function run(): Promise<void> {
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<void> {
...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
}