Skip to content

Commit eb29e63

Browse files
authored
Merge pull request #1017 from CleverCloud/fix-webhooks
2 parents 5639fd9 + b4be4a0 commit eb29e63

File tree

9 files changed

+24
-19
lines changed

9 files changed

+24
-19
lines changed

docs/llms-documentation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ name Notification name
16051605
--notify <email-address|user-id|organisation> Notify a user, a specific email address or the whole organisation (multiple values allowed, comma separated) (required)
16061606
--event <event-type> Restrict notifications to specific event types
16071607
-o, --org, --owner <org-id|org-name> Organisation to target by its ID (or name, if unambiguous)
1608-
--service <service-id> Restrict notifications to specific applications and add-ons
1608+
--service <service-id> Restrict notifications to specific applications and add-ons (requires --org)
16091609

16101610
### notify-email remove
16111611

@@ -2161,7 +2161,7 @@ url Webhook URL
21612161
--event <event-type> Restrict notifications to specific event types
21622162
--format <format> Format of the body sent to the webhook ('raw', 'slack', 'gitter', or 'flowdock') (default: raw)
21632163
-o, --org, --owner <org-id|org-name> Organisation to target by its ID (or name, if unambiguous)
2164-
--service <service-id> Restrict notifications to specific applications and add-ons
2164+
--service <service-id> Restrict notifications to specific applications and add-ons (requires --org)
21652165

21662166
### webhooks remove
21672167

src/commands/global.options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export const notificationScopeOption = defineOption({
148148
.string()
149149
.transform((v) => v.split(','))
150150
.optional(),
151-
description: 'Restrict notifications to specific applications and add-ons',
151+
description: 'Restrict notifications to specific applications and add-ons (requires --org)',
152152
placeholder: 'service-id',
153153
});
154154

src/commands/notify-email/notify-email.add.command.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ export const notifyEmailAddCommand = defineCommand({
4848
async handler(options, name) {
4949
const { org, event: events, service, notify: notifTargets } = options;
5050

51-
// TODO: fix alias option
52-
const { ownerId, appId } = await getOwnerAndApp(null, org, !org && !service);
51+
if (service != null && org == null) {
52+
throw new Error('--org is required when using --service');
53+
}
54+
55+
const { ownerId, appId } = await getOwnerAndApp(org, org == null && service == null);
5356

5457
const body = {
5558
name,

src/commands/notify-email/notify-email.command.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ export const notifyEmailCommand = defineCommand({
1818
async handler(options) {
1919
const { org, listAll, format } = options;
2020

21-
// TODO: fix alias option
22-
const { ownerId, appId } = await getOwnerAndApp(null, org, !listAll);
21+
const { ownerId, appId } = await getOwnerAndApp(org, org == null && !listAll);
2322
const hooks = await getEmailhooks({ ownerId }).then(sendToApi);
2423

2524
const formattedHooks = hooks

src/commands/notify-email/notify-email.docs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ clever notify-email add --notify <email-address|user-id|organisation> <name> [op
3737
|`--notify` `<email-address\|user-id\|organisation>`|Notify a user, a specific email address or the whole organisation (multiple values allowed, comma separated) **(required)**|
3838
|`--event` `<event-type>`|Restrict notifications to specific event types|
3939
|`-o`, `--org`, `--owner` `<org-id\|org-name>`|Organisation to target by its ID (or name, if unambiguous)|
40-
|`--service` `<service-id>`|Restrict notifications to specific applications and add-ons|
40+
|`--service` `<service-id>`|Restrict notifications to specific applications and add-ons (requires --org)|
4141

4242
## ➡️ `clever notify-email remove` <kbd>Since 0.6.1</kbd>
4343

src/commands/webhooks/webhooks.add.command.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ export const webhooksAddCommand = defineCommand({
3434
async handler(options, name, hookUrl) {
3535
const { org, format, event: events, service } = options;
3636

37-
// TODO: fix alias option
38-
const { ownerId, appId } = await getOwnerAndApp(null, org, !org && !service);
37+
if (service != null && org == null) {
38+
throw new Error('--org is required when using --service');
39+
}
40+
41+
const { ownerId, appId } = await getOwnerAndApp(org, org == null && service == null);
3942

4043
const body = {
4144
name,

src/commands/webhooks/webhooks.command.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ export const webhooksCommand = defineCommand({
1818
async handler(options) {
1919
const { org, listAll, format } = options;
2020

21-
// TODO: fix alias option
22-
const { ownerId, appId } = await getOwnerAndApp(null, org, !listAll);
21+
const { ownerId, appId } = await getOwnerAndApp(org, org == null && !listAll);
2322
const hooks = await getWebhooks({ ownerId }).then(sendToApi);
2423

2524
const formattedHooks = hooks

src/commands/webhooks/webhooks.docs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ clever webhooks add <name> <url> [options]
3838
|`--event` `<event-type>`|Restrict notifications to specific event types|
3939
|`--format` `<format>`|Format of the body sent to the webhook ('raw', 'slack', 'gitter', or 'flowdock') (default: raw)|
4040
|`-o`, `--org`, `--owner` `<org-id\|org-name>`|Organisation to target by its ID (or name, if unambiguous)|
41-
|`--service` `<service-id>`|Restrict notifications to specific applications and add-ons|
41+
|`--service` `<service-id>`|Restrict notifications to specific applications and add-ons (requires --org)|
4242

4343
## ➡️ `clever webhooks remove` <kbd>Since 0.6.0</kbd>
4444

src/models/notification.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ export function getOrgaIdOrUserId(orgIdOrName) {
1010
return orgIdOrName == null ? User.getCurrentId() : Organisation.getId(orgIdOrName);
1111
}
1212

13-
export async function getOwnerAndApp(alias, org, useLinkedApp) {
14-
if (!useLinkedApp) {
15-
const ownerId = await getOrgaIdOrUserId(org);
16-
return { ownerId };
13+
export async function getOwnerAndApp(org, useLinkedApp) {
14+
if (org != null) {
15+
return { ownerId: await Organisation.getId(org) };
1716
}
18-
19-
return AppConfig.getAppDetails({ alias });
17+
if (useLinkedApp) {
18+
return AppConfig.getAppDetails({});
19+
}
20+
return { ownerId: await User.getCurrentId() };
2021
}

0 commit comments

Comments
 (0)