backport 8.4.0 → 8.4.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.
@@ -1,10 +1,15 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const promises_1 = __importDefault(require("fs/promises"));
3
7
  const child_process_promisified_1 = require("../../../lib/child-process-promisified");
4
8
  const getDevAccessToken_1 = require("../../private/getDevAccessToken");
5
9
  const sandbox_1 = require("../../sandbox");
6
10
  const runBackportViaCli_1 = require("./runBackportViaCli");
7
11
  const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
12
+ jest.setTimeout(40000);
8
13
  describe('different-merge-strategies', () => {
9
14
  it('list all commits regardless how they were merged', async () => {
10
15
  const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
@@ -33,7 +38,7 @@ describe('different-merge-strategies', () => {
33
38
  16.Initial commit"
34
39
  `);
35
40
  });
36
- describe('when selecting a merge commit', () => {
41
+ describe('when selecting a merge commit with eight commits', () => {
37
42
  let output;
38
43
  let sandboxPath;
39
44
  beforeAll(async () => {
@@ -58,8 +63,22 @@ describe('different-merge-strategies', () => {
58
63
  Backporting to 7.x:
59
64
  - Pulling latest changes
60
65
  ✔ Pulling latest changes
61
- - Cherry-picking: Merge pull request #9 from backport-org/many-merge-commits
62
- ✔ Cherry-picking: Merge pull request #9 from backport-org/many-merge-commits
66
+ - Cherry-picking: Merge strategy: First of many merges
67
+ ✔ Cherry-picking: Merge strategy: First of many merges
68
+ - Cherry-picking: Merge strategy: Second of many merges
69
+ ✔ Cherry-picking: Merge strategy: Second of many merges
70
+ - Cherry-picking: Merge strategy: Third of many merges
71
+ ✔ Cherry-picking: Merge strategy: Third of many merges
72
+ - Cherry-picking: Merge strategy: Fourth of many merges
73
+ ✔ Cherry-picking: Merge strategy: Fourth of many merges
74
+ - Cherry-picking: Merge strategy: Fifth of many merges
75
+ ✔ Cherry-picking: Merge strategy: Fifth of many merges
76
+ - Cherry-picking: Merge strategy: Sixth of many merges
77
+ ✔ Cherry-picking: Merge strategy: Sixth of many merges
78
+ - Cherry-picking: Merge strategy: Seventh of many merges
79
+ ✔ Cherry-picking: Merge strategy: Seventh of many merges
80
+ - Cherry-picking: Merge strategy: Eighth of many merges
81
+ ✔ Cherry-picking: Merge strategy: Eighth of many merges
63
82
  ✔ Dry run complete"
64
83
  `);
65
84
  });
@@ -78,7 +97,7 @@ describe('different-merge-strategies', () => {
78
97
  ]);
79
98
  });
80
99
  });
