Skip to content

Commit

Permalink
Merge pull request #77 from github/brrygrdn/remove-repo-dispatch
Browse files Browse the repository at this point in the history
Remove support for repository dispatch
  • Loading branch information
Barry Gordon authored and GitHub committed Aug 24, 2021
2 parents b666fbe + ec342a7 commit 2cb4918
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 46 deletions.
20 changes: 1 addition & 19 deletions __tests__/inputs.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Context} from '@actions/github/lib/context'
import {getJobParameters, DISPATCH_EVENT_NAME} from '../src/inputs'
import {getJobParameters} from '../src/inputs'

test('returns null on issue_comment', () => {
const ctx = new Context()
Expand All @@ -9,24 +9,6 @@ test('returns null on issue_comment', () => {
expect(params).toEqual(null)
})

test('loads repository_dispatch', () => {
const ctx = new Context()
ctx.eventName = 'repository_dispatch'
ctx.payload = {
action: DISPATCH_EVENT_NAME,
client_payload: {
jobID: 1,
jobToken: 'xxx',
credentialsToken: 'yyy'
}
}

const params = getJobParameters(ctx)
expect(params?.jobID).toEqual(1)
expect(params?.jobToken).toEqual('xxx')
expect(params?.credentialsToken).toEqual('yyy')
})

test('loads dynamic', () => {
const ctx = new Context()
ctx.eventName = 'dynamic'
Expand Down
30 changes: 4 additions & 26 deletions src/inputs.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import * as core from '@actions/core'
import {Context} from '@actions/github/lib/context'
import {
RepositoryDispatchEvent,
WorkflowDispatchEvent
} from '@octokit/webhooks-definitions/schema'
import {WorkflowDispatchEvent} from '@octokit/webhooks-definitions/schema'
import {JobParameters} from './api-client'

// FIXME: '@octokit/webhooks-definitions' assumes this is the only repository_dispatch event type, workaround that
// https://github.com/octokit/webhooks/blob/0b04a009507aa35811e91a10703bbb2a33bdeff4/payload-schemas/schemas/repository_dispatch/on-demand-test.schema.json#L14
export const DISPATCH_EVENT_NAME = 'on-demand-test'

export function getJobParameters(ctx: Context): JobParameters | null {
switch (ctx.eventName) {
case 'dynamic':
case 'workflow_dispatch':
return fromWorkflowInputs(ctx)
case 'repository_dispatch':
return fromRepoDispatch(ctx)
}
core.debug(`Unknown event name: ${ctx.eventName}`)
core.info(
`Dependabot Updater Action does not support '${ctx.eventName}' events.`
)
return null
}

Expand All @@ -31,18 +24,3 @@ function fromWorkflowInputs(ctx: Context): JobParameters {
evt.inputs.dependabotAPIURL as string
)
}

function fromRepoDispatch(ctx: Context): JobParameters | null {
const evt = ctx.payload as RepositoryDispatchEvent
if (evt.action !== DISPATCH_EVENT_NAME) {
core.debug(`skipping repository_dispatch for ${evt.action}`)
return null
}
const payload = evt.client_payload
return new JobParameters(
payload.jobID as number,
payload.jobToken as string,
payload.credentialsToken as string,
payload.dependabotAPIURL as string
)
}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function run(): Promise<void> {
// Decode JobParameters:
const params = getJobParameters(github.context)
if (params === null) {
return
return // No parameters, nothing to do
}

core.info(JSON.stringify(params))
Expand Down

0 comments on commit 2cb4918

Please sign in to comment.