backport 8.5.1 → 8.5.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/backportRun.js +1 -5
- package/dist/entrypoint.module.private.test.js +7 -3
- package/dist/lib/BackportError.d.ts +3 -0
- package/dist/lib/BackportError.js +2 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +3 -2
- package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +18 -0
- package/dist/lib/getCommits.js +1 -1
- package/dist/lib/getTargetBranches.test.js +0 -4
- package/dist/lib/git.js +9 -2
- package/dist/lib/github/v4/validateTargetBranch.d.ts +15 -0
- package/dist/lib/github/v4/{validateTargetBranches.js → validateTargetBranch.js} +13 -17
- package/dist/lib/github/v4/{validateTargetBranches.private.test.d.ts → validateTargetBranch.private.test.d.ts} +0 -0
- package/dist/lib/github/v4/validateTargetBranch.private.test.js +23 -0
- package/dist/runSequentially.js +9 -3
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +2 -2
- package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +10 -8
- package/dist/test/nockHelpers.js +1 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +1 -1
- package/dist/lib/github/v4/validateTargetBranches.d.ts +0 -9
- package/dist/lib/github/v4/validateTargetBranches.private.test.js +0 -51
package/dist/backportRun.js
CHANGED
|
@@ -11,7 +11,6 @@ const getCommits_1 = require("./lib/getCommits");
|
|
|
11
11
|
const getTargetBranches_1 = require("./lib/getTargetBranches");
|
|
12
12
|
const createStatusComment_1 = require("./lib/github/v3/createStatusComment");
|
|
13
13
|
const apiRequestV4_1 = require("./lib/github/v4/apiRequestV4");
|
|
14
|
-
const validateTargetBranches_1 = require("./lib/github/v4/validateTargetBranches");
|
|
15
14
|
const logger_1 = require("./lib/logger");
|
|
16
15
|
const ora_1 = require("./lib/ora");
|
|
17
16
|
const setupRepo_1 = require("./lib/setupRepo");
|
|
@@ -52,10 +51,7 @@ async function backportRun({ processArgs, optionsFromModule = {}, exitCodeOnFail
|
|
|
52
51
|
}
|
|
53
52
|
const targetBranches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
|
|
54
53
|
logger.info('Target branches', targetBranches);
|
|
55
|
-
await
|
|
56
|
-
(0, setupRepo_1.setupRepo)(options),
|
|
57
|
-
(0, validateTargetBranches_1.validateTargetBranches)(options, targetBranches),
|
|
58
|
-
]);
|
|
54
|
+
await (0, setupRepo_1.setupRepo)(options);
|
|
59
55
|
const results = await (0, runSequentially_1.runSequentially)({
|
|
60
56
|
options,
|
|
61
57
|
commits,
|
|
@@ -56,9 +56,13 @@ describe('entrypoint.module', () => {
|
|
|
56
56
|
},
|
|
57
57
|
}));
|
|
58
58
|
});
|
|
59
|
-
it('should
|
|
60
|
-
expect(response.status).toBe('
|
|
61
|
-
expect
|
|
59
|
+
it('should return handled error', async () => {
|
|
60
|
+
expect(response.status).toBe('success');
|
|
61
|
+
// @ts-expect-error
|
|
62
|
+
expect(response.results[0].error.errorContext).toEqual({
|
|
63
|
+
code: 'invalid-branch-exception',
|
|
64
|
+
branchName: '--foo',
|
|
65
|
+
});
|
|
62
66
|
});
|
|
63
67
|
});
|
|
64
68
|
describe('when missing branches to backport to', () => {
|
|
@@ -9,6 +9,8 @@ function getMessage(errorContext) {
|
|
|
9
9
|
return 'There are no branches to backport to. Aborting.';
|
|
10
10
|
case 'abort-conflict-resolution-exception':
|
|
11
11
|
return 'Conflict resolution was aborted by the user';
|
|
12
|
+
case 'invalid-branch-exception':
|
|
13
|
+
return `The branch "${errorContext.branchName}" does not exist`;
|
|
12
14
|
case 'message-only-exception':
|
|
13
15
|
return errorContext.message;
|
|
14
16
|
}
|
|
@@ -19,6 +19,7 @@ const addReviewersToPullRequest_1 = require("./github/v3/addReviewersToPullReque
|
|
|
19
19
|
const createPullRequest_1 = require("./github/v3/createPullRequest");
|
|
20
20
|
const enablePullRequestAutoMerge_1 = require("./github/v4/enablePullRequestAutoMerge");
|
|
21
21
|
const fetchCommitBySha_1 = require("./github/v4/fetchCommits/fetchCommitBySha");
|
|
22
|
+
const validateTargetBranch_1 = require("./github/v4/validateTargetBranch");
|
|
22
23
|
const logger_1 = require("./logger");
|
|
23
24
|
const ora_1 = require("./ora");
|
|
24
25
|
const prompts_1 = require("./prompts");
|
|
@@ -33,12 +34,12 @@ async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBr
|
|
|
33
34
|
const backportBranch = getBackportBranchName(targetBranch, commits);
|
|
34
35
|
const repoForkOwner = (0, git_1.getRepoForkOwner)(options);
|
|
35
36
|
(0, logger_1.consoleLog)(`\n${chalk_1.default.bold(`Backporting to ${targetBranch}:`)}`);
|
|
36
|
-
|
|
37
|
+
await (0, validateTargetBranch_1.validateTargetBranch)({ ...options, branchName: targetBranch });
|
|
37
38
|
const [gitConfigAuthor] = await Promise.all([
|
|
38
39
|
(0, author_1.getGitConfigAuthor)(options),
|
|
39
40
|
(0, git_1.createBackportBranch)({
|
|
40
41
|
options,
|
|
41
|
-
sourceBranch,
|
|
42
|
+
sourceBranch: getSourceBranchFromCommits(commits),
|
|
42
43
|
targetBranch,
|
|
43
44
|
backportBranch,
|
|
44
45
|
}),
|
|
@@ -76,6 +76,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
76
76
|
sourceBranch: 'myDefaultSourceBranch',
|
|
77
77
|
sourcePRLabels: [],
|
|
78
78
|
targetPRLabels: ['backport'],
|
|
79
|
+
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
79
80
|
};
|
|
80
81
|
const commits = [
|
|
81
82
|
{
|
|
@@ -125,6 +126,11 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
125
126
|
pullRequestStates: [],
|
|
126
127
|
},
|
|
127
128
|
];
|
|
129
|
+
(0, nockHelpers_1.mockGqlRequest)({
|
|
130
|
+
name: 'GetBranchId',
|
|
131
|
+
statusCode: 200,
|
|
132
|
+
body: { data: { repository: { ref: { id: 'foo' } } } },
|
|
133
|
+
});
|
|
128
134
|
const scope = (0, nock_1.default)('https://api.github.com')
|
|
129
135
|
.post('/repos/elastic/kibana/pulls')
|
|
130
136
|
.reply(200, { number: 1337, html_url: 'myHtmlUrl' });
|
|
@@ -176,6 +182,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
176
182
|
expect(ora_1.default.mock.calls.map((call) => call[0].text))
|
|
177
183
|
.toMatchInlineSnapshot(`
|
|
178
184
|
Array [
|
|
185
|
+
"",
|
|
179
186
|
"Pulling latest changes",
|
|
180
187
|
"Cherry-picking: My original commit message (#1000)",
|
|
181
188
|
"Cherry-picking: My other commit message (#2000)",
|
|
@@ -203,6 +210,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
203
210
|
reviewers: [],
|
|
204
211
|
sourcePRLabels: [],
|
|
205
212
|
targetPRLabels: ['backport'],
|
|
213
|
+
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
206
214
|
};
|
|
207
215
|
const commits = [
|
|
208
216
|
{
|
|
@@ -221,6 +229,11 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
221
229
|
pullRequestStates: [],
|
|
222
230
|
},
|
|
223
231
|
];
|
|
232
|
+
(0, nockHelpers_1.mockGqlRequest)({
|
|
233
|
+
name: 'GetBranchId',
|
|
234
|
+
statusCode: 200,
|
|
235
|
+
body: { data: { repository: { ref: { id: 'foo' } } } },
|
|
236
|
+
});
|
|
224
237
|
const scope = (0, nock_1.default)('https://api.github.com')
|
|
225
238
|
.post('/repos/elastic/kibana/pulls')
|
|
226
239
|
.reply(200, { number: 1337, html_url: 'myHtmlUrl' });
|
|
@@ -276,6 +289,11 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
276
289
|
sourcePRLabels: [],
|
|
277
290
|
targetPRLabels: ['backport'],
|
|
278
291
|
};
|
|
292
|
+
(0, nockHelpers_1.mockGqlRequest)({
|
|
293
|
+
name: 'GetBranchId',
|
|
294
|
+
statusCode: 200,
|
|
295
|
+
body: { data: { repository: { ref: { id: 'foo' } } } },
|
|
296
|
+
});
|
|
279
297
|
const scope = (0, nock_1.default)('https://api.github.com')
|
|
280
298
|
.post('/repos/elastic/kibana/pulls')
|
|
281
299
|
.reply(200, { number: 1337, html_url: 'myHtmlUrl' });
|
package/dist/lib/getCommits.js
CHANGED
|
@@ -35,7 +35,7 @@ async function getCommits(options) {
|
|
|
35
35
|
const pullNumbers = Array.isArray(options.pullNumber)
|
|
36
36
|
? options.pullNumber
|
|
37
37
|
: [options.pullNumber];
|
|
38
|
-
spinner.text = `Loading pull request
|
|
38
|
+
spinner.text = `Loading pull request ${pullNumbers
|
|
39
39
|
.map((pullNumber) => `#${pullNumber}`)
|
|
40
40
|
.join(', ')}`;
|
|
41
41
|
const commits = await Promise.all(pullNumbers.map((pullNumber) => (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({ ...options, pullNumber })));
|
|
@@ -24,7 +24,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const getTargetBranches_1 = require("./getTargetBranches");
|
|
27
|
-
const validateTargetBranches = __importStar(require("./github/v4/validateTargetBranches"));
|
|
28
27
|
const prompts = __importStar(require("./prompts"));
|
|
29
28
|
describe('getTargetBranches', () => {
|
|
30
29
|
let promptSpy;
|
|
@@ -80,9 +79,6 @@ describe('getTargetBranches', () => {
|
|
|
80
79
|
describe('when `options.targetBranches` is not empty', () => {
|
|
81
80
|
let branches;
|
|
82
81
|
beforeEach(async () => {
|
|
83
|
-
jest
|
|
84
|
-
.spyOn(validateTargetBranches, 'validateTargetBranches')
|
|
85
|
-
.mockResolvedValueOnce();
|
|
86
82
|
branches = await (0, getTargetBranches_1.getTargetBranches)({
|
|
87
83
|
targetBranches: ['branchA', 'branchB'],
|
|
88
84
|
targetBranchChoices: [],
|
package/dist/lib/git.js
CHANGED
|
@@ -176,8 +176,15 @@ async function fetchBranch(options, branch) {
|
|
|
176
176
|
exports.fetchBranch = fetchBranch;
|
|
177
177
|
async function getIsMergeCommit(options, sha) {
|
|
178
178
|
const cwd = (0, env_1.getRepoPath)(options);
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
try {
|
|
180
|
+
const res = await (0, child_process_promisified_1.spawnPromise)('git', ['rev-list', '-1', '--merges', `${sha}~1..${sha}`], cwd);
|
|
181
|
+
return res.stdout !== '';
|
|
182
|
+
}
|
|
183
|
+
catch (e) {
|
|
184
|
+
const shortSha = (0, commitFormatters_1.getShortSha)(sha);
|
|
185
|
+
logger_1.logger.info(`Could not determine if ${shortSha} is a merge commit. Will assume it is not`, e);
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
181
188
|
}
|
|
182
189
|
exports.getIsMergeCommit = getIsMergeCommit;
|
|
183
190
|
async function getShasInMergeCommit(options, sha) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface TargetBranchResponse {
|
|
2
|
+
repository: {
|
|
3
|
+
ref: {
|
|
4
|
+
id: string;
|
|
5
|
+
} | null;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export declare function validateTargetBranch({ accessToken, repoName, repoOwner, branchName, githubApiBaseUrlV4, interactive, }: {
|
|
9
|
+
accessToken: string;
|
|
10
|
+
repoOwner: string;
|
|
11
|
+
repoName: string;
|
|
12
|
+
branchName: string;
|
|
13
|
+
githubApiBaseUrlV4?: string;
|
|
14
|
+
interactive: boolean;
|
|
15
|
+
}): Promise<void>;
|
|
@@ -3,13 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.validateTargetBranch = void 0;
|
|
7
7
|
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
8
|
const BackportError_1 = require("../../BackportError");
|
|
9
|
+
const ora_1 = require("../../ora");
|
|
9
10
|
const apiRequestV4_1 = require("./apiRequestV4");
|
|
10
|
-
async function
|
|
11
|
+
async function validateTargetBranch({ accessToken, repoName, repoOwner, branchName, githubApiBaseUrlV4 = 'https://api.github.com/graphql', interactive, }) {
|
|
11
12
|
const query = (0, graphql_tag_1.default) `
|
|
12
|
-
query
|
|
13
|
+
query GetBranchId(
|
|
13
14
|
$repoOwner: String!
|
|
14
15
|
$repoName: String!
|
|
15
16
|
$branchName: String!
|
|
@@ -21,6 +22,7 @@ async function fetchTargetBranch({ accessToken, repoName, repoOwner, branchName,
|
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
`;
|
|
25
|
+
const spinner = (0, ora_1.ora)(interactive, '').start();
|
|
24
26
|
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
25
27
|
githubApiBaseUrlV4,
|
|
26
28
|
accessToken,
|
|
@@ -28,19 +30,13 @@ async function fetchTargetBranch({ accessToken, repoName, repoOwner, branchName,
|
|
|
28
30
|
variables: { repoOwner, repoName, branchName },
|
|
29
31
|
});
|
|
30
32
|
if (!res.repository.ref) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
async function validateTargetBranches({ accessToken, repoName, repoOwner, githubApiBaseUrlV4 }, targetBranches) {
|
|
36
|
-
await Promise.all(targetBranches.map((targetBranch) => {
|
|
37
|
-
return fetchTargetBranch({
|
|
38
|
-
accessToken,
|
|
39
|
-
repoName,
|
|
40
|
-
repoOwner,
|
|
41
|
-
branchName: targetBranch,
|
|
42
|
-
githubApiBaseUrlV4,
|
|
33
|
+
spinner.fail(`The branch "${branchName}" does not exist`);
|
|
34
|
+
throw new BackportError_1.BackportError({
|
|
35
|
+
code: 'invalid-branch-exception',
|
|
36
|
+
branchName: branchName,
|
|
43
37
|
});
|
|
44
|
-
}
|
|
38
|
+
}
|
|
39
|
+
spinner.stop();
|
|
40
|
+
return;
|
|
45
41
|
}
|
|
46
|
-
exports.
|
|
42
|
+
exports.validateTargetBranch = validateTargetBranch;
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
|
|
4
|
+
const validateTargetBranch_1 = require("./validateTargetBranch");
|
|
5
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
6
|
+
describe('validateTargetBranch', () => {
|
|
7
|
+
it('throws when branch is invalid', async () => {
|
|
8
|
+
const options = {
|
|
9
|
+
repoOwner: 'backport-org',
|
|
10
|
+
repoName: 'repo-with-target-branches',
|
|
11
|
+
accessToken,
|
|
12
|
+
};
|
|
13
|
+
await expect(() => (0, validateTargetBranch_1.validateTargetBranch)({ ...options, branchName: 'foo' })).rejects.toThrowError('The branch "foo" does not exist');
|
|
14
|
+
});
|
|
15
|
+
it('resolves when branch is valid', async () => {
|
|
16
|
+
const options = {
|
|
17
|
+
repoOwner: 'backport-org',
|
|
18
|
+
repoName: 'repo-with-target-branches',
|
|
19
|
+
accessToken,
|
|
20
|
+
};
|
|
21
|
+
expect(await (0, validateTargetBranch_1.validateTargetBranch)({ ...options, branchName: 'production' })).toEqual(undefined);
|
|
22
|
+
});
|
|
23
|
+
});
|
package/dist/runSequentially.js
CHANGED
|
@@ -43,10 +43,16 @@ async function runSequentially({ options, commits, targetBranches, }) {
|
|
|
43
43
|
else {
|
|
44
44
|
throw e;
|
|
45
45
|
}
|
|
46
|
-
(0, logger_1.consoleLog)(isHandledError
|
|
47
|
-
? e.message
|
|
48
|
-
: 'An unhandled error occurred while backporting commit. Please see the logs for details');
|
|
49
46
|
logger_1.logger.error('runSequentially failed', e);
|
|
47
|
+
if (isHandledError) {
|
|
48
|
+
// don't output anything. Already handled in application
|
|
49
|
+
if (e.errorContext.code === 'invalid-branch-exception') {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
(0, logger_1.consoleLog)(e.message);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
(0, logger_1.consoleLog)('An unhandled error occurred while backporting commit. Please see the logs for details');
|
|
50
56
|
}
|
|
51
57
|
});
|
|
52
58
|
// return the results for consumers to programatically read
|
|
@@ -49,8 +49,8 @@ describe('interactive error handling', () => {
|
|
|
49
49
|
'--repo=backport-org/backport-e2e',
|
|
50
50
|
'--pr=9',
|
|
51
51
|
`--accessToken=${accessToken}`,
|
|
52
|
-
]);
|
|
53
|
-
expect(output).
|
|
52
|
+
], { showOra: true });
|
|
53
|
+
expect(output).toContain('✖ The branch "foo" does not exist');
|
|
54
54
|
});
|
|
55
55
|
it(`when encountering conflicts`, async () => {
|
|
56
56
|
const backportDir = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
@@ -95,12 +95,13 @@ describe('non interactive (json) error handling', () => {
|
|
|
95
95
|
`--accessToken=${accessToken}`,
|
|
96
96
|
]);
|
|
97
97
|
const backportResult = JSON.parse(output);
|
|
98
|
-
expect(backportResult.status).toBe('
|
|
99
|
-
expect
|
|
98
|
+
expect(backportResult.status).toBe('success');
|
|
99
|
+
//@ts-expect-error
|
|
100
|
+
expect(backportResult.results[0].error).toEqual({
|
|
100
101
|
name: 'BackportError',
|
|
101
102
|
errorContext: {
|
|
102
|
-
code: '
|
|
103
|
-
|
|
103
|
+
code: 'invalid-branch-exception',
|
|
104
|
+
branchName: 'foobar',
|
|
104
105
|
},
|
|
105
106
|
});
|
|
106
107
|
});
|
|
@@ -113,12 +114,13 @@ describe('non interactive (json) error handling', () => {
|
|
|
113
114
|
`--accessToken=${accessToken}`,
|
|
114
115
|
]);
|
|
115
116
|
const backportResult = JSON.parse(output);
|
|
116
|
-
expect(backportResult.status).toBe('
|
|
117
|
-
expect
|
|
117
|
+
expect(backportResult.status).toBe('success');
|
|
118
|
+
//@ts-expect-error
|
|
119
|
+
expect(backportResult.results[0].error).toEqual({
|
|
118
120
|
name: 'BackportError',
|
|
119
121
|
errorContext: {
|
|
120
|
-
code: '
|
|
121
|
-
|
|
122
|
+
code: 'invalid-branch-exception',
|
|
123
|
+
branchName: '--foo bar',
|
|
122
124
|
},
|
|
123
125
|
});
|
|
124
126
|
});
|
package/dist/test/nockHelpers.js
CHANGED
|
@@ -12,6 +12,7 @@ const nock_1 = __importDefault(require("nock"));
|
|
|
12
12
|
function mockGqlRequest({ name, statusCode, body, headers, apiBaseUrl, }) {
|
|
13
13
|
const { origin, pathname } = new url_1.URL(
|
|
14
14
|
// default to localhost as host to avoid CORS issues
|
|
15
|
+
// Remember to set `githubApiBaseUrlV4: 'http://localhost/graphql'` in options
|
|
15
16
|
apiBaseUrl ?? 'http://localhost/graphql');
|
|
16
17
|
const scope = (0, nock_1.default)(origin)
|
|
17
18
|
.post(pathname, (body) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "8.5.
|
|
1
|
+
export declare const PACKAGE_VERSION = "8.5.2";
|
package/package.json
CHANGED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ValidConfigOptions } from '../../../options/options';
|
|
2
|
-
export interface TargetBranchResponse {
|
|
3
|
-
repository: {
|
|
4
|
-
ref: {
|
|
5
|
-
id: string;
|
|
6
|
-
} | null;
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
export declare function validateTargetBranches({ accessToken, repoName, repoOwner, githubApiBaseUrlV4 }: ValidConfigOptions, targetBranches: string[]): Promise<void>;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
|
|
4
|
-
const validateTargetBranches_1 = require("./validateTargetBranches");
|
|
5
|
-
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
6
|
-
describe('validateTargetBranches', () => {
|
|
7
|
-
describe('no branches', () => {
|
|
8
|
-
it('resolves', async () => {
|
|
9
|
-
const options = {
|
|
10
|
-
repoOwner: 'backport-org',
|
|
11
|
-
repoName: 'repo-with-target-branches',
|
|
12
|
-
accessToken,
|
|
13
|
-
};
|
|
14
|
-
const targetBranches = [];
|
|
15
|
-
expect(await (0, validateTargetBranches_1.validateTargetBranches)(options, targetBranches)).toEqual(undefined);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
describe('one invalid and one valid branch', () => {
|
|
19
|
-
it('throws', async () => {
|
|
20
|
-
const options = {
|
|
21
|
-
repoOwner: 'backport-org',
|
|
22
|
-
repoName: 'repo-with-target-branches',
|
|
23
|
-
accessToken,
|
|
24
|
-
};
|
|
25
|
-
const targetBranches = ['production', 'foo'];
|
|
26
|
-
await expect(() => (0, validateTargetBranches_1.validateTargetBranches)(options, targetBranches)).rejects.toThrowError('The branch "foo" does not exist');
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
describe('two valid branches', () => {
|
|
30
|
-
it('resolves', async () => {
|
|
31
|
-
const options = {
|
|
32
|
-
repoOwner: 'backport-org',
|
|
33
|
-
repoName: 'repo-with-target-branches',
|
|
34
|
-
accessToken,
|
|
35
|
-
};
|
|
36
|
-
const targetBranches = ['production', 'staging'];
|
|
37
|
-
expect(await (0, validateTargetBranches_1.validateTargetBranches)(options, targetBranches)).toEqual(undefined);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
describe('two invalid branches', () => {
|
|
41
|
-
it('throws', async () => {
|
|
42
|
-
const options = {
|
|
43
|
-
repoOwner: 'backport-org',
|
|
44
|
-
repoName: 'repo-with-target-branches',
|
|
45
|
-
accessToken,
|
|
46
|
-
};
|
|
47
|
-
const targetBranches = ['foo', 'bar'];
|
|
48
|
-
await expect(() => (0, validateTargetBranches_1.validateTargetBranches)(options, targetBranches)).rejects.toThrow(/The branch "(foo|bar)" does not exist/);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|