81
- describe('when selecting anoter merge commit', () => {
100
+ describe('when selecting a merge commit with two commits', () => {
82
101
  let sandboxPath;
83
102
  beforeAll(async () => {
84
103
  sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
@@ -101,6 +120,103 @@ describe('different-merge-strategies', () => {
101
120
  ]);
102
121
  });
103
122
  });
123
+ describe('when selecting a merge commit with eight commits and a conflict occurs', () => {
124
+ let sandboxPath;
125
+ let output;
126
+ beforeAll(async () => {
127
+ sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
128
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
129
+ const proc = await (0, runBackportViaCli_1.runBackportViaCli)([
130
+ '--branch=7.1',
131
+ '--repo=backport-org/different-merge-strategies',
132
+ `--accessToken=${accessToken}`,
133
+ `--dir=${sandboxPath}`,
134
+ '--pr=9',
135
+ '--dry-run',
136
+ ], {
137
+ keepAlive: true,
138
+ timeoutSeconds: 5,
139
+ showOra: true,
140
+ waitForString: 'Press ENTER when the conflicts are resolved and files are staged',
141
+ });
142
+ await (0, child_process_promisified_1.exec)(`git status`, { cwd: sandboxPath });
143
+ await promises_1.default.writeFile(`${sandboxPath}/new-file-added-with-many-merge-commits.txt`, `File added directly to 7.1 to cause merge conflict\nPrevious merge commit didn't have enough commits\n`);
144
+ await (0, child_process_promisified_1.exec)(`git add -A`, { cwd: sandboxPath });
145
+ const res = await proc.keypress('enter', {
146
+ showOra: true,
147
+ timeoutSeconds: 5,
148
+ });
149
+ output = res.output.replaceAll(sandboxPath, '');
150
+ });
151
+ it('has the right output', async () => {
152
+ function stripSandboxPath(str) {
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(`
160
+ "- Initializing...
161
+ ? Select pull request Merge pull request #9 from backport-org/many-merge-commits
162
+ ✔ 100% Cloning repository from github.com (one-time operation)
163
+
164
+ Backporting to 7.1:
165
+ - Pulling latest changes
166
+ ✔ Pulling latest changes
167
+ - Cherry-picking: Merge strategy: First of many merges
168
+ ✖ Cherry-picking: Merge strategy: First of many merges
169
+
170
+ The commit could not be backported due to conflicts
171
+
172
+ Please fix the conflicts in
173
+ ? Fix the following conflicts manually:
174
+
175
+ Conflicting files:
176
+ - <SANDBOX_PATH>/new-file-added-with-many-merge-commits.txt
177
+
178
+
179
+ Press ENTER when the conflicts are resolved and files are staged (Y/n) ? Fix the following conflicts manually:
180
+
181
+ Conflicting files:
182
+ - <SANDBOX_PATH>/new-file-added-with-many-merge-commits.txt
183
+
184
+
185
+ Press ENTER when the conflicts are resolved and files are staged Yes
186
+ ✔ Cherry-picking: Merge strategy: First of many merges
187
+ - Cherry-picking: Merge strategy: Second of many merges
188
+ ✔ Cherry-picking: Merge strategy: Second of many merges
189
+ - Cherry-picking: Merge strategy: Third of many merges
190
+ ✔ Cherry-picking: Merge strategy: Third of many merges
191
+ - Cherry-picking: Merge strategy: Fourth of many merges
192
+ ✔ Cherry-picking: Merge strategy: Fourth of many merges
193
+ - Cherry-picking: Merge strategy: Fifth of many merges
194
+ ✔ Cherry-picking: Merge strategy: Fifth of many merges
195
+ - Cherry-picking: Merge strategy: Sixth of many merges
196
+ ✔ Cherry-picking: Merge strategy: Sixth of many merges
197
+ - Cherry-picking: Merge strategy: Seventh of many merges
198
+ ✔ Cherry-picking: Merge strategy: Seventh of many merges
199
+ - Cherry-picking: Merge strategy: Eighth of many merges
200
+ ✔ Cherry-picking: Merge strategy: Eighth of many merges
201
+ ✔ Dry run complete"
202
+ `);
203
+ });
204
+ it('backports all immediate children of the merge commit', async () => {
205
+ const commits = await listCommits(sandboxPath);
206
+ expect(commits).toEqual([
207
+ 'Merge strategy: Eighth of many merges',
208
+ 'Merge strategy: Seventh of many merges',
209
+ 'Merge strategy: Sixth of many merges',
210
+ 'Merge strategy: Fifth of many merges',
211
+ 'Merge strategy: Fourth of many merges',
212
+ 'Merge strategy: Third of many merges',
213
+ 'Merge strategy: Second of many merges',
214
+ 'Merge strategy: First of many merges',
215
+ 'Create new-file-added-with-many-merge-commits.txt',
216
+ 'Initial commit',
217
+ ]);
218
+ });
219
+ });
104
220
  });
105
221
  async function listCommits(sandboxPath) {
106
222
  const { stdout } = await (0, child_process_promisified_1.exec)('git --no-pager log --pretty=format:%s', {
@@ -4,6 +4,7 @@ const getDevAccessToken_1 = require("../../private/getDevAccessToken");
4
4
  const sandbox_1 = require("../../sandbox");
5
5
  const runBackportViaCli_1 = require("./runBackportViaCli");
6
6
  const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
7
+ jest.setTimeout(15000);
7
8
  describe('interactive error handling', () => {
8
9
  it('when branch is missing', async () => {
9
10
  const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
@@ -14,7 +15,7 @@ describe('interactive error handling', () => {
14
15
  expect(output).toMatchInlineSnapshot(`
15
16
  "Please specify a target branch: \\"--branch 6.1\\".
16
17
 
17
- Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
18
+ Read more: https://github.com/sqren/backport/blob/main/docs/config-file-options.md#project-config-backportrcjson"
18
19
  `);
19
20
  });
20
21
  it('when supplying invalid argument', async () => {
@@ -9,6 +9,7 @@ const getDevAccessToken_1 = require("../../private/getDevAccessToken");
9
9
  const sandbox_1 = require("../../sandbox");
10
10
  const runBackportViaCli_1 = require("./runBackportViaCli");
11
11
  const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
12
+ jest.setTimeout(15000);
12
13
  describe('non interactive (json) error handling', () => {
13
14
  it(`when access token is missing`, async () => {
14
15
  const configFilePath = await createConfigFile({ editor: 'code' });
@@ -25,7 +26,7 @@ describe('non interactive (json) error handling', () => {
25
26
  "Please update your config file: \\"<GLOBAL_CONFIG_FILE>\\".
26
27
  It must contain a valid \\"accessToken\\".
27
28
 
28
- Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#global-config-backportconfigjson"
29
+ Read more: https://github.com/sqren/backport/blob/main/docs/config-file-options.md#global-config-backportconfigjson"
29
30
  `);
30
31
  });
31
32
  it('when target branches cannot be inferred from pull request', async () => {
@@ -55,7 +56,7 @@ describe('non interactive (json) error handling', () => {
55
56
  expect(backportResult.errorMessage).toMatchInlineSnapshot(`
56
57
  "Please specify a target branch: \\"--branch 6.1\\".
57
58
 
58
- Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
59
+ Read more: https://github.com/sqren/backport/blob/main/docs/config-file-options.md#project-config-backportrcjson"
59
60
  `);
60
61
  });
61
62
  it(`when argument is invalid`, async () => {
@@ -9,7 +9,7 @@ describe('repo-with-backportrc-removed (missing .backportrc.json config file)',
9
9
  '--branch=production',
10
10
  '--repo=backport-org/repo-with-backportrc-removed',
11
11
  `--accessToken=${accessToken}`,
12
- ], { waitForString: 'Select commit' });
12
+ ], { waitForString: 'Select commit', timeoutSeconds: 4 });
13
13
  expect(output).toMatchInlineSnapshot(`
14
14
  "? Select commit (Use arrow keys)
15
15
  ❯ 1. Rename README.me to README.md
@@ -31,7 +31,7 @@ describe('repo-with-backportrc-removed (missing .backportrc.json config file)',
31
31
  ], {
32
32
  showOra: true,
33
33
  });
34
- expect(output).toContain('Cherry-picking: Merge pull request #1 from backport-org/add-readme');
34
+ expect(output).toContain('Cherry-picking: Create README.me');
35
35
  });
36
36
  it('backport by commit sha', async () => {
37
37
  const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
@@ -1,9 +1,15 @@
1
- export declare function runBackportViaCli(backportArgs: string[], { timeoutSeconds, showOra, waitForString, cwd, }?: {
1
+ declare type RunBackportOptions = {
2
2
  timeoutSeconds?: number;
3
3
  showOra?: boolean;
4
4
  waitForString?: string;
5
5
  cwd?: string;
6
- }): Promise<{
6
+ keepAlive?: boolean;
7
+ };
8
+ export declare function runBackportViaCli(backportArgs: string[], runBackportOptions?: RunBackportOptions): Promise<{
7
9
  output: string;
8
10
  code: number | null;
11
+ keypress: (keyCode: "up" | "down" | "enter", runBackportOptions?: RunBackportOptions | undefined) => Promise<{
12
+ output: string;
13
+ }>;
9
14
  }>;
15
+ export {};
@@ -9,10 +9,11 @@ const path_1 = __importDefault(require("path"));
9
9
  const lodash_1 = require("lodash");
10
10
  const strip_ansi_1 = __importDefault(require("strip-ansi"));
11
11
  const sandbox_1 = require("../../sandbox");
12
+ const tsNodeBinary = path_1.default.resolve('./node_modules/.bin/ts-node');
13
+ const entrypointFile = path_1.default.resolve('./src/entrypoint.cli.ts');
12
14
  jest.setTimeout(15000);
13
- function runBackportViaCli(backportArgs, { timeoutSeconds = 3, showOra, waitForString, cwd, } = {}) {
14
- const tsNodeBinary = path_1.default.resolve('./node_modules/.bin/ts-node');
15
- const entrypointFile = path_1.default.resolve('./src/entrypoint.cli.ts');
15
+ function runBackportViaCli(backportArgs, runBackportOptions = {}) {
16
+ const chunks = '';
16
17
  const randomString = Math.random().toString(36).slice(2);
17
18
  const sandboxPath = (0, sandbox_1.getSandboxPath)({
18
19
  filename: __filename,
@@ -28,30 +29,52 @@ function runBackportViaCli(backportArgs, { timeoutSeconds = 3, showOra, waitForS
28
29
  : [`--dir=${sandboxPath}`]),
29
30
  ...backportArgs,
30
31
  ];
31
- const proc = (0, child_process_1.spawn)(tsNodeBinary, cmdArgs, { cwd });
32
+ const proc = (0, child_process_1.spawn)(tsNodeBinary, cmdArgs, { cwd: runBackportOptions.cwd });
33
+ return getPromise(proc, runBackportOptions, cmdArgs, chunks);
34
+ }
35
+ exports.runBackportViaCli = runBackportViaCli;
36
+ const keyCodeMap = {
37
+ down: '\x1B\x5B\x42',
38
+ up: '\x1B\x5B\x41',
39
+ enter: '\x0D',
40
+ };
41
+ function getPromise(proc, runBackportOptions, cmdArgs, chunks) {
42
+ if (proc.killed) {
43
+ throw new Error('Process is already killed. Did you forget `keepAlive: true`?');
44
+ }
45
+ const { timeoutSeconds = 3, waitForString, showOra, keepAlive, } = runBackportOptions;
32
46
  return new Promise((resolve, reject) => {
33
- let data = '';
34
47
  const postponeTimeout = (0, lodash_1.debounce)(() => {
35
- const formattedData = formatData(data);
48
+ const formattedChunks = formatChunk(chunks);
36
49
  const cmd = [tsNodeBinary, ...cmdArgs].join(' ');
37
50
  reject(waitForString
38
- ? `Expectation '${waitForString}' not found within ${timeoutSeconds} second in:\n\n${formattedData}\n\nCommand: ${cmd}`
39
- : `Timeout. Received:\n${formattedData}\n\nCommand: ${cmd}`);
40
- }, timeoutSeconds * 1000, { maxWait: 15000 });
41
- function formatData(data) {
51
+ ? `Expectation '${waitForString}' not found within ${timeoutSeconds} second in:\n\n${formattedChunks}\n\nCommand: ${cmd}`
52
+ : `Process did not complete within ${timeoutSeconds} seconds. Received:\n${formattedChunks}\n\nCommand: ${cmd}`);
53
+ }, timeoutSeconds * 1000, { maxWait: 10000 });
54
+ function formatChunk(data) {
42
55
  return (0, strip_ansi_1.default)(data.toString()).trim();
43
56
  }
57
+ function keypress(keyCode, runBackportOptions = {}) {
58
+ const p = getPromise(proc, runBackportOptions, cmdArgs, chunks);
59
+ proc.stdin.write(keyCodeMap[keyCode]);
60
+ return p;
61
+ }
44
62
  const onChunk = (chunk) => {
45
- data += chunk;
46
- const output = formatData(data);
47
- if (waitForString && output.includes(waitForString)) {
63
+ chunks += chunk;
64
+ const formattedChunk = formatChunk(chunk);
65
+ if (waitForString && formattedChunk.includes(waitForString)) {
48
66
  postponeTimeout.cancel();
49
- resolve({ output, code: null });
67
+ resolve({ output: formatChunk(chunks), code: null, keypress });
50
68
  }
51
69
  };
52
70
  proc.on('exit', (code) => {
53
71
  postponeTimeout.cancel();
54
- resolve({ output: formatData(data), code });
72
+ if (waitForString) {
73
+ reject(`runBackportViaCli exited before finding: ${waitForString}. Output: `);
74
+ }
75
+ else {
76
+ resolve({ output: formatChunk(chunks), code, keypress });
77
+ }
55
78
  });
56
79
  proc.stdout.on('data', (chunk) => {
57
80
  postponeTimeout();
@@ -68,7 +91,14 @@ function runBackportViaCli(backportArgs, { timeoutSeconds = 3, showOra, waitForS
68
91
  reject(`runBackportViaCli failed with: ${err}`);
69
92
  });
70
93
  }).finally(() => {
71
- proc.kill();
94
+ if (!keepAlive) {
95
+ proc.kill();
96
+ }
97
+ else {
98
+ proc.removeAllListeners('exit');
99
+ proc.stdout.removeAllListeners('data');
100
+ proc.stderr.removeAllListeners('data');
101
+ proc.removeAllListeners('errors');
102
+ }
72
103
  });
73
104
  }
74
- exports.runBackportViaCli = runBackportViaCli;
@@ -5,6 +5,7 @@ const getDevAccessToken_1 = require("../../private/getDevAccessToken");
5
5
  const sandbox_1 = require("../../sandbox");
6
6
  const runBackportViaCli_1 = require("./runBackportViaCli");
7
7
  const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
8
+ jest.setTimeout(15000);
8
9
  describe('test-that-repo-can-be-cloned', () => {
9
10
  describe('when local repo does not exist', () => {
10
11
  let sandboxPath;
@@ -8,7 +8,7 @@ const sandbox_1 = require("../../sandbox");
8
8
  jest.unmock('find-up');
9
9
  jest.unmock('del');
10
10
  jest.unmock('make-dir');
11
- jest.setTimeout(10000);
11
+ jest.setTimeout(15000);
12
12
  const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
13
13
  const octokit = new rest_1.Octokit({ auth: accessToken });
14
14
  const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
@@ -5,7 +5,7 @@ const getDevAccessToken_1 = require("./private/getDevAccessToken");
5
5
  const sandbox_1 = require("./sandbox");
6
6
  const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
7
7
  jest.unmock('find-up');
8
- jest.setTimeout(15000);
8
+ jest.setTimeout(20000);
9
9
  describe('Handle unbackported pull requests', () => {
10
10
  it('shows missing backports for PR number 8', async () => {
11
11
  const commits = await (0, entrypoint_module_1.getCommits)({
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "8.4.0";
1
+ export declare const PACKAGE_VERSION = "8.4.1";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PACKAGE_VERSION = void 0;
4
- exports.PACKAGE_VERSION = '8.4.0';
4
+ exports.PACKAGE_VERSION = '8.4.1';
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "branches",
15
15
  "branching"
16
16
  ],
17
- "version": "8.4.0",
17
+ "version": "8.4.1",
18
18
  "main": "./dist/entrypoint.module.js",
19
19
  "types": "dist/entrypoint.module.d.ts",
20
20
  "bin": {
@@ -69,9 +69,9 @@
69
69
  "del": "^6.0.0",
70
70
  "dotenv": "^16.0.0",
71
71
  "find-up": "^5.0.0",
72
- "graphql": "^16.3.0",
72
+ "graphql": "^16.4.0",
73
73
  "graphql-tag": "^2.12.6",
74
- "inquirer": "^8.2.2",
74
+ "inquirer": "^8.2.3",
75
75
  "lodash": "^4.17.21",
76
76
  "make-dir": "^3.1.0",
77
77
  "ora": "^5.4.1",
@@ -79,8 +79,8 @@
79
79
  "strip-json-comments": "^3.1.1",
80
80
  "terminal-link": "^2.1.1",
81
81
  "utility-types": "^3.10.0",
82
- "winston": "^3.6.0",
83
- "yargs": "^17.4.0",
82
+ "winston": "^3.7.2",
83
+ "yargs": "^17.4.1",
84
84
  "yargs-parser": "^21.0.1"
85
85
  },
86
86
  "devDependencies": {
@@ -88,23 +88,23 @@
88
88
  "@types/dedent": "^0.7.0",
89
89
  "@types/inquirer": "^8.2.1",
90
90
  "@types/jest": "^27.4.1",
91
- "@types/lodash": "^4.14.181",
92
- "@types/node": "^17.0.23",
91
+ "@types/lodash": "^4.14.182",
92
+ "@types/node": "^17.0.29",
93
93
  "@types/safe-json-stringify": "^1.1.2",
94
94
  "@types/yargs": "^17.0.10",
95
95
  "@types/yargs-parser": "^21.0.0",
96
- "@typescript-eslint/eslint-plugin": "^5.17.0",
97
- "@typescript-eslint/parser": "^5.17.0",
98
- "eslint": "^8.12.0",
96
+ "@typescript-eslint/eslint-plugin": "^5.21.0",
97
+ "@typescript-eslint/parser": "^5.21.0",
98
+ "eslint": "^8.14.0",
99
99
  "eslint-config-prettier": "^8.5.0",
100
- "eslint-plugin-import": "^2.25.4",
101
- "eslint-plugin-jest": "^26.1.3",
100
+ "eslint-plugin-import": "^2.26.0",
101
+ "eslint-plugin-jest": "^26.1.5",
102
102
  "eslint-plugin-prettier": "^4.0.0",
103
- "graphql-config": "^4.2.0",
103
+ "graphql-config": "^4.3.0",
104
104
  "husky": "^7.0.4",
105
105
  "jest": "^27.5.1",
106
106
  "jest-snapshot-serializer-ansi": "^1.0.0",
107
- "lint-staged": "^12.3.7",
107
+ "lint-staged": "^12.4.1",
108
108
  "nock": "^13.2.4",
109
109
  "prettier": "^2.6.2",
110
110
  "strip-ansi": "^6.0.1",