backport 6.2.0 → 6.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/README.md +2 -1
- package/dist/entrypoint.cli.js +3 -5
- package/dist/entrypoint.module.d.ts +2 -2
- package/dist/entrypoint.module.js +4 -4
- package/dist/options/ConfigOptions.d.ts +3 -1
- package/dist/options/cliArgs.d.ts +16 -14
- package/dist/options/cliArgs.js +12 -3
- package/dist/options/config/config.d.ts +8 -4
- package/dist/options/config/config.js +8 -2
- package/dist/options/config/config.test.js +27 -1
- package/dist/options/config/globalConfig.d.ts +1 -1
- package/dist/options/config/globalConfig.js +12 -6
- package/dist/options/config/globalConfig.test.js +8 -2
- package/dist/options/config/projectConfig.d.ts +3 -1
- package/dist/options/config/projectConfig.js +5 -2
- package/dist/options/config/projectConfig.test.js +35 -6
- package/dist/options/config/readConfigFile.d.ts +25 -23
- package/dist/options/options.d.ts +14 -12
- package/dist/options/options.js +4 -4
- package/dist/options/options.test.js +35 -33
- package/dist/runSequentially.test.js +2 -6
- package/dist/scripts/postinstall.js +3 -3
- package/dist/services/env.d.ts +3 -1
- package/dist/services/env.js +4 -1
- package/dist/services/github/v3/createPullRequest.js +8 -5
- package/dist/services/github/v3/createPullRequest.test.js +57 -7
- package/dist/services/github/v3/createStatusComment.d.ts +1 -1
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +3 -1
- package/dist/services/logger.d.ts +4 -1
- package/dist/services/logger.js +28 -29
- package/dist/test/backport-e2e.private.test.js +2 -4
- package/dist/test/inquirer.private.test.js +3 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +3 -8
- package/package.json +9 -9
- package/yarn.lock +109 -153
|
@@ -22,7 +22,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const os_1 = __importDefault(require("os"));
|
|
25
26
|
const nock_1 = __importDefault(require("nock"));
|
|
27
|
+
const fs = __importStar(require("../services/fs-promisified"));
|
|
26
28
|
const logger = __importStar(require("../services/logger"));
|
|
27
29
|
const mockConfigFiles_1 = require("../test/mockConfigFiles");
|
|
28
30
|
const nockHelpers_1 = require("../test/nockHelpers");
|
|
@@ -45,6 +47,9 @@ describe('getOptions', () => {
|
|
|
45
47
|
});
|
|
46
48
|
beforeEach(() => {
|
|
47
49
|
(0, mockConfigFiles_1.mockConfigFiles)(defaultConfigs);
|
|
50
|
+
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
51
|
+
jest.spyOn(fs, 'writeFile').mockResolvedValue();
|
|
52
|
+
jest.spyOn(fs, 'chmod').mockResolvedValue();
|
|
48
53
|
});
|
|
49
54
|
describe('should throw', () => {
|
|
50
55
|
beforeEach(() => {
|
|
@@ -55,13 +60,13 @@ describe('getOptions', () => {
|
|
|
55
60
|
projectConfig: defaultConfigs.projectConfig,
|
|
56
61
|
globalConfig: { accessToken: undefined },
|
|
57
62
|
});
|
|
58
|
-
await expect(() => (0, options_1.getOptions)([])).rejects
|
|
63
|
+
await expect(() => (0, options_1.getOptions)([], { ci: true })).rejects
|
|
59
64
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
"Please update your config file: \\"/myHomeDir/.backport/config.json\\".
|
|
66
|
+
It must contain a valid \\"accessToken\\".
|
|
62
67
|
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#global-config-backportconfigjson"
|
|
69
|
+
`);
|
|
65
70
|
});
|
|
66
71
|
it('when `targetBranches`, `targetBranchChoices` and `branchLabelMapping` are all empty', async () => {
|
|
67
72
|
mockProjectConfig({
|
|
@@ -69,7 +74,7 @@ describe('getOptions', () => {
|
|
|
69
74
|
targetBranchChoices: undefined,
|
|
70
75
|
branchLabelMapping: undefined,
|
|
71
76
|
});
|
|
72
|
-
await expect(() => (0, options_1.getOptions)([])).rejects
|
|
77
|
+
await expect(() => (0, options_1.getOptions)([], {})).rejects
|
|
73
78
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
74
79
|
"Please specify a target branch: \\"--branch 6.1\\".
|
|
75
80
|
|
|
@@ -78,7 +83,7 @@ describe('getOptions', () => {
|
|
|
78
83
|
});
|
|
79
84
|
it('when repoName is missing', async () => {
|
|
80
85
|
mockProjectConfig({ repoName: '' });
|
|
81
|
-
await expect(() => (0, options_1.getOptions)([])).rejects
|
|
86
|
+
await expect(() => (0, options_1.getOptions)([], {})).rejects
|
|
82
87
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
83
88
|
"Please specify a repo name: \\"--repo-name kibana\\".
|
|
84
89
|
|
|
@@ -87,7 +92,7 @@ describe('getOptions', () => {
|
|
|
87
92
|
});
|
|
88
93
|
it('when repoOwner is missing', async () => {
|
|
89
94
|
mockProjectConfig({ repoOwner: '' });
|
|
90
|
-
await expect(() => (0, options_1.getOptions)([])).rejects
|
|
95
|
+
await expect(() => (0, options_1.getOptions)([], {})).rejects
|
|
91
96
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
92
97
|
"Please specify a repo owner: \\"--repo-owner elastic\\".
|
|
93
98
|
|
|
@@ -97,7 +102,7 @@ describe('getOptions', () => {
|
|
|
97
102
|
});
|
|
98
103
|
it('should ensure that "backport" branch does not exist', async () => {
|
|
99
104
|
mockGithubConfigOptions({ refName: 'backport' });
|
|
100
|
-
await expect((0, options_1.getOptions)([])).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
|
|
105
|
+
await expect((0, options_1.getOptions)([], {})).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
|
|
101
106
|
});
|
|
102
107
|
it('should merge config options and module options', async () => {
|
|
103
108
|
mockGithubConfigOptions({});
|
|
@@ -107,7 +112,7 @@ describe('getOptions', () => {
|
|
|
107
112
|
});
|
|
108
113
|
it('should call updateLogger', async () => {
|
|
109
114
|
mockGithubConfigOptions({});
|
|
110
|
-
await (0, options_1.getOptions)([]);
|
|
115
|
+
await (0, options_1.getOptions)([], {});
|
|
111
116
|
expect(logger.updateLogger).toHaveBeenCalledTimes(1);
|
|
112
117
|
});
|
|
113
118
|
it('should return options', async () => {
|
|
@@ -121,7 +126,7 @@ describe('getOptions', () => {
|
|
|
121
126
|
},
|
|
122
127
|
],
|
|
123
128
|
});
|
|
124
|
-
const options = await (0, options_1.getOptions)([]);
|
|
129
|
+
const options = await (0, options_1.getOptions)([], {});
|
|
125
130
|
expect(options).toEqual({
|
|
126
131
|
accessToken: 'abc',
|
|
127
132
|
assignees: [],
|
|
@@ -171,14 +176,11 @@ describe('getOptions', () => {
|
|
|
171
176
|
mockGithubConfigOptions({ defaultBranchRef: 'some-default-branch' });
|
|
172
177
|
});
|
|
173
178
|
it('uses the `defaultBranchRef` as default', async () => {
|
|
174
|
-
const options = await (0, options_1.getOptions)([]);
|
|
179
|
+
const options = await (0, options_1.getOptions)([], {});
|
|
175
180
|
expect(options.sourceBranch).toBe('some-default-branch');
|
|
176
181
|
});
|
|
177
182
|
it('uses the sourceBranch given via cli instead of `defaultBranchRef`', async () => {
|
|
178
|
-
const options = await (0, options_1.getOptions)([
|
|
179
|
-
'--source-branch',
|
|
180
|
-
'cli-source-branch',
|
|
181
|
-
]);
|
|
183
|
+
const options = await (0, options_1.getOptions)(['--source-branch', 'cli-source-branch'], {});
|
|
182
184
|
expect(options.sourceBranch).toBe('cli-source-branch');
|
|
183
185
|
});
|
|
184
186
|
});
|
|
@@ -187,16 +189,16 @@ describe('getOptions', () => {
|
|
|
187
189
|
mockGithubConfigOptions({});
|
|
188
190
|
});
|
|
189
191
|
it('is enabled by default', async () => {
|
|
190
|
-
const { fork } = await (0, options_1.getOptions)([]);
|
|
192
|
+
const { fork } = await (0, options_1.getOptions)([], {});
|
|
191
193
|
expect(fork).toBe(true);
|
|
192
194
|
});
|
|
193
195
|
it('can be disabled via `--no-fork` flag', async () => {
|
|
194
|
-
const { fork } = await (0, options_1.getOptions)(['--no-fork']);
|
|
196
|
+
const { fork } = await (0, options_1.getOptions)(['--no-fork'], {});
|
|
195
197
|
expect(fork).toBe(false);
|
|
196
198
|
});
|
|
197
199
|
it('can be disabled via config file', async () => {
|
|
198
200
|
mockProjectConfig({ fork: false });
|
|
199
|
-
const { fork } = await (0, options_1.getOptions)([]);
|
|
201
|
+
const { fork } = await (0, options_1.getOptions)([], {});
|
|
200
202
|
expect(fork).toBe(false);
|
|
201
203
|
});
|
|
202
204
|
});
|
|
@@ -205,12 +207,12 @@ describe('getOptions', () => {
|
|
|
205
207
|
mockGithubConfigOptions({});
|
|
206
208
|
});
|
|
207
209
|
it('can be set via `--reviewer` flag', async () => {
|
|
208
|
-
const { reviewers } = await (0, options_1.getOptions)(['--reviewer', 'peter']);
|
|
210
|
+
const { reviewers } = await (0, options_1.getOptions)(['--reviewer', 'peter'], {});
|
|
209
211
|
expect(reviewers).toEqual(['peter']);
|
|
210
212
|
});
|
|
211
213
|
it('can be set via config file', async () => {
|
|
212
214
|
mockProjectConfig({ reviewers: ['john'] });
|
|
213
|
-
const { reviewers } = await (0, options_1.getOptions)([]);
|
|
215
|
+
const { reviewers } = await (0, options_1.getOptions)([], {});
|
|
214
216
|
expect(reviewers).toEqual(['john']);
|
|
215
217
|
});
|
|
216
218
|
});
|
|
@@ -219,15 +221,15 @@ describe('getOptions', () => {
|
|
|
219
221
|
mockGithubConfigOptions({});
|
|
220
222
|
});
|
|
221
223
|
it('is not enabled by default', async () => {
|
|
222
|
-
const { mainline } = await (0, options_1.getOptions)([]);
|
|
224
|
+
const { mainline } = await (0, options_1.getOptions)([], {});
|
|
223
225
|
expect(mainline).toBe(undefined);
|
|
224
226
|
});
|
|
225
227
|
it('can be set via `--mainline` flag', async () => {
|
|
226
|
-
const { mainline } = await (0, options_1.getOptions)(['--mainline']);
|
|
228
|
+
const { mainline } = await (0, options_1.getOptions)(['--mainline'], {});
|
|
227
229
|
expect(mainline).toBe(1);
|
|
228
230
|
});
|
|
229
231
|
it('accepts numeric values', async () => {
|
|
230
|
-
const { mainline } = await (0, options_1.getOptions)(['--mainline', '2']);
|
|
232
|
+
const { mainline } = await (0, options_1.getOptions)(['--mainline', '2'], {});
|
|
231
233
|
expect(mainline).toBe(2);
|
|
232
234
|
});
|
|
233
235
|
});
|
|
@@ -236,25 +238,25 @@ describe('getOptions', () => {
|
|
|
236
238
|
mockGithubConfigOptions({ viewerLogin: 'billy.bob' });
|
|
237
239
|
});
|
|
238
240
|
it('defaults to authenticated user', async () => {
|
|
239
|
-
const { author } = await (0, options_1.getOptions)([]);
|
|
241
|
+
const { author } = await (0, options_1.getOptions)([], {});
|
|
240
242
|
expect(author).toBe('billy.bob');
|
|
241
243
|
});
|
|
242
244
|
it('can be overridden via `--author` flag', async () => {
|
|
243
|
-
const { author } = await (0, options_1.getOptions)(['--author', 'john.doe']);
|
|
245
|
+
const { author } = await (0, options_1.getOptions)(['--author', 'john.doe'], {});
|
|
244
246
|
expect(author).toBe('john.doe');
|
|
245
247
|
});
|
|
246
248
|
it('can be reset via `--all` flag', async () => {
|
|
247
|
-
const { author } = await (0, options_1.getOptions)(['--all']);
|
|
249
|
+
const { author } = await (0, options_1.getOptions)(['--all'], {});
|
|
248
250
|
expect(author).toBe(null);
|
|
249
251
|
});
|
|
250
252
|
it('can be reset via config file (similar to `--all` flag)', async () => {
|
|
251
253
|
mockProjectConfig({ author: null });
|
|
252
|
-
const { author } = await (0, options_1.getOptions)([]);
|
|
254
|
+
const { author } = await (0, options_1.getOptions)([], {});
|
|
253
255
|
expect(author).toBe(null);
|
|
254
256
|
});
|
|
255
257
|
it('can be overridden via config file', async () => {
|
|
256
258
|
mockProjectConfig({ author: 'jane.doe' });
|
|
257
|
-
const { author } = await (0, options_1.getOptions)([]);
|
|
259
|
+
const { author } = await (0, options_1.getOptions)([], {});
|
|
258
260
|
expect(author).toBe('jane.doe');
|
|
259
261
|
});
|
|
260
262
|
});
|
|
@@ -263,21 +265,21 @@ describe('getOptions', () => {
|
|
|
263
265
|
mockGithubConfigOptions({});
|
|
264
266
|
});
|
|
265
267
|
it('should default to true', async () => {
|
|
266
|
-
const { cherrypickRef } = await (0, options_1.getOptions)([]);
|
|
268
|
+
const { cherrypickRef } = await (0, options_1.getOptions)([], {});
|
|
267
269
|
expect(cherrypickRef).toBe(true);
|
|
268
270
|
});
|
|
269
271
|
it('should negate with `noCherrypickRef` cli arg', async () => {
|
|
270
|
-
const { cherrypickRef } = await (0, options_1.getOptions)(['--no-cherrypick-ref']);
|
|
272
|
+
const { cherrypickRef } = await (0, options_1.getOptions)(['--no-cherrypick-ref'], {});
|
|
271
273
|
expect(cherrypickRef).toBe(false);
|
|
272
274
|
});
|
|
273
275
|
it('should be settable via config file', async () => {
|
|
274
276
|
mockProjectConfig({ cherrypickRef: false });
|
|
275
|
-
const { cherrypickRef } = await (0, options_1.getOptions)([]);
|
|
277
|
+
const { cherrypickRef } = await (0, options_1.getOptions)([], {});
|
|
276
278
|
expect(cherrypickRef).toBe(false);
|
|
277
279
|
});
|
|
278
280
|
it('cli args overwrites config', async () => {
|
|
279
281
|
mockProjectConfig({ cherrypickRef: false });
|
|
280
|
-
const { cherrypickRef } = await (0, options_1.getOptions)(['--cherrypick-ref']);
|
|
282
|
+
const { cherrypickRef } = await (0, options_1.getOptions)(['--cherrypick-ref'], {});
|
|
281
283
|
expect(cherrypickRef).toBe(true);
|
|
282
284
|
});
|
|
283
285
|
});
|
|
@@ -82,9 +82,7 @@ describe('runSequentially', () => {
|
|
|
82
82
|
multipleBranches: false,
|
|
83
83
|
multipleCommits: false,
|
|
84
84
|
noVerify: true,
|
|
85
|
-
prDescription: 'myPrDescription',
|
|
86
85
|
prFilter: undefined,
|
|
87
|
-
prTitle: 'myPrTitle {targetBranch} {commitMessages}',
|
|
88
86
|
publishStatusComment: true,
|
|
89
87
|
pullNumber: undefined,
|
|
90
88
|
repoName: 'kibana',
|
|
@@ -153,11 +151,9 @@ describe('runSequentially', () => {
|
|
|
153
151
|
- #55
|
|
154
152
|
|
|
155
153
|
### Questions ?
|
|
156
|
-
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
157
|
-
|
|
158
|
-
myPrDescription",
|
|
154
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
|
|
159
155
|
"head": "sqren_authenticated:backport/7.x/pr-55",
|
|
160
|
-
"title": "
|
|
156
|
+
"title": "[7.x] My commit message",
|
|
161
157
|
},
|
|
162
158
|
]
|
|
163
159
|
`);
|
|
@@ -6,10 +6,10 @@ const env_1 = require("../services/env");
|
|
|
6
6
|
const logger_1 = require("../services/logger");
|
|
7
7
|
async function postinstall() {
|
|
8
8
|
try {
|
|
9
|
-
const
|
|
9
|
+
const globalConfigPath = (0, env_1.getGlobalConfigPath)();
|
|
10
|
+
const didCreate = await (0, globalConfig_1.createGlobalConfigAndFolderIfNotExist)(globalConfigPath);
|
|
10
11
|
if (didCreate) {
|
|
11
|
-
|
|
12
|
-
(0, logger_1.consoleLog)(`Global config successfully created in ${GLOBAL_CONFIG_PATH}`);
|
|
12
|
+
(0, logger_1.consoleLog)(`Global config successfully created in ${globalConfigPath}`);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
catch (e) {
|
package/dist/services/env.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../options/options';
|
|
2
2
|
export declare function getBackportDirPath(): string;
|
|
3
|
-
export declare function getLogfilePath(
|
|
3
|
+
export declare function getLogfilePath({ logFilePath }: {
|
|
4
|
+
logFilePath?: string;
|
|
5
|
+
}): string;
|
|
4
6
|
export declare function getGlobalConfigPath(): string;
|
|
5
7
|
export declare function getRepoPath({ repoOwner, repoName, dir }: ValidConfigOptions): string;
|
package/dist/services/env.js
CHANGED
|
@@ -10,7 +10,10 @@ function getBackportDirPath() {
|
|
|
10
10
|
return path_1.default.join((0, os_1.homedir)(), '.backport');
|
|
11
11
|
}
|
|
12
12
|
exports.getBackportDirPath = getBackportDirPath;
|
|
13
|
-
function getLogfilePath() {
|
|
13
|
+
function getLogfilePath({ logFilePath }) {
|
|
14
|
+
if (logFilePath) {
|
|
15
|
+
return path_1.default.resolve(logFilePath);
|
|
16
|
+
}
|
|
14
17
|
return path_1.default.join((0, os_1.homedir)(), '.backport', 'backport.log');
|
|
15
18
|
}
|
|
16
19
|
exports.getLogfilePath = getLogfilePath;
|
|
@@ -55,7 +55,6 @@ async function createPullRequest({ options, prPayload, }) {
|
|
|
55
55
|
}
|
|
56
56
|
exports.createPullRequest = createPullRequest;
|
|
57
57
|
function getPullRequestBody({ options, commits, targetBranch, }) {
|
|
58
|
-
const bodySuffix = options.prDescription ? `\n${options.prDescription}` : '';
|
|
59
58
|
const commitMessages = commits
|
|
60
59
|
.map((c) => {
|
|
61
60
|
const message = c.pullNumber
|
|
@@ -64,21 +63,25 @@ function getPullRequestBody({ options, commits, targetBranch, }) {
|
|
|
64
63
|
return ` - ${message}`;
|
|
65
64
|
})
|
|
66
65
|
.join('\n');
|
|
67
|
-
|
|
66
|
+
const defaultPrDescription = `# Backport
|
|
68
67
|
|
|
69
68
|
This is an automatic backport to \`${targetBranch}\` of:
|
|
70
69
|
${commitMessages}
|
|
71
70
|
|
|
72
71
|
### Questions ?
|
|
73
|
-
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
74
|
-
|
|
72
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)`;
|
|
73
|
+
return (options.prDescription ?? defaultPrDescription)
|
|
74
|
+
.replace('{targetBranch}', targetBranch)
|
|
75
|
+
.replace('{commitMessages}', commitMessages)
|
|
76
|
+
.replace('{defaultPrDescription}', defaultPrDescription);
|
|
75
77
|
}
|
|
76
78
|
exports.getPullRequestBody = getPullRequestBody;
|
|
77
79
|
function getTitle({ options, commits, targetBranch, }) {
|
|
78
80
|
const commitMessages = commits
|
|
79
81
|
.map((commit) => (0, commitFormatters_1.getFirstLine)(commit.originalMessage))
|
|
80
82
|
.join(' | ');
|
|
81
|
-
|
|
83
|
+
const defaultPrTitle = '[{targetBranch}] {commitMessages}';
|
|
84
|
+
return (options.prTitle ?? defaultPrTitle)
|
|
82
85
|
.replace('{targetBranch}', targetBranch)
|
|
83
86
|
.replace('{commitMessages}', commitMessages)
|
|
84
87
|
.slice(0, 240);
|
|
@@ -20,8 +20,7 @@ describe('getPullRequestBody', () => {
|
|
|
20
20
|
- #55
|
|
21
21
|
|
|
22
22
|
### Questions ?
|
|
23
|
-
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
24
|
-
"
|
|
23
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
25
24
|
`);
|
|
26
25
|
});
|
|
27
26
|
it('when a single commit (non pull request) is backported', () => {
|
|
@@ -41,8 +40,7 @@ describe('getPullRequestBody', () => {
|
|
|
41
40
|
- My commit message (abcdefgh)
|
|
42
41
|
|
|
43
42
|
### Questions ?
|
|
44
|
-
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
45
|
-
"
|
|
43
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
46
44
|
`);
|
|
47
45
|
});
|
|
48
46
|
it('when multiple commits are backported', () => {
|
|
@@ -63,18 +61,70 @@ describe('getPullRequestBody', () => {
|
|
|
63
61
|
})).toMatchInlineSnapshot(`
|
|
64
62
|
"# Backport
|
|
65
63
|
|
|
64
|
+
This is an automatic backport to \`7.x\` of:
|
|
65
|
+
- #55
|
|
66
|
+
- Another commit message (qwertyui)
|
|
67
|
+
|
|
68
|
+
### Questions ?
|
|
69
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
70
|
+
`);
|
|
71
|
+
});
|
|
72
|
+
it('replaces template variables in PR description', () => {
|
|
73
|
+
expect((0, createPullRequest_1.getPullRequestBody)({
|
|
74
|
+
options: {
|
|
75
|
+
prDescription: 'Backporting the following to {targetBranch}:\n{commitMessages}',
|
|
76
|
+
},
|
|
77
|
+
commits: [
|
|
78
|
+
{
|
|
79
|
+
pullNumber: 55,
|
|
80
|
+
sha: 'abcdefghijklm',
|
|
81
|
+
originalMessage: 'My commit message',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
sha: 'qwertyuiop',
|
|
85
|
+
originalMessage: 'Another commit message',
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
targetBranch: '7.x',
|
|
89
|
+
})).toMatchInlineSnapshot(`
|
|
90
|
+
"Backporting the following to 7.x:
|
|
91
|
+
- #55
|
|
92
|
+
- Another commit message (qwertyui)"
|
|
93
|
+
`);
|
|
94
|
+
});
|
|
95
|
+
it('appends text to the default descriptions', () => {
|
|
96
|
+
expect((0, createPullRequest_1.getPullRequestBody)({
|
|
97
|
+
options: {
|
|
98
|
+
prDescription: '{defaultPrDescription}\n\ntext to append',
|
|
99
|
+
},
|
|
100
|
+
commits: [
|
|
101
|
+
{
|
|
102
|
+
pullNumber: 55,
|
|
103
|
+
sha: 'abcdefghijklm',
|
|
104
|
+
originalMessage: 'My commit message',
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
sha: 'qwertyuiop',
|
|
108
|
+
originalMessage: 'Another commit message',
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
targetBranch: '7.x',
|
|
112
|
+
})).toMatchInlineSnapshot(`
|
|
113
|
+
"# Backport
|
|
114
|
+
|
|
66
115
|
This is an automatic backport to \`7.x\` of:
|
|
67
116
|
- #55
|
|
68
117
|
- Another commit message (qwertyui)
|
|
69
118
|
|
|
70
119
|
### Questions ?
|
|
71
120
|
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
72
|
-
|
|
121
|
+
|
|
122
|
+
text to append"
|
|
73
123
|
`);
|
|
74
124
|
});
|
|
75
125
|
});
|
|
76
126
|
describe('getTitle', () => {
|
|
77
|
-
it('
|
|
127
|
+
it('has the default title', () => {
|
|
78
128
|
expect((0, createPullRequest_1.getTitle)({
|
|
79
129
|
options: {},
|
|
80
130
|
commits: [
|
|
@@ -92,7 +142,7 @@ describe('getTitle', () => {
|
|
|
92
142
|
targetBranch: '7.x',
|
|
93
143
|
})).toEqual('[7.x] My commit message | Another commit message');
|
|
94
144
|
});
|
|
95
|
-
it('
|
|
145
|
+
it('replaces template variables in PR title', () => {
|
|
96
146
|
expect((0, createPullRequest_1.getTitle)({
|
|
97
147
|
options: {
|
|
98
148
|
prTitle: 'Branch: "{targetBranch}". Messages: {commitMessages}',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BackportResponse } from '../../../
|
|
1
|
+
import { BackportResponse } from '../../../backportRun';
|
|
2
2
|
import { ValidConfigOptions } from '../../../options/options';
|
|
3
3
|
export declare function createStatusComment({ options, backportResponse, }: {
|
|
4
4
|
options: ValidConfigOptions;
|
|
@@ -32,13 +32,15 @@ export declare function getOptionsFromGithub(options: {
|
|
|
32
32
|
cherrypickRef?: boolean | undefined;
|
|
33
33
|
ci?: boolean | undefined;
|
|
34
34
|
commitPaths?: string[] | undefined;
|
|
35
|
-
|
|
35
|
+
configFile?: string | undefined;
|
|
36
36
|
details?: boolean | undefined;
|
|
37
|
+
dir?: string | undefined;
|
|
37
38
|
editor?: string | undefined;
|
|
38
39
|
fork?: boolean | undefined;
|
|
39
40
|
gitHostname?: string | undefined;
|
|
40
41
|
githubApiBaseUrlV3?: string | undefined;
|
|
41
42
|
githubApiBaseUrlV4?: string | undefined;
|
|
43
|
+
logFilePath?: string | undefined;
|
|
42
44
|
maxNumber?: number | undefined;
|
|
43
45
|
multiple?: boolean | undefined;
|
|
44
46
|
multipleBranches?: boolean | undefined;
|
|
@@ -9,7 +9,10 @@ export declare const logger: {
|
|
|
9
9
|
debug: (message: string, meta?: unknown) => void;
|
|
10
10
|
};
|
|
11
11
|
export declare function updateLogger(options: ConfigFileOptions): void;
|
|
12
|
-
export declare function initLogger(
|
|
12
|
+
export declare function initLogger({ ci, logFilePath, }: {
|
|
13
|
+
ci?: boolean;
|
|
14
|
+
logFilePath?: string;
|
|
15
|
+
}): {
|
|
13
16
|
error: (message: string, meta?: unknown) => void;
|
|
14
17
|
warn: (message: string, meta?: unknown) => void;
|
|
15
18
|
info: (message: string, meta?: unknown) => void;
|
package/dist/services/logger.js
CHANGED
|
@@ -60,10 +60,6 @@ function updateLogger(options) {
|
|
|
60
60
|
accessToken = options.accessToken;
|
|
61
61
|
// set log level
|
|
62
62
|
winstonInstance.level = options.verbose ? 'debug' : 'info';
|
|
63
|
-
// output logs to console in ci env
|
|
64
|
-
if (options.ci) {
|
|
65
|
-
winstonInstance.add(new winston_1.default.transports.Console());
|
|
66
|
-
}
|
|
67
63
|
}
|
|
68
64
|
exports.updateLogger = updateLogger;
|
|
69
65
|
function redactAccessToken(str) {
|
|
@@ -73,32 +69,12 @@ function redactAccessToken(str) {
|
|
|
73
69
|
}
|
|
74
70
|
return str;
|
|
75
71
|
}
|
|
76
|
-
function initLogger() {
|
|
72
|
+
function initLogger({ ci, logFilePath, }) {
|
|
73
|
+
const fileTransport = getFileTransport({ logFilePath });
|
|
77
74
|
winstonInstance = winston_1.default.createLogger({
|
|
78
|
-
transports:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
level: 'debug',
|
|
82
|
-
format: combine(winston_1.format.splat(), winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston_1.default.format.metadata({
|
|
83
|
-
fillExcept: ['message', 'level', 'timestamp', 'label'],
|
|
84
|
-
}), winston_1.format.printf((info) => {
|
|
85
|
-
// format without metadata
|
|
86
|
-
if (!info.metadata.meta) {
|
|
87
|
-
return redactAccessToken(`${info.timestamp}: ${info.message}`);
|
|
88
|
-
}
|
|
89
|
-
// format when metadata is a string
|
|
90
|
-
if ((0, lodash_1.isString)(info.metadata.meta)) {
|
|
91
|
-
return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, dedent_1.default)(info.metadata.meta)}\n`);
|
|
92
|
-
}
|
|
93
|
-
if (info.metadata.meta.stack) {
|
|
94
|
-
return redactAccessToken(`${info.timestamp}: ${info.message}\n${info.metadata.meta.stack}\n`);
|
|
95
|
-
}
|
|
96
|
-
// format when metadata is an object
|
|
97
|
-
return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, safe_json_stringify_1.default)(info.metadata.meta, null, 2)}\n`);
|
|
98
|
-
})),
|
|
99
|
-
filename: (0, env_1.getLogfilePath)(),
|
|
100
|
-
}),
|
|
101
|
-
],
|
|
75
|
+
transports: ci
|
|
76
|
+
? [fileTransport, new winston_1.default.transports.Console()]
|
|
77
|
+
: [fileTransport],
|
|
102
78
|
});
|
|
103
79
|
// wait exiting until logs have been flushed to disk
|
|
104
80
|
winstonInstance.on('finish', () => {
|
|
@@ -107,6 +83,29 @@ function initLogger() {
|
|
|
107
83
|
return exports.logger;
|
|
108
84
|
}
|
|
109
85
|
exports.initLogger = initLogger;
|
|
86
|
+
function getFileTransport({ logFilePath }) {
|
|
87
|
+
return new winston_1.default.transports.File({
|
|
88
|
+
level: 'debug',
|
|
89
|
+
format: combine(winston_1.format.splat(), winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston_1.default.format.metadata({
|
|
90
|
+
fillExcept: ['message', 'level', 'timestamp', 'label'],
|
|
91
|
+
}), winston_1.format.printf((info) => {
|
|
92
|
+
// format without metadata
|
|
93
|
+
if (!info.metadata.meta) {
|
|
94
|
+
return redactAccessToken(`${info.timestamp}: ${info.message}`);
|
|
95
|
+
}
|
|
96
|
+
// format when metadata is a string
|
|
97
|
+
if ((0, lodash_1.isString)(info.metadata.meta)) {
|
|
98
|
+
return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, dedent_1.default)(info.metadata.meta)}\n`);
|
|
99
|
+
}
|
|
100
|
+
if (info.metadata.meta.stack) {
|
|
101
|
+
return redactAccessToken(`${info.timestamp}: ${info.message}\n${info.metadata.meta.stack}\n`);
|
|
102
|
+
}
|
|
103
|
+
// format when metadata is an object
|
|
104
|
+
return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, safe_json_stringify_1.default)(info.metadata.meta, null, 2)}\n`);
|
|
105
|
+
})),
|
|
106
|
+
filename: (0, env_1.getLogfilePath)({ logFilePath }),
|
|
107
|
+
});
|
|
108
|
+
}
|
|
110
109
|
// log levels:
|
|
111
110
|
// - error
|
|
112
111
|
// - warn
|
|
@@ -82,8 +82,7 @@ describe('backport e2e', () => {
|
|
|
82
82
|
- Add ❤️ emoji (5bf29b7d)
|
|
83
83
|
|
|
84
84
|
### Questions ?
|
|
85
|
-
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
86
|
-
",
|
|
85
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
|
|
87
86
|
"head": "sqren:backport/7.x/commit-5bf29b7d",
|
|
88
87
|
"title": "[7.x] Add ❤️ emoji",
|
|
89
88
|
},
|
|
@@ -218,8 +217,7 @@ describe('backport e2e', () => {
|
|
|
218
217
|
- Add ❤️ emoji (5bf29b7d)
|
|
219
218
|
|
|
220
219
|
### Questions ?
|
|
221
|
-
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
222
|
-
",
|
|
220
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
|
|
223
221
|
"head": "backport-org:backport/7.x/commit-5bf29b7d",
|
|
224
222
|
"title": "[7.x] Add ❤️ emoji",
|
|
225
223
|
},
|
|
@@ -50,7 +50,7 @@ describe('inquirer cli', () => {
|
|
|
50
50
|
devAccessToken,
|
|
51
51
|
]);
|
|
52
52
|
const lineCount = res.split('\n').length;
|
|
53
|
-
expect(lineCount).
|
|
53
|
+
expect(lineCount).toBeGreaterThan(10);
|
|
54
54
|
expect(res.includes('Select commit (Use arrow keys)')).toBe(true);
|
|
55
55
|
});
|
|
56
56
|
it('should return error when access token is invalid', async () => {
|
|
@@ -141,6 +141,8 @@ function runBackportAsync(options, { waitForString, } = {}) {
|
|
|
141
141
|
const proc = (0, child_process_1.spawn)('./node_modules/.bin/ts-node', [
|
|
142
142
|
'--transpile-only',
|
|
143
143
|
'./src/entrypoint.cli.ts',
|
|
144
|
+
'--log-file-path',
|
|
145
|
+
'/dev/null',
|
|
144
146
|
...options,
|
|
145
147
|
]);
|
|
146
148
|
const p = new Promise((resolve, reject) => {
|
|
@@ -63,7 +63,6 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
63
63
|
assignees: [],
|
|
64
64
|
authenticatedUsername: 'sqren_authenticated',
|
|
65
65
|
fork: true,
|
|
66
|
-
prDescription: 'myPrSuffix',
|
|
67
66
|
prTitle: '[{targetBranch}] {commitMessages}',
|
|
68
67
|
repoName: 'kibana',
|
|
69
68
|
repoOwner: 'elastic',
|
|
@@ -115,9 +114,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
115
114
|
- #2000
|
|
116
115
|
|
|
117
116
|
### Questions ?
|
|
118
|
-
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
119
|
-
|
|
120
|
-
myPrSuffix",
|
|
117
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
|
|
121
118
|
"head": "sqren_authenticated:backport/6.x/pr-1000_pr-2000",
|
|
122
119
|
"title": "[6.x] My original commit message (#1000) | My other commit message (#2000)",
|
|
123
120
|
},
|
|
@@ -201,8 +198,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
201
198
|
- My original commit message (mySha)
|
|
202
199
|
|
|
203
200
|
### Questions ?
|
|
204
|
-
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
205
|
-
",
|
|
201
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
|
|
206
202
|
"head": "sqren_authenticated:backport/6.x/commit-mySha",
|
|
207
203
|
"title": "[6.x] My original commit message",
|
|
208
204
|
},
|
|
@@ -274,8 +270,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
274
270
|
- My original commit message (mySha)
|
|
275
271
|
|
|
276
272
|
### Questions ?
|
|
277
|
-
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
278
|
-
",
|
|
273
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
|
|
279
274
|
"head": "sqren_authenticated:backport/6.x/commit-mySha",
|
|
280
275
|
"title": "[6.x] My original commit message",
|
|
281
276
|
},
|