backport 8.1.0 → 8.2.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/backportRun.js +5 -14
- package/dist/entrypoint.cli.js +1 -1
- package/dist/lib/cherrypickAndCreateTargetPullRequest.d.ts +1 -3
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +6 -2
- package/dist/lib/child-process-promisified.js +5 -3
- package/dist/lib/env.d.ts +3 -1
- package/dist/lib/env.js +2 -2
- package/dist/lib/getTargetBranches.d.ts +1 -1
- package/dist/lib/getTargetBranches.js +1 -1
- package/dist/lib/getTargetBranches.test.js +11 -7
- package/dist/lib/github/v3/addLabelsToPullRequest.js +1 -1
- package/dist/lib/github/v3/addReviewersToPullRequest.js +1 -1
- package/dist/lib/github/v3/createPullRequest.js +6 -6
- package/dist/lib/github/v3/createStatusComment.js +6 -4
- package/dist/lib/github/v3/createStatusComment.test.js +108 -3
- package/dist/lib/github/v4/apiRequestV4.js +7 -7
- package/dist/lib/github/v4/validateTargetBranches.d.ts +14 -0
- package/dist/lib/github/v4/validateTargetBranches.js +46 -0
- package/dist/lib/github/v4/validateTargetBranches.private.test.d.ts +1 -0
- package/dist/lib/github/v4/validateTargetBranches.private.test.js +51 -0
- package/dist/lib/logger.d.ts +2 -0
- package/dist/lib/logger.js +20 -14
- package/dist/options/cliArgs.d.ts +6 -6
- package/dist/options/cliArgs.js +3 -3
- package/dist/options/cliArgs.test.js +10 -10
- package/dist/options/config/readConfigFile.d.ts +5 -5
- package/dist/options/options.d.ts +4 -4
- package/dist/options/options.js +4 -0
- package/dist/runSequentially.d.ts +1 -3
- package/dist/runSequentially.js +2 -3
- package/dist/test/e2e/cli/different-merge-strategies.private.test.js +1 -1
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +7 -260
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +80 -0
- package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +199 -0
- package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/interactive-error-handling.private.test.js +80 -0
- package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +198 -0
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +1 -1
- package/dist/test/e2e/cli/runBackportViaCli.js +1 -1
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +5 -5
- package/yarn.lock +60 -55
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
4
|
+
const sandbox_1 = require("../../sandbox");
|
|
5
|
+
const runBackportViaCli_1 = require("./runBackportViaCli");
|
|
6
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
7
|
+
describe('interactive error handling', () => {
|
|
8
|
+
it('when branch is missing', async () => {
|
|
9
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
10
|
+
'--skip-remote-config',
|
|
11
|
+
'--repo=backport-org/backport-e2e',
|
|
12
|
+
`--accessToken=${accessToken}`,
|
|
13
|
+
]);
|
|
14
|
+
expect(output).toMatchInlineSnapshot(`
|
|
15
|
+
"Please specify a target branch: \\"--branch 6.1\\".
|
|
16
|
+
|
|
17
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
|
|
18
|
+
`);
|
|
19
|
+
});
|
|
20
|
+
it('when supplying invalid argument', async () => {
|
|
21
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([`--foo`]);
|
|
22
|
+
expect(output).toMatchInlineSnapshot(`
|
|
23
|
+
"Unknown argument: foo
|
|
24
|
+
Run \\"backport --help\\" to see all options"
|
|
25
|
+
`);
|
|
26
|
+
});
|
|
27
|
+
it('when access token is invalid', async () => {
|
|
28
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
29
|
+
'--branch=foo',
|
|
30
|
+
'--repo=foo/bar',
|
|
31
|
+
'--accessToken=some-token',
|
|
32
|
+
]);
|
|
33
|
+
expect(output).toContain('Please check your access token and make sure it is valid');
|
|
34
|
+
});
|
|
35
|
+
it(`when repo doesn't exist`, async () => {
|
|
36
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
37
|
+
'--branch=foo',
|
|
38
|
+
'--repo=foo/bar',
|
|
39
|
+
'--author=sqren',
|
|
40
|
+
`--accessToken=${accessToken}`,
|
|
41
|
+
]);
|
|
42
|
+
expect(output).toMatchInlineSnapshot(`"The repository \\"foo/bar\\" doesn't exist"`);
|
|
43
|
+
});
|
|
44
|
+
it(`when given branch is invalid`, async () => {
|
|
45
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
46
|
+
'--branch=foo',
|
|
47
|
+
'--repo=backport-org/backport-e2e',
|
|
48
|
+
'--pr=9',
|
|
49
|
+
`--accessToken=${accessToken}`,
|
|
50
|
+
]);
|
|
51
|
+
expect(output).toMatchInlineSnapshot(`"The branch \\"foo\\" does not exist"`);
|
|
52
|
+
});
|
|
53
|
+
it(`when encountering conflicts`, async () => {
|
|
54
|
+
const backportDir = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
55
|
+
await (0, sandbox_1.resetSandbox)(backportDir);
|
|
56
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
57
|
+
'--repo=backport-org/repo-with-conflicts',
|
|
58
|
+
'--pr=12',
|
|
59
|
+
'--branch=7.x',
|
|
60
|
+
`--accessToken=${accessToken}`,
|
|
61
|
+
`--dir=${backportDir}`,
|
|
62
|
+
'--dry-run',
|
|
63
|
+
], {
|
|
64
|
+
waitForString: 'Press ENTER when the conflicts',
|
|
65
|
+
timeoutSeconds: 5,
|
|
66
|
+
});
|
|
67
|
+
// //@ts-expect-error
|
|
68
|
+
// const lineToReplace = output.match(
|
|
69
|
+
// /Conflicting files:[\s]+- (.*[\s].*)la-liga.md/
|
|
70
|
+
// )[1];
|
|
71
|
+
// const lineWithoutBreaks = lineToReplace.replace(/\s/g, '');
|
|
72
|
+
// const outputReplaced = output
|
|
73
|
+
// .replace(lineToReplace, lineWithoutBreaks)
|
|
74
|
+
// .replaceAll(backportDir, '<BACKPORT_DIR>');
|
|
75
|
+
const outputReplaced = output
|
|
76
|
+
.replaceAll('\n', '')
|
|
77
|
+
.replaceAll(backportDir, '<BACKPORT_DIR>');
|
|
78
|
+
expect(outputReplaced).toMatchInlineSnapshot(`"Backporting to 7.x:The commit could not be backported due to conflictsPlease fix the conflicts in <BACKPORT_DIR>Hint: Before fixing the conflicts manually you should consider backporting the following pull requests to \\"7.x\\": - Change Barca to Braithwaite (#8) (backport missing) https://github.com/backport-org/repo-with-conflicts/pull/8? Fix the following conflicts manually:Conflicting files: - <BACKPORT_DIR>/la-liga.mdPress ENTER when the conflicts are resolved and files are staged (Y/n)"`);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
9
|
+
const sandbox_1 = require("../../sandbox");
|
|
10
|
+
const runBackportViaCli_1 = require("./runBackportViaCli");
|
|
11
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
12
|
+
describe('non interactive (json) error handling', () => {
|
|
13
|
+
it(`when access token is missing`, async () => {
|
|
14
|
+
const configFilePath = await createConfigFile({ editor: 'code' });
|
|
15
|
+
const { output, code } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
16
|
+
'--json',
|
|
17
|
+
`--globalConfigFile=${configFilePath}`,
|
|
18
|
+
]);
|
|
19
|
+
const backportResult = JSON.parse(output);
|
|
20
|
+
// remove absolute path to avoid issues on ci
|
|
21
|
+
const errorMessage = backportResult.errorMessage.replace(configFilePath, '<GLOBAL_CONFIG_FILE>');
|
|
22
|
+
expect(code).toBe(1);
|
|
23
|
+
expect(backportResult.status).toBe('failure');
|
|
24
|
+
expect(errorMessage).toMatchInlineSnapshot(`
|
|
25
|
+
"Please update your config file: \\"<GLOBAL_CONFIG_FILE>\\".
|
|
26
|
+
It must contain a valid \\"accessToken\\".
|
|
27
|
+
|
|
28
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#global-config-backportconfigjson"
|
|
29
|
+
`);
|
|
30
|
+
});
|
|
31
|
+
it('when target branches cannot be inferred from pull request', async () => {
|
|
32
|
+
const { output, code } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
33
|
+
'--json',
|
|
34
|
+
'--repo=backport-org/backport-e2e',
|
|
35
|
+
'--pr=9',
|
|
36
|
+
`--accessToken=${accessToken}`,
|
|
37
|
+
]);
|
|
38
|
+
expect(code).toBe(0);
|
|
39
|
+
const backportResult = JSON.parse(output);
|
|
40
|
+
expect(backportResult.status).toBe('aborted');
|
|
41
|
+
expect(backportResult.error).toEqual({
|
|
42
|
+
errorContext: { code: 'no-branches-exception' },
|
|
43
|
+
name: 'BackportError',
|
|
44
|
+
});
|
|
45
|
+
expect(backportResult.errorMessage).toBe('There are no branches to backport to. Aborting.');
|
|
46
|
+
});
|
|
47
|
+
it(`when target branch and branch label mapping are missing`, async () => {
|
|
48
|
+
const { output, code } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
49
|
+
'--json',
|
|
50
|
+
`--access-token=${accessToken}`,
|
|
51
|
+
]);
|
|
52
|
+
expect(code).toBe(1);
|
|
53
|
+
const backportResult = JSON.parse(output);
|
|
54
|
+
expect(backportResult.status).toBe('failure');
|
|
55
|
+
expect(backportResult.errorMessage).toMatchInlineSnapshot(`
|
|
56
|
+
"Please specify a target branch: \\"--branch 6.1\\".
|
|
57
|
+
|
|
58
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
|
|
59
|
+
`);
|
|
60
|
+
});
|
|
61
|
+
it(`when argument is invalid`, async () => {
|
|
62
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)(['--json', '--foo'], {});
|
|
63
|
+
const backportResult = JSON.parse(output);
|
|
64
|
+
expect(backportResult.status).toBe('failure');
|
|
65
|
+
expect(backportResult.errorMessage).toEqual('Unknown argument: foo');
|
|
66
|
+
});
|
|
67
|
+
it('when `--repo` is invalid', async () => {
|
|
68
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
69
|
+
'--json',
|
|
70
|
+
'--repo=backport-org/backport-e2e-foo',
|
|
71
|
+
`--accessToken=${accessToken}`,
|
|
72
|
+
]);
|
|
73
|
+
const backportResult = JSON.parse(output);
|
|
74
|
+
expect(backportResult.status).toBe('failure');
|
|
75
|
+
expect(backportResult.errorMessage).toEqual('The repository "backport-org/backport-e2e-foo" doesn\'t exist');
|
|
76
|
+
});
|
|
77
|
+
it('when `--sha` is invalid', async () => {
|
|
78
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
79
|
+
'--json',
|
|
80
|
+
'--repo=backport-org/backport-e2e',
|
|
81
|
+
'--sha=abcdefg',
|
|
82
|
+
`--accessToken=${accessToken}`,
|
|
83
|
+
]);
|
|
84
|
+
const backportResult = JSON.parse(output);
|
|
85
|
+
expect(backportResult.status).toBe('failure');
|
|
86
|
+
expect(backportResult.errorMessage).toEqual('No commit found on branch "master" with sha "abcdefg"');
|
|
87
|
+
});
|
|
88
|
+
it('when `--branch` is invalid', async () => {
|
|
89
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
90
|
+
'--json',
|
|
91
|
+
'--repo=backport-org/backport-e2e',
|
|
92
|
+
'--pr=9',
|
|
93
|
+
'--branch=foobar',
|
|
94
|
+
`--accessToken=${accessToken}`,
|
|
95
|
+
]);
|
|
96
|
+
const backportResult = JSON.parse(output);
|
|
97
|
+
expect(backportResult.status).toBe('failure');
|
|
98
|
+
expect(backportResult.error).toEqual({
|
|
99
|
+
name: 'BackportError',
|
|
100
|
+
errorContext: {
|
|
101
|
+
code: 'message-only-exception',
|
|
102
|
+
message: 'The branch "foobar" does not exist',
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
it('when `--branch` tries to inject argument', async () => {
|
|
107
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
108
|
+
'--json',
|
|
109
|
+
'--repo=backport-org/backport-e2e',
|
|
110
|
+
'--pr=9',
|
|
111
|
+
'--branch=--foo bar',
|
|
112
|
+
`--accessToken=${accessToken}`,
|
|
113
|
+
]);
|
|
114
|
+
const backportResult = JSON.parse(output);
|
|
115
|
+
expect(backportResult.status).toBe('failure');
|
|
116
|
+
expect(backportResult.error).toEqual({
|
|
117
|
+
name: 'BackportError',
|
|
118
|
+
errorContext: {
|
|
119
|
+
code: 'message-only-exception',
|
|
120
|
+
message: 'The branch "--foo bar" does not exist',
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
it('when `--pr` is invalid', async () => {
|
|
125
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
126
|
+
'--json',
|
|
127
|
+
'--repo=backport-org/backport-e2e',
|
|
128
|
+
'--pr=900',
|
|
129
|
+
'--branch=7.x',
|
|
130
|
+
`--accessToken=${accessToken}`,
|
|
131
|
+
]);
|
|
132
|
+
const backportResult = JSON.parse(output);
|
|
133
|
+
expect(backportResult.status).toEqual('failure');
|
|
134
|
+
expect(backportResult.errorMessage).toEqual('Could not resolve to a PullRequest with the number of 900. (Github API v4)');
|
|
135
|
+
});
|
|
136
|
+
it('when encountering conflicts', async () => {
|
|
137
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
138
|
+
'--json',
|
|
139
|
+
'--repo=backport-org/repo-with-conflicts',
|
|
140
|
+
'--pr=12',
|
|
141
|
+
'--branch=7.x',
|
|
142
|
+
`--accessToken=${accessToken}`,
|
|
143
|
+
]);
|
|
144
|
+
const backportResult = JSON.parse(output);
|
|
145
|
+
expect(backportResult.status).toEqual('success');
|
|
146
|
+
expect(
|
|
147
|
+
//@ts-expect-error
|
|
148
|
+
backportResult.results[0].error.errorContext.conflictingFiles).toEqual(['la-liga.md']);
|
|
149
|
+
});
|
|
150
|
+
it('when `--source-branch` is invalid', async () => {
|
|
151
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
152
|
+
'--json',
|
|
153
|
+
'--repo=backport-org/backport-e2e',
|
|
154
|
+
'--pr=9',
|
|
155
|
+
'--branch=7.x',
|
|
156
|
+
'--source-branch=foo',
|
|
157
|
+
`--accessToken=${accessToken}`,
|
|
158
|
+
]);
|
|
159
|
+
const backportResult = JSON.parse(output);
|
|
160
|
+
expect(backportResult.status).toBe('success');
|
|
161
|
+
expect(backportResult.results[0]).toEqual({
|
|
162
|
+
error: {
|
|
163
|
+
context: {
|
|
164
|
+
cmdArgs: ['checkout', 'foo'],
|
|
165
|
+
code: 1,
|
|
166
|
+
stderr: "error: pathspec 'foo' did not match any file(s) known to git\n",
|
|
167
|
+
stdout: '',
|
|
168
|
+
},
|
|
169
|
+
name: 'SpawnError',
|
|
170
|
+
},
|
|
171
|
+
status: 'unhandled-error',
|
|
172
|
+
targetBranch: '7.x',
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
it('when attempting to backport unmerged PR', async () => {
|
|
176
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
177
|
+
'--json',
|
|
178
|
+
'--repo=backport-org/backport-e2e',
|
|
179
|
+
'--pr=12',
|
|
180
|
+
`--accessToken=${accessToken}`,
|
|
181
|
+
]);
|
|
182
|
+
const backportResult = JSON.parse(output);
|
|
183
|
+
expect(backportResult.status).toBe('failure');
|
|
184
|
+
expect(backportResult.error).toEqual({
|
|
185
|
+
errorContext: {
|
|
186
|
+
code: 'message-only-exception',
|
|
187
|
+
message: 'The PR #12 is not merged',
|
|
188
|
+
},
|
|
189
|
+
name: 'BackportError',
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
async function createConfigFile(options) {
|
|
194
|
+
const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
195
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
196
|
+
const configPath = path_1.default.join(sandboxPath, 'config.json');
|
|
197
|
+
await promises_1.default.writeFile(configPath, JSON.stringify(options));
|
|
198
|
+
return configPath;
|
|
199
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
4
|
+
const sandbox_1 = require("../../sandbox");
|
|
5
|
+
const runBackportViaCli_1 = require("./runBackportViaCli");
|
|
6
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
7
|
+
describe('interactive error handling', () => {
|
|
8
|
+
it('when branch is missing', async () => {
|
|
9
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
10
|
+
'--skip-remote-config',
|
|
11
|
+
'--repo=backport-org/backport-e2e',
|
|
12
|
+
`--accessToken=${accessToken}`,
|
|
13
|
+
]);
|
|
14
|
+
expect(output).toMatchInlineSnapshot(`
|
|
15
|
+
"Please specify a target branch: \\"--branch 6.1\\".
|
|
16
|
+
|
|
17
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
|
|
18
|
+
`);
|
|
19
|
+
});
|
|
20
|
+
it('when supplying invalid argument', async () => {
|
|
21
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([`--foo`]);
|
|
22
|
+
expect(output).toMatchInlineSnapshot(`
|
|
23
|
+
"Unknown argument: foo
|
|
24
|
+
Run \\"backport --help\\" to see all options"
|
|
25
|
+
`);
|
|
26
|
+
});
|
|
27
|
+
it('when access token is invalid', async () => {
|
|
28
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
29
|
+
'--branch=foo',
|
|
30
|
+
'--repo=foo/bar',
|
|
31
|
+
'--accessToken=some-token',
|
|
32
|
+
]);
|
|
33
|
+
expect(output).toContain('Please check your access token and make sure it is valid');
|
|
34
|
+
});
|
|
35
|
+
it(`when repo doesn't exist`, async () => {
|
|
36
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
37
|
+
'--branch=foo',
|
|
38
|
+
'--repo=foo/bar',
|
|
39
|
+
'--author=sqren',
|
|
40
|
+
`--accessToken=${accessToken}`,
|
|
41
|
+
]);
|
|
42
|
+
expect(output).toMatchInlineSnapshot(`"The repository \\"foo/bar\\" doesn't exist"`);
|
|
43
|
+
});
|
|
44
|
+
it(`when given branch is invalid`, async () => {
|
|
45
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
46
|
+
'--branch=foo',
|
|
47
|
+
'--repo=backport-org/backport-e2e',
|
|
48
|
+
'--pr=9',
|
|
49
|
+
`--accessToken=${accessToken}`,
|
|
50
|
+
]);
|
|
51
|
+
expect(output).toMatchInlineSnapshot(`"The branch \\"foo\\" does not exist"`);
|
|
52
|
+
});
|
|
53
|
+
it(`when encountering conflicts`, async () => {
|
|
54
|
+
const backportDir = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
55
|
+
await (0, sandbox_1.resetSandbox)(backportDir);
|
|
56
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
57
|
+
'--repo=backport-org/repo-with-conflicts',
|
|
58
|
+
'--pr=12',
|
|
59
|
+
'--branch=7.x',
|
|
60
|
+
`--accessToken=${accessToken}`,
|
|
61
|
+
`--dir=${backportDir}`,
|
|
62
|
+
'--dry-run',
|
|
63
|
+
], {
|
|
64
|
+
waitForString: 'Press ENTER when the conflicts',
|
|
65
|
+
timeoutSeconds: 5,
|
|
66
|
+
});
|
|
67
|
+
// //@ts-expect-error
|
|
68
|
+
// const lineToReplace = output.match(
|
|
69
|
+
// /Conflicting files:[\s]+- (.*[\s].*)la-liga.md/
|
|
70
|
+
// )[1];
|
|
71
|
+
// const lineWithoutBreaks = lineToReplace.replace(/\s/g, '');
|
|
72
|
+
// const outputReplaced = output
|
|
73
|
+
// .replace(lineToReplace, lineWithoutBreaks)
|
|
74
|
+
// .replaceAll(backportDir, '<BACKPORT_DIR>');
|
|
75
|
+
const outputReplaced = output
|
|
76
|
+
.replaceAll('\n', '')
|
|
77
|
+
.replaceAll(backportDir, '<BACKPORT_DIR>');
|
|
78
|
+
expect(outputReplaced).toMatchInlineSnapshot(`"Backporting to 7.x:The commit could not be backported due to conflictsPlease fix the conflicts in <BACKPORT_DIR>Hint: Before fixing the conflicts manually you should consider backporting the following pull requests to \\"7.x\\": - Change Barca to Braithwaite (#8) (backport missing) https://github.com/backport-org/repo-with-conflicts/pull/8? Fix the following conflicts manually:Conflicting files: - <BACKPORT_DIR>/la-liga.mdPress ENTER when the conflicts are resolved and files are staged (Y/n)"`);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
9
|
+
const sandbox_1 = require("../../sandbox");
|
|
10
|
+
const runBackportViaCli_1 = require("./runBackportViaCli");
|
|
11
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
12
|
+
describe('non interactive (json) error handling', () => {
|
|
13
|
+
it(`when access token is missing`, async () => {
|
|
14
|
+
const configFilePath = await createConfigFile({});
|
|
15
|
+
const { output, code } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
16
|
+
'--json',
|
|
17
|
+
`--globalConfigFile=${configFilePath}`,
|
|
18
|
+
]);
|
|
19
|
+
const backportResult = JSON.parse(output);
|
|
20
|
+
// remove absolute path to avoid issues on ci
|
|
21
|
+
const errorMessage = backportResult.errorMessage.replace(configFilePath, '<GLOBAL_CONFIG_FILE>');
|
|
22
|
+
expect(code).toBe(1);
|
|
23
|
+
expect(backportResult.status).toBe('failure');
|
|
24
|
+
expect(errorMessage).toMatchInlineSnapshot(`
|
|
25
|
+
"Please update your config file: \\"<GLOBAL_CONFIG_FILE>\\".
|
|
26
|
+
It must contain a valid \\"accessToken\\".
|
|
27
|
+
|
|
28
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#global-config-backportconfigjson"
|
|
29
|
+
`);
|
|
30
|
+
});
|
|
31
|
+
it('when target branches cannot be inferred from pull request', async () => {
|
|
32
|
+
const { output, code } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
33
|
+
'--json',
|
|
34
|
+
'--repo=backport-org/backport-e2e',
|
|
35
|
+
'--pr=9',
|
|
36
|
+
`--accessToken=${accessToken}`,
|
|
37
|
+
]);
|
|
38
|
+
expect(code).toBe(0);
|
|
39
|
+
const backportResult = JSON.parse(output);
|
|
40
|
+
expect(backportResult.status).toBe('aborted');
|
|
41
|
+
expect(backportResult.error).toEqual({
|
|
42
|
+
errorContext: { code: 'no-branches-exception' },
|
|
43
|
+
name: 'BackportError',
|
|
44
|
+
});
|
|
45
|
+
expect(backportResult.errorMessage).toBe('There are no branches to backport to. Aborting.');
|
|
46
|
+
});
|
|
47
|
+
it(`when target branch and branch label mapping are missing`, async () => {
|
|
48
|
+
const { output, code } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
49
|
+
'--json',
|
|
50
|
+
`--access-token=${accessToken}`,
|
|
51
|
+
]);
|
|
52
|
+
expect(code).toBe(1);
|
|
53
|
+
const backportResult = JSON.parse(output);
|
|
54
|
+
expect(backportResult.status).toBe('failure');
|
|
55
|
+
expect(backportResult.errorMessage).toMatchInlineSnapshot(`
|
|
56
|
+
"Please specify a target branch: \\"--branch 6.1\\".
|
|
57
|
+
|
|
58
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
|
|
59
|
+
`);
|
|
60
|
+
});
|
|
61
|
+
it(`when argument is invalid`, async () => {
|
|
62
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)(['--json', '--foo'], {});
|
|
63
|
+
const backportResult = JSON.parse(output);
|
|
64
|
+
expect(backportResult.status).toBe('failure');
|
|
65
|
+
expect(backportResult.errorMessage).toEqual('Unknown argument: foo');
|
|
66
|
+
});
|
|
67
|
+
it('when `--repo` is invalid', async () => {
|
|
68
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
69
|
+
'--json',
|
|
70
|
+
'--repo=backport-org/backport-e2e-foo',
|
|
71
|
+
`--accessToken=${accessToken}`,
|
|
72
|
+
]);
|
|
73
|
+
const backportResult = JSON.parse(output);
|
|
74
|
+
expect(backportResult.status).toBe('failure');
|
|
75
|
+
expect(backportResult.errorMessage).toEqual('The repository "backport-org/backport-e2e-foo" doesn\'t exist');
|
|
76
|
+
});
|
|
77
|
+
it('when `--sha` is invalid', async () => {
|
|
78
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
79
|
+
'--json',
|
|
80
|
+
'--repo=backport-org/backport-e2e',
|
|
81
|
+
'--sha=abcdefg',
|
|
82
|
+
`--accessToken=${accessToken}`,
|
|
83
|
+
]);
|
|
84
|
+
const backportResult = JSON.parse(output);
|
|
85
|
+
expect(backportResult.status).toBe('failure');
|
|
86
|
+
expect(backportResult.errorMessage).toEqual('No commit found on branch "master" with sha "abcdefg"');
|
|
87
|
+
});
|
|
88
|
+
it('when `--branch` is invalid', async () => {
|
|
89
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
90
|
+
'--json',
|
|
91
|
+
'--repo=backport-org/backport-e2e',
|
|
92
|
+
'--pr=9',
|
|
93
|
+
'--branch=foobar',
|
|
94
|
+
`--accessToken=${accessToken}`,
|
|
95
|
+
]);
|
|
96
|
+
const backportResult = JSON.parse(output);
|
|
97
|
+
expect(backportResult.status).toBe('failure');
|
|
98
|
+
expect(backportResult.error).toEqual({
|
|
99
|
+
name: 'BackportError',
|
|
100
|
+
errorContext: {
|
|
101
|
+
code: 'message-only-exception',
|
|
102
|
+
message: 'The branch "foobar" does not exist',
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
it('when `--branch` tries to inject argument', async () => {
|
|
107
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
108
|
+
'--json',
|
|
109
|
+
'--repo=backport-org/backport-e2e',
|
|
110
|
+
'--pr=9',
|
|
111
|
+
'--branch=--foo bar',
|
|
112
|
+
`--accessToken=${accessToken}`,
|
|
113
|
+
]);
|
|
114
|
+
const backportResult = JSON.parse(output);
|
|
115
|
+
expect(backportResult.status).toBe('failure');
|
|
116
|
+
expect(backportResult.error).toEqual({
|
|
117
|
+
name: 'BackportError',
|
|
118
|
+
errorContext: {
|
|
119
|
+
code: 'message-only-exception',
|
|
120
|
+
message: 'The branch "--foo bar" does not exist',
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
it('when `--pr` is invalid', async () => {
|
|
125
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
126
|
+
'--json',
|
|
127
|
+
'--repo=backport-org/backport-e2e',
|
|
128
|
+
'--pr=900',
|
|
129
|
+
'--branch=7.x',
|
|
130
|
+
`--accessToken=${accessToken}`,
|
|
131
|
+
]);
|
|
132
|
+
const backportResult = JSON.parse(output);
|
|
133
|
+
expect(backportResult.status).toEqual('failure');
|
|
134
|
+
expect(backportResult.errorMessage).toEqual('Could not resolve to a PullRequest with the number of 900. (Github API v4)');
|
|
135
|
+
});
|
|
136
|
+
it('when encountering conflicts', async () => {
|
|
137
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
138
|
+
'--json',
|
|
139
|
+
'--repo=backport-org/repo-with-conflicts',
|
|
140
|
+
'--pr=12',
|
|
141
|
+
'--branch=7.x',
|
|
142
|
+
`--accessToken=${accessToken}`,
|
|
143
|
+
]);
|
|
144
|
+
const backportResult = JSON.parse(output);
|
|
145
|
+
expect(backportResult.status).toEqual('success');
|
|
146
|
+
expect(
|
|
147
|
+
//@ts-expect-error
|
|
148
|
+
backportResult.results[0].error.errorContext.conflictingFiles).toEqual(['la-liga.md']);
|
|
149
|
+
});
|
|
150
|
+
it('when `--source-branch` is invalid', async () => {
|
|
151
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
152
|
+
'--json',
|
|
153
|
+
'--repo=backport-org/backport-e2e',
|
|
154
|
+
'--pr=9',
|
|
155
|
+
'--branch=7.x',
|
|
156
|
+
'--source-branch=foo',
|
|
157
|
+
`--accessToken=${accessToken}`,
|
|
158
|
+
]);
|
|
159
|
+
const backportResult = JSON.parse(output);
|
|
160
|
+
expect(backportResult.status).toBe('success');
|
|
161
|
+
expect(backportResult.results[0]).toEqual({
|
|
162
|
+
error: {
|
|
163
|
+
context: {
|
|
164
|
+
cmdArgs: ['checkout', 'foo'],
|
|
165
|
+
code: 1,
|
|
166
|
+
stderr: "error: pathspec 'foo' did not match any file(s) known to git\n",
|
|
167
|
+
stdout: '',
|
|
168
|
+
},
|
|
169
|
+
name: 'SpawnError',
|
|
170
|
+
},
|
|
171
|
+
status: 'unhandled-error',
|
|
172
|
+
targetBranch: '7.x',
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
it('when attempting to backport unmerged PR', async () => {
|
|
176
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
177
|
+
'--json',
|
|
178
|
+
'--repo=backport-org/backport-e2e',
|
|
179
|
+
'--pr=12',
|
|
180
|
+
`--accessToken=${accessToken}`,
|
|
181
|
+
]);
|
|
182
|
+
const backportResult = JSON.parse(output);
|
|
183
|
+
expect(backportResult.status).toBe('failure');
|
|
184
|
+
expect(backportResult.error).toEqual({
|
|
185
|
+
errorContext: {
|
|
186
|
+
code: 'message-only-exception',
|
|
187
|
+
message: 'The PR #12 is not merged',
|
|
188
|
+
},
|
|
189
|
+
name: 'BackportError',
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
async function createConfigFile(options) {
|
|
194
|
+
const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
195
|
+
const configPath = path_1.default.join(sandboxPath, 'config.json');
|
|
196
|
+
await promises_1.default.writeFile(configPath, JSON.stringify(options));
|
|
197
|
+
return configPath;
|
|
198
|
+
}
|
|
@@ -6,7 +6,7 @@ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
|
6
6
|
describe('repo-with-backportrc-removed (missing .backportrc.json config file)', () => {
|
|
7
7
|
it('lists commits', async () => {
|
|
8
8
|
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
9
|
-
'--branch=
|
|
9
|
+
'--branch=production',
|
|
10
10
|
'--repo=backport-org/repo-with-backportrc-removed',
|
|
11
11
|
`--accessToken=${accessToken}`,
|
|
12
12
|
], { waitForString: 'Select commit' });
|
|
@@ -10,7 +10,7 @@ const lodash_1 = require("lodash");
|
|
|
10
10
|
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
11
11
|
const sandbox_1 = require("../../sandbox");
|
|
12
12
|
jest.setTimeout(15000);
|
|
13
|
-
function runBackportViaCli(backportArgs, { timeoutSeconds =
|
|
13
|
+
function runBackportViaCli(backportArgs, { timeoutSeconds = 3, showOra, waitForString, cwd, } = {}) {
|
|
14
14
|
const tsNodeBinary = path_1.default.resolve('./node_modules/.bin/ts-node');
|
|
15
15
|
const entrypointFile = path_1.default.resolve('./src/entrypoint.cli.ts');
|
|
16
16
|
const randomString = Math.random().toString(36).slice(2);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "8.
|
|
1
|
+
export declare const PACKAGE_VERSION = "8.2.0";
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"branches",
|
|
15
15
|
"branching"
|
|
16
16
|
],
|
|
17
|
-
"version": "8.
|
|
17
|
+
"version": "8.2.0",
|
|
18
18
|
"main": "./dist/entrypoint.module.js",
|
|
19
19
|
"types": "dist/entrypoint.module.d.ts",
|
|
20
20
|
"bin": {
|
|
@@ -90,16 +90,16 @@
|
|
|
90
90
|
"@types/inquirer": "^8.2.0",
|
|
91
91
|
"@types/jest": "^27.4.1",
|
|
92
92
|
"@types/lodash": "^4.14.180",
|
|
93
|
-
"@types/node": "^17.0.
|
|
93
|
+
"@types/node": "^17.0.23",
|
|
94
94
|
"@types/safe-json-stringify": "^1.1.2",
|
|
95
95
|
"@types/yargs": "^17.0.10",
|
|
96
96
|
"@types/yargs-parser": "^21.0.0",
|
|
97
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
98
|
-
"@typescript-eslint/parser": "^5.
|
|
97
|
+
"@typescript-eslint/eslint-plugin": "^5.16.0",
|
|
98
|
+
"@typescript-eslint/parser": "^5.16.0",
|
|
99
99
|
"eslint": "^8.11.0",
|
|
100
100
|
"eslint-config-prettier": "^8.5.0",
|
|
101
101
|
"eslint-plugin-import": "^2.25.4",
|
|
102
|
-
"eslint-plugin-jest": "^26.1.
|
|
102
|
+
"eslint-plugin-jest": "^26.1.2",
|
|
103
103
|
"eslint-plugin-prettier": "^4.0.0",
|
|
104
104
|
"graphql-config": "^4.1.0",
|
|
105
105
|
"husky": "^7.0.4",
|