deploy-vir 2.1.0 → 3.0.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/cli/cli.js +3 -14
- package/dist/config.d.ts +2 -0
- package/dist/git.d.ts +3 -2
- package/dist/git.js +14 -3
- package/dist/notifications/slack.d.ts +1 -1
- package/dist/notifications/slack.js +2 -2
- package/package.json +25 -25
- package/src/cli/cli.ts +5 -16
- package/src/config.ts +2 -0
- package/src/git.ts +117 -94
- package/src/notifications/slack.ts +2 -2
package/dist/cli/cli.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { assertWrap } from '@augment-vir/assert';
|
|
2
|
-
import {
|
|
2
|
+
import { extractErrorMessage, log } from '@augment-vir/common';
|
|
3
3
|
import { select } from '@inquirer/prompts';
|
|
4
4
|
import { resolve } from 'node:path';
|
|
5
|
-
import simpleGit from 'simple-git';
|
|
5
|
+
import { simpleGit } from 'simple-git';
|
|
6
6
|
import { getGitRemoteName, pushDeploy } from '../git.js';
|
|
7
7
|
import { KnownError } from '../known.error.js';
|
|
8
|
-
import { sendNotifications } from '../notifications/send-notifications.js';
|
|
9
8
|
/**
|
|
10
9
|
* Run the deploy-vir CLI.
|
|
11
10
|
*
|
|
@@ -49,17 +48,7 @@ export async function runDeployVir(args, config) {
|
|
|
49
48
|
const branchConfig = assertWrap.isDefined(repoConfig.deploys.find((deploy) => deploy.deployName === args.deployName, `Failed to find a deploy named '${args.deployName}' in repo '${args.repoName}'.`));
|
|
50
49
|
const remoteName = await getGitRemoteName(git, repoConfig);
|
|
51
50
|
log.faint(`Remote: ${remoteName}`);
|
|
52
|
-
|
|
53
|
-
const notifications = config.notifications;
|
|
54
|
-
if (notifications?.length) {
|
|
55
|
-
await awaitedForEach(deployResults, async (deployResult) => {
|
|
56
|
-
await sendNotifications(notifications, {
|
|
57
|
-
branchConfig,
|
|
58
|
-
deployResult,
|
|
59
|
-
repoConfig,
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
}
|
|
51
|
+
await pushDeploy(git, branchConfig, repoConfig, remoteName, config.notifications, args.bypassConfirmation);
|
|
63
52
|
}
|
|
64
53
|
catch (error) {
|
|
65
54
|
if (error instanceof KnownError) {
|
package/dist/config.d.ts
CHANGED
|
@@ -82,6 +82,7 @@ export type DeployVirRepoConfig = {
|
|
|
82
82
|
*/
|
|
83
83
|
commitBaseUrl?: string | undefined;
|
|
84
84
|
deploys: DeployVirBranchConfig[];
|
|
85
|
+
enableNotifications?: boolean | undefined;
|
|
85
86
|
};
|
|
86
87
|
/**
|
|
87
88
|
* A deploy configuration.
|
|
@@ -93,6 +94,7 @@ export type DeployVirBranchConfig = {
|
|
|
93
94
|
branches: {
|
|
94
95
|
fromBranch: string;
|
|
95
96
|
toBranch: string;
|
|
97
|
+
enableNotifications?: boolean | undefined;
|
|
96
98
|
}[];
|
|
97
99
|
};
|
|
98
100
|
/**
|
package/dist/git.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type DefaultLogFields, type ListLogLine, type SimpleGit } from 'simple-git';
|
|
2
|
-
import { type DeployVirBranchConfig, type DeployVirRepoConfig } from './config.js';
|
|
2
|
+
import { type DeployVirBranchConfig, type DeployVirRepoConfig, type NotificationConfig } from './config.js';
|
|
3
3
|
/**
|
|
4
4
|
* Find the git remote's name, or create a new one.
|
|
5
5
|
*
|
|
@@ -38,10 +38,11 @@ export type DeployBranchStatus = {
|
|
|
38
38
|
export type DeployResult = {
|
|
39
39
|
deployCommits: DeployCommits;
|
|
40
40
|
branchStatus: DeployBranchStatus;
|
|
41
|
+
toBranchName: string;
|
|
41
42
|
};
|
|
42
43
|
/**
|
|
43
44
|
* Push the deploy via git.
|
|
44
45
|
*
|
|
45
46
|
* @category Internal
|
|
46
47
|
*/
|
|
47
|
-
export declare function pushDeploy(git: Readonly<SimpleGit>,
|
|
48
|
+
export declare function pushDeploy(git: Readonly<SimpleGit>, branchConfig: Readonly<DeployVirBranchConfig>, repoConfig: Readonly<DeployVirRepoConfig>, remoteName: string, notifications: ReadonlyArray<Readonly<NotificationConfig>> | undefined, bypassConfirmation?: boolean): Promise<DeployResult[]>;
|
package/dist/git.js
CHANGED
|
@@ -2,6 +2,7 @@ import { assert, assertWrap, check } from '@augment-vir/assert';
|
|
|
2
2
|
import { awaitedBlockingMap, log, logColors } from '@augment-vir/common';
|
|
3
3
|
import { confirm } from '@inquirer/prompts';
|
|
4
4
|
import { KnownError } from './known.error.js';
|
|
5
|
+
import { sendNotifications } from './notifications/send-notifications.js';
|
|
5
6
|
/**
|
|
6
7
|
* Find the git remote's name, or create a new one.
|
|
7
8
|
*
|
|
@@ -30,8 +31,9 @@ export async function getGitRemoteName(git, repoConfig) {
|
|
|
30
31
|
*
|
|
31
32
|
* @category Internal
|
|
32
33
|
*/
|
|
33
|
-
export async function pushDeploy(git,
|
|
34
|
-
|
|
34
|
+
export async function pushDeploy(git, branchConfig, repoConfig, remoteName, notifications, bypassConfirmation = false) {
|
|
35
|
+
const { deployName, branches } = branchConfig;
|
|
36
|
+
return await awaitedBlockingMap(branches, async ({ fromBranch, toBranch, enableNotifications }) => {
|
|
35
37
|
assert.isTruthy(fromBranch, `Deploy '${deployName}' fromBranch cannot be empty.`);
|
|
36
38
|
assert.isTruthy(toBranch, `Deploy '${deployName}' toBranch cannot be empty.`);
|
|
37
39
|
assert.isTruthy(remoteName, 'Remote name cannot be empty.');
|
|
@@ -87,7 +89,8 @@ export async function pushDeploy(git, { deployName, branches }, remoteName, bypa
|
|
|
87
89
|
else {
|
|
88
90
|
await git.push(remoteName, pushString);
|
|
89
91
|
}
|
|
90
|
-
|
|
92
|
+
const deployResult = {
|
|
93
|
+
toBranchName: toBranch,
|
|
91
94
|
deployCommits: {
|
|
92
95
|
deployedCommits: commitsAhead,
|
|
93
96
|
overwrittenCommits: commitsBehind,
|
|
@@ -97,5 +100,13 @@ export async function pushDeploy(git, { deployName, branches }, remoteName, bypa
|
|
|
97
100
|
after: afterCommit,
|
|
98
101
|
},
|
|
99
102
|
};
|
|
103
|
+
if (notifications?.length && (repoConfig.enableNotifications || enableNotifications)) {
|
|
104
|
+
await sendNotifications(notifications, {
|
|
105
|
+
branchConfig,
|
|
106
|
+
deployResult,
|
|
107
|
+
repoConfig,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return deployResult;
|
|
100
111
|
});
|
|
101
112
|
}
|
|
@@ -5,4 +5,4 @@ export { type ChatPostMessageArguments } from '@slack/web-api';
|
|
|
5
5
|
*
|
|
6
6
|
* @category Internal
|
|
7
7
|
*/
|
|
8
|
-
export declare function sendNotificationToSlack({
|
|
8
|
+
export declare function sendNotificationToSlack({ deployResult: { deployCommits: { deployedCommits, overwrittenCommits }, branchStatus: { after, before }, toBranchName, }, notification, repoConfig, }: Readonly<NotificationParams>): Promise<void>;
|
|
@@ -38,7 +38,7 @@ function chunkSectionLines(lines) {
|
|
|
38
38
|
*
|
|
39
39
|
* @category Internal
|
|
40
40
|
*/
|
|
41
|
-
export async function sendNotificationToSlack({
|
|
41
|
+
export async function sendNotificationToSlack({ deployResult: { deployCommits: { deployedCommits, overwrittenCommits }, branchStatus: { after, before }, toBranchName, }, notification, repoConfig, }) {
|
|
42
42
|
const deployedCommitBullets = deployedCommits.map((commit) => formatCommit(repoConfig.commitBaseUrl, commit));
|
|
43
43
|
const overwrittenCommitBullets = overwrittenCommits.map((commit) => formatCommit(repoConfig.commitBaseUrl, commit));
|
|
44
44
|
const deployedCommitBulletLines = deployedCommitBullets.map((bullet) => `- ${bullet}`);
|
|
@@ -56,7 +56,7 @@ export async function sendNotificationToSlack({ branchConfig, deployResult: { de
|
|
|
56
56
|
type: 'section',
|
|
57
57
|
text: {
|
|
58
58
|
type: 'mrkdwn',
|
|
59
|
-
text: `*${setFirstLetterCasing(repoConfig.name, StringCase.Upper)} ${setFirstLetterCasing(
|
|
59
|
+
text: `*${setFirstLetterCasing(repoConfig.name, StringCase.Upper)} ${setFirstLetterCasing(toBranchName, StringCase.Upper)}* Pushed`,
|
|
60
60
|
},
|
|
61
61
|
},
|
|
62
62
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deploy-vir",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Deploy a branch to another branch with notifications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deploy",
|
|
@@ -41,51 +41,51 @@
|
|
|
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.
|
|
47
|
-
"@inquirer/prompts": "^8.1
|
|
48
|
-
"@slack/web-api": "^7.
|
|
44
|
+
"@augment-vir/assert": "^31.61.0",
|
|
45
|
+
"@augment-vir/common": "^31.61.0",
|
|
46
|
+
"@augment-vir/node": "^31.61.0",
|
|
47
|
+
"@inquirer/prompts": "^8.2.1",
|
|
48
|
+
"@slack/web-api": "^7.14.1",
|
|
49
49
|
"cli-vir": "^1.0.3",
|
|
50
|
-
"simple-git": "^3.
|
|
50
|
+
"simple-git": "^3.31.1",
|
|
51
51
|
"tsx": "^4.21.0",
|
|
52
52
|
"url-vir": "^2.1.7"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@eslint/eslintrc": "^3.3.3",
|
|
56
56
|
"@eslint/js": "^9.39.2",
|
|
57
|
-
"@stylistic/eslint-plugin": "^5.
|
|
57
|
+
"@stylistic/eslint-plugin": "^5.8.0",
|
|
58
58
|
"@stylistic/eslint-plugin-ts": "^4.4.1",
|
|
59
|
-
"@types/node": "^25.
|
|
60
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
61
|
-
"cspell": "^9.4
|
|
62
|
-
"dependency-cruiser": "^17.3.
|
|
63
|
-
"esbuild": "^0.27.
|
|
59
|
+
"@types/node": "^25.2.3",
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "^8.56.0",
|
|
61
|
+
"cspell": "^9.6.4",
|
|
62
|
+
"dependency-cruiser": "^17.3.8",
|
|
63
|
+
"esbuild": "^0.27.3",
|
|
64
64
|
"eslint": "^9.39.2",
|
|
65
65
|
"eslint-config-prettier": "^10.1.8",
|
|
66
|
-
"eslint-plugin-jsdoc": "^
|
|
66
|
+
"eslint-plugin-jsdoc": "^62.5.0",
|
|
67
67
|
"eslint-plugin-monorepo-cop": "^1.0.2",
|
|
68
|
-
"eslint-plugin-playwright": "^2.
|
|
69
|
-
"eslint-plugin-prettier": "^5.5.
|
|
68
|
+
"eslint-plugin-playwright": "^2.5.1",
|
|
69
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
70
70
|
"eslint-plugin-require-extensions": "^0.1.3",
|
|
71
|
-
"eslint-plugin-sonarjs": "^3.0.
|
|
72
|
-
"eslint-plugin-unicorn": "^
|
|
71
|
+
"eslint-plugin-sonarjs": "^3.0.6",
|
|
72
|
+
"eslint-plugin-unicorn": "^63.0.0",
|
|
73
73
|
"istanbul-smart-text-reporter": "^1.1.5",
|
|
74
74
|
"markdown-code-example-inserter": "^3.0.3",
|
|
75
|
-
"npm-check-updates": "^19.2
|
|
75
|
+
"npm-check-updates": "^19.3.2",
|
|
76
76
|
"prettier": "~3.3.3",
|
|
77
77
|
"prettier-plugin-interpolated-html-tags": "^2.0.1",
|
|
78
78
|
"prettier-plugin-jsdoc": "^1.8.0",
|
|
79
|
-
"prettier-plugin-multiline-arrays": "^4.1.
|
|
79
|
+
"prettier-plugin-multiline-arrays": "^4.1.4",
|
|
80
80
|
"prettier-plugin-organize-imports": "^4.3.0",
|
|
81
|
-
"prettier-plugin-packagejson": "^
|
|
82
|
-
"prettier-plugin-sort-json": "^4.
|
|
81
|
+
"prettier-plugin-packagejson": "^3.0.0",
|
|
82
|
+
"prettier-plugin-sort-json": "^4.2.0",
|
|
83
83
|
"prettier-plugin-toml": "^2.0.6",
|
|
84
84
|
"runstorm": "^1.0.0",
|
|
85
|
-
"typedoc": "^0.28.
|
|
85
|
+
"typedoc": "^0.28.17",
|
|
86
86
|
"typescript": "^5.9.3",
|
|
87
|
-
"typescript-eslint": "^8.
|
|
88
|
-
"virmator": "^14.
|
|
87
|
+
"typescript-eslint": "^8.56.0",
|
|
88
|
+
"virmator": "^14.5.2"
|
|
89
89
|
},
|
|
90
90
|
"engines": {
|
|
91
91
|
"node": ">=22"
|
package/src/cli/cli.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import {assertWrap} from '@augment-vir/assert';
|
|
2
|
-
import {
|
|
2
|
+
import {extractErrorMessage, log} from '@augment-vir/common';
|
|
3
3
|
import {select} from '@inquirer/prompts';
|
|
4
4
|
import {resolve} from 'node:path';
|
|
5
|
-
import simpleGit from 'simple-git';
|
|
5
|
+
import {simpleGit} from 'simple-git';
|
|
6
6
|
import {type DeployVirConfig} from '../config.js';
|
|
7
7
|
import {getGitRemoteName, pushDeploy} from '../git.js';
|
|
8
8
|
import {KnownError} from '../known.error.js';
|
|
9
|
-
import {sendNotifications} from '../notifications/send-notifications.js';
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* Run the deploy-vir CLI.
|
|
@@ -106,24 +105,14 @@ export async function runDeployVir(
|
|
|
106
105
|
const remoteName = await getGitRemoteName(git, repoConfig);
|
|
107
106
|
log.faint(`Remote: ${remoteName}`);
|
|
108
107
|
|
|
109
|
-
|
|
108
|
+
await pushDeploy(
|
|
110
109
|
git,
|
|
111
110
|
branchConfig,
|
|
111
|
+
repoConfig,
|
|
112
112
|
remoteName,
|
|
113
|
+
config.notifications,
|
|
113
114
|
args.bypassConfirmation,
|
|
114
115
|
);
|
|
115
|
-
|
|
116
|
-
const notifications = config.notifications;
|
|
117
|
-
|
|
118
|
-
if (notifications?.length) {
|
|
119
|
-
await awaitedForEach(deployResults, async (deployResult) => {
|
|
120
|
-
await sendNotifications(notifications, {
|
|
121
|
-
branchConfig,
|
|
122
|
-
deployResult,
|
|
123
|
-
repoConfig,
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
116
|
} catch (error) {
|
|
128
117
|
if (error instanceof KnownError) {
|
|
129
118
|
/** If its a known error, don't log the whole stack trace. */
|
package/src/config.ts
CHANGED
|
@@ -87,6 +87,7 @@ export type DeployVirRepoConfig = {
|
|
|
87
87
|
*/
|
|
88
88
|
commitBaseUrl?: string | undefined;
|
|
89
89
|
deploys: DeployVirBranchConfig[];
|
|
90
|
+
enableNotifications?: boolean | undefined;
|
|
90
91
|
};
|
|
91
92
|
|
|
92
93
|
/**
|
|
@@ -99,6 +100,7 @@ export type DeployVirBranchConfig = {
|
|
|
99
100
|
branches: {
|
|
100
101
|
fromBranch: string;
|
|
101
102
|
toBranch: string;
|
|
103
|
+
enableNotifications?: boolean | undefined;
|
|
102
104
|
}[];
|
|
103
105
|
};
|
|
104
106
|
|
package/src/git.ts
CHANGED
|
@@ -2,8 +2,13 @@ import {assert, assertWrap, check} from '@augment-vir/assert';
|
|
|
2
2
|
import {awaitedBlockingMap, log, logColors} from '@augment-vir/common';
|
|
3
3
|
import {confirm} from '@inquirer/prompts';
|
|
4
4
|
import {type DefaultLogFields, type ListLogLine, type SimpleGit} from 'simple-git';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
type DeployVirBranchConfig,
|
|
7
|
+
type DeployVirRepoConfig,
|
|
8
|
+
type NotificationConfig,
|
|
9
|
+
} from './config.js';
|
|
6
10
|
import {KnownError} from './known.error.js';
|
|
11
|
+
import {sendNotifications} from './notifications/send-notifications.js';
|
|
7
12
|
|
|
8
13
|
/**
|
|
9
14
|
* Find the git remote's name, or create a new one.
|
|
@@ -79,6 +84,7 @@ export type DeployBranchStatus = {
|
|
|
79
84
|
export type DeployResult = {
|
|
80
85
|
deployCommits: DeployCommits;
|
|
81
86
|
branchStatus: DeployBranchStatus;
|
|
87
|
+
toBranchName: string;
|
|
82
88
|
};
|
|
83
89
|
|
|
84
90
|
/**
|
|
@@ -88,112 +94,129 @@ export type DeployResult = {
|
|
|
88
94
|
*/
|
|
89
95
|
export async function pushDeploy(
|
|
90
96
|
git: Readonly<SimpleGit>,
|
|
91
|
-
|
|
97
|
+
branchConfig: Readonly<DeployVirBranchConfig>,
|
|
98
|
+
repoConfig: Readonly<DeployVirRepoConfig>,
|
|
92
99
|
remoteName: string,
|
|
100
|
+
notifications: ReadonlyArray<Readonly<NotificationConfig>> | undefined,
|
|
93
101
|
bypassConfirmation = false,
|
|
94
102
|
): Promise<DeployResult[]> {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
const {deployName, branches} = branchConfig;
|
|
104
|
+
return await awaitedBlockingMap(
|
|
105
|
+
branches,
|
|
106
|
+
async ({fromBranch, toBranch, enableNotifications}): Promise<DeployResult> => {
|
|
107
|
+
assert.isTruthy(fromBranch, `Deploy '${deployName}' fromBranch cannot be empty.`);
|
|
108
|
+
assert.isTruthy(toBranch, `Deploy '${deployName}' toBranch cannot be empty.`);
|
|
109
|
+
assert.isTruthy(remoteName, 'Remote name cannot be empty.');
|
|
110
|
+
|
|
111
|
+
log.faint(`Pushing ${remoteName}/${fromBranch} to ${toBranch}`);
|
|
112
|
+
|
|
113
|
+
await git.fetch(remoteName, fromBranch);
|
|
114
|
+
await git.fetch(remoteName, toBranch);
|
|
115
|
+
|
|
116
|
+
const pushString = `${remoteName}/${fromBranch}:${toBranch}`;
|
|
117
|
+
|
|
118
|
+
// Get the current commit on the target branch before pushing
|
|
119
|
+
const beforeCommit = assertWrap.isDefined(
|
|
120
|
+
(
|
|
121
|
+
await git.log([
|
|
122
|
+
`${remoteName}/${toBranch}`,
|
|
123
|
+
'-1',
|
|
124
|
+
])
|
|
125
|
+
).latest,
|
|
126
|
+
`Failed to get current commit for ${remoteName}/${toBranch}`,
|
|
127
|
+
);
|
|
104
128
|
|
|
105
|
-
|
|
129
|
+
const afterCommit = assertWrap.isDefined(
|
|
130
|
+
(
|
|
131
|
+
await git.log([
|
|
132
|
+
`${remoteName}/${fromBranch}`,
|
|
133
|
+
'-1',
|
|
134
|
+
])
|
|
135
|
+
).latest,
|
|
136
|
+
`Failed to get current commit for ${remoteName}/${fromBranch}`,
|
|
137
|
+
);
|
|
106
138
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
(
|
|
139
|
+
/** Get commits that are on {@link toBranch} but not on {@link fromBranch}. */
|
|
140
|
+
const commitsAhead = (
|
|
110
141
|
await git.log([
|
|
111
|
-
`${remoteName}/${toBranch}`,
|
|
112
|
-
'-1',
|
|
142
|
+
`${remoteName}/${toBranch}..${remoteName}/${fromBranch}`,
|
|
113
143
|
])
|
|
114
|
-
).
|
|
115
|
-
|
|
116
|
-
|
|
144
|
+
).all;
|
|
145
|
+
|
|
146
|
+
if (!commitsAhead.length) {
|
|
147
|
+
throw new KnownError('No commit diff: nothing to deploy!');
|
|
148
|
+
}
|
|
117
149
|
|
|
118
|
-
|
|
119
|
-
(
|
|
150
|
+
/** Get commits that are on {@link toBranch} but not on {@link fromBranch}. */
|
|
151
|
+
const commitsBehind = (
|
|
120
152
|
await git.log([
|
|
121
|
-
`${remoteName}/${fromBranch}`,
|
|
122
|
-
'-1',
|
|
153
|
+
`${remoteName}/${fromBranch}..${remoteName}/${toBranch}`,
|
|
123
154
|
])
|
|
124
|
-
).
|
|
125
|
-
`Failed to get current commit for ${remoteName}/${fromBranch}`,
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
/** Get commits that are on {@link toBranch} but not on {@link fromBranch}. */
|
|
129
|
-
const commitsAhead = (
|
|
130
|
-
await git.log([
|
|
131
|
-
`${remoteName}/${toBranch}..${remoteName}/${fromBranch}`,
|
|
132
|
-
])
|
|
133
|
-
).all;
|
|
134
|
-
|
|
135
|
-
if (!commitsAhead.length) {
|
|
136
|
-
throw new KnownError('No commit diff: nothing to deploy!');
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/** Get commits that are on {@link toBranch} but not on {@link fromBranch}. */
|
|
140
|
-
const commitsBehind = (
|
|
141
|
-
await git.log([
|
|
142
|
-
`${remoteName}/${fromBranch}..${remoteName}/${toBranch}`,
|
|
143
|
-
])
|
|
144
|
-
).all;
|
|
145
|
-
|
|
146
|
-
const requiresForcePush = commitsBehind.length > 0;
|
|
147
|
-
|
|
148
|
-
log.info(
|
|
149
|
-
`\n${requiresForcePush ? 'Only on' : 'Releasing from'} ${logColors.bold}${fromBranch}${logColors.reset}:`,
|
|
150
|
-
);
|
|
151
|
-
commitsAhead.forEach((commit, index) => {
|
|
152
|
-
log.faint(
|
|
153
|
-
` ${index + 1}. ${commit.hash.slice(0, 7)} (${commit.author_name}) - ${commit.message}`,
|
|
154
|
-
);
|
|
155
|
-
});
|
|
155
|
+
).all;
|
|
156
156
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
const requiresForcePush = commitsBehind.length > 0;
|
|
158
|
+
|
|
159
|
+
log.info(
|
|
160
|
+
`\n${requiresForcePush ? 'Only on' : 'Releasing from'} ${logColors.bold}${fromBranch}${logColors.reset}:`,
|
|
161
|
+
);
|
|
162
|
+
commitsAhead.forEach((commit, index) => {
|
|
160
163
|
log.faint(
|
|
161
164
|
` ${index + 1}. ${commit.hash.slice(0, 7)} (${commit.author_name}) - ${commit.message}`,
|
|
162
165
|
);
|
|
163
166
|
});
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
)
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
167
|
+
|
|
168
|
+
if (requiresForcePush) {
|
|
169
|
+
log.info(`\nOnly on ${logColors.bold}${toBranch}${logColors.reset}:`);
|
|
170
|
+
commitsBehind.forEach((commit, index) => {
|
|
171
|
+
log.faint(
|
|
172
|
+
` ${index + 1}. ${commit.hash.slice(0, 7)} (${commit.author_name}) - ${commit.message}`,
|
|
173
|
+
);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const shouldPush =
|
|
178
|
+
bypassConfirmation ||
|
|
179
|
+
(await confirm({
|
|
180
|
+
message: requiresForcePush
|
|
181
|
+
? `\n${logColors.warning}Do you want to force push ${logColors.bold}${fromBranch}${logColors.normalWeight} to ${logColors.bold}${toBranch}${logColors.normalWeight}?\n\nThis will overwrite the commits only on ${logColors.bold}${toBranch}${logColors.normalWeight}.${logColors.reset}?`
|
|
182
|
+
: 'Ready to deploy?',
|
|
183
|
+
default: false,
|
|
184
|
+
}));
|
|
185
|
+
|
|
186
|
+
if (!shouldPush) {
|
|
187
|
+
throw new KnownError(`Deploy aborted.`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (requiresForcePush) {
|
|
191
|
+
await git.push(remoteName, pushString, ['--force']);
|
|
192
|
+
log.warning(
|
|
193
|
+
`Force pushed ${logColors.bold}${fromBranch}${logColors.normalWeight} to ${logColors.bold}${toBranch}${logColors.reset}.`,
|
|
194
|
+
);
|
|
195
|
+
} else {
|
|
196
|
+
await git.push(remoteName, pushString);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const deployResult: DeployResult = {
|
|
200
|
+
toBranchName: toBranch,
|
|
201
|
+
deployCommits: {
|
|
202
|
+
deployedCommits: commitsAhead,
|
|
203
|
+
overwrittenCommits: commitsBehind,
|
|
204
|
+
},
|
|
205
|
+
branchStatus: {
|
|
206
|
+
before: beforeCommit,
|
|
207
|
+
after: afterCommit,
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
if (notifications?.length && (repoConfig.enableNotifications || enableNotifications)) {
|
|
212
|
+
await sendNotifications(notifications, {
|
|
213
|
+
branchConfig,
|
|
214
|
+
deployResult,
|
|
215
|
+
repoConfig,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return deployResult;
|
|
220
|
+
},
|
|
221
|
+
);
|
|
199
222
|
}
|
|
@@ -53,10 +53,10 @@ function chunkSectionLines(lines: ReadonlyArray<string>): string[][] {
|
|
|
53
53
|
* @category Internal
|
|
54
54
|
*/
|
|
55
55
|
export async function sendNotificationToSlack({
|
|
56
|
-
branchConfig,
|
|
57
56
|
deployResult: {
|
|
58
57
|
deployCommits: {deployedCommits, overwrittenCommits},
|
|
59
58
|
branchStatus: {after, before},
|
|
59
|
+
toBranchName,
|
|
60
60
|
},
|
|
61
61
|
notification,
|
|
62
62
|
repoConfig,
|
|
@@ -86,7 +86,7 @@ export async function sendNotificationToSlack({
|
|
|
86
86
|
type: 'section',
|
|
87
87
|
text: {
|
|
88
88
|
type: 'mrkdwn',
|
|
89
|
-
text: `*${setFirstLetterCasing(repoConfig.name, StringCase.Upper)} ${setFirstLetterCasing(
|
|
89
|
+
text: `*${setFirstLetterCasing(repoConfig.name, StringCase.Upper)} ${setFirstLetterCasing(toBranchName, StringCase.Upper)}* Pushed`,
|
|
90
90
|
},
|
|
91
91
|
},
|
|
92
92
|
{
|