backport 8.4.1 → 8.4.2
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/lib/cherrypickAndCreateTargetPullRequest.js +13 -2
- package/dist/lib/git.d.ts +3 -2
- package/dist/lib/git.js +16 -2
- package/dist/lib/git.private.test.js +3 -0
- package/dist/lib/git.test.js +19 -3
- package/dist/lib/github/v4/apiRequestV4.js +14 -8
- package/dist/test/e2e/cli/different-merge-strategies.private.test.js +14 -14
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +25 -12
- package/dist/test/e2e/cli/gracefully-handles-corrupt-repo.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/gracefully-handles-corrupt-repo.private.test.js +52 -0
- package/dist/test/e2e/cli/repo-with-programatically-added-commits.mutation.test.d.ts +1 -0
- package/dist/test/e2e/cli/repo-with-programatically-added-commits.mutation.test.js +114 -0
- package/dist/test/e2e/cli/runBackportViaCli.js +1 -1
- package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +6 -1
- package/dist/test/replaceStringAndLinebreaks.d.ts +5 -0
- package/dist/test/replaceStringAndLinebreaks.js +8 -0
- package/dist/test/sandbox.js +6 -2
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +15 -15
- package/yarn.lock +797 -902
|
@@ -23,13 +23,25 @@ const logger_1 = require("./logger");
|
|
|
23
23
|
const ora_1 = require("./ora");
|
|
24
24
|
const prompts_1 = require("./prompts");
|
|
25
25
|
const sequentially_1 = require("./sequentially");
|
|
26
|
+
function getSourceBranchFromCommits(commits) {
|
|
27
|
+
// sourceBranch should be the same for all commits, so picking `sourceBranch` from the first commit should be fine 🤞
|
|
28
|
+
// this is specifically needed when backporting a PR like `backport --pr 123` and the source PR was merged to a non-default (aka non-master) branch.
|
|
29
|
+
const { sourceBranch } = commits[0];
|
|
30
|
+
return sourceBranch;
|
|
31
|
+
}
|
|
26
32
|
async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBranch, }) {
|
|
27
33
|
const backportBranch = getBackportBranchName(targetBranch, commits);
|
|
28
34
|
const repoForkOwner = (0, git_1.getRepoForkOwner)(options);
|
|
29
35
|
(0, logger_1.consoleLog)(`\n${chalk_1.default.bold(`Backporting to ${targetBranch}:`)}`);
|
|
36
|
+
const sourceBranch = getSourceBranchFromCommits(commits);
|
|
30
37
|
const [gitConfigAuthor] = await Promise.all([
|
|
31
38
|
(0, getGitConfigAuthor_1.getGitConfigAuthor)(options),
|
|
32
|
-
(0, git_1.createBackportBranch)({
|
|
39
|
+
(0, git_1.createBackportBranch)({
|
|
40
|
+
options,
|
|
41
|
+
sourceBranch,
|
|
42
|
+
targetBranch,
|
|
43
|
+
backportBranch,
|
|
44
|
+
}),
|
|
33
45
|
]);
|
|
34
46
|
const commitsFlattened = (0, lodash_1.flatten)(await Promise.all(commits.map((c) => getMergeCommits(options, c))));
|
|
35
47
|
await (0, sequentially_1.sequentially)(commitsFlattened, (commit) => waitForCherrypick(options, commit, targetBranch, gitConfigAuthor));
|
|
@@ -111,7 +123,6 @@ function getBackportBranchName(targetBranch, commits) {
|
|
|
111
123
|
async function waitForCherrypick(options, commit, targetBranch, gitConfigAuthor) {
|
|
112
124
|
const spinnerText = `Cherry-picking: ${chalk_1.default.greenBright((0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message))}`;
|
|
113
125
|
const cherrypickSpinner = (0, ora_1.ora)(options.interactive, spinnerText).start();
|
|
114
|
-
await (0, git_1.fetchBranch)(options, commit.sourceBranch);
|
|
115
126
|
await cherrypickAndHandleConflicts(options, commit, targetBranch, cherrypickSpinner, gitConfigAuthor);
|
|
116
127
|
// Conflicts should be resolved and files staged at this point
|
|
117
128
|
try {
|
package/dist/lib/git.d.ts
CHANGED
|
@@ -55,10 +55,11 @@ export declare function getGitConfig({ dir, key, }: {
|
|
|
55
55
|
dir: string;
|
|
56
56
|
key: 'user.name' | 'user.email';
|
|
57
57
|
}): Promise<string | undefined>;
|
|
58
|
-
export declare function createBackportBranch({ options,
|
|
58
|
+
export declare function createBackportBranch({ options, sourceBranch, backportBranch, targetBranch, }: {
|
|
59
59
|
options: ValidConfigOptions;
|
|
60
|
-
|
|
60
|
+
sourceBranch: string;
|
|
61
61
|
backportBranch: string;
|
|
62
|
+
targetBranch: string;
|
|
62
63
|
}): Promise<void>;
|
|
63
64
|
export declare function deleteBackportBranch({ options, backportBranch, }: {
|
|
64
65
|
options: ValidConfigOptions;
|
package/dist/lib/git.js
CHANGED
|
@@ -338,13 +338,18 @@ exports.getGitConfig = getGitConfig;
|
|
|
338
338
|
// How the commit flows:
|
|
339
339
|
// ${sourceBranch} -> ${backportBranch} -> ${targetBranch}
|
|
340
340
|
// master -> backport/7.x/pr-1234 -> 7.x
|
|
341
|
-
async function createBackportBranch({ options,
|
|
341
|
+
async function createBackportBranch({ options, sourceBranch, backportBranch, targetBranch, }) {
|
|
342
342
|
const spinner = (0, ora_1.ora)(options.interactive, 'Pulling latest changes').start();
|
|
343
343
|
try {
|
|
344
344
|
const cwd = (0, env_1.getRepoPath)(options);
|
|
345
345
|
await (0, child_process_promisified_1.spawnPromise)('git', ['reset', '--hard'], cwd);
|
|
346
346
|
await (0, child_process_promisified_1.spawnPromise)('git', ['clean', '-d', '--force'], cwd);
|
|
347
|
-
|
|
347
|
+
// create tmp branch. This can be necessary when fetching to the currently selected branch
|
|
348
|
+
const tmpBranchName = '__backport_tool_tmp';
|
|
349
|
+
await (0, child_process_promisified_1.spawnPromise)('git', ['checkout', '-B', tmpBranchName], cwd);
|
|
350
|
+
// fetch target branch
|
|
351
|
+
await fetchBranch(options, targetBranch);
|
|
352
|
+
// checkout backport branch and point it to target branch
|
|
348
353
|
await (0, child_process_promisified_1.spawnPromise)('git', [
|
|
349
354
|
'checkout',
|
|
350
355
|
'-B',
|
|
@@ -352,6 +357,15 @@ async function createBackportBranch({ options, targetBranch, backportBranch, })
|
|
|
352
357
|
`${options.repoOwner}/${targetBranch}`,
|
|
353
358
|
'--no-track',
|
|
354
359
|
], cwd);
|
|
360
|
+
// delete tmp branch (if it still exists)
|
|
361
|
+
try {
|
|
362
|
+
await (0, child_process_promisified_1.spawnPromise)('git', ['branch', '-D', tmpBranchName], cwd);
|
|
363
|
+
}
|
|
364
|
+
catch (e) {
|
|
365
|
+
//
|
|
366
|
+
}
|
|
367
|
+
// fetch commits for source branch
|
|
368
|
+
await fetchBranch(options, sourceBranch);
|
|
355
369
|
spinner.succeed();
|
|
356
370
|
}
|
|
357
371
|
catch (e) {
|
|
@@ -121,6 +121,7 @@ describe('git.integration', () => {
|
|
|
121
121
|
repoOwner: 'origin',
|
|
122
122
|
dir: cwd,
|
|
123
123
|
},
|
|
124
|
+
sourceBranch: 'main',
|
|
124
125
|
targetBranch: '7.x',
|
|
125
126
|
backportBranch: 'my-backport-branch',
|
|
126
127
|
});
|
|
@@ -133,6 +134,7 @@ describe('git.integration', () => {
|
|
|
133
134
|
repoOwner: 'origin',
|
|
134
135
|
dir: cwd,
|
|
135
136
|
},
|
|
137
|
+
sourceBranch: 'main',
|
|
136
138
|
targetBranch: 'foo',
|
|
137
139
|
backportBranch: 'my-backport-branch',
|
|
138
140
|
});
|
|
@@ -152,6 +154,7 @@ describe('git.integration', () => {
|
|
|
152
154
|
repoOwner: 'origin',
|
|
153
155
|
dir: cwd,
|
|
154
156
|
},
|
|
157
|
+
sourceBranch: 'main',
|
|
155
158
|
targetBranch: '7.x',
|
|
156
159
|
backportBranch: 'my-backport-branch',
|
|
157
160
|
});
|
package/dist/lib/git.test.js
CHANGED
|
@@ -238,6 +238,7 @@ describe('createBackportBranch', () => {
|
|
|
238
238
|
repoOwner: 'elastic',
|
|
239
239
|
repoName: 'kibana',
|
|
240
240
|
};
|
|
241
|
+
const sourceBranch = 'main';
|
|
241
242
|
const targetBranch = '4.x';
|
|
242
243
|
const backportBranch = 'backport/4.x/commit-72f94e76';
|
|
243
244
|
it(`should handle "couldn't find remote ref" error`, async () => {
|
|
@@ -249,7 +250,12 @@ describe('createBackportBranch', () => {
|
|
|
249
250
|
stderr: "fatal: couldn't find remote ref 4.x\n",
|
|
250
251
|
});
|
|
251
252
|
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
252
|
-
await expect((0, git_1.createBackportBranch)({
|
|
253
|
+
await expect((0, git_1.createBackportBranch)({
|
|
254
|
+
options,
|
|
255
|
+
sourceBranch,
|
|
256
|
+
targetBranch,
|
|
257
|
+
backportBranch,
|
|
258
|
+
})).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
|
|
253
259
|
});
|
|
254
260
|
it('should throw "Invalid refspec" error', async () => {
|
|
255
261
|
expect.assertions(1);
|
|
@@ -260,14 +266,24 @@ describe('createBackportBranch', () => {
|
|
|
260
266
|
stderr: "fatal: Invalid refspec 'https://github.com/elastic/kibana.git'\n",
|
|
261
267
|
});
|
|
262
268
|
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
263
|
-
await expect((0, git_1.createBackportBranch)({
|
|
269
|
+
await expect((0, git_1.createBackportBranch)({
|
|
270
|
+
options,
|
|
271
|
+
sourceBranch,
|
|
272
|
+
targetBranch,
|
|
273
|
+
backportBranch,
|
|
274
|
+
})).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
|
|
264
275
|
});
|
|
265
276
|
it('should rethrow normal error', async () => {
|
|
266
277
|
expect.assertions(1);
|
|
267
278
|
const err = new Error('just a normal error');
|
|
268
279
|
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
269
280
|
expect.assertions(1);
|
|
270
|
-
await expect((0, git_1.createBackportBranch)({
|
|
281
|
+
await expect((0, git_1.createBackportBranch)({
|
|
282
|
+
options,
|
|
283
|
+
sourceBranch,
|
|
284
|
+
targetBranch,
|
|
285
|
+
backportBranch,
|
|
286
|
+
})).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
|
|
271
287
|
});
|
|
272
288
|
});
|
|
273
289
|
describe('deleteRemote', () => {
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getQueryName = exports.GithubV4Exception = exports.apiRequestV4 = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const printer_1 = require("graphql/language/printer");
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
9
10
|
const BackportError_1 = require("../../BackportError");
|
|
10
11
|
const logger_1 = require("../../logger");
|
|
11
12
|
async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graphql', accessToken, query, variables, }) {
|
|
@@ -28,7 +29,7 @@ async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graph
|
|
|
28
29
|
return response.data.data;
|
|
29
30
|
}
|
|
30
31
|
catch (e) {
|
|
31
|
-
if (
|
|
32
|
+
if (isAxiosGithubError(e) && e.response) {
|
|
32
33
|
addDebugLogs({
|
|
33
34
|
githubApiBaseUrlV4,
|
|
34
35
|
query,
|
|
@@ -42,13 +43,10 @@ async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graph
|
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
exports.apiRequestV4 = apiRequestV4;
|
|
45
|
-
function
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
logger_1.logger.verbose('Variables:', variables);
|
|
50
|
-
logger_1.logger.verbose('Response headers:', githubResponse.headers);
|
|
51
|
-
logger_1.logger.verbose('Response data:', githubResponse.data);
|
|
46
|
+
function isAxiosGithubError(e) {
|
|
47
|
+
return (axios_1.default.isAxiosError(e) &&
|
|
48
|
+
e.response !== undefined &&
|
|
49
|
+
(0, lodash_1.isObject)(e.response.data));
|
|
52
50
|
}
|
|
53
51
|
class GithubV4Exception extends Error {
|
|
54
52
|
constructor(githubResponse, errorMessage) {
|
|
@@ -69,3 +67,11 @@ function getQueryName(query) {
|
|
|
69
67
|
return query.definitions[0].name?.value;
|
|
70
68
|
}
|
|
71
69
|
exports.getQueryName = getQueryName;
|
|
70
|
+
function addDebugLogs({ githubApiBaseUrlV4, query, variables, githubResponse, didThrow = false, }) {
|
|
71
|
+
const gqlQueryName = getQueryName(query);
|
|
72
|
+
logger_1.logger.info(`POST ${githubApiBaseUrlV4} (name:${gqlQueryName}, status: ${githubResponse.status}${didThrow ? ', EXCEPTION THROWN' : ''})`);
|
|
73
|
+
logger_1.logger.verbose(`Query: ${(0, printer_1.print)(query)}`);
|
|
74
|
+
logger_1.logger.verbose('Variables:', variables);
|
|
75
|
+
logger_1.logger.verbose('Response headers:', githubResponse.headers);
|
|
76
|
+
logger_1.logger.verbose('Response data:', githubResponse.data);
|
|
77
|
+
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
7
7
|
const child_process_promisified_1 = require("../../../lib/child-process-promisified");
|
|
8
8
|
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
9
|
+
const replaceStringAndLinebreaks_1 = require("../../replaceStringAndLinebreaks");
|
|
9
10
|
const sandbox_1 = require("../../sandbox");
|
|
10
11
|
const runBackportViaCli_1 = require("./runBackportViaCli");
|
|
11
12
|
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
@@ -29,8 +30,8 @@ describe('different-merge-strategies', () => {
|
|
|
29
30
|
7. Merge strategy: Third of many merges
|
|
30
31
|
8. Merge strategy: Second of many merges
|
|
31
32
|
9. Merge strategy: First of many merges
|
|
32
|
-
10.Using squash to merge commits (#3)
|
|
33
|
-
11.Rebase strategy: Second commit
|
|
33
|
+
10.Using squash to merge commits (#3)
|
|
34
|
+
11.Rebase strategy: Second commit
|
|
34
35
|
12.Rebase strategy: First commit
|
|
35
36
|
13.Merge pull request #1 from backport-org/merge-strategy
|
|
36
37
|
14.Merge strategy: Second commit
|
|
@@ -146,17 +147,14 @@ describe('different-merge-strategies', () => {
|
|
|
146
147
|
showOra: true,
|
|
147
148
|
timeoutSeconds: 5,
|
|
148
149
|
});
|
|
149
|
-
output =
|
|
150
|
+
output = (0, replaceStringAndLinebreaks_1.replaceStringAndLinebreaks)({
|
|
151
|
+
haystack: res.output,
|
|
152
|
+
stringBefore: sandboxPath,
|
|
153
|
+
stringAfter: '<SANDBOX_PATH>',
|
|
154
|
+
});
|
|
150
155
|
});
|
|
151
156
|
it('has the right output', async () => {
|
|
152
|
-
|
|
153
|
-
const regex = sandboxPath
|
|
154
|
-
.split('')
|
|
155
|
-
.map((s) => `${s}\\s?`)
|
|
156
|
-
.join('');
|
|
157
|
-
return str.replace(new RegExp(regex, 'g'), '<SANDBOX_PATH>');
|
|
158
|
-
}
|
|
159
|
-
expect(stripSandboxPath(output)).toMatchInlineSnapshot(`
|
|
157
|
+
expect(output).toMatchInlineSnapshot(`
|
|
160
158
|
"- Initializing...
|
|
161
159
|
? Select pull request Merge pull request #9 from backport-org/many-merge-commits
|
|
162
160
|
✔ 100% Cloning repository from github.com (one-time operation)
|
|
@@ -169,17 +167,19 @@ describe('different-merge-strategies', () => {
|
|
|
169
167
|
|
|
170
168
|
The commit could not be backported due to conflicts
|
|
171
169
|
|
|
172
|
-
Please fix the conflicts in
|
|
170
|
+
Please fix the conflicts in <SANDBOX_PATH>
|
|
173
171
|
? Fix the following conflicts manually:
|
|
174
172
|
|
|
175
173
|
Conflicting files:
|
|
176
|
-
- <SANDBOX_PATH>/new-
|
|
174
|
+
- <SANDBOX_PATH>/new-fi
|
|
175
|
+
le-added-with-many-merge-commits.txt
|
|
177
176
|
|
|
178
177
|
|
|
179
178
|
Press ENTER when the conflicts are resolved and files are staged (Y/n) ? Fix the following conflicts manually:
|
|
180
179
|
|
|
181
180
|
Conflicting files:
|
|
182
|
-
- <SANDBOX_PATH>/new-
|
|
181
|
+
- <SANDBOX_PATH>/new-fi
|
|
182
|
+
le-added-with-many-merge-commits.txt
|
|
183
183
|
|
|
184
184
|
|
|
185
185
|
Press ENTER when the conflicts are resolved and files are staged Yes
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
4
|
+
const replaceStringAndLinebreaks_1 = require("../../replaceStringAndLinebreaks");
|
|
4
5
|
const sandbox_1 = require("../../sandbox");
|
|
5
6
|
const runBackportViaCli_1 = require("./runBackportViaCli");
|
|
6
7
|
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
@@ -65,17 +66,29 @@ describe('interactive error handling', () => {
|
|
|
65
66
|
waitForString: 'Press ENTER when the conflicts',
|
|
66
67
|
timeoutSeconds: 5,
|
|
67
68
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
69
|
+
expect((0, replaceStringAndLinebreaks_1.replaceStringAndLinebreaks)({
|
|
70
|
+
haystack: output,
|
|
71
|
+
stringBefore: backportDir,
|
|
72
|
+
stringAfter: '<BACKPORT_DIR>',
|
|
73
|
+
})).toMatchInlineSnapshot(`
|
|
74
|
+
"Backporting to 7.x:
|
|
75
|
+
|
|
76
|
+
The commit could not be backported due to conflicts
|
|
77
|
+
|
|
78
|
+
Please fix the conflicts in <BACKPORT_DIR>
|
|
79
|
+
Hint: Before fixing the conflicts manually you should consider backporting the following pull requests to \\"7.x\\":
|
|
80
|
+
- Change Barca to Braithwaite (#8) (backport missing)
|
|
81
|
+
https://github.com/backport-org/repo-with-conflicts/pull/8
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
? Fix the following conflicts manually:
|
|
85
|
+
|
|
86
|
+
Conflicting files:
|
|
87
|
+
- <BACKPORT_DIR>/l
|
|
88
|
+
a-liga.md
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
Press ENTER when the conflicts are resolved and files are staged (Y/n)"
|
|
92
|
+
`);
|
|
80
93
|
});
|
|
81
94
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const child_process_promisified_1 = require("../../../lib/child-process-promisified");
|
|
4
|
+
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
5
|
+
const sandbox_1 = require("../../sandbox");
|
|
6
|
+
const runBackportViaCli_1 = require("./runBackportViaCli");
|
|
7
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
8
|
+
jest.setTimeout(15000);
|
|
9
|
+
describe('gracefully handle corrupted repo', () => {
|
|
10
|
+
it('backports correctly', async () => {
|
|
11
|
+
const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
12
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
13
|
+
// first run: backport should clone the repo
|
|
14
|
+
await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
15
|
+
'--repo=backport-org/integration-test',
|
|
16
|
+
'--sha=16cfd987b82f49a79ebc663506f5d215b7a81c5c',
|
|
17
|
+
'--branch=7.x',
|
|
18
|
+
`--accessToken=${accessToken}`,
|
|
19
|
+
`--dir=${sandboxPath}`,
|
|
20
|
+
'--dry-run',
|
|
21
|
+
], {
|
|
22
|
+
showOra: true,
|
|
23
|
+
timeoutSeconds: 10,
|
|
24
|
+
});
|
|
25
|
+
// remove all git objects and references
|
|
26
|
+
await (0, child_process_promisified_1.exec)('rm -rf .git', { cwd: sandboxPath });
|
|
27
|
+
await (0, child_process_promisified_1.exec)('git init', { cwd: sandboxPath });
|
|
28
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
29
|
+
'--repo=backport-org/integration-test',
|
|
30
|
+
'--sha=16cfd987b82f49a79ebc663506f5d215b7a81c5c',
|
|
31
|
+
'--branch=7.x',
|
|
32
|
+
`--accessToken=${accessToken}`,
|
|
33
|
+
`--dir=${sandboxPath}`,
|
|
34
|
+
'--dry-run',
|
|
35
|
+
], {
|
|
36
|
+
showOra: true,
|
|
37
|
+
timeoutSeconds: 10,
|
|
38
|
+
});
|
|
39
|
+
// second run: backport should re-create remotes and branches correctly
|
|
40
|
+
expect(output).toMatchInlineSnapshot(`
|
|
41
|
+
"- Initializing...
|
|
42
|
+
? Select commit Bump to 8.0.0
|
|
43
|
+
|
|
44
|
+
Backporting to 7.x:
|
|
45
|
+
- Pulling latest changes
|
|
46
|
+
✔ Pulling latest changes
|
|
47
|
+
- Cherry-picking: Bump to 8.0.0
|
|
48
|
+
✔ Cherry-picking: Bump to 8.0.0
|
|
49
|
+
✔ Dry run complete"
|
|
50
|
+
`);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
const rest_1 = require("@octokit/rest");
|
|
5
|
+
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
6
|
+
const sandbox_1 = require("../../sandbox");
|
|
7
|
+
const runBackportViaCli_1 = require("./runBackportViaCli");
|
|
8
|
+
jest.setTimeout(15000);
|
|
9
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
10
|
+
const octokit = new rest_1.Octokit({ auth: accessToken });
|
|
11
|
+
describe('Programatically add new commits', () => {
|
|
12
|
+
it('should backport commits added after the first run', async () => {
|
|
13
|
+
const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
14
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
15
|
+
// first run: backport should clone the repo
|
|
16
|
+
await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
17
|
+
'--repo=backport-org/repo-with-programatically-added-commits',
|
|
18
|
+
'--pr=1',
|
|
19
|
+
'--branch=7.x',
|
|
20
|
+
`--accessToken=${accessToken}`,
|
|
21
|
+
`--dir=${sandboxPath}`,
|
|
22
|
+
'--dry-run',
|
|
23
|
+
], { showOra: true });
|
|
24
|
+
const formattedDate = new Date().toLocaleString('da-DK');
|
|
25
|
+
const commitMessage = `Automatically added at ${formattedDate}`;
|
|
26
|
+
const sha = await createAndCommitFile({
|
|
27
|
+
commitMessage,
|
|
28
|
+
files: [
|
|
29
|
+
{
|
|
30
|
+
path: `files/${formattedDate}.md`,
|
|
31
|
+
sha: await createBlob(`# Hello\nSome content added @ ${formattedDate}`),
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
});
|
|
35
|
+
// second run: backport should find and backport the new commit
|
|
36
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
37
|
+
'--repo=backport-org/repo-with-programatically-added-commits',
|
|
38
|
+
`--sha=${sha}`,
|
|
39
|
+
'--branch=7.x',
|
|
40
|
+
`--accessToken=${accessToken}`,
|
|
41
|
+
`--dir=${sandboxPath}`,
|
|
42
|
+
'--dry-run',
|
|
43
|
+
], { showOra: true });
|
|
44
|
+
expect(output).toContain(commitMessage);
|
|
45
|
+
expect(output).toContain('Dry run complete');
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
async function createAndCommitFile({ commitMessage, files, }) {
|
|
49
|
+
const latestCommitSha = await getLatestCommitSha();
|
|
50
|
+
const treeSha = await createTree(files);
|
|
51
|
+
const commitSha = await createCommit({
|
|
52
|
+
latestCommitSha,
|
|
53
|
+
commitMessage,
|
|
54
|
+
treeSha,
|
|
55
|
+
});
|
|
56
|
+
await updateRef(commitSha);
|
|
57
|
+
return commitSha;
|
|
58
|
+
}
|
|
59
|
+
async function updateRef(sha) {
|
|
60
|
+
try {
|
|
61
|
+
const res = await octokit.rest.git.updateRef({
|
|
62
|
+
owner: 'backport-org',
|
|
63
|
+
repo: 'repo-with-programatically-added-commits',
|
|
64
|
+
ref: 'heads/main',
|
|
65
|
+
sha,
|
|
66
|
+
});
|
|
67
|
+
return res.data;
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
console.log(e);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async function createCommit({ latestCommitSha, commitMessage, treeSha, }) {
|
|
74
|
+
const res = await octokit.rest.git.createCommit({
|
|
75
|
+
owner: 'backport-org',
|
|
76
|
+
repo: 'repo-with-programatically-added-commits',
|
|
77
|
+
message: commitMessage,
|
|
78
|
+
parents: [latestCommitSha],
|
|
79
|
+
tree: treeSha,
|
|
80
|
+
});
|
|
81
|
+
return res.data.sha;
|
|
82
|
+
}
|
|
83
|
+
async function createTree(files) {
|
|
84
|
+
const res = await octokit.git.createTree({
|
|
85
|
+
owner: 'backport-org',
|
|
86
|
+
repo: 'repo-with-programatically-added-commits',
|
|
87
|
+
tree: files.map((f) => {
|
|
88
|
+
return {
|
|
89
|
+
path: f.path,
|
|
90
|
+
sha: f.sha,
|
|
91
|
+
mode: '100644',
|
|
92
|
+
type: 'blob',
|
|
93
|
+
};
|
|
94
|
+
}),
|
|
95
|
+
});
|
|
96
|
+
return res.data.sha;
|
|
97
|
+
}
|
|
98
|
+
async function createBlob(content) {
|
|
99
|
+
const res = await octokit.rest.git.createBlob({
|
|
100
|
+
owner: 'backport-org',
|
|
101
|
+
repo: 'repo-with-programatically-added-commits',
|
|
102
|
+
content: content,
|
|
103
|
+
encoding: 'utf-8',
|
|
104
|
+
});
|
|
105
|
+
return res.data.sha;
|
|
106
|
+
}
|
|
107
|
+
async function getLatestCommitSha() {
|
|
108
|
+
const res = await octokit.repos.getBranch({
|
|
109
|
+
owner: 'backport-org',
|
|
110
|
+
repo: 'repo-with-programatically-added-commits',
|
|
111
|
+
branch: 'main',
|
|
112
|
+
});
|
|
113
|
+
return res.data.commit.sha;
|
|
114
|
+
}
|
|
@@ -70,7 +70,7 @@ function getPromise(proc, runBackportOptions, cmdArgs, chunks) {
|
|
|
70
70
|
proc.on('exit', (code) => {
|
|
71
71
|
postponeTimeout.cancel();
|
|
72
72
|
if (waitForString) {
|
|
73
|
-
reject(`runBackportViaCli exited before finding: ${waitForString}. Output: `);
|
|
73
|
+
reject(`runBackportViaCli exited before finding: ${waitForString}. Output: ${formatChunk(chunks)}`);
|
|
74
74
|
}
|
|
75
75
|
else {
|
|
76
76
|
resolve({ output: formatChunk(chunks), code, keypress });
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const child_process_promisified_1 = require("../../../lib/child-process-promisified");
|
|
4
4
|
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
5
|
+
const replaceStringAndLinebreaks_1 = require("../../replaceStringAndLinebreaks");
|
|
5
6
|
const sandbox_1 = require("../../sandbox");
|
|
6
7
|
const runBackportViaCli_1 = require("./runBackportViaCli");
|
|
7
8
|
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
@@ -76,7 +77,11 @@ describe('test-that-repo-can-be-cloned', () => {
|
|
|
76
77
|
}
|
|
77
78
|
it('clones using the local repo', async () => {
|
|
78
79
|
const { output } = await run();
|
|
79
|
-
expect(
|
|
80
|
+
expect((0, replaceStringAndLinebreaks_1.replaceStringAndLinebreaks)({
|
|
81
|
+
haystack: output,
|
|
82
|
+
stringBefore: sourceRepo,
|
|
83
|
+
stringAfter: '<SOURCE_REPO>',
|
|
84
|
+
})).toContain('✔ 100% Cloning repository from <SOURCE_REPO> (one-time operation)');
|
|
80
85
|
});
|
|
81
86
|
});
|
|
82
87
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.replaceStringAndLinebreaks = void 0;
|
|
4
|
+
function replaceStringAndLinebreaks({ haystack, stringBefore, stringAfter, }) {
|
|
5
|
+
const regex = stringBefore.split('').join('\\s?');
|
|
6
|
+
return haystack.replace(new RegExp(regex, 'g'), stringAfter);
|
|
7
|
+
}
|
|
8
|
+
exports.replaceStringAndLinebreaks = replaceStringAndLinebreaks;
|
package/dist/test/sandbox.js
CHANGED
|
@@ -27,6 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.resetSandbox = exports.getSandboxPath = void 0;
|
|
30
|
+
const os_1 = require("os");
|
|
30
31
|
const path_1 = __importStar(require("path"));
|
|
31
32
|
const del_1 = __importDefault(require("del"));
|
|
32
33
|
const make_dir_1 = __importDefault(require("make-dir"));
|
|
@@ -34,11 +35,14 @@ jest.unmock('make-dir');
|
|
|
34
35
|
jest.unmock('del');
|
|
35
36
|
function getSandboxPath({ filename, specname, }) {
|
|
36
37
|
const baseFilename = getFilenameWithoutExtension(filename);
|
|
37
|
-
return (0, path_1.resolve)(`${
|
|
38
|
+
return (0, path_1.resolve)(`${(0, os_1.homedir)()}/.backport_testing/${baseFilename}${specname ? `/${specname}` : ''}`);
|
|
38
39
|
}
|
|
39
40
|
exports.getSandboxPath = getSandboxPath;
|
|
40
41
|
async function resetSandbox(sandboxPath) {
|
|
41
|
-
|
|
42
|
+
if (sandboxPath.length < 30) {
|
|
43
|
+
throw new Error(`sandboxPath "${sandboxPath}" is too short. Reset aborted`);
|
|
44
|
+
}
|
|
45
|
+
await (0, del_1.default)(sandboxPath, { force: true });
|
|
42
46
|
await (0, make_dir_1.default)(sandboxPath);
|
|
43
47
|
}
|
|
44
48
|
exports.resetSandbox = resetSandbox;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "8.4.
|
|
1
|
+
export declare const PACKAGE_VERSION = "8.4.2";
|