backport 6.1.1 → 6.1.5
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 +83 -70
- package/dist/entrypoint.module.d.ts +4 -1
- package/dist/entrypoint.module.js +10 -4
- package/dist/entrypoint.module.private.test.js +4 -1
- package/dist/main.js +5 -1
- package/dist/options/ConfigOptions.d.ts +3 -0
- package/dist/options/cliArgs.d.ts +5 -1
- package/dist/options/cliArgs.js +24 -2
- package/dist/options/cliArgs.test.js +0 -7
- package/dist/options/config/config.d.ts +7 -1
- package/dist/options/config/config.js +2 -2
- package/dist/options/config/config.test.js +1 -1
- package/dist/options/config/globalConfig.d.ts +1 -1
- package/dist/options/config/globalConfig.js +4 -8
- package/dist/options/config/readConfigFile.d.ts +4 -1
- package/dist/options/options.d.ts +10 -1
- package/dist/options/options.js +10 -2
- package/dist/options/options.test.js +113 -123
- package/dist/runSequentially.test.js +8 -5
- package/dist/services/HandledError.d.ts +1 -1
- package/dist/services/env.d.ts +2 -3
- package/dist/services/env.js +9 -10
- package/dist/services/env.test.js +0 -6
- package/dist/services/git.d.ts +2 -1
- package/dist/services/git.js +5 -3
- package/dist/services/github/v3/createPullRequest.js +1 -1
- package/dist/services/github/v3/createPullRequest.test.js +3 -3
- package/dist/services/github/v3/createStatusComment.d.ts +1 -1
- package/dist/services/github/v3/createStatusComment.js +50 -27
- package/dist/services/github/v3/createStatusComment.test.js +155 -73
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +78 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +64 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +5 -5
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +60 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +2 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +17 -10
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +72 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +6 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +8 -7
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +8 -0
- package/dist/services/github/v4/fetchProjectConfig.d.ts +1 -1
- package/dist/services/github/v4/fetchProjectConfig.js +3 -3
- package/dist/services/github/v4/fetchProjectConfig.private.test.js +5 -5
- package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.js +56 -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.d.ts +3 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -7
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +16 -5
- package/dist/services/logger.d.ts +0 -1
- package/dist/services/logger.js +3 -3
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +8 -2
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +20 -0
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +1 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +72 -46
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +22 -8
- package/dist/services/sourceCommit/parseSourceCommit.js +29 -10
- package/dist/services/sourceCommit/parseSourceCommit.test.js +10 -2
- package/dist/test/inquirer.private.test.js +4 -15
- package/dist/test/integration/integration.private.test.js +2 -2
- package/dist/test/nockHelpers.js +1 -3
- package/dist/test/setupFiles/automatic-mocks.js +1 -0
- package/dist/todo-delete.d.ts +1 -0
- package/dist/todo-delete.js +17 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -9
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +11 -48
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +224 -260
- package/dist/ui/getCommits.js +1 -1
- package/dist/ui/getCommitsWithoutBackports.d.ts +11 -0
- package/dist/ui/getCommitsWithoutBackports.js +68 -0
- package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/ui/getCommitsWithoutBackports.test.js +259 -0
- package/dist/ui/maybeSetupRepo.js +0 -6
- package/dist/utils/redact.d.ts +1 -0
- package/dist/utils/redact.js +7 -0
- package/package.json +3 -3
- package/yarn.lock +462 -284
|
@@ -22,99 +22,110 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const os_1 = __importDefault(require("os"));
|
|
25
26
|
const nock_1 = __importDefault(require("nock"));
|
|
26
27
|
const ora_1 = __importDefault(require("ora"));
|
|
27
28
|
const childProcess = __importStar(require("../services/child-process-promisified"));
|
|
29
|
+
const commitsByAuthorMock_1 = require("../services/github/v4/mocks/commitsByAuthorMock");
|
|
28
30
|
const logger = __importStar(require("../services/logger"));
|
|
29
31
|
const prompts = __importStar(require("../services/prompts"));
|
|
30
32
|
const ExecError_1 = require("../test/ExecError");
|
|
31
33
|
const nockHelpers_1 = require("../test/nockHelpers");
|
|
32
34
|
const cherrypickAndCreateTargetPullRequest_1 = require("./cherrypickAndCreateTargetPullRequest");
|
|
33
|
-
const TARGET_PULL_NUMBER = 1338;
|
|
34
35
|
describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
36
|
+
let execSpy;
|
|
37
|
+
let addLabelsScope;
|
|
35
38
|
let consoleLogSpy;
|
|
36
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: '' });
|
|
37
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);
|
|
38
52
|
});
|
|
39
53
|
afterEach(() => {
|
|
40
|
-
|
|
54
|
+
jest.clearAllMocks();
|
|
55
|
+
addLabelsScope.done();
|
|
56
|
+
nock_1.default.cleanAll();
|
|
41
57
|
});
|
|
42
58
|
describe('when commit has a pull request reference', () => {
|
|
43
59
|
let res;
|
|
44
|
-
let
|
|
45
|
-
let getAddLabelsToTargetPrCalls;
|
|
46
|
-
let getAddLabelsToSourcePr1000Calls;
|
|
47
|
-
let getAddLabelsToSourcePr2000Calls;
|
|
48
|
-
let getCreatePullRequestCalls;
|
|
60
|
+
let createPullRequestCalls;
|
|
49
61
|
beforeEach(async () => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
sourceBranch: 'myDefaultSourceBranch',
|
|
73
|
-
sourcePRLabels: [],
|
|
74
|
-
targetBranchChoices: [
|
|
75
|
-
{ name: '7.0', sourcePRLabels: ['7.0.0'] },
|
|
76
|
-
{ name: '6.x', sourcePRLabels: ['6.5.1'] },
|
|
77
|
-
],
|
|
62
|
+
const options = {
|
|
63
|
+
assignees: [],
|
|
64
|
+
authenticatedUsername: 'sqren_authenticated',
|
|
65
|
+
fork: true,
|
|
66
|
+
prDescription: 'myPrSuffix',
|
|
67
|
+
prTitle: '[{targetBranch}] {commitMessages}',
|
|
68
|
+
repoName: 'kibana',
|
|
69
|
+
repoOwner: 'elastic',
|
|
70
|
+
reviewers: [],
|
|
71
|
+
sourceBranch: 'myDefaultSourceBranch',
|
|
72
|
+
sourcePRLabels: [],
|
|
73
|
+
targetPRLabels: ['backport'],
|
|
74
|
+
author: 'sqren',
|
|
75
|
+
};
|
|
76
|
+
const commits = [
|
|
77
|
+
{
|
|
78
|
+
committedDate: 'fff',
|
|
79
|
+
sourceBranch: '7.x',
|
|
80
|
+
sha: 'mySha',
|
|
81
|
+
originalMessage: 'My original commit message (#1000)',
|
|
82
|
+
pullNumber: 1000,
|
|
83
|
+
expectedTargetPullRequests: [],
|
|
78
84
|
},
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
existingTargetPullRequests: [],
|
|
97
|
-
},
|
|
98
|
-
],
|
|
85
|
+
{
|
|
86
|
+
committedDate: 'ggg',
|
|
87
|
+
sourceBranch: '7.x',
|
|
88
|
+
sha: 'mySha2',
|
|
89
|
+
originalMessage: 'My other commit message (#2000)',
|
|
90
|
+
pullNumber: 2000,
|
|
91
|
+
expectedTargetPullRequests: [],
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
const scope = (0, nock_1.default)('https://api.github.com')
|
|
95
|
+
.post('/repos/elastic/kibana/pulls')
|
|
96
|
+
.reply(200, { number: 1337, html_url: 'myHtmlUrl' });
|
|
97
|
+
createPullRequestCalls = (0, nockHelpers_1.listenForCallsToNockScope)(scope);
|
|
98
|
+
res = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
|
|
99
|
+
options,
|
|
100
|
+
commits,
|
|
101
|
+
targetBranch: '6.x',
|
|
99
102
|
});
|
|
103
|
+
scope.done();
|
|
104
|
+
nock_1.default.cleanAll();
|
|
100
105
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
106
|
+
it('creates the pull request with multiple PR references', () => {
|
|
107
|
+
expect(createPullRequestCalls).toMatchInlineSnapshot(`
|
|
108
|
+
Array [
|
|
109
|
+
Object {
|
|
110
|
+
"base": "6.x",
|
|
111
|
+
"body": "# Backport
|
|
112
|
+
|
|
113
|
+
This is an automatic backport to \`6.x\` of:
|
|
114
|
+
- #1000
|
|
115
|
+
- #2000
|
|
116
|
+
|
|
117
|
+
### Questions ?
|
|
118
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
119
|
+
|
|
120
|
+
myPrSuffix",
|
|
121
|
+
"head": "sqren_authenticated:backport/6.x/pr-1000_pr-2000",
|
|
122
|
+
"title": "[6.x] My original commit message (#1000) | My other commit message (#2000)",
|
|
123
|
+
},
|
|
124
|
+
]
|
|
125
|
+
`);
|
|
105
126
|
});
|
|
106
127
|
it('returns the expected response', () => {
|
|
107
|
-
expect(res).toEqual({ url: 'myHtmlUrl', number:
|
|
108
|
-
});
|
|
109
|
-
it('creates pull request', () => {
|
|
110
|
-
expect(getCreatePullRequestCalls()).toEqual([
|
|
111
|
-
{
|
|
112
|
-
title: '[6.x] myCommitMessage (#1000) | myOtherCommitMessage (#2000)',
|
|
113
|
-
head: 'sqren:backport/6.x/pr-1000_pr-2000',
|
|
114
|
-
base: '6.x',
|
|
115
|
-
body: 'Backports the following commits to 6.x:\n - myCommitMessage (#1000)\n - myOtherCommitMessage (#2000)\n\nmyPrSuffix',
|
|
116
|
-
},
|
|
117
|
-
]);
|
|
128
|
+
expect(res).toEqual({ didUpdate: false, url: 'myHtmlUrl', number: 1337 });
|
|
118
129
|
});
|
|
119
130
|
it('should make correct git commands', () => {
|
|
120
131
|
expect(execSpy.mock.calls).toMatchSnapshot();
|
|
@@ -132,211 +143,152 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
132
143
|
.toMatchInlineSnapshot(`
|
|
133
144
|
Array [
|
|
134
145
|
"Pulling latest changes",
|
|
135
|
-
"Cherry-picking:
|
|
136
|
-
"Cherry-picking:
|
|
137
|
-
"Pushing branch \\"
|
|
146
|
+
"Cherry-picking: My original commit message (#1000)",
|
|
147
|
+
"Cherry-picking: My other commit message (#2000)",
|
|
148
|
+
"Pushing branch \\"sqren_authenticated:backport/6.x/pr-1000_pr-2000\\"",
|
|
138
149
|
undefined,
|
|
139
150
|
"Creating pull request",
|
|
140
|
-
"Adding labels:
|
|
141
|
-
"Adding labels: \\"6.5.1\\" to #1000",
|
|
142
|
-
"Adding labels: \\"6.5.1\\" to #2000",
|
|
151
|
+
"Adding labels: backport",
|
|
143
152
|
]
|
|
144
153
|
`);
|
|
145
154
|
});
|
|
146
|
-
it('adds labels to the target pull request', () => {
|
|
147
|
-
expect(getAddLabelsToTargetPrCalls()).toEqual([{ labels: ['backport'] }]);
|
|
148
|
-
});
|
|
149
|
-
it('adds labels to source pull requests', () => {
|
|
150
|
-
expect(getAddLabelsToSourcePr1000Calls()).toEqual([
|
|
151
|
-
{ labels: ['6.5.1'] },
|
|
152
|
-
]);
|
|
153
|
-
expect(getAddLabelsToSourcePr2000Calls()).toEqual([
|
|
154
|
-
{ labels: ['6.5.1'] },
|
|
155
|
-
]);
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
describe('when sourcePRLabels includes wildcard', () => {
|
|
159
|
-
let execSpy;
|
|
160
|
-
let getAddLabelsToSourcePr1000Calls;
|
|
161
|
-
let getAddLabelsToSourcePr2000Calls;
|
|
162
|
-
beforeEach(async () => {
|
|
163
|
-
execSpy = jest
|
|
164
|
-
.spyOn(childProcess, 'exec')
|
|
165
|
-
// mock all exec commands to respond without errors
|
|
166
|
-
.mockResolvedValue({ stdout: '', stderr: '' });
|
|
167
|
-
// ensure labels are added to source PR
|
|
168
|
-
getAddLabelsToSourcePr1000Calls = mockAddLabelCall(1000);
|
|
169
|
-
getAddLabelsToSourcePr2000Calls = mockAddLabelCall(2000);
|
|
170
|
-
// mock create pull request
|
|
171
|
-
mockCreatePullRequestCall();
|
|
172
|
-
await cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest({
|
|
173
|
-
targetBranch: '6.x',
|
|
174
|
-
options: {
|
|
175
|
-
assignees: [],
|
|
176
|
-
githubApiBaseUrlV3: 'https://api.github.com',
|
|
177
|
-
fork: true,
|
|
178
|
-
targetPRLabels: ['backport'],
|
|
179
|
-
prDescription: 'myPrSuffix',
|
|
180
|
-
prTitle: '[{targetBranch}] {commitMessages}',
|
|
181
|
-
repoName: 'kibana',
|
|
182
|
-
repoOwner: 'elastic',
|
|
183
|
-
username: 'sqren',
|
|
184
|
-
sourceBranch: 'myDefaultSourceBranch',
|
|
185
|
-
sourcePRLabels: [],
|
|
186
|
-
targetBranchChoices: [
|
|
187
|
-
{ name: '7.0', sourcePRLabels: ['7.0.0'] },
|
|
188
|
-
{ name: '6.x', sourcePRLabels: ['6.5.*'] },
|
|
189
|
-
],
|
|
190
|
-
},
|
|
191
|
-
commits: [
|
|
192
|
-
{
|
|
193
|
-
sourceBranch: '7.x',
|
|
194
|
-
sha: 'mySha',
|
|
195
|
-
formattedMessage: 'myCommitMessage (#1000)',
|
|
196
|
-
originalMessage: 'My original commit message',
|
|
197
|
-
pullNumber: 1000,
|
|
198
|
-
sourcePRLabels: [],
|
|
199
|
-
existingTargetPullRequests: [],
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
sourceBranch: '7.x',
|
|
203
|
-
sha: 'mySha2',
|
|
204
|
-
formattedMessage: 'myOtherCommitMessage (#2000)',
|
|
205
|
-
originalMessage: 'My original commit message',
|
|
206
|
-
pullNumber: 2000,
|
|
207
|
-
sourcePRLabels: [],
|
|
208
|
-
existingTargetPullRequests: [],
|
|
209
|
-
},
|
|
210
|
-
],
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
afterEach(() => {
|
|
214
|
-
execSpy.mockClear();
|
|
215
|
-
//@ts-expect-error
|
|
216
|
-
ora_1.default.mockClear();
|
|
217
|
-
});
|
|
218
|
-
it('does not add labels to source pull requests', () => {
|
|
219
|
-
expect(getAddLabelsToSourcePr1000Calls()).toEqual([]);
|
|
220
|
-
expect(getAddLabelsToSourcePr2000Calls()).toEqual([]);
|
|
221
|
-
});
|
|
222
155
|
});
|
|
223
156
|
describe('when commit does not have a pull request reference', () => {
|
|
224
157
|
let res;
|
|
225
|
-
let
|
|
226
|
-
let getAddLabelsToTargetPrCalls;
|
|
158
|
+
let createPullRequestCalls;
|
|
227
159
|
beforeEach(async () => {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
targetBranchChoices: [
|
|
248
|
-
{ name: '7.0', sourcePRLabels: ['7.0.0'] },
|
|
249
|
-
{ name: '6.x', sourcePRLabels: ['6.5.1'] },
|
|
250
|
-
],
|
|
160
|
+
const options = {
|
|
161
|
+
assignees: [],
|
|
162
|
+
authenticatedUsername: 'sqren_authenticated',
|
|
163
|
+
fork: true,
|
|
164
|
+
prTitle: '[{targetBranch}] {commitMessages}',
|
|
165
|
+
repoName: 'kibana',
|
|
166
|
+
repoOwner: 'elastic',
|
|
167
|
+
reviewers: [],
|
|
168
|
+
sourcePRLabels: [],
|
|
169
|
+
targetPRLabels: ['backport'],
|
|
170
|
+
author: 'sqren',
|
|
171
|
+
};
|
|
172
|
+
const commits = [
|
|
173
|
+
{
|
|
174
|
+
committedDate: 'hhh',
|
|
175
|
+
sourceBranch: '7.x',
|
|
176
|
+
sha: 'mySha',
|
|
177
|
+
originalMessage: 'My original commit message',
|
|
178
|
+
expectedTargetPullRequests: [],
|
|
251
179
|
},
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
],
|
|
180
|
+
];
|
|
181
|
+
const scope = (0, nock_1.default)('https://api.github.com')
|
|
182
|
+
.post('/repos/elastic/kibana/pulls')
|
|
183
|
+
.reply(200, { number: 1337, html_url: 'myHtmlUrl' });
|
|
184
|
+
createPullRequestCalls = (0, nockHelpers_1.listenForCallsToNockScope)(scope);
|
|
185
|
+
res = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
|
|
186
|
+
options,
|
|
187
|
+
commits,
|
|
188
|
+
targetBranch: '6.x',
|
|
262
189
|
});
|
|
190
|
+
scope.done();
|
|
191
|
+
nock_1.default.cleanAll();
|
|
263
192
|
});
|
|
264
|
-
it('creates pull request', () => {
|
|
265
|
-
expect(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
193
|
+
it('creates the pull request with commit reference', () => {
|
|
194
|
+
expect(createPullRequestCalls).toMatchInlineSnapshot(`
|
|
195
|
+
Array [
|
|
196
|
+
Object {
|
|
197
|
+
"base": "6.x",
|
|
198
|
+
"body": "# Backport
|
|
199
|
+
|
|
200
|
+
This is an automatic backport to \`6.x\` of:
|
|
201
|
+
- My original commit message (mySha)
|
|
202
|
+
|
|
203
|
+
### Questions ?
|
|
204
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
205
|
+
",
|
|
206
|
+
"head": "sqren_authenticated:backport/6.x/commit-mySha",
|
|
207
|
+
"title": "[6.x] My original commit message",
|
|
208
|
+
},
|
|
209
|
+
]
|
|
210
|
+
`);
|
|
273
211
|
});
|
|
274
212
|
it('returns the expected response', () => {
|
|
275
|
-
expect(res).toEqual({ url: 'myHtmlUrl', number:
|
|
276
|
-
});
|
|
277
|
-
it('adds labels to the target pull request', () => {
|
|
278
|
-
expect(getAddLabelsToTargetPrCalls()).toEqual([{ labels: ['backport'] }]);
|
|
213
|
+
expect(res).toEqual({ didUpdate: false, url: 'myHtmlUrl', number: 1337 });
|
|
279
214
|
});
|
|
280
215
|
});
|
|
281
216
|
describe('when cherry-picking fails', () => {
|
|
282
217
|
let res;
|
|
283
218
|
let promptSpy;
|
|
284
219
|
let execSpy;
|
|
285
|
-
let
|
|
220
|
+
let commitsByAuthorCalls;
|
|
221
|
+
let createPullRequestCalls;
|
|
286
222
|
beforeEach(async () => {
|
|
287
223
|
// spies
|
|
288
224
|
promptSpy = jest.spyOn(prompts, 'confirmPrompt').mockResolvedValue(true);
|
|
289
|
-
execSpy =
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
225
|
+
execSpy = setupExecSpyForCherryPick();
|
|
226
|
+
const options = {
|
|
227
|
+
assignees: [],
|
|
228
|
+
authenticatedUsername: 'sqren_authenticated',
|
|
229
|
+
fork: true,
|
|
230
|
+
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
231
|
+
prTitle: '[{targetBranch}] {commitMessages}',
|
|
232
|
+
repoName: 'kibana',
|
|
233
|
+
repoOwner: 'elastic',
|
|
234
|
+
reviewers: [],
|
|
235
|
+
sourceBranch: 'myDefaultSourceBranch',
|
|
236
|
+
sourcePRLabels: [],
|
|
237
|
+
targetPRLabels: ['backport'],
|
|
238
|
+
author: 'sqren',
|
|
239
|
+
};
|
|
240
|
+
const scope = (0, nock_1.default)('https://api.github.com')
|
|
241
|
+
.post('/repos/elastic/kibana/pulls')
|
|
242
|
+
.reply(200, { number: 1337, html_url: 'myHtmlUrl' });
|
|
243
|
+
createPullRequestCalls = (0, nockHelpers_1.listenForCallsToNockScope)(scope);
|
|
244
|
+
commitsByAuthorCalls =
|
|
245
|
+
(0, nockHelpers_1.mockGqlRequest)({
|
|
246
|
+
name: 'CommitsByAuthor',
|
|
247
|
+
statusCode: 200,
|
|
248
|
+
body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
|
|
249
|
+
});
|
|
250
|
+
res = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
|
|
251
|
+
options,
|
|
305
252
|
commits: [
|
|
306
253
|
{
|
|
254
|
+
committedDate: '2021-08-18T16:11:38Z',
|
|
307
255
|
sourceBranch: '7.x',
|
|
308
256
|
sha: 'mySha',
|
|
309
|
-
formattedMessage: 'myCommitMessage (mySha)',
|
|
310
257
|
originalMessage: 'My original commit message',
|
|
311
|
-
|
|
312
|
-
existingTargetPullRequests: [],
|
|
258
|
+
expectedTargetPullRequests: [],
|
|
313
259
|
},
|
|
314
260
|
],
|
|
261
|
+
targetBranch: '6.x',
|
|
315
262
|
});
|
|
263
|
+
scope.done();
|
|
264
|
+
nock_1.default.cleanAll();
|
|
316
265
|
});
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
]
|
|
266
|
+
it('creates the pull request with commit reference', () => {
|
|
267
|
+
expect(createPullRequestCalls).toMatchInlineSnapshot(`
|
|
268
|
+
Array [
|
|
269
|
+
Object {
|
|
270
|
+
"base": "6.x",
|
|
271
|
+
"body": "# Backport
|
|
272
|
+
|
|
273
|
+
This is an automatic backport to \`6.x\` of:
|
|
274
|
+
- My original commit message (mySha)
|
|
275
|
+
|
|
276
|
+
### Questions ?
|
|
277
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
278
|
+
",
|
|
279
|
+
"head": "sqren_authenticated:backport/6.x/commit-mySha",
|
|
280
|
+
"title": "[6.x] My original commit message",
|
|
281
|
+
},
|
|
282
|
+
]
|
|
283
|
+
`);
|
|
332
284
|
});
|
|
333
285
|
it('returns the expected response', () => {
|
|
334
|
-
expect(res).toEqual({ url: 'myHtmlUrl', number:
|
|
286
|
+
expect(res).toEqual({ didUpdate: false, url: 'myHtmlUrl', number: 1337 });
|
|
335
287
|
});
|
|
336
288
|
it('shows the right prompts', () => {
|
|
337
|
-
expect(promptSpy.mock.calls.length).toBe(
|
|
289
|
+
expect(promptSpy.mock.calls.length).toBe(4);
|
|
338
290
|
expect(promptSpy.mock.calls[0][0]).toMatchInlineSnapshot(`
|
|
339
|
-
"
|
|
291
|
+
"Fix the following conflicts manually:
|
|
340
292
|
|
|
341
293
|
Conflicting files:
|
|
342
294
|
- /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
|
|
@@ -345,7 +297,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
345
297
|
Press ENTER when the conflicts are resolved and files are staged"
|
|
346
298
|
`);
|
|
347
299
|
expect(promptSpy.mock.calls[1][0]).toMatchInlineSnapshot(`
|
|
348
|
-
"
|
|
300
|
+
"Fix the following conflicts manually:
|
|
349
301
|
|
|
350
302
|
Conflicting files:
|
|
351
303
|
- /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
|
|
@@ -354,13 +306,27 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
354
306
|
Press ENTER when the conflicts are resolved and files are staged"
|
|
355
307
|
`);
|
|
356
308
|
expect(promptSpy.mock.calls[2][0]).toMatchInlineSnapshot(`
|
|
357
|
-
"
|
|
358
|
-
|
|
309
|
+
"Fix the following conflicts manually:
|
|
359
310
|
|
|
360
|
-
|
|
311
|
+
Conflicting files:
|
|
361
312
|
- /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
|
|
362
313
|
|
|
314
|
+
|
|
363
315
|
Press ENTER when the conflicts are resolved and files are staged"
|
|
316
|
+
`);
|
|
317
|
+
});
|
|
318
|
+
it('commitsByAuthor is called with correct arguments', () => {
|
|
319
|
+
expect(commitsByAuthorCalls[0].variables).toMatchInlineSnapshot(`
|
|
320
|
+
Object {
|
|
321
|
+
"authorId": null,
|
|
322
|
+
"commitPath": "conflicting-file.txt",
|
|
323
|
+
"dateSince": null,
|
|
324
|
+
"dateUntil": "2021-08-18T16:11:38Z",
|
|
325
|
+
"maxNumber": 10,
|
|
326
|
+
"repoName": "kibana",
|
|
327
|
+
"repoOwner": "elastic",
|
|
328
|
+
"sourceBranch": "myDefaultSourceBranch",
|
|
329
|
+
}
|
|
364
330
|
`);
|
|
365
331
|
});
|
|
366
332
|
it('calls exec correctly', () => {
|
|
@@ -371,12 +337,12 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
371
337
|
.toMatchInlineSnapshot(`
|
|
372
338
|
Array [
|
|
373
339
|
"Pulling latest changes",
|
|
374
|
-
"Cherry-picking:
|
|
340
|
+
"Cherry-picking: My original commit message",
|
|
375
341
|
"Finalizing cherrypick",
|
|
376
|
-
"Pushing branch \\"
|
|
342
|
+
"Pushing branch \\"sqren_authenticated:backport/6.x/commit-mySha\\"",
|
|
377
343
|
undefined,
|
|
378
344
|
"Creating pull request",
|
|
379
|
-
"Adding labels:
|
|
345
|
+
"Adding labels: backport",
|
|
380
346
|
]
|
|
381
347
|
`);
|
|
382
348
|
});
|
|
@@ -387,7 +353,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
387
353
|
`);
|
|
388
354
|
expect(consoleLogSpy.mock.calls[1][0]).toMatchInlineSnapshot(`
|
|
389
355
|
"
|
|
390
|
-
|
|
356
|
+
The commit could not be backported due to conflicts
|
|
391
357
|
"
|
|
392
358
|
`);
|
|
393
359
|
expect(consoleLogSpy.mock.calls[2][0]).toMatchInlineSnapshot(`
|
|
@@ -395,11 +361,15 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
395
361
|
----------------------------------------
|
|
396
362
|
"
|
|
397
363
|
`);
|
|
398
|
-
expect(consoleLogSpy.mock.calls[3][0]).toMatchInlineSnapshot(`
|
|
364
|
+
expect(consoleLogSpy.mock.calls[3][0]).toMatchInlineSnapshot(`
|
|
365
|
+
"
|
|
366
|
+
----------------------------------------
|
|
367
|
+
"
|
|
368
|
+
`);
|
|
399
369
|
});
|
|
400
370
|
});
|
|
401
371
|
});
|
|
402
|
-
function
|
|
372
|
+
function setupExecSpyForCherryPick() {
|
|
403
373
|
let conflictingFilesCheck = 0;
|
|
404
374
|
let unstagedFilesCheck = 0;
|
|
405
375
|
return jest
|
|
@@ -414,9 +384,13 @@ function setupExecSpy() {
|
|
|
414
384
|
return { stderr: '', stdout: '' };
|
|
415
385
|
}
|
|
416
386
|
// cherrypick
|
|
417
|
-
if (cmd === 'git cherry-pick mySha') {
|
|
387
|
+
if (cmd === 'git cherry-pick -x mySha') {
|
|
418
388
|
throw new ExecError_1.ExecError({ cmd });
|
|
419
389
|
}
|
|
390
|
+
// getIsCommitInBranch
|
|
391
|
+
if (cmd.startsWith('git merge-base --is-ancestor')) {
|
|
392
|
+
return { stderr: '', stdout: '' };
|
|
393
|
+
}
|
|
420
394
|
// getConflictingFiles
|
|
421
395
|
if (cmd === 'git --no-pager diff --check') {
|
|
422
396
|
conflictingFilesCheck++;
|
|
@@ -453,16 +427,6 @@ function setupExecSpy() {
|
|
|
453
427
|
if (cmd.includes('git branch -D ')) {
|
|
454
428
|
return { stdout: ``, stderr: '' };
|
|
455
429
|
}
|
|
456
|
-
throw new Error(`Missing mock for "${cmd}"`);
|
|
430
|
+
throw new Error(`Missing exec mock for "${cmd}"`);
|
|
457
431
|
});
|
|
458
432
|
}
|
|
459
|
-
function mockCreatePullRequestCall() {
|
|
460
|
-
return nockHelpers_1.createNockListener(nock_1.default('https://api.github.com')
|
|
461
|
-
.post('/repos/elastic/kibana/pulls')
|
|
462
|
-
.reply(200, { html_url: 'myHtmlUrl', number: TARGET_PULL_NUMBER }));
|
|
463
|
-
}
|
|
464
|
-
function mockAddLabelCall(pullNumber) {
|
|
465
|
-
return nockHelpers_1.createNockListener(nock_1.default('https://api.github.com')
|
|
466
|
-
.post(`/repos/elastic/kibana/issues/${pullNumber}/labels`)
|
|
467
|
-
.reply(200));
|
|
468
|
-
}
|
package/dist/ui/getCommits.js
CHANGED
|
@@ -35,7 +35,7 @@ async function getCommits(options) {
|
|
|
35
35
|
pullNumber: options.pullNumber, // must extract pullNumber to satisfy the ts gods
|
|
36
36
|
});
|
|
37
37
|
// add styles to make it look like a prompt question
|
|
38
|
-
spinner.stopAndPersist(getOraPersistsOption('Select pull request', commit.originalMessage));
|
|
38
|
+
spinner.stopAndPersist(getOraPersistsOption('Select pull request', (0, commitFormatters_1.getFirstLine)(commit.originalMessage)));
|
|
39
39
|
return [commit];
|
|
40
40
|
}
|
|
41
41
|
if (options.ci) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Commit } from '../entrypoint.module';
|
|
2
|
+
import { ValidConfigOptions } from '../options/options';
|
|
3
|
+
export declare function getCommitsWithoutBackports({ options, commit, targetBranch, conflictingFiles, }: {
|
|
4
|
+
options: ValidConfigOptions;
|
|
5
|
+
commit: Commit;
|
|
6
|
+
targetBranch: string;
|
|
7
|
+
conflictingFiles: string[];
|
|
8
|
+
}): Promise<{
|
|
9
|
+
formatted: string;
|
|
10
|
+
commit: Commit;
|
|
11
|
+
}[]>;
|