deploy-vir 0.2.8 → 0.2.9
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.
|
@@ -8,7 +8,7 @@ import { type DeployResult } from '../git.js';
|
|
|
8
8
|
export type NotificationParams<Target extends NotificationTarget = NotificationTarget> = {
|
|
9
9
|
deployResult: Readonly<DeployResult>;
|
|
10
10
|
branchConfig: Readonly<DeployVirBranchConfig>;
|
|
11
|
-
repoConfig: Readonly<Pick<DeployVirRepoConfig, 'commitBaseUrl'>>;
|
|
11
|
+
repoConfig: Readonly<Pick<DeployVirRepoConfig, 'commitBaseUrl' | 'name'>>;
|
|
12
12
|
notification: Readonly<Extract<NotificationConfig, {
|
|
13
13
|
target: Target;
|
|
14
14
|
}>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addPrefix,
|
|
1
|
+
import { addPrefix, log, setFirstLetterCasing, StringCase } from '@augment-vir/common';
|
|
2
2
|
import { joinUrlPaths } from 'url-vir';
|
|
3
3
|
function truncateString(value, truncateAt = 100) {
|
|
4
4
|
if (value.length > truncateAt) {
|
|
@@ -16,6 +16,23 @@ function formatCommit(baseCommitUrl, commit) {
|
|
|
16
16
|
return `${commit.hash.slice(0, 7)} (${commit.author_name}) ${truncateString(commit.message)}`;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
const slackMaxSectionLength = 2500;
|
|
20
|
+
function pushAndGet(array, item) {
|
|
21
|
+
array.push(item);
|
|
22
|
+
return item;
|
|
23
|
+
}
|
|
24
|
+
function chunkSectionLines(lines) {
|
|
25
|
+
const sectionLines = [];
|
|
26
|
+
lines.forEach((line) => {
|
|
27
|
+
const latestSection = sectionLines.slice(-1)[0];
|
|
28
|
+
const currentSection = latestSection && latestSection.length + line.length < slackMaxSectionLength
|
|
29
|
+
? latestSection
|
|
30
|
+
: pushAndGet(sectionLines, { length: 0, lines: [] });
|
|
31
|
+
currentSection.length += line.length;
|
|
32
|
+
currentSection.lines.push(line);
|
|
33
|
+
});
|
|
34
|
+
return sectionLines.map(({ lines }) => lines);
|
|
35
|
+
}
|
|
19
36
|
/**
|
|
20
37
|
* Send a notification to Slack.
|
|
21
38
|
*
|
|
@@ -24,11 +41,9 @@ function formatCommit(baseCommitUrl, commit) {
|
|
|
24
41
|
export async function sendNotificationToSlack({ branchConfig, deployResult: { deployCommits: { deployedCommits, overwrittenCommits }, branchStatus: { after, before }, }, notification, repoConfig, }) {
|
|
25
42
|
const deployedCommitBullets = deployedCommits.map((commit) => formatCommit(repoConfig.commitBaseUrl, commit));
|
|
26
43
|
const overwrittenCommitBullets = overwrittenCommits.map((commit) => formatCommit(repoConfig.commitBaseUrl, commit));
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
.
|
|
30
|
-
const overwrittenCommitBulletsText = overwrittenCommitBullets.length
|
|
31
|
-
? overwrittenCommitBullets.map((bullet) => `- ${bullet}`).join('\n')
|
|
44
|
+
const deployedCommitBulletLines = deployedCommitBullets.map((bullet) => `- ${bullet}`);
|
|
45
|
+
const overwrittenCommitBulletLines = overwrittenCommitBullets.length
|
|
46
|
+
? overwrittenCommitBullets.map((bullet) => `- ${bullet}`)
|
|
32
47
|
: undefined;
|
|
33
48
|
const beforeText = repoConfig.commitBaseUrl
|
|
34
49
|
? `<${joinUrlPaths(repoConfig.commitBaseUrl, before.hash)}|${before.hash.slice(0, 7)}>`
|
|
@@ -36,23 +51,12 @@ export async function sendNotificationToSlack({ branchConfig, deployResult: { de
|
|
|
36
51
|
const afterText = repoConfig.commitBaseUrl
|
|
37
52
|
? `<${joinUrlPaths(repoConfig.commitBaseUrl, after.hash)}|${after.hash.slice(0, 7)}>`
|
|
38
53
|
: before.hash;
|
|
39
|
-
const overwrittenCommitBlocks = overwrittenCommitBulletsText
|
|
40
|
-
? [
|
|
41
|
-
{
|
|
42
|
-
type: 'section',
|
|
43
|
-
text: {
|
|
44
|
-
type: 'mrkdwn',
|
|
45
|
-
text: `\n*Overwritten Commits*\n${overwrittenCommitBulletsText}`,
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
]
|
|
49
|
-
: [];
|
|
50
54
|
const blocks = [
|
|
51
55
|
{
|
|
52
56
|
type: 'section',
|
|
53
57
|
text: {
|
|
54
58
|
type: 'mrkdwn',
|
|
55
|
-
text: `*${
|
|
59
|
+
text: `*${setFirstLetterCasing(repoConfig.name, StringCase.Upper)} ${setFirstLetterCasing(branchConfig.deployName, StringCase.Upper)}* Pushed`,
|
|
56
60
|
},
|
|
57
61
|
},
|
|
58
62
|
{
|
|
@@ -68,10 +72,38 @@ export async function sendNotificationToSlack({ branchConfig, deployResult: { de
|
|
|
68
72
|
type: 'section',
|
|
69
73
|
text: {
|
|
70
74
|
type: 'mrkdwn',
|
|
71
|
-
text: `\n*Deployed Commits*\n
|
|
75
|
+
text: `\n*Deployed Commits*\n`,
|
|
72
76
|
},
|
|
73
77
|
},
|
|
74
|
-
...
|
|
78
|
+
...chunkSectionLines(deployedCommitBulletLines).map((lines) => {
|
|
79
|
+
return {
|
|
80
|
+
type: 'section',
|
|
81
|
+
text: {
|
|
82
|
+
type: 'mrkdwn',
|
|
83
|
+
text: lines.join('\n'),
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}),
|
|
87
|
+
...(overwrittenCommitBulletLines?.length
|
|
88
|
+
? [
|
|
89
|
+
{
|
|
90
|
+
type: 'section',
|
|
91
|
+
text: {
|
|
92
|
+
type: 'mrkdwn',
|
|
93
|
+
text: `\n*Overwritten Commits*\n`,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
...chunkSectionLines(overwrittenCommitBulletLines).map((lines) => {
|
|
97
|
+
return {
|
|
98
|
+
type: 'section',
|
|
99
|
+
text: {
|
|
100
|
+
type: 'mrkdwn',
|
|
101
|
+
text: lines.join('\n'),
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}),
|
|
105
|
+
]
|
|
106
|
+
: []),
|
|
75
107
|
];
|
|
76
108
|
await sendSlackMessage(notification, {
|
|
77
109
|
attachments: [],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deploy-vir",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "Deploy a branch to another branch with notifications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deploy",
|
|
@@ -41,37 +41,37 @@
|
|
|
41
41
|
"test:update": "npm run test update"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@augment-vir/assert": "^31.
|
|
45
|
-
"@augment-vir/common": "^31.
|
|
46
|
-
"@augment-vir/node": "^31.
|
|
44
|
+
"@augment-vir/assert": "^31.32.2",
|
|
45
|
+
"@augment-vir/common": "^31.32.2",
|
|
46
|
+
"@augment-vir/node": "^31.32.2",
|
|
47
47
|
"@slack/web-api": "^7.9.3",
|
|
48
48
|
"simple-git": "^3.28.0",
|
|
49
|
-
"tsx": "^4.20.
|
|
49
|
+
"tsx": "^4.20.4",
|
|
50
50
|
"url-vir": "^2.1.3"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@eslint/eslintrc": "^3.3.1",
|
|
54
|
-
"@eslint/js": "^9.
|
|
55
|
-
"@stylistic/eslint-plugin": "^5.2.
|
|
54
|
+
"@eslint/js": "^9.33.0",
|
|
55
|
+
"@stylistic/eslint-plugin": "^5.2.3",
|
|
56
56
|
"@stylistic/eslint-plugin-ts": "^4.4.1",
|
|
57
|
-
"@types/node": "^24.1
|
|
58
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
57
|
+
"@types/node": "^24.2.1",
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^8.39.1",
|
|
59
59
|
"cspell": "^9.2.0",
|
|
60
|
-
"dependency-cruiser": "^17.0.
|
|
61
|
-
"esbuild": "^0.25.
|
|
62
|
-
"eslint": "^9.
|
|
60
|
+
"dependency-cruiser": "^17.0.1",
|
|
61
|
+
"esbuild": "^0.25.9",
|
|
62
|
+
"eslint": "^9.33.0",
|
|
63
63
|
"eslint-config-prettier": "^10.1.8",
|
|
64
|
-
"eslint-plugin-jsdoc": "^
|
|
64
|
+
"eslint-plugin-jsdoc": "^54.0.0",
|
|
65
65
|
"eslint-plugin-monorepo-cop": "^1.0.2",
|
|
66
|
-
"eslint-plugin-playwright": "^2.2.
|
|
67
|
-
"eslint-plugin-prettier": "^5.5.
|
|
66
|
+
"eslint-plugin-playwright": "^2.2.2",
|
|
67
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
68
68
|
"eslint-plugin-require-extensions": "^0.1.3",
|
|
69
69
|
"eslint-plugin-sonarjs": "^3.0.4",
|
|
70
70
|
"eslint-plugin-unicorn": "^57.0.0",
|
|
71
71
|
"istanbul-smart-text-reporter": "^1.1.5",
|
|
72
72
|
"markdown-code-example-inserter": "^3.0.3",
|
|
73
73
|
"npm-check-updates": "^18.0.2",
|
|
74
|
-
"prettier": "
|
|
74
|
+
"prettier": "~3.3.3",
|
|
75
75
|
"prettier-plugin-interpolated-html-tags": "^2.0.1",
|
|
76
76
|
"prettier-plugin-jsdoc": "^1.3.3",
|
|
77
77
|
"prettier-plugin-multiline-arrays": "^4.0.3",
|
|
@@ -79,10 +79,10 @@
|
|
|
79
79
|
"prettier-plugin-packagejson": "^2.5.19",
|
|
80
80
|
"prettier-plugin-sort-json": "^4.1.1",
|
|
81
81
|
"prettier-plugin-toml": "^2.0.6",
|
|
82
|
-
"typedoc": "^0.28.
|
|
83
|
-
"typescript": "^5.
|
|
84
|
-
"typescript-eslint": "^8.
|
|
85
|
-
"virmator": "^13.
|
|
82
|
+
"typedoc": "^0.28.10",
|
|
83
|
+
"typescript": "^5.9.2",
|
|
84
|
+
"typescript-eslint": "^8.39.1",
|
|
85
|
+
"virmator": "^13.16.2"
|
|
86
86
|
},
|
|
87
87
|
"engines": {
|
|
88
88
|
"node": ">=22"
|
|
@@ -14,6 +14,6 @@ import {type DeployResult} from '../git.js';
|
|
|
14
14
|
export type NotificationParams<Target extends NotificationTarget = NotificationTarget> = {
|
|
15
15
|
deployResult: Readonly<DeployResult>;
|
|
16
16
|
branchConfig: Readonly<DeployVirBranchConfig>;
|
|
17
|
-
repoConfig: Readonly<Pick<DeployVirRepoConfig, 'commitBaseUrl'>>;
|
|
17
|
+
repoConfig: Readonly<Pick<DeployVirRepoConfig, 'commitBaseUrl' | 'name'>>;
|
|
18
18
|
notification: Readonly<Extract<NotificationConfig, {target: Target}>>;
|
|
19
19
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {addPrefix,
|
|
1
|
+
import {addPrefix, log, setFirstLetterCasing, StringCase} from '@augment-vir/common';
|
|
2
2
|
import {type ChatPostMessageArguments, type KnownBlock} from '@slack/web-api';
|
|
3
3
|
import {joinUrlPaths} from 'url-vir';
|
|
4
4
|
import {type SlackNotificationConfig} from '../config.js';
|
|
@@ -23,6 +23,30 @@ function formatCommit(baseCommitUrl: string | undefined, commit: Readonly<Commit
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
const slackMaxSectionLength = 2500;
|
|
27
|
+
|
|
28
|
+
function pushAndGet<T>(array: T[], item: T) {
|
|
29
|
+
array.push(item);
|
|
30
|
+
return item;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function chunkSectionLines(lines: ReadonlyArray<string>): string[][] {
|
|
34
|
+
const sectionLines: {length: number; lines: string[]}[] = [];
|
|
35
|
+
|
|
36
|
+
lines.forEach((line) => {
|
|
37
|
+
const latestSection = sectionLines.slice(-1)[0];
|
|
38
|
+
|
|
39
|
+
const currentSection =
|
|
40
|
+
latestSection && latestSection.length + line.length < slackMaxSectionLength
|
|
41
|
+
? latestSection
|
|
42
|
+
: pushAndGet(sectionLines, {length: 0, lines: []});
|
|
43
|
+
currentSection.length += line.length;
|
|
44
|
+
currentSection.lines.push(line);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return sectionLines.map(({lines}) => lines);
|
|
48
|
+
}
|
|
49
|
+
|
|
26
50
|
/**
|
|
27
51
|
* Send a notification to Slack.
|
|
28
52
|
*
|
|
@@ -44,12 +68,10 @@ export async function sendNotificationToSlack({
|
|
|
44
68
|
formatCommit(repoConfig.commitBaseUrl, commit),
|
|
45
69
|
);
|
|
46
70
|
|
|
47
|
-
const
|
|
48
|
-
.map((bullet) => `- ${bullet}`)
|
|
49
|
-
.join('\n');
|
|
71
|
+
const deployedCommitBulletLines = deployedCommitBullets.map((bullet) => `- ${bullet}`);
|
|
50
72
|
|
|
51
|
-
const
|
|
52
|
-
? overwrittenCommitBullets.map((bullet) => `- ${bullet}`)
|
|
73
|
+
const overwrittenCommitBulletLines = overwrittenCommitBullets.length
|
|
74
|
+
? overwrittenCommitBullets.map((bullet) => `- ${bullet}`)
|
|
53
75
|
: undefined;
|
|
54
76
|
|
|
55
77
|
const beforeText = repoConfig.commitBaseUrl
|
|
@@ -59,24 +81,12 @@ export async function sendNotificationToSlack({
|
|
|
59
81
|
? `<${joinUrlPaths(repoConfig.commitBaseUrl, after.hash)}|${after.hash.slice(0, 7)}>`
|
|
60
82
|
: before.hash;
|
|
61
83
|
|
|
62
|
-
const overwrittenCommitBlocks: KnownBlock[] = overwrittenCommitBulletsText
|
|
63
|
-
? [
|
|
64
|
-
{
|
|
65
|
-
type: 'section',
|
|
66
|
-
text: {
|
|
67
|
-
type: 'mrkdwn',
|
|
68
|
-
text: `\n*Overwritten Commits*\n${overwrittenCommitBulletsText}`,
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
]
|
|
72
|
-
: [];
|
|
73
|
-
|
|
74
84
|
const blocks: KnownBlock[] = [
|
|
75
85
|
{
|
|
76
86
|
type: 'section',
|
|
77
87
|
text: {
|
|
78
88
|
type: 'mrkdwn',
|
|
79
|
-
text: `*${
|
|
89
|
+
text: `*${setFirstLetterCasing(repoConfig.name, StringCase.Upper)} ${setFirstLetterCasing(branchConfig.deployName, StringCase.Upper)}* Pushed`,
|
|
80
90
|
},
|
|
81
91
|
},
|
|
82
92
|
{
|
|
@@ -92,10 +102,39 @@ export async function sendNotificationToSlack({
|
|
|
92
102
|
type: 'section',
|
|
93
103
|
text: {
|
|
94
104
|
type: 'mrkdwn',
|
|
95
|
-
text: `\n*Deployed Commits*\n
|
|
105
|
+
text: `\n*Deployed Commits*\n`,
|
|
96
106
|
},
|
|
97
107
|
},
|
|
98
|
-
...
|
|
108
|
+
...chunkSectionLines(deployedCommitBulletLines).map((lines): KnownBlock => {
|
|
109
|
+
return {
|
|
110
|
+
type: 'section',
|
|
111
|
+
text: {
|
|
112
|
+
type: 'mrkdwn',
|
|
113
|
+
text: lines.join('\n'),
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}),
|
|
117
|
+
...(overwrittenCommitBulletLines?.length
|
|
118
|
+
? ([
|
|
119
|
+
{
|
|
120
|
+
type: 'section',
|
|
121
|
+
text: {
|
|
122
|
+
type: 'mrkdwn',
|
|
123
|
+
text: `\n*Overwritten Commits*\n`,
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
...chunkSectionLines(overwrittenCommitBulletLines).map((lines): KnownBlock => {
|
|
128
|
+
return {
|
|
129
|
+
type: 'section',
|
|
130
|
+
text: {
|
|
131
|
+
type: 'mrkdwn',
|
|
132
|
+
text: lines.join('\n'),
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}),
|
|
136
|
+
] satisfies KnownBlock[])
|
|
137
|
+
: []),
|
|
99
138
|
];
|
|
100
139
|
|
|
101
140
|
await sendSlackMessage(notification, {
|