-
Notifications
You must be signed in to change notification settings - Fork 76
/
update.ts
61 lines (53 loc) · 1.99 KB
/
update.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Flags } from '@oclif/core';
import EasCommand from '../../commandUtils/EasCommand';
import { EASNonInteractiveFlag } from '../../commandUtils/flags';
import { WebhookType } from '../../graphql/generated';
import { WebhookMutation } from '../../graphql/mutations/WebhookMutation';
import { WebhookQuery } from '../../graphql/queries/WebhookQuery';
import { ora } from '../../ora';
import pick from '../../utils/expodash/pick';
import { prepareInputParamsAsync } from '../../webhooks/input';
export default class WebhookUpdate extends EasCommand {
static override description = 'update a webhook';
static override flags = {
id: Flags.string({
description: 'Webhook ID',
required: true,
}),
event: Flags.enum({
description: 'Event type that triggers the webhook',
options: [WebhookType.Build, WebhookType.Submit],
}),
url: Flags.string({
description: 'Webhook URL',
}),
secret: Flags.string({
description:
"Secret used to create a hash signature of the request payload, provided in the 'Expo-Signature' header.",
}),
...EASNonInteractiveFlag,
};
static override contextDefinition = {
...this.ContextOptions.LoggedIn,
};
async runAsync(): Promise<void> {
const { flags } = await this.parse(WebhookUpdate);
const {
loggedIn: { graphqlClient },
} = await this.getContextAsync(WebhookUpdate, { nonInteractive: flags['non-interactive'] });
const webhookId = flags.id;
const webhook = await WebhookQuery.byIdAsync(graphqlClient, webhookId);
const webhookInputParams = await prepareInputParamsAsync(
pick(flags, ['event', 'url', 'secret', 'non-interactive']),
webhook
);
const spinner = ora('Updating a webhook').start();
try {
await WebhookMutation.updateWebhookAsync(graphqlClient, webhookId, webhookInputParams);
spinner.succeed('Successfully updated a webhook');
} catch (err) {
spinner.fail('Failed to update a webhook');
throw err;
}
}
}