backport 6.0.0 → 6.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +179 -52
- package/dist/entrypoint.cli.js +2 -0
- package/dist/entrypoint.module.d.ts +16 -4
- package/dist/entrypoint.module.js +41 -13
- package/dist/entrypoint.module.private.test.d.ts +1 -0
- package/dist/entrypoint.module.private.test.js +34 -0
- package/dist/main.js +1 -2
- package/dist/options/ConfigOptions.d.ts +16 -6
- package/dist/options/cliArgs.d.ts +36 -37
- package/dist/options/cliArgs.js +25 -24
- package/dist/options/cliArgs.test.js +6 -10
- package/dist/options/config/config.d.ts +28 -52
- package/dist/options/config/config.js +2 -36
- package/dist/options/config/config.test.js +10 -27
- package/dist/options/config/getOptionsFromGit.d.ts +3 -2
- package/dist/options/config/getOptionsFromGit.js +1 -3
- package/dist/options/config/globalConfig.js +2 -5
- package/dist/options/config/globalConfig.test.js +0 -2
- package/dist/options/config/projectConfig.test.js +51 -14
- package/dist/options/config/readConfigFile.d.ts +52 -0
- package/dist/options/config/readConfigFile.js +28 -2
- package/dist/options/options.d.ts +55 -32
- package/dist/options/options.js +101 -7
- package/dist/options/options.test.js +248 -97
- package/dist/options/parseRequiredOptions.d.ts +3 -3
- package/dist/options/parseRequiredOptions.js +2 -4
- package/dist/options/parseRequiredOptions.test.js +6 -11
- package/dist/runSequentially.test.js +40 -78
- package/dist/services/git.d.ts +5 -2
- package/dist/services/git.js +11 -10
- package/dist/services/git.test.js +12 -9
- package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -3
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +4 -5
- package/dist/services/github/v3/createPullRequest.js +10 -13
- package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/createPullRequest.test.js +110 -0
- package/dist/services/github/v3/createStatusComment.js +12 -14
- package/dist/services/github/v3/createStatusComment.test.js +58 -29
- package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
- package/dist/services/github/v4/apiRequestV4.js +1 -1
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +1 -1
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -1
- package/dist/services/github/v4/fetchAuthorId.d.ts +5 -2
- package/dist/services/github/v4/fetchAuthorId.js +5 -6
- package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +8 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +6 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +8 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +12 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +6 -8
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +10 -12
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +5 -7
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +5 -5
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +2 -6
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -2
- package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
- package/dist/services/github/v4/fetchProjectConfig.js +56 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
- package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +67 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +3 -1
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +22 -1
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +4 -1
- package/dist/services/github/v4/getOptionsFromGithub/query.js +3 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +32 -15
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +5 -1
- package/dist/services/sourceCommit/parseSourceCommit.js +2 -2
- package/dist/services/sourceCommit/parseSourceCommit.test.js +120 -5
- package/dist/test/inquirer.private.test.js +33 -36
- package/dist/test/integration/integration.private.test.js +114 -95
- package/dist/test/mockConfigFiles.d.ts +5 -0
- package/dist/test/mockConfigFiles.js +37 -0
- package/dist/test/nockHelpers.d.ts +1 -1
- package/dist/test/nockHelpers.js +4 -4
- package/dist/test/private/getDevAccessToken.js +1 -1
- package/dist/test/setupFiles/automatic-mocks.js +1 -29
- package/dist/ui/cherrypickAndCreatePullRequest.test.js +80 -28
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -9
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +13 -48
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +222 -260
- package/dist/ui/getCommits.d.ts +1 -1
- package/dist/ui/getCommitsWithoutBackports.d.ts +11 -0
- package/dist/ui/getCommitsWithoutBackports.js +53 -0
- package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/ui/getCommitsWithoutBackports.test.js +259 -0
- package/dist/ui/getTargetBranches.d.ts +2 -1
- package/dist/ui/getTargetBranches.js +17 -1
- package/dist/ui/maybeSetupRepo.js +4 -3
- package/dist/ui/maybeSetupRepo.test.js +49 -3
- package/dist/utils/excludeUndefined.d.ts +6 -0
- package/dist/utils/excludeUndefined.js +7 -0
- package/dist/utils/excludeUndefined.test.d.ts +1 -0
- package/dist/utils/excludeUndefined.test.js +24 -0
- package/package.json +9 -8
- package/yarn.lock +98 -77
|
@@ -3,6 +3,7 @@ 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
|
+
/* eslint-disable jest/no-commented-out-tests */
|
|
6
7
|
const os_1 = __importDefault(require("os"));
|
|
7
8
|
const path_1 = require("path");
|
|
8
9
|
const rest_1 = require("@octokit/rest");
|
|
@@ -11,6 +12,7 @@ const nock_1 = __importDefault(require("nock"));
|
|
|
11
12
|
const options_1 = require("../../options/options");
|
|
12
13
|
const runSequentially_1 = require("../../runSequentially");
|
|
13
14
|
const getCommits_1 = require("../../ui/getCommits");
|
|
15
|
+
const mockConfigFiles_1 = require("../mockConfigFiles");
|
|
14
16
|
const nockHelpers_1 = require("../nockHelpers");
|
|
15
17
|
const getDevAccessToken_1 = require("../private/getDevAccessToken");
|
|
16
18
|
jest.unmock('make-dir');
|
|
@@ -21,7 +23,7 @@ const HOMEDIR_PATH = (0, path_1.resolve)('./src/test/integration/mock-environmen
|
|
|
21
23
|
const REPO_OWNER = 'backport-org';
|
|
22
24
|
const REPO_NAME = 'integration-test';
|
|
23
25
|
const BRANCH_NAME = 'backport/7.x/commit-5bf29b7d';
|
|
24
|
-
const
|
|
26
|
+
const AUHTOR = 'sqren';
|
|
25
27
|
describe('integration', () => {
|
|
26
28
|
afterAll(() => {
|
|
27
29
|
nock_1.default.cleanAll();
|
|
@@ -29,6 +31,10 @@ describe('integration', () => {
|
|
|
29
31
|
beforeAll(() => {
|
|
30
32
|
// set alternative homedir
|
|
31
33
|
jest.spyOn(os_1.default, 'homedir').mockReturnValue(HOMEDIR_PATH);
|
|
34
|
+
(0, mockConfigFiles_1.mockConfigFiles)({
|
|
35
|
+
globalConfig: {},
|
|
36
|
+
projectConfig: {},
|
|
37
|
+
});
|
|
32
38
|
});
|
|
33
39
|
describe('when a single commit is backported', () => {
|
|
34
40
|
let res;
|
|
@@ -45,9 +51,10 @@ describe('integration', () => {
|
|
|
45
51
|
githubApiBaseUrlV3: 'https://api.foo.com',
|
|
46
52
|
ci: true,
|
|
47
53
|
sha: '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad',
|
|
48
|
-
|
|
54
|
+
author: AUHTOR,
|
|
49
55
|
accessToken,
|
|
50
|
-
|
|
56
|
+
repoOwner: 'backport-org',
|
|
57
|
+
repoName: 'integration-test',
|
|
51
58
|
});
|
|
52
59
|
const commits = await (0, getCommits_1.getCommits)(options);
|
|
53
60
|
const targetBranches = ['7.x'];
|
|
@@ -65,14 +72,23 @@ describe('integration', () => {
|
|
|
65
72
|
]);
|
|
66
73
|
});
|
|
67
74
|
it('sends the correct http body when creating pull request', () => {
|
|
68
|
-
expect(createPullRequestsMockCalls).
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
expect(createPullRequestsMockCalls).toMatchInlineSnapshot(`
|
|
76
|
+
Array [
|
|
77
|
+
Object {
|
|
78
|
+
"base": "7.x",
|
|
79
|
+
"body": "# Backport
|
|
80
|
+
|
|
81
|
+
This is an automatic backport to 7.x of:
|
|
82
|
+
- Add ❤️ emoji (5bf29b7d)
|
|
83
|
+
|
|
84
|
+
### Questions ?
|
|
85
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
86
|
+
",
|
|
87
|
+
"head": "sqren:backport/7.x/commit-5bf29b7d",
|
|
88
|
+
"title": "[7.x] Add ❤️ emoji",
|
|
89
|
+
},
|
|
90
|
+
]
|
|
91
|
+
`);
|
|
76
92
|
});
|
|
77
93
|
it('should not create new branches in origin (backport-org/integration-test)', async () => {
|
|
78
94
|
const branches = await getBranches({
|
|
@@ -85,7 +101,7 @@ describe('integration', () => {
|
|
|
85
101
|
it('should create branch in the fork (sqren/integration-test)', async () => {
|
|
86
102
|
const branches = await getBranches({
|
|
87
103
|
accessToken,
|
|
88
|
-
repoOwner:
|
|
104
|
+
repoOwner: AUHTOR,
|
|
89
105
|
repoName: REPO_NAME,
|
|
90
106
|
});
|
|
91
107
|
expect(branches.map((b) => b.name)).toEqual([
|
|
@@ -97,82 +113,75 @@ describe('integration', () => {
|
|
|
97
113
|
it('should have cherry picked the correct commit', async () => {
|
|
98
114
|
const branches = await getBranches({
|
|
99
115
|
accessToken,
|
|
100
|
-
repoOwner:
|
|
116
|
+
repoOwner: AUHTOR,
|
|
101
117
|
repoName: REPO_NAME,
|
|
102
118
|
});
|
|
103
119
|
const sha = branches.find((branch) => branch.name === '7.x')?.commit.sha;
|
|
104
120
|
expect(sha).toEqual('b68e4fcaaf4427fe1e902c718b3bb3f07b560fb5');
|
|
105
121
|
});
|
|
106
122
|
});
|
|
107
|
-
//
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
repoOwner: USERNAME,
|
|
170
|
-
repoName: REPO_NAME,
|
|
171
|
-
});
|
|
172
|
-
const sha = branches.find((branch) => branch.name === '7.x')?.commit.sha;
|
|
173
|
-
expect(sha).toEqual('foo');
|
|
174
|
-
});
|
|
175
|
-
});
|
|
123
|
+
// describe.skip('when two commits are backported', () => {
|
|
124
|
+
// let createPullRequestsMockCalls: unknown[];
|
|
125
|
+
// let res: Awaited<ReturnType<typeof runSequentially>>;
|
|
126
|
+
// let accessToken: string;
|
|
127
|
+
// beforeAll(async () => {
|
|
128
|
+
// accessToken = await getDevAccessToken();
|
|
129
|
+
// await resetState(accessToken);
|
|
130
|
+
// createPullRequestsMockCalls = mockCreatePullRequest({
|
|
131
|
+
// number: 1337,
|
|
132
|
+
// html_url: 'myHtmlUrl',
|
|
133
|
+
// });
|
|
134
|
+
// const options = {
|
|
135
|
+
// githubApiBaseUrlV3: 'https://api.foo.com',
|
|
136
|
+
// ci: true,
|
|
137
|
+
// sha: '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad',
|
|
138
|
+
// author: AUHTOR,
|
|
139
|
+
// accessToken,
|
|
140
|
+
// repoOwner: 'backport-org',
|
|
141
|
+
// reponame: 'integration-test',
|
|
142
|
+
// } as ValidConfigOptions;
|
|
143
|
+
// const commits = await getCommits(options);
|
|
144
|
+
// const targetBranches: string[] = ['7.x'];
|
|
145
|
+
// res = await runSequentially({ options, commits, targetBranches });
|
|
146
|
+
// });
|
|
147
|
+
// it('sends the correct http body when creating pull request', () => {
|
|
148
|
+
// expect(createPullRequestsMockCalls).toMatchInlineSnapshot();
|
|
149
|
+
// });
|
|
150
|
+
// it('returns pull request', () => {
|
|
151
|
+
// expect(res).toEqual([
|
|
152
|
+
// { pullRequestUrl: 'myHtmlUrl', success: true, targetBranch: '6.0' },
|
|
153
|
+
// ]);
|
|
154
|
+
// });
|
|
155
|
+
// it('should not create new branches in origin (backport-org/integration-test)', async () => {
|
|
156
|
+
// const branches = await getBranches({
|
|
157
|
+
// accessToken,
|
|
158
|
+
// repoOwner: REPO_OWNER,
|
|
159
|
+
// repoName: REPO_NAME,
|
|
160
|
+
// });
|
|
161
|
+
// expect(branches.map((b) => b.name)).toEqual(['7.x', '* master']);
|
|
162
|
+
// });
|
|
163
|
+
// it('should create branch in the fork (sqren/integration-test)', async () => {
|
|
164
|
+
// const branches = await getBranches({
|
|
165
|
+
// accessToken,
|
|
166
|
+
// repoOwner: AUHTOR,
|
|
167
|
+
// repoName: REPO_NAME,
|
|
168
|
+
// });
|
|
169
|
+
// expect(branches.map((b) => b.name)).toEqual([
|
|
170
|
+
// '7.x',
|
|
171
|
+
// 'backport/6.0/pr-85_commit-2e63475c',
|
|
172
|
+
// 'master',
|
|
173
|
+
// ]);
|
|
174
|
+
// });
|
|
175
|
+
// it('should have cherry picked the correct commit', async () => {
|
|
176
|
+
// const branches = await getBranches({
|
|
177
|
+
// accessToken,
|
|
178
|
+
// repoOwner: AUHTOR,
|
|
179
|
+
// repoName: REPO_NAME,
|
|
180
|
+
// });
|
|
181
|
+
// const sha = branches.find((branch) => branch.name === '7.x')?.commit.sha;
|
|
182
|
+
// expect(sha).toEqual('foo');
|
|
183
|
+
// });
|
|
184
|
+
// });
|
|
176
185
|
describe('when disabling fork mode', () => {
|
|
177
186
|
let res;
|
|
178
187
|
let accessToken;
|
|
@@ -185,12 +194,13 @@ describe('integration', () => {
|
|
|
185
194
|
html_url: 'myHtmlUrl',
|
|
186
195
|
});
|
|
187
196
|
const options = await (0, options_1.getOptions)([], {
|
|
197
|
+
author: AUHTOR,
|
|
188
198
|
githubApiBaseUrlV3: 'https://api.foo.com',
|
|
189
199
|
ci: true,
|
|
190
200
|
sha: '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad',
|
|
191
|
-
username: USERNAME,
|
|
192
201
|
accessToken,
|
|
193
|
-
|
|
202
|
+
repoOwner: 'backport-org',
|
|
203
|
+
repoName: 'integration-test',
|
|
194
204
|
fork: false,
|
|
195
205
|
});
|
|
196
206
|
const commits = await (0, getCommits_1.getCommits)(options);
|
|
@@ -198,14 +208,23 @@ describe('integration', () => {
|
|
|
198
208
|
res = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
|
|
199
209
|
});
|
|
200
210
|
it('sends the correct http body when creating pull request', () => {
|
|
201
|
-
expect(createPullRequestsMockCalls).
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
211
|
+
expect(createPullRequestsMockCalls).toMatchInlineSnapshot(`
|
|
212
|
+
Array [
|
|
213
|
+
Object {
|
|
214
|
+
"base": "7.x",
|
|
215
|
+
"body": "# Backport
|
|
216
|
+
|
|
217
|
+
This is an automatic backport to 7.x of:
|
|
218
|
+
- Add ❤️ emoji (5bf29b7d)
|
|
219
|
+
|
|
220
|
+
### Questions ?
|
|
221
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
222
|
+
",
|
|
223
|
+
"head": "backport-org:backport/7.x/commit-5bf29b7d",
|
|
224
|
+
"title": "[7.x] Add ❤️ emoji",
|
|
225
|
+
},
|
|
226
|
+
]
|
|
227
|
+
`);
|
|
209
228
|
});
|
|
210
229
|
it('returns pull request', () => {
|
|
211
230
|
expect(res).toEqual([
|
|
@@ -233,7 +252,7 @@ describe('integration', () => {
|
|
|
233
252
|
it('should NOT create branch in the fork (sqren/integration-test)', async () => {
|
|
234
253
|
const branches = await getBranches({
|
|
235
254
|
accessToken,
|
|
236
|
-
repoOwner:
|
|
255
|
+
repoOwner: AUHTOR,
|
|
237
256
|
repoName: REPO_NAME,
|
|
238
257
|
});
|
|
239
258
|
expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
|
|
@@ -253,7 +272,7 @@ function mockCreatePullRequest(response) {
|
|
|
253
272
|
const scope = (0, nock_1.default)('https://api.foo.com', { allowUnmocked: true })
|
|
254
273
|
.post('/repos/backport-org/integration-test/pulls')
|
|
255
274
|
.reply(200, response);
|
|
256
|
-
return (0, nockHelpers_1.
|
|
275
|
+
return (0, nockHelpers_1.listenForCallsToNockScope)(scope);
|
|
257
276
|
}
|
|
258
277
|
async function getBranches({ accessToken, repoOwner, repoName, }) {
|
|
259
278
|
// console.log(`fetch branches for ${repoOwner}`);
|
|
@@ -300,7 +319,7 @@ async function resetState(accessToken) {
|
|
|
300
319
|
});
|
|
301
320
|
await deleteBranch({
|
|
302
321
|
accessToken,
|
|
303
|
-
repoOwner:
|
|
322
|
+
repoOwner: AUHTOR,
|
|
304
323
|
repoName: REPO_NAME,
|
|
305
324
|
branchName: BRANCH_NAME,
|
|
306
325
|
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.mockConfigFiles = void 0;
|
|
23
|
+
const fs = __importStar(require("../services/fs-promisified"));
|
|
24
|
+
function mockConfigFiles({ projectConfig, globalConfig, }) {
|
|
25
|
+
jest
|
|
26
|
+
.spyOn(fs, 'readFile')
|
|
27
|
+
//@ts-expect-error
|
|
28
|
+
.mockImplementation(async (filepath) => {
|
|
29
|
+
if (filepath === '/path/to/project/config') {
|
|
30
|
+
return JSON.stringify(projectConfig);
|
|
31
|
+
}
|
|
32
|
+
if (filepath.endsWith('.backport/config.json')) {
|
|
33
|
+
return JSON.stringify(globalConfig);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
exports.mockConfigFiles = mockConfigFiles;
|
|
@@ -13,4 +13,4 @@ export declare function mockGqlRequest<T>({ name, statusCode, body, headers, api
|
|
|
13
13
|
query: string;
|
|
14
14
|
variables: string;
|
|
15
15
|
}[];
|
|
16
|
-
export declare function
|
|
16
|
+
export declare function listenForCallsToNockScope(scope: nock.Scope): unknown[];
|
package/dist/test/nockHelpers.js
CHANGED
|
@@ -3,7 +3,7 @@ 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.listenForCallsToNockScope = exports.mockGqlRequest = void 0;
|
|
7
7
|
const url_1 = require("url");
|
|
8
8
|
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
9
9
|
const nock_1 = __importDefault(require("nock"));
|
|
@@ -14,7 +14,7 @@ function mockGqlRequest({ name, statusCode, body, headers, apiBaseUrl, }) {
|
|
|
14
14
|
const scope = (0, nock_1.default)(origin)
|
|
15
15
|
.post(pathname, (body) => getGqlName(body.query) === name)
|
|
16
16
|
.reply(statusCode, body, headers);
|
|
17
|
-
return
|
|
17
|
+
return listenForCallsToNockScope(scope);
|
|
18
18
|
}
|
|
19
19
|
exports.mockGqlRequest = mockGqlRequest;
|
|
20
20
|
function getGqlName(query) {
|
|
@@ -24,11 +24,11 @@ function getGqlName(query) {
|
|
|
24
24
|
// @ts-expect-error
|
|
25
25
|
return obj.definitions[0].name.value;
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function listenForCallsToNockScope(scope) {
|
|
28
28
|
const calls = [];
|
|
29
29
|
scope.on('request', (req, interceptor, body) => {
|
|
30
30
|
calls.push(JSON.parse(body));
|
|
31
31
|
});
|
|
32
32
|
return calls;
|
|
33
33
|
}
|
|
34
|
-
exports.
|
|
34
|
+
exports.listenForCallsToNockScope = listenForCallsToNockScope;
|
|
@@ -18,7 +18,7 @@ async function getDevAccessToken() {
|
|
|
18
18
|
return accessToken.trim();
|
|
19
19
|
}
|
|
20
20
|
catch (e) {
|
|
21
|
-
throw new Error(`Missing
|
|
21
|
+
throw new Error(`Missing accessToken in "${accessTokenFile}"`);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
exports.getDevAccessToken = getDevAccessToken;
|
|
@@ -4,34 +4,6 @@
|
|
|
4
4
|
* It will be run once per test file
|
|
5
5
|
*/
|
|
6
6
|
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
7
|
-
jest.mock('../../services/fs-promisified', () => {
|
|
8
|
-
return {
|
|
9
|
-
writeFile: jest.fn(async () => 'fs.writeFile mock value'),
|
|
10
|
-
readFile: jest.fn(async (filepath) => {
|
|
11
|
-
// mock project config
|
|
12
|
-
if (filepath === '/path/to/project/config') {
|
|
13
|
-
return JSON.stringify({
|
|
14
|
-
upstream: 'backport-org/backport-demo',
|
|
15
|
-
targetBranchChoices: ['6.0', '5.9'],
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
// mock global config
|
|
19
|
-
if (filepath.endsWith('/.backport/config.json')) {
|
|
20
|
-
return JSON.stringify({
|
|
21
|
-
username: 'sqren',
|
|
22
|
-
accessToken: 'myAccessToken',
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
throw new Error(`Unknown filepath: "${filepath}"`);
|
|
26
|
-
}),
|
|
27
|
-
stat: jest.fn(async () => {
|
|
28
|
-
return {
|
|
29
|
-
isDirectory: () => { },
|
|
30
|
-
};
|
|
31
|
-
}),
|
|
32
|
-
chmod: jest.fn(async () => 'fs.chmod mock value'),
|
|
33
|
-
};
|
|
34
|
-
});
|
|
35
7
|
jest.mock('find-up', () => {
|
|
36
8
|
return jest.fn(async () => '/path/to/project/config');
|
|
37
9
|
});
|
|
@@ -56,9 +28,9 @@ jest.mock('ora', () => {
|
|
|
56
28
|
jest.mock('../../services/logger', () => {
|
|
57
29
|
const spy = jest.fn();
|
|
58
30
|
return {
|
|
31
|
+
redactAccessToken: jest.fn((str) => str),
|
|
59
32
|
consoleLog: jest.fn(),
|
|
60
33
|
updateLogger: jest.fn(),
|
|
61
|
-
redact: () => { },
|
|
62
34
|
logger: {
|
|
63
35
|
spy: spy,
|
|
64
36
|
info: (msg, meta) => spy(`[INFO] ${msg}`, meta),
|