deploy-vir 0.1.1 → 0.2.1
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/cli/cli.js +4 -3
- package/dist/git.d.ts +19 -1
- package/dist/git.js +36 -16
- package/dist/notifications/notification-params.d.ts +2 -2
- package/dist/notifications/send-notifications.d.ts +1 -1
- package/dist/notifications/send-notifications.js +2 -4
- package/dist/notifications/slack.d.ts +1 -1
- package/dist/notifications/slack.js +16 -3
- package/package.json +1 -1
- package/src/cli/cli.ts +4 -3
- package/src/git.ts +70 -17
- package/src/notifications/notification-params.ts +2 -2
- package/src/notifications/send-notifications.ts +2 -4
- package/src/notifications/slack.ts +20 -3
package/dist/cli/cli.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assertWrap } from '@augment-vir/assert';
|
|
2
2
|
import { extractErrorMessage, log } from '@augment-vir/common';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
3
4
|
import simpleGit from 'simple-git';
|
|
4
5
|
import { getGitRemoteName, pushDeploy } from '../git.js';
|
|
5
6
|
import { KnownError } from '../known.error.js';
|
|
@@ -13,7 +14,7 @@ export async function runDeployVirCli(args, cwd = process.cwd()) {
|
|
|
13
14
|
const configPath = assertWrap.isTruthy(args[0], 'Missing config path.');
|
|
14
15
|
const repoName = assertWrap.isTruthy(args[1], 'Missing repo name.');
|
|
15
16
|
const deployName = assertWrap.isTruthy(args[2], 'Missing deploy name.');
|
|
16
|
-
const config = (await import(configPath)).default;
|
|
17
|
+
const config = (await import(resolve(cwd, configPath))).default;
|
|
17
18
|
await runDeployVir({ cwd, deployName, repoName }, config);
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
@@ -28,11 +29,11 @@ export async function runDeployVir(args, config) {
|
|
|
28
29
|
const branchConfig = assertWrap.isDefined(repoConfig.deploys.find((deploy) => deploy.deployName === args.deployName, `Failed to find a deploy named '${args.deployName}' in repo '${args.repoName}'.`));
|
|
29
30
|
const remoteName = await getGitRemoteName(git, repoConfig);
|
|
30
31
|
log.faint(`Remote: ${remoteName}`);
|
|
31
|
-
const
|
|
32
|
+
const deployResult = await pushDeploy(git, branchConfig, remoteName);
|
|
32
33
|
if (config.notifications?.length) {
|
|
33
34
|
await sendNotifications(config.notifications, {
|
|
34
35
|
branchConfig,
|
|
35
|
-
|
|
36
|
+
deployResult,
|
|
36
37
|
repoConfig,
|
|
37
38
|
});
|
|
38
39
|
}
|
package/dist/git.d.ts
CHANGED
|
@@ -21,9 +21,27 @@ export type DeployCommits = {
|
|
|
21
21
|
deployedCommits: ReadonlyArray<Readonly<Commit>>;
|
|
22
22
|
overwrittenCommits: ReadonlyArray<Readonly<Commit>>;
|
|
23
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Before/after of the branch deployed to.
|
|
26
|
+
*
|
|
27
|
+
* @category Internal
|
|
28
|
+
*/
|
|
29
|
+
export type DeployBranchStatus = {
|
|
30
|
+
before: Readonly<Commit>;
|
|
31
|
+
after: Readonly<Commit>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Output from {@link pushDeploy}.
|
|
35
|
+
*
|
|
36
|
+
* @category Internal
|
|
37
|
+
*/
|
|
38
|
+
export type DeployResult = {
|
|
39
|
+
deployCommits: DeployCommits;
|
|
40
|
+
branchStatus: DeployBranchStatus;
|
|
41
|
+
};
|
|
24
42
|
/**
|
|
25
43
|
* Push the deploy via git.
|
|
26
44
|
*
|
|
27
45
|
* @category Internal
|
|
28
46
|
*/
|
|
29
|
-
export declare function pushDeploy(git: Readonly<SimpleGit>, { deployName, fromBranch, toBranch }: Readonly<DeployVirBranchConfig>, remoteName: string): Promise<
|
|
47
|
+
export declare function pushDeploy(git: Readonly<SimpleGit>, { deployName, fromBranch, toBranch }: Readonly<DeployVirBranchConfig>, remoteName: string): Promise<DeployResult>;
|
package/dist/git.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assert, check } from '@augment-vir/assert';
|
|
1
|
+
import { assert, assertWrap, check } from '@augment-vir/assert';
|
|
2
2
|
import { extractErrorMessage, log, logColors } from '@augment-vir/common';
|
|
3
3
|
import { askQuestion } from '@augment-vir/node';
|
|
4
4
|
import { KnownError } from './known.error.js';
|
|
@@ -36,32 +36,46 @@ export async function pushDeploy(git, { deployName, fromBranch, toBranch }, remo
|
|
|
36
36
|
assert.isTruthy(remoteName, 'Remote name cannot be empty.');
|
|
37
37
|
log.faint(`Pushing ${remoteName}/${fromBranch} to ${toBranch}`);
|
|
38
38
|
await git.fetch(remoteName, fromBranch);
|
|
39
|
+
await git.fetch(remoteName, toBranch);
|
|
39
40
|
const pushString = `${remoteName}/${fromBranch}:${toBranch}`;
|
|
41
|
+
// Get the current commit on the target branch before pushing
|
|
42
|
+
const beforeCommit = assertWrap.isDefined((await git.log([
|
|
43
|
+
`${remoteName}/${toBranch}`,
|
|
44
|
+
'-1',
|
|
45
|
+
])).latest, `Failed to get current commit for ${remoteName}/${toBranch}`);
|
|
46
|
+
const afterCommit = assertWrap.isDefined((await git.log([
|
|
47
|
+
`${remoteName}/${fromBranch}`,
|
|
48
|
+
'-1',
|
|
49
|
+
])).latest, `Failed to get current commit for ${remoteName}/${fromBranch}`);
|
|
40
50
|
/** Get commits that are on {@link toBranch} but not on {@link fromBranch}. */
|
|
41
|
-
const commitsAhead = (await git.log(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
})).all;
|
|
51
|
+
const commitsAhead = (await git.log([
|
|
52
|
+
'${remoteName}/${toBranch}..${remoteName}/${fromBranch}',
|
|
53
|
+
])).all;
|
|
45
54
|
if (!commitsAhead.length) {
|
|
46
55
|
throw new KnownError('No commit diff: nothing to deploy!');
|
|
47
56
|
}
|
|
48
57
|
try {
|
|
49
58
|
await git.push(remoteName, pushString);
|
|
50
59
|
return {
|
|
51
|
-
|
|
52
|
-
|
|
60
|
+
deployCommits: {
|
|
61
|
+
deployedCommits: commitsAhead,
|
|
62
|
+
overwrittenCommits: [],
|
|
63
|
+
},
|
|
64
|
+
branchStatus: {
|
|
65
|
+
before: beforeCommit,
|
|
66
|
+
after: afterCommit,
|
|
67
|
+
},
|
|
53
68
|
};
|
|
54
69
|
}
|
|
55
70
|
catch (error) {
|
|
56
71
|
log.error(`Push failed: ${extractErrorMessage(error)}`);
|
|
57
72
|
/** Get commits that are on {@link toBranch} but not on {@link fromBranch}. */
|
|
58
|
-
const commitsBehind = await git.log(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
commitsBehind.all.forEach((commit, index) => {
|
|
73
|
+
const commitsBehind = (await git.log([
|
|
74
|
+
'${remoteName}/${fromBranch}..${remoteName}/${toBranch}',
|
|
75
|
+
])).all;
|
|
76
|
+
if (commitsBehind.length > 0) {
|
|
77
|
+
log.info(`\nThe following ${commitsBehind.length} commit${commitsBehind.length === 1 ? '' : 's'} are on ${logColors.bold}${toBranch}${logColors.reset} but not on ${logColors.bold}${fromBranch}${logColors.reset}:`);
|
|
78
|
+
commitsBehind.forEach((commit, index) => {
|
|
65
79
|
log.faint(` ${index + 1}. ${commit.hash.slice(0, 7)} (${commit.author_name}) - ${commit.message}`);
|
|
66
80
|
});
|
|
67
81
|
}
|
|
@@ -74,8 +88,14 @@ export async function pushDeploy(git, { deployName, fromBranch, toBranch }, remo
|
|
|
74
88
|
throw new KnownError(`Deploy aborted.`);
|
|
75
89
|
}
|
|
76
90
|
return {
|
|
77
|
-
|
|
78
|
-
|
|
91
|
+
deployCommits: {
|
|
92
|
+
deployedCommits: commitsAhead,
|
|
93
|
+
overwrittenCommits: commitsBehind,
|
|
94
|
+
},
|
|
95
|
+
branchStatus: {
|
|
96
|
+
before: beforeCommit,
|
|
97
|
+
after: afterCommit,
|
|
98
|
+
},
|
|
79
99
|
};
|
|
80
100
|
}
|
|
81
101
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { type DeployVirBranchConfig, type DeployVirRepoConfig, type NotificationConfig, type NotificationTarget } from '../config.js';
|
|
2
|
-
import { type
|
|
2
|
+
import { type DeployResult } from '../git.js';
|
|
3
3
|
/**
|
|
4
4
|
* Params for sending a notification.
|
|
5
5
|
*
|
|
6
6
|
* @category Internal
|
|
7
7
|
*/
|
|
8
8
|
export type NotificationParams<Target extends NotificationTarget = NotificationTarget> = {
|
|
9
|
-
|
|
9
|
+
deployResult: Readonly<DeployResult>;
|
|
10
10
|
branchConfig: Readonly<DeployVirBranchConfig>;
|
|
11
11
|
repoConfig: Readonly<Pick<DeployVirRepoConfig, 'commitBaseUrl'>>;
|
|
12
12
|
notification: Readonly<Extract<NotificationConfig, {
|
|
@@ -5,4 +5,4 @@ import { type NotificationParams } from './notification-params.js';
|
|
|
5
5
|
*
|
|
6
6
|
* @category Internal
|
|
7
7
|
*/
|
|
8
|
-
export declare function sendNotifications(notifications: ReadonlyArray<Readonly<NotificationConfig>>,
|
|
8
|
+
export declare function sendNotifications(notifications: ReadonlyArray<Readonly<NotificationConfig>>, params: Readonly<Omit<NotificationParams, 'notification'>>): Promise<void>;
|
|
@@ -6,14 +6,12 @@ import { sendNotificationToSlack } from './slack.js';
|
|
|
6
6
|
*
|
|
7
7
|
* @category Internal
|
|
8
8
|
*/
|
|
9
|
-
export async function sendNotifications(notifications,
|
|
9
|
+
export async function sendNotifications(notifications, params) {
|
|
10
10
|
await Promise.all(notifications.map(async (notification) => {
|
|
11
11
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
12
12
|
if (notification.target === NotificationTarget.Slack) {
|
|
13
13
|
await sendNotificationToSlack({
|
|
14
|
-
|
|
15
|
-
branchConfig,
|
|
16
|
-
repoConfig,
|
|
14
|
+
...params,
|
|
17
15
|
notification,
|
|
18
16
|
});
|
|
19
17
|
}
|
|
@@ -5,4 +5,4 @@ export { type ChatPostMessageArguments } from '@slack/web-api';
|
|
|
5
5
|
*
|
|
6
6
|
* @category Internal
|
|
7
7
|
*/
|
|
8
|
-
export declare function sendNotificationToSlack({ branchConfig, deployCommits: { deployedCommits, overwrittenCommits }, notification, repoConfig, }: Readonly<NotificationParams>): Promise<void>;
|
|
8
|
+
export declare function sendNotificationToSlack({ branchConfig, deployResult: { deployCommits: { deployedCommits, overwrittenCommits }, branchStatus: { after, before }, }, notification, repoConfig, }: Readonly<NotificationParams>): Promise<void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addPrefix } from '@augment-vir/common';
|
|
1
|
+
import { addPrefix, capitalizeFirstLetter } from '@augment-vir/common';
|
|
2
2
|
import { joinUrlPaths } from 'url-vir';
|
|
3
3
|
function truncateString(value, truncateAt = 100) {
|
|
4
4
|
if (value.length > truncateAt) {
|
|
@@ -22,7 +22,7 @@ function formatCommit(baseCommitUrl, commit) {
|
|
|
22
22
|
*
|
|
23
23
|
* @category Internal
|
|
24
24
|
*/
|
|
25
|
-
export async function sendNotificationToSlack({ branchConfig, deployCommits: { deployedCommits, overwrittenCommits }, notification, repoConfig, }) {
|
|
25
|
+
export async function sendNotificationToSlack({ branchConfig, deployResult: { deployCommits: { deployedCommits, overwrittenCommits }, branchStatus: { after, before }, }, notification, repoConfig, }) {
|
|
26
26
|
const deployedCommitBullets = deployedCommits.map((commit) => formatCommit(repoConfig.commitBaseUrl, commit));
|
|
27
27
|
const overwrittenCommitBullets = overwrittenCommits.map((commit) => formatCommit(repoConfig.commitBaseUrl, commit));
|
|
28
28
|
const deployedCommitBulletsText = deployedCommitBullets
|
|
@@ -31,12 +31,25 @@ export async function sendNotificationToSlack({ branchConfig, deployCommits: { d
|
|
|
31
31
|
const overwrittenCommitBulletsText = overwrittenCommitBullets.length
|
|
32
32
|
? overwrittenCommitBullets.map((bullet) => `- ${bullet}`).join('\n')
|
|
33
33
|
: undefined;
|
|
34
|
+
const beforeText = repoConfig.commitBaseUrl
|
|
35
|
+
? `<${joinUrlPaths(repoConfig.commitBaseUrl, before.hash)}|${before.hash.slice(0, 7)}>`
|
|
36
|
+
: before.hash;
|
|
37
|
+
const afterText = repoConfig.commitBaseUrl
|
|
38
|
+
? `<${joinUrlPaths(repoConfig.commitBaseUrl, after.hash)}|${after.hash.slice(0, 7)}>`
|
|
39
|
+
: before.hash;
|
|
34
40
|
const blocks = [
|
|
35
41
|
{
|
|
36
42
|
type: 'section',
|
|
37
43
|
text: {
|
|
38
44
|
type: 'mrkdwn',
|
|
39
|
-
text: `*${branchConfig.deployName}*
|
|
45
|
+
text: `*${capitalizeFirstLetter(branchConfig.deployName)}* Pushed`,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
type: 'context',
|
|
50
|
+
text: {
|
|
51
|
+
type: 'mrkdwn',
|
|
52
|
+
text: `${beforeText} -> ${afterText}`,
|
|
40
53
|
},
|
|
41
54
|
},
|
|
42
55
|
{
|
package/package.json
CHANGED
package/src/cli/cli.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {assertWrap} from '@augment-vir/assert';
|
|
2
2
|
import {extractErrorMessage, log} from '@augment-vir/common';
|
|
3
|
+
import {resolve} from 'node:path';
|
|
3
4
|
import simpleGit from 'simple-git';
|
|
4
5
|
import {type DeployVirConfig} from '../config.js';
|
|
5
6
|
import {getGitRemoteName, pushDeploy} from '../git.js';
|
|
@@ -16,7 +17,7 @@ export async function runDeployVirCli(args: ReadonlyArray<string>, cwd = process
|
|
|
16
17
|
const repoName = assertWrap.isTruthy(args[1], 'Missing repo name.');
|
|
17
18
|
const deployName = assertWrap.isTruthy(args[2], 'Missing deploy name.');
|
|
18
19
|
|
|
19
|
-
const config = (await import(configPath)).default;
|
|
20
|
+
const config = (await import(resolve(cwd, configPath))).default;
|
|
20
21
|
|
|
21
22
|
await runDeployVir({cwd, deployName, repoName}, config);
|
|
22
23
|
}
|
|
@@ -61,12 +62,12 @@ export async function runDeployVir(
|
|
|
61
62
|
const remoteName = await getGitRemoteName(git, repoConfig);
|
|
62
63
|
log.faint(`Remote: ${remoteName}`);
|
|
63
64
|
|
|
64
|
-
const
|
|
65
|
+
const deployResult = await pushDeploy(git, branchConfig, remoteName);
|
|
65
66
|
|
|
66
67
|
if (config.notifications?.length) {
|
|
67
68
|
await sendNotifications(config.notifications, {
|
|
68
69
|
branchConfig,
|
|
69
|
-
|
|
70
|
+
deployResult,
|
|
70
71
|
repoConfig,
|
|
71
72
|
});
|
|
72
73
|
}
|
package/src/git.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {assert, check} from '@augment-vir/assert';
|
|
1
|
+
import {assert, assertWrap, check} from '@augment-vir/assert';
|
|
2
2
|
import {extractErrorMessage, log, logColors} from '@augment-vir/common';
|
|
3
3
|
import {askQuestion} from '@augment-vir/node';
|
|
4
4
|
import {type DefaultLogFields, type ListLogLine, type SimpleGit} from 'simple-git';
|
|
@@ -61,6 +61,25 @@ export type DeployCommits = {
|
|
|
61
61
|
deployedCommits: ReadonlyArray<Readonly<Commit>>;
|
|
62
62
|
overwrittenCommits: ReadonlyArray<Readonly<Commit>>;
|
|
63
63
|
};
|
|
64
|
+
/**
|
|
65
|
+
* Before/after of the branch deployed to.
|
|
66
|
+
*
|
|
67
|
+
* @category Internal
|
|
68
|
+
*/
|
|
69
|
+
export type DeployBranchStatus = {
|
|
70
|
+
before: Readonly<Commit>;
|
|
71
|
+
after: Readonly<Commit>;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Output from {@link pushDeploy}.
|
|
76
|
+
*
|
|
77
|
+
* @category Internal
|
|
78
|
+
*/
|
|
79
|
+
export type DeployResult = {
|
|
80
|
+
deployCommits: DeployCommits;
|
|
81
|
+
branchStatus: DeployBranchStatus;
|
|
82
|
+
};
|
|
64
83
|
|
|
65
84
|
/**
|
|
66
85
|
* Push the deploy via git.
|
|
@@ -71,7 +90,7 @@ export async function pushDeploy(
|
|
|
71
90
|
git: Readonly<SimpleGit>,
|
|
72
91
|
{deployName, fromBranch, toBranch}: Readonly<DeployVirBranchConfig>,
|
|
73
92
|
remoteName: string,
|
|
74
|
-
): Promise<
|
|
93
|
+
): Promise<DeployResult> {
|
|
75
94
|
assert.isTruthy(fromBranch, `Deploy '${deployName}' fromBranch cannot be empty.`);
|
|
76
95
|
assert.isTruthy(toBranch, `Deploy '${deployName}' toBranch cannot be empty.`);
|
|
77
96
|
assert.isTruthy(remoteName, 'Remote name cannot be empty.');
|
|
@@ -79,15 +98,36 @@ export async function pushDeploy(
|
|
|
79
98
|
log.faint(`Pushing ${remoteName}/${fromBranch} to ${toBranch}`);
|
|
80
99
|
|
|
81
100
|
await git.fetch(remoteName, fromBranch);
|
|
101
|
+
await git.fetch(remoteName, toBranch);
|
|
82
102
|
|
|
83
103
|
const pushString = `${remoteName}/${fromBranch}:${toBranch}`;
|
|
84
104
|
|
|
105
|
+
// Get the current commit on the target branch before pushing
|
|
106
|
+
const beforeCommit = assertWrap.isDefined(
|
|
107
|
+
(
|
|
108
|
+
await git.log([
|
|
109
|
+
`${remoteName}/${toBranch}`,
|
|
110
|
+
'-1',
|
|
111
|
+
])
|
|
112
|
+
).latest,
|
|
113
|
+
`Failed to get current commit for ${remoteName}/${toBranch}`,
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const afterCommit = assertWrap.isDefined(
|
|
117
|
+
(
|
|
118
|
+
await git.log([
|
|
119
|
+
`${remoteName}/${fromBranch}`,
|
|
120
|
+
'-1',
|
|
121
|
+
])
|
|
122
|
+
).latest,
|
|
123
|
+
`Failed to get current commit for ${remoteName}/${fromBranch}`,
|
|
124
|
+
);
|
|
125
|
+
|
|
85
126
|
/** Get commits that are on {@link toBranch} but not on {@link fromBranch}. */
|
|
86
127
|
const commitsAhead = (
|
|
87
|
-
await git.log(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
})
|
|
128
|
+
await git.log([
|
|
129
|
+
'${remoteName}/${toBranch}..${remoteName}/${fromBranch}',
|
|
130
|
+
])
|
|
91
131
|
).all;
|
|
92
132
|
|
|
93
133
|
if (!commitsAhead.length) {
|
|
@@ -98,23 +138,30 @@ export async function pushDeploy(
|
|
|
98
138
|
await git.push(remoteName, pushString);
|
|
99
139
|
|
|
100
140
|
return {
|
|
101
|
-
|
|
102
|
-
|
|
141
|
+
deployCommits: {
|
|
142
|
+
deployedCommits: commitsAhead,
|
|
143
|
+
overwrittenCommits: [],
|
|
144
|
+
},
|
|
145
|
+
branchStatus: {
|
|
146
|
+
before: beforeCommit,
|
|
147
|
+
after: afterCommit,
|
|
148
|
+
},
|
|
103
149
|
};
|
|
104
150
|
} catch (error) {
|
|
105
151
|
log.error(`Push failed: ${extractErrorMessage(error)}`);
|
|
106
152
|
|
|
107
153
|
/** Get commits that are on {@link toBranch} but not on {@link fromBranch}. */
|
|
108
|
-
const commitsBehind =
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
154
|
+
const commitsBehind = (
|
|
155
|
+
await git.log([
|
|
156
|
+
'${remoteName}/${fromBranch}..${remoteName}/${toBranch}',
|
|
157
|
+
])
|
|
158
|
+
).all;
|
|
112
159
|
|
|
113
|
-
if (commitsBehind.
|
|
160
|
+
if (commitsBehind.length > 0) {
|
|
114
161
|
log.info(
|
|
115
|
-
`\nThe following ${commitsBehind.
|
|
162
|
+
`\nThe following ${commitsBehind.length} commit${commitsBehind.length === 1 ? '' : 's'} are on ${logColors.bold}${toBranch}${logColors.reset} but not on ${logColors.bold}${fromBranch}${logColors.reset}:`,
|
|
116
163
|
);
|
|
117
|
-
commitsBehind.
|
|
164
|
+
commitsBehind.forEach((commit, index) => {
|
|
118
165
|
log.faint(
|
|
119
166
|
` ${index + 1}. ${commit.hash.slice(0, 7)} (${commit.author_name}) - ${commit.message}`,
|
|
120
167
|
);
|
|
@@ -135,8 +182,14 @@ export async function pushDeploy(
|
|
|
135
182
|
}
|
|
136
183
|
|
|
137
184
|
return {
|
|
138
|
-
|
|
139
|
-
|
|
185
|
+
deployCommits: {
|
|
186
|
+
deployedCommits: commitsAhead,
|
|
187
|
+
overwrittenCommits: commitsBehind,
|
|
188
|
+
},
|
|
189
|
+
branchStatus: {
|
|
190
|
+
before: beforeCommit,
|
|
191
|
+
after: afterCommit,
|
|
192
|
+
},
|
|
140
193
|
};
|
|
141
194
|
}
|
|
142
195
|
}
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
type NotificationConfig,
|
|
5
5
|
type NotificationTarget,
|
|
6
6
|
} from '../config.js';
|
|
7
|
-
import {type
|
|
7
|
+
import {type DeployResult} from '../git.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Params for sending a notification.
|
|
@@ -12,7 +12,7 @@ import {type DeployCommits} from '../git.js';
|
|
|
12
12
|
* @category Internal
|
|
13
13
|
*/
|
|
14
14
|
export type NotificationParams<Target extends NotificationTarget = NotificationTarget> = {
|
|
15
|
-
|
|
15
|
+
deployResult: Readonly<DeployResult>;
|
|
16
16
|
branchConfig: Readonly<DeployVirBranchConfig>;
|
|
17
17
|
repoConfig: Readonly<Pick<DeployVirRepoConfig, 'commitBaseUrl'>>;
|
|
18
18
|
notification: Readonly<Extract<NotificationConfig, {target: Target}>>;
|
|
@@ -10,16 +10,14 @@ import {sendNotificationToSlack} from './slack.js';
|
|
|
10
10
|
*/
|
|
11
11
|
export async function sendNotifications(
|
|
12
12
|
notifications: ReadonlyArray<Readonly<NotificationConfig>>,
|
|
13
|
-
|
|
13
|
+
params: Readonly<Omit<NotificationParams, 'notification'>>,
|
|
14
14
|
) {
|
|
15
15
|
await Promise.all(
|
|
16
16
|
notifications.map(async (notification) => {
|
|
17
17
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
18
18
|
if (notification.target === NotificationTarget.Slack) {
|
|
19
19
|
await sendNotificationToSlack({
|
|
20
|
-
|
|
21
|
-
branchConfig,
|
|
22
|
-
repoConfig,
|
|
20
|
+
...params,
|
|
23
21
|
notification,
|
|
24
22
|
});
|
|
25
23
|
} else {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {addPrefix} from '@augment-vir/common';
|
|
1
|
+
import {addPrefix, capitalizeFirstLetter} from '@augment-vir/common';
|
|
2
2
|
import {type ChatPostMessageArguments} from '@slack/web-api';
|
|
3
3
|
import {joinUrlPaths} from 'url-vir';
|
|
4
4
|
import {type SlackNotificationConfig} from '../config.js';
|
|
@@ -32,7 +32,10 @@ function formatCommit(baseCommitUrl: string | undefined, commit: Readonly<Commit
|
|
|
32
32
|
*/
|
|
33
33
|
export async function sendNotificationToSlack({
|
|
34
34
|
branchConfig,
|
|
35
|
-
|
|
35
|
+
deployResult: {
|
|
36
|
+
deployCommits: {deployedCommits, overwrittenCommits},
|
|
37
|
+
branchStatus: {after, before},
|
|
38
|
+
},
|
|
36
39
|
notification,
|
|
37
40
|
repoConfig,
|
|
38
41
|
}: Readonly<NotificationParams>) {
|
|
@@ -51,12 +54,26 @@ export async function sendNotificationToSlack({
|
|
|
51
54
|
? overwrittenCommitBullets.map((bullet) => `- ${bullet}`).join('\n')
|
|
52
55
|
: undefined;
|
|
53
56
|
|
|
57
|
+
const beforeText = repoConfig.commitBaseUrl
|
|
58
|
+
? `<${joinUrlPaths(repoConfig.commitBaseUrl, before.hash)}|${before.hash.slice(0, 7)}>`
|
|
59
|
+
: before.hash;
|
|
60
|
+
const afterText = repoConfig.commitBaseUrl
|
|
61
|
+
? `<${joinUrlPaths(repoConfig.commitBaseUrl, after.hash)}|${after.hash.slice(0, 7)}>`
|
|
62
|
+
: before.hash;
|
|
63
|
+
|
|
54
64
|
const blocks: any[] = [
|
|
55
65
|
{
|
|
56
66
|
type: 'section',
|
|
57
67
|
text: {
|
|
58
68
|
type: 'mrkdwn',
|
|
59
|
-
text: `*${branchConfig.deployName}*
|
|
69
|
+
text: `*${capitalizeFirstLetter(branchConfig.deployName)}* Pushed`,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
type: 'context',
|
|
74
|
+
text: {
|
|
75
|
+
type: 'mrkdwn',
|
|
76
|
+
text: `${beforeText} -> ${afterText}`,
|
|
60
77
|
},
|
|
61
78
|
},
|
|
62
79
|
{
|