deploy-vir 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config.d.ts +16 -3
- package/dist/git.js +9 -10
- package/dist/notifications/notification-params.d.ts +2 -1
- package/dist/notifications/slack.d.ts +1 -1
- package/dist/notifications/slack.js +23 -1
- package/package.json +1 -1
- package/src/config.ts +21 -3
- package/src/git.ts +4 -4
- package/src/notifications/notification-params.ts +2 -0
- package/src/notifications/slack.ts +23 -0
package/dist/config.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type MaybePromise } from '@augment-vir/common';
|
|
1
|
+
import { type MaybePromise, type PartialWithUndefined } from '@augment-vir/common';
|
|
2
2
|
import { type DeployResult } from './git.js';
|
|
3
3
|
/**
|
|
4
4
|
* The full deploy-vir config object.
|
|
@@ -18,9 +18,10 @@ export type DeployVirConfig = {
|
|
|
18
18
|
export type DeployVirHooks = {
|
|
19
19
|
/**
|
|
20
20
|
* Runs after the user accepts (or bypasses confirmation for) a deploy and the push has
|
|
21
|
-
* completed successfully. Fires once per branch deploy.
|
|
21
|
+
* completed successfully. Fires once per branch deploy. May optionally return values that
|
|
22
|
+
* modify the resulting notification message.
|
|
22
23
|
*/
|
|
23
|
-
postAccept?: ((params: Readonly<PostAcceptHookParams>) => MaybePromise<void>) | undefined;
|
|
24
|
+
postAccept?: ((params: Readonly<PostAcceptHookParams>) => MaybePromise<PostAcceptHookResult | void | undefined>) | undefined;
|
|
24
25
|
};
|
|
25
26
|
/**
|
|
26
27
|
* Params passed to a {@link DeployVirHooks.postAccept} hook.
|
|
@@ -35,6 +36,18 @@ export type PostAcceptHookParams = {
|
|
|
35
36
|
remoteName: string;
|
|
36
37
|
deployResult: Readonly<DeployResult>;
|
|
37
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* Optional values that a {@link DeployVirHooks.postAccept} hook can return to augment the resulting
|
|
41
|
+
* notification message.
|
|
42
|
+
*
|
|
43
|
+
* @category Config
|
|
44
|
+
*/
|
|
45
|
+
export type PostAcceptHookResult = PartialWithUndefined<{
|
|
46
|
+
/** Inserted into the notification immediately after the "<X> Pushed" header line. */
|
|
47
|
+
prependToNotification: string;
|
|
48
|
+
/** Appended to the very end of the notification message. */
|
|
49
|
+
appendToNotification: string;
|
|
50
|
+
}>;
|
|
38
51
|
/**
|
|
39
52
|
* All available targets for sending notifications to.
|
|
40
53
|
*
|
package/dist/git.js
CHANGED
|
@@ -100,16 +100,14 @@ export async function pushDeploy(git, branchConfig, repoConfig, remoteName, noti
|
|
|
100
100
|
after: afterCommit,
|
|
101
101
|
},
|
|
102
102
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
});
|
|
112
|
-
}
|
|
103
|
+
const hookResult = (await hooks?.postAccept?.({
|
|
104
|
+
branchConfig,
|
|
105
|
+
deployResult,
|
|
106
|
+
fromBranch,
|
|
107
|
+
remoteName,
|
|
108
|
+
repoConfig,
|
|
109
|
+
toBranch,
|
|
110
|
+
})) || undefined;
|
|
113
111
|
const resolvedNotifications = resolveNotifications({
|
|
114
112
|
branchConfig,
|
|
115
113
|
enableNotifications,
|
|
@@ -120,6 +118,7 @@ export async function pushDeploy(git, branchConfig, repoConfig, remoteName, noti
|
|
|
120
118
|
await sendNotifications(resolvedNotifications, {
|
|
121
119
|
branchConfig,
|
|
122
120
|
deployResult,
|
|
121
|
+
hookResult: hookResult || undefined,
|
|
123
122
|
repoConfig,
|
|
124
123
|
});
|
|
125
124
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type DeployVirBranchConfig, type DeployVirRepoConfig, type NotificationConfig, type NotificationTarget } from '../config.js';
|
|
1
|
+
import { type DeployVirBranchConfig, type DeployVirRepoConfig, type NotificationConfig, type NotificationTarget, type PostAcceptHookResult } from '../config.js';
|
|
2
2
|
import { type DeployResult } from '../git.js';
|
|
3
3
|
/**
|
|
4
4
|
* Params for sending a notification.
|
|
@@ -12,4 +12,5 @@ export type NotificationParams<Target extends NotificationTarget = NotificationT
|
|
|
12
12
|
notification: Readonly<Extract<NotificationConfig, {
|
|
13
13
|
target: Target;
|
|
14
14
|
}>>;
|
|
15
|
+
hookResult?: Readonly<PostAcceptHookResult> | undefined;
|
|
15
16
|
};
|
|
@@ -5,4 +5,4 @@ export { type ChatPostMessageArguments } from '@slack/web-api';
|
|
|
5
5
|
*
|
|
6
6
|
* @category Internal
|
|
7
7
|
*/
|
|
8
|
-
export declare function sendNotificationToSlack({ deployResult: { deployCommits: { deployedCommits, overwrittenCommits }, branchStatus: { after, before }, toBranchName, }, notification, repoConfig, }: Readonly<NotificationParams>): Promise<void>;
|
|
8
|
+
export declare function sendNotificationToSlack({ deployResult: { deployCommits: { deployedCommits, overwrittenCommits }, branchStatus: { after, before }, toBranchName, }, hookResult, notification, repoConfig, }: Readonly<NotificationParams>): Promise<void>;
|
|
@@ -41,7 +41,7 @@ function chunkSectionLines(lines) {
|
|
|
41
41
|
*
|
|
42
42
|
* @category Internal
|
|
43
43
|
*/
|
|
44
|
-
export async function sendNotificationToSlack({ deployResult: { deployCommits: { deployedCommits, overwrittenCommits }, branchStatus: { after, before }, toBranchName, }, notification, repoConfig, }) {
|
|
44
|
+
export async function sendNotificationToSlack({ deployResult: { deployCommits: { deployedCommits, overwrittenCommits }, branchStatus: { after, before }, toBranchName, }, hookResult, notification, repoConfig, }) {
|
|
45
45
|
const deployedCommitBullets = deployedCommits.map((commit) => formatCommit(repoConfig.commitBaseUrl, commit));
|
|
46
46
|
const overwrittenCommitBullets = overwrittenCommits.map((commit) => formatCommit(repoConfig.commitBaseUrl, commit));
|
|
47
47
|
const deployedCommitBulletLines = deployedCommitBullets.map((bullet) => `- ${bullet}`);
|
|
@@ -62,6 +62,17 @@ export async function sendNotificationToSlack({ deployResult: { deployCommits: {
|
|
|
62
62
|
text: `*${setFirstLetterCasing(repoConfig.name, StringCase.Upper)} ${setFirstLetterCasing(toBranchName, StringCase.Upper)}* Pushed`,
|
|
63
63
|
},
|
|
64
64
|
},
|
|
65
|
+
...(hookResult?.prependToNotification
|
|
66
|
+
? [
|
|
67
|
+
{
|
|
68
|
+
type: 'section',
|
|
69
|
+
text: {
|
|
70
|
+
type: 'mrkdwn',
|
|
71
|
+
text: hookResult.prependToNotification,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
]
|
|
75
|
+
: []),
|
|
65
76
|
{
|
|
66
77
|
type: 'context',
|
|
67
78
|
elements: [
|
|
@@ -107,6 +118,17 @@ export async function sendNotificationToSlack({ deployResult: { deployCommits: {
|
|
|
107
118
|
}),
|
|
108
119
|
]
|
|
109
120
|
: []),
|
|
121
|
+
...(hookResult?.appendToNotification
|
|
122
|
+
? [
|
|
123
|
+
{
|
|
124
|
+
type: 'section',
|
|
125
|
+
text: {
|
|
126
|
+
type: 'mrkdwn',
|
|
127
|
+
text: hookResult.appendToNotification,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
]
|
|
131
|
+
: []),
|
|
110
132
|
];
|
|
111
133
|
await sendSlackMessage(notification, {
|
|
112
134
|
attachments: [],
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {type MaybePromise} from '@augment-vir/common';
|
|
1
|
+
import {type MaybePromise, type PartialWithUndefined} from '@augment-vir/common';
|
|
2
2
|
import {type DeployResult} from './git.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -20,9 +20,14 @@ export type DeployVirConfig = {
|
|
|
20
20
|
export type DeployVirHooks = {
|
|
21
21
|
/**
|
|
22
22
|
* Runs after the user accepts (or bypasses confirmation for) a deploy and the push has
|
|
23
|
-
* completed successfully. Fires once per branch deploy.
|
|
23
|
+
* completed successfully. Fires once per branch deploy. May optionally return values that
|
|
24
|
+
* modify the resulting notification message.
|
|
24
25
|
*/
|
|
25
|
-
postAccept?:
|
|
26
|
+
postAccept?:
|
|
27
|
+
| ((
|
|
28
|
+
params: Readonly<PostAcceptHookParams>,
|
|
29
|
+
) => MaybePromise<PostAcceptHookResult | void | undefined>)
|
|
30
|
+
| undefined;
|
|
26
31
|
};
|
|
27
32
|
|
|
28
33
|
/**
|
|
@@ -39,6 +44,19 @@ export type PostAcceptHookParams = {
|
|
|
39
44
|
deployResult: Readonly<DeployResult>;
|
|
40
45
|
};
|
|
41
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Optional values that a {@link DeployVirHooks.postAccept} hook can return to augment the resulting
|
|
49
|
+
* notification message.
|
|
50
|
+
*
|
|
51
|
+
* @category Config
|
|
52
|
+
*/
|
|
53
|
+
export type PostAcceptHookResult = PartialWithUndefined<{
|
|
54
|
+
/** Inserted into the notification immediately after the "<X> Pushed" header line. */
|
|
55
|
+
prependToNotification: string;
|
|
56
|
+
/** Appended to the very end of the notification message. */
|
|
57
|
+
appendToNotification: string;
|
|
58
|
+
}>;
|
|
59
|
+
|
|
42
60
|
/**
|
|
43
61
|
* All available targets for sending notifications to.
|
|
44
62
|
*
|
package/src/git.ts
CHANGED
|
@@ -211,16 +211,15 @@ export async function pushDeploy(
|
|
|
211
211
|
},
|
|
212
212
|
};
|
|
213
213
|
|
|
214
|
-
|
|
215
|
-
await hooks
|
|
214
|
+
const hookResult =
|
|
215
|
+
(await hooks?.postAccept?.({
|
|
216
216
|
branchConfig,
|
|
217
217
|
deployResult,
|
|
218
218
|
fromBranch,
|
|
219
219
|
remoteName,
|
|
220
220
|
repoConfig,
|
|
221
221
|
toBranch,
|
|
222
|
-
});
|
|
223
|
-
}
|
|
222
|
+
})) || undefined;
|
|
224
223
|
|
|
225
224
|
const resolvedNotifications = resolveNotifications({
|
|
226
225
|
branchConfig,
|
|
@@ -233,6 +232,7 @@ export async function pushDeploy(
|
|
|
233
232
|
await sendNotifications(resolvedNotifications, {
|
|
234
233
|
branchConfig,
|
|
235
234
|
deployResult,
|
|
235
|
+
hookResult: hookResult || undefined,
|
|
236
236
|
repoConfig,
|
|
237
237
|
});
|
|
238
238
|
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
type DeployVirRepoConfig,
|
|
4
4
|
type NotificationConfig,
|
|
5
5
|
type NotificationTarget,
|
|
6
|
+
type PostAcceptHookResult,
|
|
6
7
|
} from '../config.js';
|
|
7
8
|
import {type DeployResult} from '../git.js';
|
|
8
9
|
|
|
@@ -16,4 +17,5 @@ export type NotificationParams<Target extends NotificationTarget = NotificationT
|
|
|
16
17
|
branchConfig: Readonly<DeployVirBranchConfig>;
|
|
17
18
|
repoConfig: Readonly<Pick<DeployVirRepoConfig, 'commitBaseUrl' | 'name'>>;
|
|
18
19
|
notification: Readonly<Extract<NotificationConfig, {target: Target}>>;
|
|
20
|
+
hookResult?: Readonly<PostAcceptHookResult> | undefined;
|
|
19
21
|
};
|
|
@@ -61,6 +61,7 @@ export async function sendNotificationToSlack({
|
|
|
61
61
|
branchStatus: {after, before},
|
|
62
62
|
toBranchName,
|
|
63
63
|
},
|
|
64
|
+
hookResult,
|
|
64
65
|
notification,
|
|
65
66
|
repoConfig,
|
|
66
67
|
}: Readonly<NotificationParams>) {
|
|
@@ -92,6 +93,17 @@ export async function sendNotificationToSlack({
|
|
|
92
93
|
text: `*${setFirstLetterCasing(repoConfig.name, StringCase.Upper)} ${setFirstLetterCasing(toBranchName, StringCase.Upper)}* Pushed`,
|
|
93
94
|
},
|
|
94
95
|
},
|
|
96
|
+
...(hookResult?.prependToNotification
|
|
97
|
+
? ([
|
|
98
|
+
{
|
|
99
|
+
type: 'section',
|
|
100
|
+
text: {
|
|
101
|
+
type: 'mrkdwn',
|
|
102
|
+
text: hookResult.prependToNotification,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
] satisfies KnownBlock[])
|
|
106
|
+
: []),
|
|
95
107
|
{
|
|
96
108
|
type: 'context',
|
|
97
109
|
elements: [
|
|
@@ -138,6 +150,17 @@ export async function sendNotificationToSlack({
|
|
|
138
150
|
}),
|
|
139
151
|
] satisfies KnownBlock[])
|
|
140
152
|
: []),
|
|
153
|
+
...(hookResult?.appendToNotification
|
|
154
|
+
? ([
|
|
155
|
+
{
|
|
156
|
+
type: 'section',
|
|
157
|
+
text: {
|
|
158
|
+
type: 'mrkdwn',
|
|
159
|
+
text: hookResult.appendToNotification,
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
] satisfies KnownBlock[])
|
|
163
|
+
: []),
|
|
141
164
|
];
|
|
142
165
|
|
|
143
166
|
await sendSlackMessage(notification, {
|