backport 7.1.0 → 7.2.0-beta.4
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/entrypoint.cli.js +0 -0
- package/dist/entrypoint.module.d.ts +4 -3
- package/dist/entrypoint.module.js +2 -7
- package/dist/options/ConfigOptions.d.ts +1 -1
- package/dist/options/cliArgs.d.ts +1 -0
- package/dist/options/cliArgs.js +4 -0
- package/dist/options/config/config.d.ts +1 -1
- package/dist/options/config/readConfigFile.d.ts +1 -1
- package/dist/options/options.d.ts +2 -1
- package/dist/runSequentially.js +1 -0
- package/dist/runSequentially.test.js +55 -29
- package/dist/services/git.d.ts +3 -3
- package/dist/services/git.integration.test.js +66 -13
- package/dist/services/git.js +47 -5
- package/dist/services/git.test.js +15 -1
- package/dist/services/github/v3/createStatusComment.js +1 -1
- package/dist/services/github/v4/apiRequestV4.d.ts +4 -3
- package/dist/services/github/v4/apiRequestV4.js +15 -14
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +19 -12
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +19 -12
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +15 -9
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +15 -8
- package/dist/services/github/v4/fetchRemoteProjectConfig.js +1 -1
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -1
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -15
- package/dist/services/github/v4/getOptionsFromGithub/query.js +1 -1
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +2 -5
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +6 -6
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +5 -5
- package/dist/services/remoteConfig.d.ts +2 -0
- package/dist/services/remoteConfig.js +15 -2
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -1
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +5 -1
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +73 -39
- package/dist/services/sourceCommit/getMockSourceCommit.js +19 -18
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +2 -2
- package/dist/services/sourceCommit/parseSourceCommit.js +9 -15
- package/dist/{entrypoint.cli.e2e.private.test.d.ts → test/e2e/cli.e2e.private.test.d.ts} +0 -0
- package/dist/{entrypoint.cli.e2e.private.test.js → test/e2e/cli.e2e.private.test.js} +153 -39
- package/dist/{services/github/v3/index.d.ts → test/e2e/module.e2e.private.test.d.ts} +0 -0
- package/dist/test/e2e/module.e2e.private.test.js +363 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +0 -2
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +12 -18
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +6 -2
- package/dist/ui/getCommits.js +6 -4
- package/dist/ui/maybeSetupRepo.js +13 -16
- package/dist/ui/maybeSetupRepo.test.js +50 -16
- package/dist/ui/ora.d.ts +1 -1
- package/dist/ui/ora.js +2 -2
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +10 -10
- package/yarn.lock +121 -114
- package/dist/services/github/v3/index.js +0 -61
- package/dist/test/backport-e2e.mutation.test.d.ts +0 -1
- package/dist/test/backport-e2e.mutation.test.js +0 -347
|
@@ -1,347 +0,0 @@
|
|
|
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
|
-
/* eslint-disable jest/no-commented-out-tests */
|
|
7
|
-
const os_1 = __importDefault(require("os"));
|
|
8
|
-
const rest_1 = require("@octokit/rest");
|
|
9
|
-
const nock_1 = __importDefault(require("nock"));
|
|
10
|
-
const options_1 = require("../options/options");
|
|
11
|
-
const runSequentially_1 = require("../runSequentially");
|
|
12
|
-
const getCommits_1 = require("../ui/getCommits");
|
|
13
|
-
const mockConfigFiles_1 = require("./mockConfigFiles");
|
|
14
|
-
const nockHelpers_1 = require("./nockHelpers");
|
|
15
|
-
const getDevAccessToken_1 = require("./private/getDevAccessToken");
|
|
16
|
-
const sandbox_1 = require("./sandbox");
|
|
17
|
-
jest.setTimeout(10000);
|
|
18
|
-
const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
19
|
-
const REPO_OWNER = 'backport-org';
|
|
20
|
-
const REPO_NAME = 'integration-test';
|
|
21
|
-
const BRANCH_WITH_ONE_COMMIT = 'backport/7.x/commit-5bf29b7d';
|
|
22
|
-
const BRANCH_WITH_TWO_COMMITS = 'backport/7.x/commit-5bf29b7d_commit-59d6ff1c';
|
|
23
|
-
const AUTHOR = 'sqren';
|
|
24
|
-
describe('backport e2e', () => {
|
|
25
|
-
let accessToken;
|
|
26
|
-
afterAll(() => {
|
|
27
|
-
nock_1.default.cleanAll();
|
|
28
|
-
});
|
|
29
|
-
beforeAll(async () => {
|
|
30
|
-
// set alternative homedir
|
|
31
|
-
jest.spyOn(os_1.default, 'homedir').mockReturnValue(`${sandboxPath}/homedir`);
|
|
32
|
-
accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
33
|
-
(0, mockConfigFiles_1.mockConfigFiles)({
|
|
34
|
-
globalConfig: {},
|
|
35
|
-
projectConfig: {},
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
describe('when a single commit is backported', () => {
|
|
39
|
-
let res;
|
|
40
|
-
let createPullRequestsMockCalls;
|
|
41
|
-
beforeAll(async () => {
|
|
42
|
-
await resetState(accessToken);
|
|
43
|
-
createPullRequestsMockCalls = mockCreatePullRequest({
|
|
44
|
-
number: 1337,
|
|
45
|
-
html_url: 'myHtmlUrl',
|
|
46
|
-
});
|
|
47
|
-
const options = await (0, options_1.getOptions)([], {
|
|
48
|
-
accessToken,
|
|
49
|
-
author: AUTHOR,
|
|
50
|
-
ci: true,
|
|
51
|
-
githubApiBaseUrlV3: 'https://api.foo.com',
|
|
52
|
-
repoName: 'integration-test',
|
|
53
|
-
repoOwner: 'backport-org',
|
|
54
|
-
sha: '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad',
|
|
55
|
-
});
|
|
56
|
-
const commits = await (0, getCommits_1.getCommits)(options);
|
|
57
|
-
const targetBranches = ['7.x'];
|
|
58
|
-
res = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
|
|
59
|
-
});
|
|
60
|
-
it('returns pull request', () => {
|
|
61
|
-
expect(res).toEqual([
|
|
62
|
-
{
|
|
63
|
-
didUpdate: false,
|
|
64
|
-
pullRequestUrl: 'myHtmlUrl',
|
|
65
|
-
pullRequestNumber: 1337,
|
|
66
|
-
status: 'success',
|
|
67
|
-
targetBranch: '7.x',
|
|
68
|
-
},
|
|
69
|
-
]);
|
|
70
|
-
});
|
|
71
|
-
it('sends the correct http body when creating pull request', () => {
|
|
72
|
-
expect(createPullRequestsMockCalls).toMatchInlineSnapshot(`
|
|
73
|
-
Array [
|
|
74
|
-
Object {
|
|
75
|
-
"base": "7.x",
|
|
76
|
-
"body": "# Backport
|
|
77
|
-
|
|
78
|
-
This will backport the following commits from \`master\` to \`7.x\`:
|
|
79
|
-
- Add ❤️ emoji (5bf29b7d)
|
|
80
|
-
|
|
81
|
-
<!--- Backport version: 1.2.3-mocked -->
|
|
82
|
-
|
|
83
|
-
### Questions ?
|
|
84
|
-
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
|
|
85
|
-
"head": "sqren:backport/7.x/commit-5bf29b7d",
|
|
86
|
-
"title": "[7.x] Add ❤️ emoji",
|
|
87
|
-
},
|
|
88
|
-
]
|
|
89
|
-
`);
|
|
90
|
-
});
|
|
91
|
-
it('should not create new branches in origin (backport-org/integration-test)', async () => {
|
|
92
|
-
const branches = await getBranches({
|
|
93
|
-
accessToken,
|
|
94
|
-
repoOwner: REPO_OWNER,
|
|
95
|
-
repoName: REPO_NAME,
|
|
96
|
-
});
|
|
97
|
-
expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
|
|
98
|
-
});
|
|
99
|
-
it('should create branch in the fork (sqren/integration-test)', async () => {
|
|
100
|
-
const branches = await getBranches({
|
|
101
|
-
accessToken,
|
|
102
|
-
repoOwner: AUTHOR,
|
|
103
|
-
repoName: REPO_NAME,
|
|
104
|
-
});
|
|
105
|
-
expect(branches.map((b) => b.name)).toEqual([
|
|
106
|
-
'7.x',
|
|
107
|
-
BRANCH_WITH_ONE_COMMIT,
|
|
108
|
-
'master',
|
|
109
|
-
]);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
describe('when two commits are backported', () => {
|
|
113
|
-
let createPullRequestsMockCalls;
|
|
114
|
-
let res;
|
|
115
|
-
beforeAll(async () => {
|
|
116
|
-
await resetState(accessToken);
|
|
117
|
-
createPullRequestsMockCalls = mockCreatePullRequest({
|
|
118
|
-
number: 1337,
|
|
119
|
-
html_url: 'myHtmlUrl',
|
|
120
|
-
});
|
|
121
|
-
const options = await (0, options_1.getOptions)([], {
|
|
122
|
-
accessToken,
|
|
123
|
-
author: AUTHOR,
|
|
124
|
-
ci: true,
|
|
125
|
-
githubApiBaseUrlV3: 'https://api.foo.com',
|
|
126
|
-
repoName: 'integration-test',
|
|
127
|
-
repoOwner: 'backport-org',
|
|
128
|
-
});
|
|
129
|
-
const commits = [
|
|
130
|
-
...(await (0, getCommits_1.getCommits)({
|
|
131
|
-
...options,
|
|
132
|
-
sha: '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad',
|
|
133
|
-
})),
|
|
134
|
-
...(await (0, getCommits_1.getCommits)({
|
|
135
|
-
...options,
|
|
136
|
-
sha: '59d6ff1ca90a4ce210c0a4f0e159214875c19d60',
|
|
137
|
-
})),
|
|
138
|
-
];
|
|
139
|
-
const targetBranches = ['7.x'];
|
|
140
|
-
res = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
|
|
141
|
-
});
|
|
142
|
-
it('contains both commits in the pull request body', () => {
|
|
143
|
-
expect(createPullRequestsMockCalls).toMatchInlineSnapshot(`
|
|
144
|
-
Array [
|
|
145
|
-
Object {
|
|
146
|
-
"base": "7.x",
|
|
147
|
-
"body": "# Backport
|
|
148
|
-
|
|
149
|
-
This will backport the following commits from \`master\` to \`7.x\`:
|
|
150
|
-
- Add ❤️ emoji (5bf29b7d)
|
|
151
|
-
- Add family emoji (#2) (59d6ff1c)
|
|
152
|
-
|
|
153
|
-
<!--- Backport version: 1.2.3-mocked -->
|
|
154
|
-
|
|
155
|
-
### Questions ?
|
|
156
|
-
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
|
|
157
|
-
"head": "sqren:backport/7.x/commit-5bf29b7d_commit-59d6ff1c",
|
|
158
|
-
"title": "[7.x] Add ❤️ emoji | Add family emoji (#2)",
|
|
159
|
-
},
|
|
160
|
-
]
|
|
161
|
-
`);
|
|
162
|
-
});
|
|
163
|
-
it('returns the pull request response', () => {
|
|
164
|
-
expect(res).toEqual([
|
|
165
|
-
{
|
|
166
|
-
didUpdate: false,
|
|
167
|
-
pullRequestNumber: 1337,
|
|
168
|
-
status: 'success',
|
|
169
|
-
pullRequestUrl: 'myHtmlUrl',
|
|
170
|
-
targetBranch: '7.x',
|
|
171
|
-
},
|
|
172
|
-
]);
|
|
173
|
-
});
|
|
174
|
-
it('should not create new branches in origin (backport-org/integration-test)', async () => {
|
|
175
|
-
const branches = await getBranches({
|
|
176
|
-
accessToken,
|
|
177
|
-
repoOwner: REPO_OWNER,
|
|
178
|
-
repoName: REPO_NAME,
|
|
179
|
-
});
|
|
180
|
-
expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
|
|
181
|
-
});
|
|
182
|
-
it('should create branch in the fork (sqren/integration-test)', async () => {
|
|
183
|
-
const branches = await getBranches({
|
|
184
|
-
accessToken,
|
|
185
|
-
repoOwner: AUTHOR,
|
|
186
|
-
repoName: REPO_NAME,
|
|
187
|
-
});
|
|
188
|
-
expect(branches.map((b) => b.name)).toEqual([
|
|
189
|
-
'7.x',
|
|
190
|
-
BRANCH_WITH_TWO_COMMITS,
|
|
191
|
-
'master',
|
|
192
|
-
]);
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
describe('when disabling fork mode', () => {
|
|
196
|
-
let res;
|
|
197
|
-
let createPullRequestsMockCalls;
|
|
198
|
-
beforeAll(async () => {
|
|
199
|
-
await resetState(accessToken);
|
|
200
|
-
createPullRequestsMockCalls = mockCreatePullRequest({
|
|
201
|
-
number: 1337,
|
|
202
|
-
html_url: 'myHtmlUrl',
|
|
203
|
-
});
|
|
204
|
-
const options = await (0, options_1.getOptions)([], {
|
|
205
|
-
accessToken,
|
|
206
|
-
author: AUTHOR,
|
|
207
|
-
ci: true,
|
|
208
|
-
fork: false,
|
|
209
|
-
githubApiBaseUrlV3: 'https://api.foo.com',
|
|
210
|
-
repoName: 'integration-test',
|
|
211
|
-
repoOwner: 'backport-org',
|
|
212
|
-
sha: '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad',
|
|
213
|
-
});
|
|
214
|
-
const commits = await (0, getCommits_1.getCommits)(options);
|
|
215
|
-
const targetBranches = ['7.x'];
|
|
216
|
-
res = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
|
|
217
|
-
});
|
|
218
|
-
it('sends the correct http body when creating pull request', () => {
|
|
219
|
-
expect(createPullRequestsMockCalls).toMatchInlineSnapshot(`
|
|
220
|
-
Array [
|
|
221
|
-
Object {
|
|
222
|
-
"base": "7.x",
|
|
223
|
-
"body": "# Backport
|
|
224
|
-
|
|
225
|
-
This will backport the following commits from \`master\` to \`7.x\`:
|
|
226
|
-
- Add ❤️ emoji (5bf29b7d)
|
|
227
|
-
|
|
228
|
-
<!--- Backport version: 1.2.3-mocked -->
|
|
229
|
-
|
|
230
|
-
### Questions ?
|
|
231
|
-
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
|
|
232
|
-
"head": "backport-org:backport/7.x/commit-5bf29b7d",
|
|
233
|
-
"title": "[7.x] Add ❤️ emoji",
|
|
234
|
-
},
|
|
235
|
-
]
|
|
236
|
-
`);
|
|
237
|
-
});
|
|
238
|
-
it('returns pull request', () => {
|
|
239
|
-
expect(res).toEqual([
|
|
240
|
-
{
|
|
241
|
-
didUpdate: false,
|
|
242
|
-
pullRequestNumber: 1337,
|
|
243
|
-
pullRequestUrl: 'myHtmlUrl',
|
|
244
|
-
status: 'success',
|
|
245
|
-
targetBranch: '7.x',
|
|
246
|
-
},
|
|
247
|
-
]);
|
|
248
|
-
});
|
|
249
|
-
it('should create new branches in origin (backport-org/integration-test)', async () => {
|
|
250
|
-
const branches = await getBranches({
|
|
251
|
-
accessToken,
|
|
252
|
-
repoOwner: REPO_OWNER,
|
|
253
|
-
repoName: REPO_NAME,
|
|
254
|
-
});
|
|
255
|
-
expect(branches.map((b) => b.name)).toEqual([
|
|
256
|
-
'7.x',
|
|
257
|
-
BRANCH_WITH_ONE_COMMIT,
|
|
258
|
-
'master',
|
|
259
|
-
]);
|
|
260
|
-
});
|
|
261
|
-
it('should NOT create branch in the fork (sqren/integration-test)', async () => {
|
|
262
|
-
const branches = await getBranches({
|
|
263
|
-
accessToken,
|
|
264
|
-
repoOwner: AUTHOR,
|
|
265
|
-
repoName: REPO_NAME,
|
|
266
|
-
});
|
|
267
|
-
expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
function mockCreatePullRequest(response) {
|
|
272
|
-
const scope = (0, nock_1.default)('https://api.foo.com', { allowUnmocked: true })
|
|
273
|
-
.post('/repos/backport-org/integration-test/pulls')
|
|
274
|
-
.reply(200, response);
|
|
275
|
-
return (0, nockHelpers_1.listenForCallsToNockScope)(scope);
|
|
276
|
-
}
|
|
277
|
-
async function getBranches({ accessToken, repoOwner, repoName, }) {
|
|
278
|
-
// console.log(`fetch branches for ${repoOwner}`);
|
|
279
|
-
const octokit = new rest_1.Octokit({
|
|
280
|
-
auth: accessToken,
|
|
281
|
-
});
|
|
282
|
-
const res = await octokit.repos.listBranches({
|
|
283
|
-
owner: repoOwner,
|
|
284
|
-
repo: repoName,
|
|
285
|
-
});
|
|
286
|
-
return res.data;
|
|
287
|
-
}
|
|
288
|
-
async function deleteBranch({ accessToken, repoOwner, repoName, branchName, }) {
|
|
289
|
-
try {
|
|
290
|
-
const octokit = new rest_1.Octokit({
|
|
291
|
-
auth: accessToken,
|
|
292
|
-
});
|
|
293
|
-
// console.log({ accessToken });
|
|
294
|
-
const opts = {
|
|
295
|
-
owner: repoOwner,
|
|
296
|
-
repo: repoName,
|
|
297
|
-
ref: `heads/${branchName}`,
|
|
298
|
-
};
|
|
299
|
-
const res = await octokit.git.deleteRef(opts);
|
|
300
|
-
// console.log(`Deleted ${repoOwner}:heads/${branchName}`);
|
|
301
|
-
return res.data;
|
|
302
|
-
}
|
|
303
|
-
catch (e) {
|
|
304
|
-
// console.log(
|
|
305
|
-
// `Could not delete ${repoOwner}:heads/${branchName} (${e.message})`
|
|
306
|
-
// );
|
|
307
|
-
if (e.message === 'Reference does not exist') {
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
throw e;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
async function resetState(accessToken) {
|
|
314
|
-
const ownerBranches = await getBranches({
|
|
315
|
-
accessToken,
|
|
316
|
-
repoOwner: REPO_OWNER,
|
|
317
|
-
repoName: REPO_NAME,
|
|
318
|
-
});
|
|
319
|
-
// delete all branches except master and 7.x
|
|
320
|
-
await Promise.all(ownerBranches
|
|
321
|
-
.filter((b) => b.name !== 'master' && b.name !== '7.x')
|
|
322
|
-
.map((b) => {
|
|
323
|
-
return deleteBranch({
|
|
324
|
-
accessToken,
|
|
325
|
-
repoOwner: REPO_OWNER,
|
|
326
|
-
repoName: REPO_NAME,
|
|
327
|
-
branchName: b.name,
|
|
328
|
-
});
|
|
329
|
-
}));
|
|
330
|
-
const forkBranches = await getBranches({
|
|
331
|
-
accessToken,
|
|
332
|
-
repoOwner: AUTHOR,
|
|
333
|
-
repoName: REPO_NAME,
|
|
334
|
-
});
|
|
335
|
-
// delete all branches except master and 7.x
|
|
336
|
-
await Promise.all(forkBranches
|
|
337
|
-
.filter((b) => b.name !== 'master' && b.name !== '7.x')
|
|
338
|
-
.map((b) => {
|
|
339
|
-
return deleteBranch({
|
|
340
|
-
accessToken,
|
|
341
|
-
repoOwner: AUTHOR,
|
|
342
|
-
repoName: REPO_NAME,
|
|
343
|
-
branchName: b.name,
|
|
344
|
-
});
|
|
345
|
-
}));
|
|
346
|
-
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
347
|
-
}
|