deploy-vir 3.2.0 → 3.4.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 CHANGED
@@ -1,5 +1,5 @@
1
- import { type MaybePromise } from '@augment-vir/common';
2
- import { type DeployResult } from './git.js';
1
+ import { type MaybePromise, type PartialWithUndefined } from '@augment-vir/common';
2
+ import { type Commit, type DeployResult } from './git.js';
3
3
  /**
4
4
  * The full deploy-vir config object.
5
5
  *
@@ -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.
@@ -34,7 +35,24 @@ export type PostAcceptHookParams = {
34
35
  toBranch: string;
35
36
  remoteName: string;
36
37
  deployResult: Readonly<DeployResult>;
38
+ /**
39
+ * All commits included in this deploy (the commits being pushed from `fromBranch` to
40
+ * `toBranch`).
41
+ */
42
+ newCommits: ReadonlyArray<Readonly<Commit>>;
37
43
  };
44
+ /**
45
+ * Optional values that a {@link DeployVirHooks.postAccept} hook can return to augment the resulting
46
+ * notification message.
47
+ *
48
+ * @category Config
49
+ */
50
+ export type PostAcceptHookResult = PartialWithUndefined<{
51
+ /** Inserted into the notification immediately after the "<X> Pushed" header line. */
52
+ prependToNotification: string;
53
+ /** Appended to the very end of the notification message. */
54
+ appendToNotification: string;
55
+ }>;
38
56
  /**
39
57
  * All available targets for sending notifications to.
40
58
  *
package/dist/git.js CHANGED
@@ -100,16 +100,15 @@ export async function pushDeploy(git, branchConfig, repoConfig, remoteName, noti
100
100
  after: afterCommit,
101
101
  },
102
102
  };
103
- if (hooks?.postAccept) {
104
- await hooks.postAccept({
105
- branchConfig,
106
- deployResult,
107
- fromBranch,
108
- remoteName,
109
- repoConfig,
110
- toBranch,
111
- });
112
- }
103
+ const hookResult = (await hooks?.postAccept?.({
104
+ branchConfig,
105
+ deployResult,
106
+ fromBranch,
107
+ newCommits: commitsAhead,
108
+ remoteName,
109
+ repoConfig,
110
+ toBranch,
111
+ })) || undefined;
113
112
  const resolvedNotifications = resolveNotifications({
114
113
  branchConfig,
115
114
  enableNotifications,
@@ -120,6 +119,7 @@ export async function pushDeploy(git, branchConfig, repoConfig, remoteName, noti
120
119
  await sendNotifications(resolvedNotifications, {
121
120
  branchConfig,
122
121
  deployResult,
122
+ hookResult: hookResult || undefined,
123
123
  repoConfig,
124
124
  });
125
125
  }
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deploy-vir",
3
- "version": "3.2.0",
3
+ "version": "3.4.0",
4
4
  "description": "Deploy a branch to another branch with notifications.",
5
5
  "keywords": [
6
6
  "deploy",
package/src/config.ts CHANGED
@@ -1,5 +1,5 @@
1
- import {type MaybePromise} from '@augment-vir/common';
2
- import {type DeployResult} from './git.js';
1
+ import {type MaybePromise, type PartialWithUndefined} from '@augment-vir/common';
2
+ import {type Commit, type DeployResult} from './git.js';
3
3
 
4
4
  /**
5
5
  * The full deploy-vir config object.
@@ -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?: ((params: Readonly<PostAcceptHookParams>) => MaybePromise<void>) | undefined;
26
+ postAccept?:
27
+ | ((
28
+ params: Readonly<PostAcceptHookParams>,
29
+ ) => MaybePromise<PostAcceptHookResult | void | undefined>)
30
+ | undefined;
26
31
  };
27
32
 
28
33
  /**
@@ -37,8 +42,26 @@ export type PostAcceptHookParams = {
37
42
  toBranch: string;
38
43
  remoteName: string;
39
44
  deployResult: Readonly<DeployResult>;
45
+ /**
46
+ * All commits included in this deploy (the commits being pushed from `fromBranch` to
47
+ * `toBranch`).
48
+ */
49
+ newCommits: ReadonlyArray<Readonly<Commit>>;
40
50
  };
41
51
 
52
+ /**
53
+ * Optional values that a {@link DeployVirHooks.postAccept} hook can return to augment the resulting
54
+ * notification message.
55
+ *
56
+ * @category Config
57
+ */
58
+ export type PostAcceptHookResult = PartialWithUndefined<{
59
+ /** Inserted into the notification immediately after the "<X> Pushed" header line. */
60
+ prependToNotification: string;
61
+ /** Appended to the very end of the notification message. */
62
+ appendToNotification: string;
63
+ }>;
64
+
42
65
  /**
43
66
  * All available targets for sending notifications to.
44
67
  *
package/src/git.ts CHANGED
@@ -211,16 +211,16 @@ export async function pushDeploy(
211
211
  },
212
212
  };
213
213
 
214
- if (hooks?.postAccept) {
215
- await hooks.postAccept({
214
+ const hookResult =
215
+ (await hooks?.postAccept?.({
216
216
  branchConfig,
217
217
  deployResult,
218
218
  fromBranch,
219
+ newCommits: commitsAhead,
219
220
  remoteName,
220
221
  repoConfig,
221
222
  toBranch,
222
- });
223
- }
223
+ })) || undefined;
224
224
 
225
225
  const resolvedNotifications = resolveNotifications({
226
226
  branchConfig,
@@ -233,6 +233,7 @@ export async function pushDeploy(
233
233
  await sendNotifications(resolvedNotifications, {
234
234
  branchConfig,
235
235
  deployResult,
236
+ hookResult: hookResult || undefined,
236
237
  repoConfig,
237
238
  });
238
239
  }
@@ -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, {