backport 7.2.0-beta.2 → 7.2.0-beta.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/dist/entrypoint.cli.private.test.d.ts +1 -0
- package/dist/entrypoint.cli.private.test.js +46 -0
- package/dist/options/cliArgs.test.d.ts +1 -0
- package/dist/options/cliArgs.test.js +182 -0
- package/dist/options/config/config.test.d.ts +1 -0
- package/dist/options/config/config.test.js +32 -0
- package/dist/options/config/globalConfig.test.d.ts +1 -0
- package/dist/options/config/globalConfig.test.js +61 -0
- package/dist/options/config/projectConfig.test.d.ts +1 -0
- package/dist/options/config/projectConfig.test.js +109 -0
- package/dist/options/options.test.d.ts +1 -0
- package/dist/options/options.test.js +384 -0
- package/dist/runSequentially.test.d.ts +1 -0
- package/dist/runSequentially.test.js +243 -0
- package/dist/scripts/postinstall.test.d.ts +1 -0
- package/dist/scripts/postinstall.test.js +53 -0
- package/dist/services/env.test.d.ts +1 -0
- package/dist/services/env.test.js +21 -0
- package/dist/services/git.d.ts +1 -3
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +320 -0
- package/dist/services/git.js +5 -3
- package/dist/services/git.test.d.ts +1 -0
- package/dist/services/git.test.js +532 -0
- package/dist/services/github/commitFormatters.test.d.ts +1 -0
- package/dist/services/github/commitFormatters.test.js +11 -0
- package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +27 -0
- package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/createPullRequest.test.js +325 -0
- package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/services/github/v3/createStatusComment.test.js +386 -0
- package/dist/services/github/v4/apiRequestV4.test.d.ts +1 -0
- package/dist/services/github/v4/apiRequestV4.test.js +109 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
- package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchAuthorId.private.test.js +28 -0
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +93 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +134 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +116 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +195 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +152 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +102 -0
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +47 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +117 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +71 -0
- package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +156 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +87 -0
- package/dist/services/prompt.test.d.ts +1 -0
- package/dist/services/prompt.test.js +134 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.js +225 -0
- package/dist/test/ExecError.d.ts +16 -0
- package/dist/test/ExecError.js +15 -0
- package/dist/test/e2e/cli.e2e.private.test.d.ts +1 -0
- package/dist/test/e2e/cli.e2e.private.test.js +433 -0
- package/dist/test/e2e/module.e2e.private.test.d.ts +1 -0
- package/dist/test/e2e/module.e2e.private.test.js +363 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +55 -0
- package/dist/test/mockConfigFiles.d.ts +5 -0
- package/dist/test/mockConfigFiles.js +21 -0
- package/dist/test/mocks.d.ts +10 -0
- package/dist/test/mocks.js +23 -0
- package/dist/test/nockHelpers.d.ts +16 -0
- package/dist/test/nockHelpers.js +36 -0
- package/dist/test/private/getDevAccessToken.d.ts +2 -0
- package/dist/test/private/getDevAccessToken.js +12 -0
- package/dist/test/sandbox.d.ts +5 -0
- package/dist/test/sandbox.js +43 -0
- package/dist/test/setupFiles/automatic-mocks.d.ts +1 -0
- package/dist/test/setupFiles/automatic-mocks.js +63 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +459 -0
- package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/ui/getCommitsWithoutBackports.test.js +311 -0
- package/dist/ui/getTargetBranches.test.d.ts +1 -0
- package/dist/ui/getTargetBranches.test.js +198 -0
- package/dist/ui/maybeSetupRepo.js +7 -3
- package/dist/ui/maybeSetupRepo.test.d.ts +1 -0
- package/dist/ui/maybeSetupRepo.test.js +238 -0
- package/dist/ui/ora.d.ts +1 -1
- package/dist/ui/ora.js +2 -2
- package/dist/utils/excludeUndefined.test.d.ts +1 -0
- package/dist/utils/excludeUndefined.test.js +24 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,459 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const os_1 = __importDefault(require("os"));
|
|
26
|
+
const nock_1 = __importDefault(require("nock"));
|
|
27
|
+
const ora_1 = __importDefault(require("ora"));
|
|
28
|
+
const childProcess = __importStar(require("../services/child-process-promisified"));
|
|
29
|
+
const commitsByAuthorMock_1 = require("../services/github/v4/mocks/commitsByAuthorMock");
|
|
30
|
+
const logger = __importStar(require("../services/logger"));
|
|
31
|
+
const prompts = __importStar(require("../services/prompts"));
|
|
32
|
+
const ExecError_1 = require("../test/ExecError");
|
|
33
|
+
const nockHelpers_1 = require("../test/nockHelpers");
|
|
34
|
+
const cherrypickAndCreateTargetPullRequest_1 = require("./cherrypickAndCreateTargetPullRequest");
|
|
35
|
+
describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
36
|
+
let execSpy;
|
|
37
|
+
let addLabelsScope;
|
|
38
|
+
let consoleLogSpy;
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
41
|
+
execSpy = jest
|
|
42
|
+
.spyOn(childProcess, 'exec')
|
|
43
|
+
// mock all exec commands to respond without errors
|
|
44
|
+
.mockResolvedValue({ stdout: '', stderr: '' });
|
|
45
|
+
consoleLogSpy = jest.spyOn(logger, 'consoleLog');
|
|
46
|
+
// ensure labels are added
|
|
47
|
+
addLabelsScope = (0, nock_1.default)('https://api.github.com')
|
|
48
|
+
.post('/repos/elastic/kibana/issues/1337/labels', {
|
|
49
|
+
labels: ['backport'],
|
|
50
|
+
})
|
|
51
|
+
.reply(200);
|
|
52
|
+
});
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
jest.clearAllMocks();
|
|
55
|
+
addLabelsScope.done();
|
|
56
|
+
nock_1.default.cleanAll();
|
|
57
|
+
});
|
|
58
|
+
describe('when commit has a pull request reference', () => {
|
|
59
|
+
let res;
|
|
60
|
+
let createPullRequestCalls;
|
|
61
|
+
beforeEach(async () => {
|
|
62
|
+
const options = {
|
|
63
|
+
assignees: [],
|
|
64
|
+
authenticatedUsername: 'sqren_authenticated',
|
|
65
|
+
fork: true,
|
|
66
|
+
prTitle: '[{targetBranch}] {commitMessages}',
|
|
67
|
+
repoName: 'kibana',
|
|
68
|
+
repoOwner: 'elastic',
|
|
69
|
+
reviewers: [],
|
|
70
|
+
sourceBranch: 'myDefaultSourceBranch',
|
|
71
|
+
sourcePRLabels: [],
|
|
72
|
+
targetPRLabels: ['backport'],
|
|
73
|
+
author: 'sqren',
|
|
74
|
+
};
|
|
75
|
+
const commits = [
|
|
76
|
+
{
|
|
77
|
+
sourceBranch: '7.x',
|
|
78
|
+
sourceCommit: {
|
|
79
|
+
committedDate: 'fff',
|
|
80
|
+
sha: 'mySha',
|
|
81
|
+
message: 'My original commit message (#1000)',
|
|
82
|
+
},
|
|
83
|
+
sourcePullRequest: {
|
|
84
|
+
url: 'foo',
|
|
85
|
+
number: 1000,
|
|
86
|
+
mergeCommit: {
|
|
87
|
+
sha: 'mySha',
|
|
88
|
+
message: 'My original commit message (#1000)',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
expectedTargetPullRequests: [],
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
sourceBranch: '7.x',
|
|
95
|
+
sourceCommit: {
|
|
96
|
+
committedDate: 'ggg',
|
|
97
|
+
sha: 'mySha2',
|
|
98
|
+
message: 'My other commit message (#2000)',
|
|
99
|
+
},
|
|
100
|
+
sourcePullRequest: {
|
|
101
|
+
url: 'foo',
|
|
102
|
+
number: 2000,
|
|
103
|
+
mergeCommit: {
|
|
104
|
+
sha: 'mySha2',
|
|
105
|
+
message: 'My other commit message (#2000)',
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
expectedTargetPullRequests: [],
|
|
109
|
+
},
|
|
110
|
+
];
|
|
111
|
+
const scope = (0, nock_1.default)('https://api.github.com')
|
|
112
|
+
.post('/repos/elastic/kibana/pulls')
|
|
113
|
+
.reply(200, { number: 1337, html_url: 'myHtmlUrl' });
|
|
114
|
+
createPullRequestCalls = (0, nockHelpers_1.listenForCallsToNockScope)(scope);
|
|
115
|
+
res = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
|
|
116
|
+
options,
|
|
117
|
+
commits,
|
|
118
|
+
targetBranch: '6.x',
|
|
119
|
+
});
|
|
120
|
+
scope.done();
|
|
121
|
+
nock_1.default.cleanAll();
|
|
122
|
+
});
|
|
123
|
+
it('creates the pull request with multiple PR references', () => {
|
|
124
|
+
expect(createPullRequestCalls).toMatchInlineSnapshot(`
|
|
125
|
+
Array [
|
|
126
|
+
Object {
|
|
127
|
+
"base": "6.x",
|
|
128
|
+
"body": "# Backport
|
|
129
|
+
|
|
130
|
+
This will backport the following commits from \`7.x\` to \`6.x\`:
|
|
131
|
+
- [My original commit message (#1000)](foo)
|
|
132
|
+
- [My other commit message (#2000)](foo)
|
|
133
|
+
|
|
134
|
+
<!--- Backport version: 1.2.3-mocked -->
|
|
135
|
+
|
|
136
|
+
### Questions ?
|
|
137
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
|
|
138
|
+
"head": "sqren_authenticated:backport/6.x/pr-1000_pr-2000",
|
|
139
|
+
"title": "[6.x] My original commit message (#1000) | My other commit message (#2000)",
|
|
140
|
+
},
|
|
141
|
+
]
|
|
142
|
+
`);
|
|
143
|
+
});
|
|
144
|
+
it('returns the expected response', () => {
|
|
145
|
+
expect(res).toEqual({ didUpdate: false, url: 'myHtmlUrl', number: 1337 });
|
|
146
|
+
});
|
|
147
|
+
it('should make correct git commands', () => {
|
|
148
|
+
expect(execSpy.mock.calls).toMatchSnapshot();
|
|
149
|
+
});
|
|
150
|
+
it('logs correctly', () => {
|
|
151
|
+
expect(consoleLogSpy.mock.calls.length).toBe(2);
|
|
152
|
+
expect(consoleLogSpy.mock.calls[0][0]).toMatchInlineSnapshot(`
|
|
153
|
+
"
|
|
154
|
+
Backporting to 6.x:"
|
|
155
|
+
`);
|
|
156
|
+
expect(consoleLogSpy.mock.calls[1][0]).toMatchInlineSnapshot(`"View pull request: myHtmlUrl"`);
|
|
157
|
+
});
|
|
158
|
+
it('should start the spinner with the correct text', () => {
|
|
159
|
+
expect(ora_1.default.mock.calls.map((call) => call[0].text))
|
|
160
|
+
.toMatchInlineSnapshot(`
|
|
161
|
+
Array [
|
|
162
|
+
"Pulling latest changes",
|
|
163
|
+
"Cherry-picking: My original commit message (#1000)",
|
|
164
|
+
"Cherry-picking: My other commit message (#2000)",
|
|
165
|
+
"Pushing branch \\"sqren_authenticated:backport/6.x/pr-1000_pr-2000\\"",
|
|
166
|
+
undefined,
|
|
167
|
+
"Creating pull request",
|
|
168
|
+
"Adding labels: backport",
|
|
169
|
+
]
|
|
170
|
+
`);
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
describe('when commit does not have a pull request reference', () => {
|
|
174
|
+
let res;
|
|
175
|
+
let createPullRequestCalls;
|
|
176
|
+
beforeEach(async () => {
|
|
177
|
+
const options = {
|
|
178
|
+
assignees: [],
|
|
179
|
+
authenticatedUsername: 'sqren_authenticated',
|
|
180
|
+
fork: true,
|
|
181
|
+
prTitle: '[{targetBranch}] {commitMessages}',
|
|
182
|
+
repoName: 'kibana',
|
|
183
|
+
repoOwner: 'elastic',
|
|
184
|
+
reviewers: [],
|
|
185
|
+
sourcePRLabels: [],
|
|
186
|
+
targetPRLabels: ['backport'],
|
|
187
|
+
author: 'sqren',
|
|
188
|
+
};
|
|
189
|
+
const commits = [
|
|
190
|
+
{
|
|
191
|
+
sourceCommit: {
|
|
192
|
+
committedDate: 'hhh',
|
|
193
|
+
sha: 'mySha',
|
|
194
|
+
message: 'My original commit message',
|
|
195
|
+
},
|
|
196
|
+
sourceBranch: '7.x',
|
|
197
|
+
expectedTargetPullRequests: [],
|
|
198
|
+
},
|
|
199
|
+
];
|
|
200
|
+
const scope = (0, nock_1.default)('https://api.github.com')
|
|
201
|
+
.post('/repos/elastic/kibana/pulls')
|
|
202
|
+
.reply(200, { number: 1337, html_url: 'myHtmlUrl' });
|
|
203
|
+
createPullRequestCalls = (0, nockHelpers_1.listenForCallsToNockScope)(scope);
|
|
204
|
+
res = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
|
|
205
|
+
options,
|
|
206
|
+
commits,
|
|
207
|
+
targetBranch: '6.x',
|
|
208
|
+
});
|
|
209
|
+
scope.done();
|
|
210
|
+
nock_1.default.cleanAll();
|
|
211
|
+
});
|
|
212
|
+
it('creates the pull request with commit reference', () => {
|
|
213
|
+
expect(createPullRequestCalls).toMatchInlineSnapshot(`
|
|
214
|
+
Array [
|
|
215
|
+
Object {
|
|
216
|
+
"base": "6.x",
|
|
217
|
+
"body": "# Backport
|
|
218
|
+
|
|
219
|
+
This will backport the following commits from \`7.x\` to \`6.x\`:
|
|
220
|
+
- My original commit message (mySha)
|
|
221
|
+
|
|
222
|
+
<!--- Backport version: 1.2.3-mocked -->
|
|
223
|
+
|
|
224
|
+
### Questions ?
|
|
225
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
|
|
226
|
+
"head": "sqren_authenticated:backport/6.x/commit-mySha",
|
|
227
|
+
"title": "[6.x] My original commit message",
|
|
228
|
+
},
|
|
229
|
+
]
|
|
230
|
+
`);
|
|
231
|
+
});
|
|
232
|
+
it('returns the expected response', () => {
|
|
233
|
+
expect(res).toEqual({ didUpdate: false, url: 'myHtmlUrl', number: 1337 });
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
describe('when cherry-picking fails', () => {
|
|
237
|
+
let res;
|
|
238
|
+
let promptSpy;
|
|
239
|
+
let execSpy;
|
|
240
|
+
let commitsByAuthorCalls;
|
|
241
|
+
let createPullRequestCalls;
|
|
242
|
+
beforeEach(async () => {
|
|
243
|
+
// spies
|
|
244
|
+
promptSpy = jest.spyOn(prompts, 'confirmPrompt').mockResolvedValue(true);
|
|
245
|
+
execSpy = setupExecSpyForCherryPick();
|
|
246
|
+
const options = {
|
|
247
|
+
assignees: [],
|
|
248
|
+
authenticatedUsername: 'sqren_authenticated',
|
|
249
|
+
fork: true,
|
|
250
|
+
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
251
|
+
prTitle: '[{targetBranch}] {commitMessages}',
|
|
252
|
+
repoName: 'kibana',
|
|
253
|
+
repoOwner: 'elastic',
|
|
254
|
+
reviewers: [],
|
|
255
|
+
sourceBranch: 'myDefaultSourceBranch',
|
|
256
|
+
sourcePRLabels: [],
|
|
257
|
+
targetPRLabels: ['backport'],
|
|
258
|
+
author: 'sqren',
|
|
259
|
+
};
|
|
260
|
+
const scope = (0, nock_1.default)('https://api.github.com')
|
|
261
|
+
.post('/repos/elastic/kibana/pulls')
|
|
262
|
+
.reply(200, { number: 1337, html_url: 'myHtmlUrl' });
|
|
263
|
+
createPullRequestCalls = (0, nockHelpers_1.listenForCallsToNockScope)(scope);
|
|
264
|
+
commitsByAuthorCalls =
|
|
265
|
+
(0, nockHelpers_1.mockGqlRequest)({
|
|
266
|
+
name: 'CommitsByAuthor',
|
|
267
|
+
statusCode: 200,
|
|
268
|
+
body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
|
|
269
|
+
});
|
|
270
|
+
res = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
|
|
271
|
+
options,
|
|
272
|
+
commits: [
|
|
273
|
+
{
|
|
274
|
+
sourceCommit: {
|
|
275
|
+
committedDate: '2021-08-18T16:11:38Z',
|
|
276
|
+
sha: 'mySha',
|
|
277
|
+
message: 'My original commit message',
|
|
278
|
+
},
|
|
279
|
+
sourceBranch: '7.x',
|
|
280
|
+
expectedTargetPullRequests: [],
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
targetBranch: '6.x',
|
|
284
|
+
});
|
|
285
|
+
scope.done();
|
|
286
|
+
nock_1.default.cleanAll();
|
|
287
|
+
});
|
|
288
|
+
it('creates the pull request with commit reference', () => {
|
|
289
|
+
expect(createPullRequestCalls).toMatchInlineSnapshot(`
|
|
290
|
+
Array [
|
|
291
|
+
Object {
|
|
292
|
+
"base": "6.x",
|
|
293
|
+
"body": "# Backport
|
|
294
|
+
|
|
295
|
+
This will backport the following commits from \`7.x\` to \`6.x\`:
|
|
296
|
+
- My original commit message (mySha)
|
|
297
|
+
|
|
298
|
+
<!--- Backport version: 1.2.3-mocked -->
|
|
299
|
+
|
|
300
|
+
### Questions ?
|
|
301
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
|
|
302
|
+
"head": "sqren_authenticated:backport/6.x/commit-mySha",
|
|
303
|
+
"title": "[6.x] My original commit message",
|
|
304
|
+
},
|
|
305
|
+
]
|
|
306
|
+
`);
|
|
307
|
+
});
|
|
308
|
+
it('returns the expected response', () => {
|
|
309
|
+
expect(res).toEqual({ didUpdate: false, url: 'myHtmlUrl', number: 1337 });
|
|
310
|
+
});
|
|
311
|
+
it('shows the right prompts', () => {
|
|
312
|
+
expect(promptSpy.mock.calls.length).toBe(4);
|
|
313
|
+
expect(promptSpy.mock.calls[0][0]).toMatchInlineSnapshot(`
|
|
314
|
+
"Fix the following conflicts manually:
|
|
315
|
+
|
|
316
|
+
Conflicting files:
|
|
317
|
+
- /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
Press ENTER when the conflicts are resolved and files are staged"
|
|
321
|
+
`);
|
|
322
|
+
expect(promptSpy.mock.calls[1][0]).toMatchInlineSnapshot(`
|
|
323
|
+
"Fix the following conflicts manually:
|
|
324
|
+
|
|
325
|
+
Conflicting files:
|
|
326
|
+
- /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
Press ENTER when the conflicts are resolved and files are staged"
|
|
330
|
+
`);
|
|
331
|
+
expect(promptSpy.mock.calls[2][0]).toMatchInlineSnapshot(`
|
|
332
|
+
"Fix the following conflicts manually:
|
|
333
|
+
|
|
334
|
+
Conflicting files:
|
|
335
|
+
- /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
Press ENTER when the conflicts are resolved and files are staged"
|
|
339
|
+
`);
|
|
340
|
+
});
|
|
341
|
+
it('commitsByAuthor is called with correct arguments', () => {
|
|
342
|
+
expect(commitsByAuthorCalls[0].variables).toMatchInlineSnapshot(`
|
|
343
|
+
Object {
|
|
344
|
+
"authorId": null,
|
|
345
|
+
"commitPath": "conflicting-file.txt",
|
|
346
|
+
"dateSince": null,
|
|
347
|
+
"dateUntil": "2021-08-18T16:11:38Z",
|
|
348
|
+
"maxNumber": 10,
|
|
349
|
+
"repoName": "kibana",
|
|
350
|
+
"repoOwner": "elastic",
|
|
351
|
+
"sourceBranch": "myDefaultSourceBranch",
|
|
352
|
+
}
|
|
353
|
+
`);
|
|
354
|
+
});
|
|
355
|
+
it('calls exec correctly', () => {
|
|
356
|
+
expect(execSpy.mock.calls).toMatchSnapshot();
|
|
357
|
+
});
|
|
358
|
+
it('calls ora correctly', () => {
|
|
359
|
+
expect(ora_1.default.mock.calls.map((call) => call[0].text))
|
|
360
|
+
.toMatchInlineSnapshot(`
|
|
361
|
+
Array [
|
|
362
|
+
"Pulling latest changes",
|
|
363
|
+
"Cherry-picking: My original commit message",
|
|
364
|
+
"Finalizing cherrypick",
|
|
365
|
+
"Pushing branch \\"sqren_authenticated:backport/6.x/commit-mySha\\"",
|
|
366
|
+
undefined,
|
|
367
|
+
"Creating pull request",
|
|
368
|
+
"Adding labels: backport",
|
|
369
|
+
]
|
|
370
|
+
`);
|
|
371
|
+
});
|
|
372
|
+
it('logs correctly', async () => {
|
|
373
|
+
expect(consoleLogSpy.mock.calls[0][0]).toMatchInlineSnapshot(`
|
|
374
|
+
"
|
|
375
|
+
Backporting to 6.x:"
|
|
376
|
+
`);
|
|
377
|
+
expect(consoleLogSpy.mock.calls[1][0]).toMatchInlineSnapshot(`
|
|
378
|
+
"
|
|
379
|
+
The commit could not be backported due to conflicts
|
|
380
|
+
"
|
|
381
|
+
`);
|
|
382
|
+
expect(consoleLogSpy.mock.calls[2][0]).toMatchInlineSnapshot(`
|
|
383
|
+
"
|
|
384
|
+
----------------------------------------
|
|
385
|
+
"
|
|
386
|
+
`);
|
|
387
|
+
expect(consoleLogSpy.mock.calls[3][0]).toMatchInlineSnapshot(`
|
|
388
|
+
"
|
|
389
|
+
----------------------------------------
|
|
390
|
+
"
|
|
391
|
+
`);
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
function setupExecSpyForCherryPick() {
|
|
396
|
+
let conflictingFilesCheck = 0;
|
|
397
|
+
let unstagedFilesCheck = 0;
|
|
398
|
+
return jest
|
|
399
|
+
.spyOn(childProcess, 'exec')
|
|
400
|
+
.mockImplementation(async (cmd) => {
|
|
401
|
+
// createFeatureBranch
|
|
402
|
+
if (cmd.includes('git checkout -B')) {
|
|
403
|
+
return { stdout: 'create feature branch succeeded', stderr: '' };
|
|
404
|
+
}
|
|
405
|
+
// git fetch
|
|
406
|
+
if (cmd.startsWith('git fetch')) {
|
|
407
|
+
return { stderr: '', stdout: '' };
|
|
408
|
+
}
|
|
409
|
+
// cherrypick
|
|
410
|
+
if (cmd === 'git cherry-pick -x mySha') {
|
|
411
|
+
throw new ExecError_1.ExecError({ cmd });
|
|
412
|
+
}
|
|
413
|
+
// getIsCommitInBranch
|
|
414
|
+
if (cmd.startsWith('git merge-base --is-ancestor')) {
|
|
415
|
+
return { stderr: '', stdout: '' };
|
|
416
|
+
}
|
|
417
|
+
// getConflictingFiles
|
|
418
|
+
if (cmd === 'git --no-pager diff --check') {
|
|
419
|
+
conflictingFilesCheck++;
|
|
420
|
+
if (conflictingFilesCheck >= 4) {
|
|
421
|
+
return { stderr: '', stdout: '' };
|
|
422
|
+
}
|
|
423
|
+
throw new ExecError_1.ExecError({
|
|
424
|
+
code: 2,
|
|
425
|
+
cmd,
|
|
426
|
+
stdout: `conflicting-file.txt:1: leftover conflict marker\nconflicting-file.txt:3: leftover conflict marker\nconflicting-file.txt:5: leftover conflict marker\n`,
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
// getUnstagedFiles
|
|
430
|
+
if (cmd === 'git --no-pager diff --name-only') {
|
|
431
|
+
unstagedFilesCheck++;
|
|
432
|
+
if (unstagedFilesCheck >= 5) {
|
|
433
|
+
return { stderr: '', stdout: '' };
|
|
434
|
+
}
|
|
435
|
+
return { stdout: `conflicting-file.txt\n`, stderr: '' };
|
|
436
|
+
}
|
|
437
|
+
// addUnstagedFiles
|
|
438
|
+
if (cmd === 'git add --update') {
|
|
439
|
+
return { stdout: ``, stderr: '' };
|
|
440
|
+
}
|
|
441
|
+
// finalizeCherrypick
|
|
442
|
+
if (cmd.includes('git commit --no-edit')) {
|
|
443
|
+
return { stdout: ``, stderr: '' };
|
|
444
|
+
}
|
|
445
|
+
// pushFeatureBranch
|
|
446
|
+
if (cmd.startsWith('git push ')) {
|
|
447
|
+
return { stdout: ``, stderr: '' };
|
|
448
|
+
}
|
|
449
|
+
// deleteFeatureBranch
|
|
450
|
+
if (cmd.includes('git branch -D ')) {
|
|
451
|
+
return { stdout: ``, stderr: '' };
|
|
452
|
+
}
|
|
453
|
+
// getIsMergeCommit
|
|
454
|
+
if (cmd.startsWith('git rev-list -1 --merges')) {
|
|
455
|
+
return { stdout: ``, stderr: '' };
|
|
456
|
+
}
|
|
457
|
+
throw new Error(`Missing exec mock for "${cmd}"`);
|
|
458
|
+
});
|
|
459
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|