Skip to content

Commit

Permalink
Update extractEvent function
Browse files Browse the repository at this point in the history
  • Loading branch information
olly committed Mar 19, 2021
1 parent 5613505 commit 8cc6a98
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
8 changes: 4 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import {Context} from '@actions/github/lib/context'
import {WebhookPayload} from '@actions/github/lib/interfaces'
import {DeploymentEnvironment} from './DeploymentEnvironment'
import {Environment} from './Environment'
import {Octokit} from '@octokit/core'
Expand All @@ -21,9 +21,9 @@ const ORGANISATION = 'switcher-ie'

function extractEvent<
EventName extends keyof EventPayloadMap,
Payload extends EventPayloadMap[EventName]
>(context: Context): Payload {
return context.payload as Payload
Event extends EventPayloadMap[EventName]
>(eventName: EventName, payload: WebhookPayload): Event {
return payload as Event
}

async function createDeployment(
Expand Down Expand Up @@ -168,16 +168,17 @@ async function triggerDeployment(): Promise<Deployment[]> {
// label which doesn't have an open PR assigned.
// - if PR event: check PR for labels, create staging deployment for each match label.
// - else: fail step

switch (github.context.eventName) {
case 'push':
return await triggerDeploymentsFromPushEvent(
client,
extractEvent(github.context)
extractEvent(github.context.eventName, github.context.payload)
)
case 'pull_request':
return await triggerDeploymentsFromPullRequestEvent(
client,
extractEvent(github.context)
extractEvent(github.context.eventName, github.context.payload)
)
default:
throw new Error(
Expand Down

0 comments on commit 8cc6a98

Please # to comment.