diff --git a/packages/eas-cli/src/commands/webhook/create.ts b/packages/eas-cli/src/commands/webhook/create.ts index 1f5334e6d6..51814f7867 100644 --- a/packages/eas-cli/src/commands/webhook/create.ts +++ b/packages/eas-cli/src/commands/webhook/create.ts @@ -7,13 +7,38 @@ import { WebhookMutation } from '../../graphql/mutations/WebhookMutation'; import { ora } from '../../ora'; import { prepareInputParamsAsync } from '../../webhooks/input'; +interface RawWebhookCreateFlags { + event?: string; + url?: string; + secret?: string; + 'non-interactive'?: boolean; +} + +interface WebhookCreateCommandFlags { + event?: WebhookType; + url?: string; + secret?: string; + 'non-interactive': boolean; +} + +export function maybeGetWebhookType( + webhookTypeString: string | undefined +): WebhookType | undefined { + if (!webhookTypeString) { + return undefined; + } + return Object.values(WebhookType).find(webhookType => webhookType === webhookTypeString); +} + +const EVENT_FLAG_OPTIONS = [WebhookType.Build, WebhookType.Submit]; + export default class WebhookCreate extends EasCommand { static override description = 'create a webhook'; static override flags = { - event: Flags.enum({ + event: Flags.string({ description: 'Event type that triggers the webhook', - options: [WebhookType.Build, WebhookType.Submit], + options: EVENT_FLAG_OPTIONS, }), url: Flags.string({ description: 'Webhook URL', @@ -31,7 +56,8 @@ export default class WebhookCreate extends EasCommand { }; async runAsync(): Promise { - const { flags } = await this.parse(WebhookCreate); + const { flags: rawFlags } = await this.parse(WebhookCreate); + const flags = await this.sanitizeFlagsAsync(rawFlags); const { privateProjectConfig: { projectId }, loggedIn: { graphqlClient }, @@ -49,4 +75,14 @@ export default class WebhookCreate extends EasCommand { throw err; } } + + private async sanitizeFlagsAsync( + flags: RawWebhookCreateFlags + ): Promise { + return { + ...flags, + event: maybeGetWebhookType(flags.event), + 'non-interactive': flags['non-interactive'] ?? false, + }; + } } diff --git a/packages/eas-cli/src/commands/webhook/delete.ts b/packages/eas-cli/src/commands/webhook/delete.ts index 13d0b42325..f3a8357114 100644 --- a/packages/eas-cli/src/commands/webhook/delete.ts +++ b/packages/eas-cli/src/commands/webhook/delete.ts @@ -1,3 +1,4 @@ +import { Args } from '@oclif/core'; import assert from 'assert'; import chalk from 'chalk'; import nullthrows from 'nullthrows'; @@ -16,13 +17,12 @@ import { formatWebhook } from '../../webhooks/formatWebhook'; export default class WebhookDelete extends EasCommand { static override description = 'delete a webhook'; - static override args = [ - { - name: 'ID', + static override args = { + ID: Args.string({ required: false, description: 'ID of the webhook to delete', - }, - ]; + }), + }; static override flags = { ...EASNonInteractiveFlag, @@ -45,8 +45,9 @@ export default class WebhookDelete extends EasCommand { nonInteractive, }); - let webhook: WebhookFragment | undefined = - webhookId && (await WebhookQuery.byIdAsync(graphqlClient, webhookId)); + let webhook: WebhookFragment | undefined = webhookId + ? await WebhookQuery.byIdAsync(graphqlClient, webhookId) + : undefined; if (!webhookId) { const webhooks = await fetchWebhooksByAppIdAsync(graphqlClient, projectId); if (webhooks.length === 0) { diff --git a/packages/eas-cli/src/commands/webhook/list.ts b/packages/eas-cli/src/commands/webhook/list.ts index 08b82c7865..f8b8f29b3b 100644 --- a/packages/eas-cli/src/commands/webhook/list.ts +++ b/packages/eas-cli/src/commands/webhook/list.ts @@ -10,14 +10,27 @@ import { ora } from '../../ora'; import { getDisplayNameForProjectIdAsync } from '../../project/projectUtils'; import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json'; import { formatWebhook } from '../../webhooks/formatWebhook'; +import { maybeGetWebhookType } from './create'; + +interface RawWebhookListFlags { + event?: string; + json?: boolean; +} + +interface WebhookListCommandFlags { + event?: WebhookType; + json?: boolean; +} + +const EVENT_FLAG_OPTIONS = [WebhookType.Build, WebhookType.Submit]; export default class WebhookList extends EasCommand { static override description = 'list webhooks'; static override flags = { - event: Flags.enum({ + event: Flags.string({ description: 'Event type that triggers the webhook', - options: [WebhookType.Build, WebhookType.Submit], + options: EVENT_FLAG_OPTIONS, }), ...EasJsonOnlyFlag, }; @@ -28,9 +41,8 @@ export default class WebhookList extends EasCommand { }; async runAsync(): Promise { - const { - flags: { event, json }, - } = await this.parse(WebhookList); + const { flags: rawFlags } = await this.parse(WebhookList); + const { event, json } = await this.sanitizeFlagsAsync(rawFlags); if (json) { enableJsonOutput(); } @@ -72,4 +84,11 @@ export default class WebhookList extends EasCommand { throw err; } } + + private async sanitizeFlagsAsync(flags: RawWebhookListFlags): Promise { + return { + ...flags, + event: maybeGetWebhookType(flags.event), + }; + } } diff --git a/packages/eas-cli/src/commands/webhook/update.ts b/packages/eas-cli/src/commands/webhook/update.ts index 2f6a6707f0..d905043789 100644 --- a/packages/eas-cli/src/commands/webhook/update.ts +++ b/packages/eas-cli/src/commands/webhook/update.ts @@ -8,6 +8,25 @@ import { WebhookQuery } from '../../graphql/queries/WebhookQuery'; import { ora } from '../../ora'; import pick from '../../utils/expodash/pick'; import { prepareInputParamsAsync } from '../../webhooks/input'; +import { maybeGetWebhookType } from './create'; + +interface RawWebhookUpdateFlags { + id: string; + event?: string; + url?: string; + secret?: string; + 'non-interactive'?: boolean; +} + +interface WebhookUpdateCommandFlags { + id: string; + event?: WebhookType; + url?: string; + secret?: string; + 'non-interactive': boolean; +} + +const EVENT_FLAG_OPTIONS = [WebhookType.Build, WebhookType.Submit]; export default class WebhookUpdate extends EasCommand { static override description = 'update a webhook'; @@ -17,9 +36,9 @@ export default class WebhookUpdate extends EasCommand { description: 'Webhook ID', required: true, }), - event: Flags.enum({ + event: Flags.string({ description: 'Event type that triggers the webhook', - options: [WebhookType.Build, WebhookType.Submit], + options: EVENT_FLAG_OPTIONS, }), url: Flags.string({ description: 'Webhook URL', @@ -36,7 +55,8 @@ export default class WebhookUpdate extends EasCommand { }; async runAsync(): Promise { - const { flags } = await this.parse(WebhookUpdate); + const { flags: rawFlags } = await this.parse(WebhookUpdate); + const flags = await this.sanitizeFlagsAsync(rawFlags); const { loggedIn: { graphqlClient }, } = await this.getContextAsync(WebhookUpdate, { nonInteractive: flags['non-interactive'] }); @@ -58,4 +78,14 @@ export default class WebhookUpdate extends EasCommand { throw err; } } + + private async sanitizeFlagsAsync( + flags: RawWebhookUpdateFlags + ): Promise { + return { + ...flags, + event: maybeGetWebhookType(flags.event), + 'non-interactive': flags['non-interactive'] ?? false, + }; + } } diff --git a/packages/eas-cli/src/commands/webhook/view.ts b/packages/eas-cli/src/commands/webhook/view.ts index a5aae947c4..a2bd4f9dc4 100644 --- a/packages/eas-cli/src/commands/webhook/view.ts +++ b/packages/eas-cli/src/commands/webhook/view.ts @@ -1,3 +1,5 @@ +import { Args } from '@oclif/core'; + import EasCommand from '../../commandUtils/EasCommand'; import { WebhookQuery } from '../../graphql/queries/WebhookQuery'; import Log from '../../log'; @@ -7,13 +9,12 @@ import { formatWebhook } from '../../webhooks/formatWebhook'; export default class WebhookView extends EasCommand { static override description = 'view a webhook'; - static override args = [ - { - name: 'ID', + static override args = { + ID: Args.string({ required: true, description: 'ID of the webhook to view', - }, - ]; + }), + }; static override contextDefinition = { ...this.ContextOptions.LoggedIn,