mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2026-04-07 13:03:14 +08:00
Update location of typescript definitions (#743)
https://github.com/octokit/webhooks.js#typescript
This commit is contained in:
@@ -59,18 +59,19 @@ const newIssue = await octokit.rest.issues.create({
|
|||||||
|
|
||||||
## Webhook payload typescript definitions
|
## 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
|
Then, assert the type based on the eventName
|
||||||
```ts
|
```ts
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as github from '@actions/github'
|
import * as github from '@actions/github'
|
||||||
import * as Webhooks from '@octokit/webhooks'
|
import {PushEvent} from '@octokit/webhooks-definitions/schema'
|
||||||
|
|
||||||
if (github.context.eventName === 'push') {
|
if (github.context.eventName === 'push') {
|
||||||
const pushPayload = github.context.payload as Webhooks.WebhookPayloadPush
|
const pushPayload = github.context.payload as PushEvent
|
||||||
core.info(`The head commit is: ${pushPayload.head}`)
|
core.info(`The head commit is: ${pushPayload.head_commit}`)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user