1
0
Fork 0
mirror of https://github.com/actions/toolkit.git synced 2025-06-08 06:27:02 +09:00

Update location of typescript definitions (#743)

https://github.com/octokit/webhooks.js#typescript
This commit is contained in:
Chris Mc 2021-05-20 16:49:57 -04:00 committed by GitHub
parent 3bd746139f
commit 8dc2d6eb6a
Signed by: github
GPG key ID: 4AEE18F83AFDEB23

View file

@ -59,18 +59,19 @@ const newIssue = await octokit.rest.issues.create({
## Webhook payload typescript definitions
The npm module `@octokit/webhooks` provides type definitions for the response payloads. You can cast the payload to these types for better type information.
The npm module `@octokit/webhooks-definitions` provides type definitions for the response payloads. You can cast the payload to these types for better type information.
First, install the npm module `npm install @octokit/webhooks`
First, install the npm module `npm install @octokit/webhooks-definitions`
Then, assert the type based on the eventName
```ts
import * as core from '@actions/core'
import * as github from '@actions/github'
import * as Webhooks from '@octokit/webhooks'
import {PushEvent} from '@octokit/webhooks-definitions/schema'
if (github.context.eventName === 'push') {
const pushPayload = github.context.payload as Webhooks.WebhookPayloadPush
core.info(`The head commit is: ${pushPayload.head}`)
const pushPayload = github.context.payload as PushEvent
core.info(`The head commit is: ${pushPayload.head_commit}`)
}
```