Skip to content

Commit

Permalink
Update location of typescript definitions (#743)
Browse files Browse the repository at this point in the history
  • Loading branch information
prince-chrismc authored May 20, 2021
1 parent 3bd7461 commit 8dc2d6e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
```

Expand Down

0 comments on commit 8dc2d6e

Please sign in to comment.