backport 6.1.2 → 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/dist/options/config/globalConfig.js +1 -1
- package/dist/options/options.test.js +2 -1
- package/dist/runSequentially.test.js +1 -0
- package/dist/services/github/v3/createPullRequest.js +1 -1
- package/dist/services/github/v3/createStatusComment.test.js +58 -29
- package/dist/test/inquirer.private.test.js +1 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +222 -260
- package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/ui/getCommitsWithoutBackports.test.js +259 -0
- package/package.json +1 -1
|
@@ -50,7 +50,7 @@ async function createGlobalConfigIfNotExist(globalConfigPath, configTemplate) {
|
|
|
50
50
|
exports.createGlobalConfigIfNotExist = createGlobalConfigIfNotExist;
|
|
51
51
|
function getConfigTemplate() {
|
|
52
52
|
return `{
|
|
53
|
-
// Github personal access token. Must be created here: https://github.com/settings/tokens
|
|
53
|
+
// Github personal access token. Must be created here: https://github.com/settings/tokens
|
|
54
54
|
// Must have "Repo: Full control of private repositories"
|
|
55
55
|
"accessToken": ""
|
|
56
56
|
}`;
|
|
@@ -126,9 +126,10 @@ describe('getOptions', () => {
|
|
|
126
126
|
accessToken: 'abc',
|
|
127
127
|
assignees: [],
|
|
128
128
|
autoAssign: false,
|
|
129
|
+
authenticatedUsername: 'john.diller',
|
|
129
130
|
autoMerge: false,
|
|
130
131
|
autoMergeMethod: 'merge',
|
|
131
|
-
|
|
132
|
+
backportBinary: 'backport',
|
|
132
133
|
branchLabelMapping: {
|
|
133
134
|
foo: 'bar',
|
|
134
135
|
},
|
|
@@ -66,7 +66,7 @@ function getPullRequestBody({ options, commits, targetBranch, }) {
|
|
|
66
66
|
.join('\n');
|
|
67
67
|
return `# Backport
|
|
68
68
|
|
|
69
|
-
This is an automatic backport to
|
|
69
|
+
This is an automatic backport to \`${targetBranch}\` of:
|
|
70
70
|
${commitMessages}
|
|
71
71
|
|
|
72
72
|
### Questions ?
|
|
@@ -5,7 +5,9 @@ const createStatusComment_1 = require("./createStatusComment");
|
|
|
5
5
|
describe('getCommentBody', () => {
|
|
6
6
|
it('when an unknown error occurs', () => {
|
|
7
7
|
expect((0, createStatusComment_1.getCommentBody)({
|
|
8
|
-
options: {
|
|
8
|
+
options: {
|
|
9
|
+
backportBinary: 'node scripts/backport',
|
|
10
|
+
},
|
|
9
11
|
pullNumber: 55,
|
|
10
12
|
backportResponse: {
|
|
11
13
|
status: 'failure',
|
|
@@ -16,9 +18,15 @@ describe('getCommentBody', () => {
|
|
|
16
18
|
The pull request could not be backported due to the following error:
|
|
17
19
|
\`A terrible error occured\`
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
## How to fix
|
|
22
|
+
|
|
23
|
+
Re-run the backport manually:
|
|
24
|
+
\`\`\`
|
|
25
|
+
node scripts/backport --pr 55
|
|
26
|
+
\`\`\`
|
|
27
|
+
|
|
28
|
+
### Questions ?
|
|
29
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
22
30
|
`);
|
|
23
31
|
});
|
|
24
32
|
it('when all backports succeed', () => {
|
|
@@ -50,12 +58,14 @@ describe('getCommentBody', () => {
|
|
|
50
58
|
"## 💚 All backports created successfully
|
|
51
59
|
|
|
52
60
|
| Status | Branch | Result |
|
|
53
|
-
|
|
61
|
+
|:------:|:------:|:------|
|
|
54
62
|
|✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
|
|
55
63
|
|✅|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
|
|
56
64
|
|
|
57
65
|
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
58
|
-
|
|
66
|
+
|
|
67
|
+
### Questions ?
|
|
68
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
59
69
|
`);
|
|
60
70
|
});
|
|
61
71
|
it('when all backports fail', () => {
|
|
@@ -64,6 +74,7 @@ describe('getCommentBody', () => {
|
|
|
64
74
|
repoName: 'kibana',
|
|
65
75
|
repoOwner: 'elastic',
|
|
66
76
|
autoMerge: true,
|
|
77
|
+
backportBinary: 'node scripts/backport',
|
|
67
78
|
},
|
|
68
79
|
pullNumber: 55,
|
|
69
80
|
backportResponse: {
|
|
@@ -87,14 +98,19 @@ describe('getCommentBody', () => {
|
|
|
87
98
|
"## 💔 Some backports could not be created
|
|
88
99
|
|
|
89
100
|
| Status | Branch | Result |
|
|
90
|
-
|
|
101
|
+
|:------:|:------:|:------|
|
|
91
102
|
|❌|7.x|My boom error!|
|
|
92
103
|
|❌|7.1|My boom error!|
|
|
93
104
|
|
|
94
|
-
|
|
95
|
-
For more info read the [Backport documentation](https://github.com/sqren/backport#backport)
|
|
105
|
+
## How to fix
|
|
96
106
|
|
|
97
|
-
|
|
107
|
+
Re-run the backport manually:
|
|
108
|
+
\`\`\`
|
|
109
|
+
node scripts/backport --pr 55
|
|
110
|
+
\`\`\`
|
|
111
|
+
|
|
112
|
+
### Questions ?
|
|
113
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
98
114
|
`);
|
|
99
115
|
});
|
|
100
116
|
it('when some backports fail', () => {
|
|
@@ -103,6 +119,7 @@ describe('getCommentBody', () => {
|
|
|
103
119
|
repoName: 'kibana',
|
|
104
120
|
repoOwner: 'elastic',
|
|
105
121
|
autoMerge: true,
|
|
122
|
+
backportBinary: 'node scripts/backport',
|
|
106
123
|
},
|
|
107
124
|
pullNumber: 55,
|
|
108
125
|
backportResponse: {
|
|
@@ -126,15 +143,20 @@ describe('getCommentBody', () => {
|
|
|
126
143
|
"## 💔 Some backports could not be created
|
|
127
144
|
|
|
128
145
|
| Status | Branch | Result |
|
|
129
|
-
|
|
146
|
+
|:------:|:------:|:------|
|
|
130
147
|
|✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
|
|
131
148
|
|❌|7.1|My boom error!|
|
|
132
149
|
|
|
133
|
-
|
|
134
|
-
For more info read the [Backport documentation](https://github.com/sqren/backport#backport)
|
|
150
|
+
## How to fix
|
|
135
151
|
|
|
152
|
+
Re-run the backport manually:
|
|
153
|
+
\`\`\`
|
|
154
|
+
node scripts/backport --pr 55
|
|
155
|
+
\`\`\`
|
|
136
156
|
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
137
|
-
|
|
157
|
+
|
|
158
|
+
### Questions ?
|
|
159
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
138
160
|
`);
|
|
139
161
|
});
|
|
140
162
|
it('when some backports fail due to conflicts', () => {
|
|
@@ -143,6 +165,7 @@ describe('getCommentBody', () => {
|
|
|
143
165
|
repoName: 'kibana',
|
|
144
166
|
repoOwner: 'elastic',
|
|
145
167
|
autoMerge: true,
|
|
168
|
+
backportBinary: 'node scripts/backport',
|
|
146
169
|
},
|
|
147
170
|
pullNumber: 55,
|
|
148
171
|
backportResponse: {
|
|
@@ -166,6 +189,15 @@ describe('getCommentBody', () => {
|
|
|
166
189
|
commit: {
|
|
167
190
|
pullNumber: 5,
|
|
168
191
|
pullUrl: 'url-to-pr-5',
|
|
192
|
+
originalMessage: 'New Zealand commit message',
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
//@ts-expect-error
|
|
197
|
+
commit: {
|
|
198
|
+
pullNumber: 44,
|
|
199
|
+
pullUrl: 'url-to-pr-44',
|
|
200
|
+
originalMessage: 'Australia commit',
|
|
169
201
|
},
|
|
170
202
|
},
|
|
171
203
|
],
|
|
@@ -177,15 +209,7 @@ describe('getCommentBody', () => {
|
|
|
177
209
|
errorMessage: 'My boom error!',
|
|
178
210
|
error: new HandledError_1.HandledError('Boom!', {
|
|
179
211
|
type: 'commitsWithoutBackports',
|
|
180
|
-
commitsWithoutBackports: [
|
|
181
|
-
{
|
|
182
|
-
//@ts-expect-error
|
|
183
|
-
commit: {
|
|
184
|
-
sha: 'acdefg',
|
|
185
|
-
originalMessage: 'Some long message\nin multiple lines',
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
],
|
|
212
|
+
commitsWithoutBackports: [],
|
|
189
213
|
}),
|
|
190
214
|
},
|
|
191
215
|
],
|
|
@@ -194,16 +218,21 @@ describe('getCommentBody', () => {
|
|
|
194
218
|
"## 💔 Some backports could not be created
|
|
195
219
|
|
|
196
220
|
| Status | Branch | Result |
|
|
197
|
-
|
|
221
|
+
|:------:|:------:|:------|
|
|
198
222
|
|✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
|
|
199
|
-
|❌|7.1
|
|
200
|
-
|❌|7.2
|
|
223
|
+
|❌|7.1|**Backport failed because of merge conflicts**<br><br>You might need to backport the following PRs to 7.1:<br> - [New Zealand commit message](url-to-pr-5)<br> - [Australia commit](url-to-pr-44)|
|
|
224
|
+
|❌|7.2|**Backport failed because of merge conflicts**|
|
|
201
225
|
|
|
202
|
-
|
|
203
|
-
For more info read the [Backport documentation](https://github.com/sqren/backport#backport)
|
|
226
|
+
## How to fix
|
|
204
227
|
|
|
228
|
+
Re-run the backport manually:
|
|
229
|
+
\`\`\`
|
|
230
|
+
node scripts/backport --pr 55
|
|
231
|
+
\`\`\`
|
|
205
232
|
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
206
|
-
|
|
233
|
+
|
|
234
|
+
### Questions ?
|
|
235
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
207
236
|
`);
|
|
208
237
|
});
|
|
209
238
|
});
|
|
@@ -50,7 +50,7 @@ describe('inquirer cli', () => {
|
|
|
50
50
|
devAccessToken,
|
|
51
51
|
]);
|
|
52
52
|
const lineCount = res.split('\n').length;
|
|
53
|
-
expect(lineCount).toBe(
|
|
53
|
+
expect(lineCount).toBe(11);
|
|
54
54
|
expect(res.includes('Select commit (Use arrow keys)')).toBe(true);
|
|
55
55
|
});
|
|
56
56
|
it('should return error when access token is invalid', async () => {
|
|
@@ -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: 'eee',
|
|
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,25 @@ 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
|
+
"maxNumber": 10,
|
|
324
|
+
"repoName": "kibana",
|
|
325
|
+
"repoOwner": "elastic",
|
|
326
|
+
"sourceBranch": "myDefaultSourceBranch",
|
|
327
|
+
}
|
|
364
328
|
`);
|
|
365
329
|
});
|
|
366
330
|
it('calls exec correctly', () => {
|
|
@@ -371,12 +335,12 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
371
335
|
.toMatchInlineSnapshot(`
|
|
372
336
|
Array [
|
|
373
337
|
"Pulling latest changes",
|
|
374
|
-
"Cherry-picking:
|
|
338
|
+
"Cherry-picking: My original commit message",
|
|
375
339
|
"Finalizing cherrypick",
|
|
376
|
-
"Pushing branch \\"
|
|
340
|
+
"Pushing branch \\"sqren_authenticated:backport/6.x/commit-mySha\\"",
|
|
377
341
|
undefined,
|
|
378
342
|
"Creating pull request",
|
|
379
|
-
"Adding labels:
|
|
343
|
+
"Adding labels: backport",
|
|
380
344
|
]
|
|
381
345
|
`);
|
|
382
346
|
});
|
|
@@ -387,7 +351,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
387
351
|
`);
|
|
388
352
|
expect(consoleLogSpy.mock.calls[1][0]).toMatchInlineSnapshot(`
|
|
389
353
|
"
|
|
390
|
-
|
|
354
|
+
The commit could not be backported due to conflicts
|
|
391
355
|
"
|
|
392
356
|
`);
|
|
393
357
|
expect(consoleLogSpy.mock.calls[2][0]).toMatchInlineSnapshot(`
|
|
@@ -395,11 +359,15 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
395
359
|
----------------------------------------
|
|
396
360
|
"
|
|
397
361
|
`);
|
|
398
|
-
expect(consoleLogSpy.mock.calls[3][0]).toMatchInlineSnapshot(`
|
|
362
|
+
expect(consoleLogSpy.mock.calls[3][0]).toMatchInlineSnapshot(`
|
|
363
|
+
"
|
|
364
|
+
----------------------------------------
|
|
365
|
+
"
|
|
366
|
+
`);
|
|
399
367
|
});
|
|
400
368
|
});
|
|
401
369
|
});
|
|
402
|
-
function
|
|
370
|
+
function setupExecSpyForCherryPick() {
|
|
403
371
|
let conflictingFilesCheck = 0;
|
|
404
372
|
let unstagedFilesCheck = 0;
|
|
405
373
|
return jest
|
|
@@ -414,9 +382,13 @@ function setupExecSpy() {
|
|
|
414
382
|
return { stderr: '', stdout: '' };
|
|
415
383
|
}
|
|
416
384
|
// cherrypick
|
|
417
|
-
if (cmd === 'git cherry-pick mySha') {
|
|
385
|
+
if (cmd === 'git cherry-pick -x mySha') {
|
|
418
386
|
throw new ExecError_1.ExecError({ cmd });
|
|
419
387
|
}
|
|
388
|
+
// getIsCommitInBranch
|
|
389
|
+
if (cmd.startsWith('git merge-base --is-ancestor')) {
|
|
390
|
+
return { stderr: '', stdout: '' };
|
|
391
|
+
}
|
|
420
392
|
// getConflictingFiles
|
|
421
393
|
if (cmd === 'git --no-pager diff --check') {
|
|
422
394
|
conflictingFilesCheck++;
|
|
@@ -453,16 +425,6 @@ function setupExecSpy() {
|
|
|
453
425
|
if (cmd.includes('git branch -D ')) {
|
|
454
426
|
return { stdout: ``, stderr: '' };
|
|
455
427
|
}
|
|
456
|
-
throw new Error(`Missing mock for "${cmd}"`);
|
|
428
|
+
throw new Error(`Missing exec mock for "${cmd}"`);
|
|
457
429
|
});
|
|
458
430
|
}
|
|
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
|
-
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,259 @@
|
|
|
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 strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
26
|
+
const git = __importStar(require("../services/git"));
|
|
27
|
+
const fetchCommitsByAuthorModule = __importStar(require("../services/github/v4/fetchCommits/fetchCommitsByAuthor"));
|
|
28
|
+
const getCommitsWithoutBackports_1 = require("./getCommitsWithoutBackports");
|
|
29
|
+
describe('getCommitsWithoutBackports', () => {
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
jest.restoreAllMocks();
|
|
32
|
+
});
|
|
33
|
+
describe('expectedTargetPullRequests', () => {
|
|
34
|
+
function setupExpectedPullRequests({ expectedTargetPullRequests, }) {
|
|
35
|
+
// simulate 1 unbackported commit
|
|
36
|
+
jest
|
|
37
|
+
.spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
|
|
38
|
+
.mockResolvedValueOnce([
|
|
39
|
+
{
|
|
40
|
+
committedDate: '10',
|
|
41
|
+
expectedTargetPullRequests,
|
|
42
|
+
originalMessage: 'First commit (#1)',
|
|
43
|
+
sha: 'xyz',
|
|
44
|
+
sourceBranch: 'main',
|
|
45
|
+
pullUrl: 'https://www.github.com/foo/bar/pull/123',
|
|
46
|
+
},
|
|
47
|
+
]);
|
|
48
|
+
// simulate commit is definitely not backported
|
|
49
|
+
jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
|
|
50
|
+
return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
|
|
51
|
+
options: {},
|
|
52
|
+
commit: {
|
|
53
|
+
committedDate: '100',
|
|
54
|
+
expectedTargetPullRequests: [],
|
|
55
|
+
originalMessage: 'Second commit (#2)',
|
|
56
|
+
sha: 'abc',
|
|
57
|
+
sourceBranch: 'main',
|
|
58
|
+
},
|
|
59
|
+
targetBranch: '7.x',
|
|
60
|
+
conflictingFiles: ['/foo/bar/baz.ts'],
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
it('should not unbackported commits if no backports were expected', async () => {
|
|
64
|
+
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
65
|
+
expectedTargetPullRequests: [],
|
|
66
|
+
});
|
|
67
|
+
expect(commitsWithoutBackports.length).toEqual(0);
|
|
68
|
+
});
|
|
69
|
+
it('should display as missing if a backport is CLOSED', async () => {
|
|
70
|
+
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
71
|
+
expectedTargetPullRequests: [
|
|
72
|
+
{
|
|
73
|
+
state: 'CLOSED',
|
|
74
|
+
branch: '7.x',
|
|
75
|
+
number: 456,
|
|
76
|
+
url: 'https://www.github.com/foo/bar/pull/456',
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
});
|
|
80
|
+
expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport missing)\n https://www.github.com/foo/bar/pull/123');
|
|
81
|
+
});
|
|
82
|
+
it('should display as missing if a backport is MISSING', async () => {
|
|
83
|
+
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
84
|
+
expectedTargetPullRequests: [{ state: 'MISSING', branch: '7.x' }],
|
|
85
|
+
});
|
|
86
|
+
expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport missing)\n https://www.github.com/foo/bar/pull/123');
|
|
87
|
+
});
|
|
88
|
+
it('should display as pending if a backport is OPEN', async () => {
|
|
89
|
+
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
90
|
+
expectedTargetPullRequests: [
|
|
91
|
+
{
|
|
92
|
+
state: 'OPEN',
|
|
93
|
+
branch: '7.x',
|
|
94
|
+
url: 'https://www.github.com/foo/bar/pull/456',
|
|
95
|
+
number: 456,
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
});
|
|
99
|
+
expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)\n https://www.github.com/foo/bar/pull/456');
|
|
100
|
+
});
|
|
101
|
+
it('should not display commit as unbackported if a backport was MERGED', async () => {
|
|
102
|
+
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
103
|
+
expectedTargetPullRequests: [
|
|
104
|
+
{
|
|
105
|
+
state: 'MERGED',
|
|
106
|
+
branch: '7.x',
|
|
107
|
+
number: 456,
|
|
108
|
+
url: 'https://www.github.com/foo/bar/pull/456',
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
});
|
|
112
|
+
expect(commitsWithoutBackports).toEqual([]);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
describe('commitDate', () => {
|
|
116
|
+
function setupCommitDateDiff({ offendingCommitDate, currentCommitDate, }) {
|
|
117
|
+
// simulate 1 commit with a pending backport
|
|
118
|
+
jest
|
|
119
|
+
.spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
|
|
120
|
+
.mockResolvedValueOnce([
|
|
121
|
+
{
|
|
122
|
+
committedDate: offendingCommitDate,
|
|
123
|
+
expectedTargetPullRequests: [
|
|
124
|
+
{
|
|
125
|
+
state: 'OPEN',
|
|
126
|
+
branch: '7.x',
|
|
127
|
+
number: 456,
|
|
128
|
+
url: 'https://www.github.com/foo/bar/pull/456',
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
originalMessage: 'First commit (#1)',
|
|
132
|
+
sha: 'xyz',
|
|
133
|
+
sourceBranch: 'main',
|
|
134
|
+
pullNumber: 123,
|
|
135
|
+
pullUrl: 'https://www.github.com/foo/bar/pull/123',
|
|
136
|
+
},
|
|
137
|
+
]);
|
|
138
|
+
// simulate commit is definitely not backported
|
|
139
|
+
jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
|
|
140
|
+
return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
|
|
141
|
+
options: {},
|
|
142
|
+
commit: {
|
|
143
|
+
committedDate: currentCommitDate,
|
|
144
|
+
expectedTargetPullRequests: [],
|
|
145
|
+
originalMessage: 'Second commit (#2)',
|
|
146
|
+
sha: 'abc',
|
|
147
|
+
sourceBranch: 'main',
|
|
148
|
+
},
|
|
149
|
+
targetBranch: '7.x',
|
|
150
|
+
conflictingFiles: ['/foo/bar/baz.ts'],
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
it('should not display commit as unbackport if is newer than the commit currently being backported', async () => {
|
|
154
|
+
const commitsWithoutBackports = await setupCommitDateDiff({
|
|
155
|
+
offendingCommitDate: '100',
|
|
156
|
+
currentCommitDate: '10',
|
|
157
|
+
});
|
|
158
|
+
expect(commitsWithoutBackports).toEqual([]);
|
|
159
|
+
});
|
|
160
|
+
it('should display commit as unbackport if is older than the commit currently being backported', async () => {
|
|
161
|
+
const commitsWithoutBackports = await setupCommitDateDiff({
|
|
162
|
+
offendingCommitDate: '10',
|
|
163
|
+
currentCommitDate: '100',
|
|
164
|
+
});
|
|
165
|
+
expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)\n https://www.github.com/foo/bar/pull/456');
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
describe('targetBranch', () => {
|
|
169
|
+
function setupTargetBranchDiff({ offendingCommitTargetBranch, currentCommitTargetBranch, }) {
|
|
170
|
+
// return mock commits that also touched the conflicting files
|
|
171
|
+
jest
|
|
172
|
+
.spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
|
|
173
|
+
.mockResolvedValueOnce([
|
|
174
|
+
{
|
|
175
|
+
pullUrl: 'https://www.github.com/foo/bar/pull/123',
|
|
176
|
+
pullNumber: 123,
|
|
177
|
+
committedDate: '10',
|
|
178
|
+
expectedTargetPullRequests: [
|
|
179
|
+
{
|
|
180
|
+
branch: offendingCommitTargetBranch,
|
|
181
|
+
state: 'OPEN',
|
|
182
|
+
url: 'https://www.github.com/foo/bar/pull/456',
|
|
183
|
+
number: 456,
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
originalMessage: 'First commit (#1)',
|
|
187
|
+
sha: 'xyz',
|
|
188
|
+
sourceBranch: 'main',
|
|
189
|
+
},
|
|
190
|
+
]);
|
|
191
|
+
// simulate commit is definitely not backported
|
|
192
|
+
jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
|
|
193
|
+
return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
|
|
194
|
+
options: {},
|
|
195
|
+
// commit that is being backported
|
|
196
|
+
commit: {
|
|
197
|
+
pullUrl: 'https://www.github.com/foo/bar/pull/123',
|
|
198
|
+
pullNumber: 123,
|
|
199
|
+
committedDate: '100',
|
|
200
|
+
expectedTargetPullRequests: [],
|
|
201
|
+
originalMessage: 'Second commit (#2)',
|
|
202
|
+
sha: 'abc',
|
|
203
|
+
sourceBranch: 'main',
|
|
204
|
+
},
|
|
205
|
+
targetBranch: currentCommitTargetBranch,
|
|
206
|
+
conflictingFiles: ['/foo/bar/baz.ts'],
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
it('should display backport as pending if target branches match', async () => {
|
|
210
|
+
const commitsWithoutBackports = await setupTargetBranchDiff({
|
|
211
|
+
offendingCommitTargetBranch: '7.x',
|
|
212
|
+
currentCommitTargetBranch: '7.x',
|
|
213
|
+
});
|
|
214
|
+
expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)\n https://www.github.com/foo/bar/pull/456');
|
|
215
|
+
});
|
|
216
|
+
it("should not display commit if target branches don't match", async () => {
|
|
217
|
+
const commitsWithoutBackports = await setupTargetBranchDiff({
|
|
218
|
+
offendingCommitTargetBranch: '7.x',
|
|
219
|
+
currentCommitTargetBranch: '8.x',
|
|
220
|
+
});
|
|
221
|
+
expect(commitsWithoutBackports.length).toBe(0);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
describe("when conflicting commit doesn't have an associated pull request", () => {
|
|
225
|
+
it('should be ignored', async () => {
|
|
226
|
+
jest
|
|
227
|
+
.spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
|
|
228
|
+
.mockResolvedValueOnce([
|
|
229
|
+
{
|
|
230
|
+
// intentionally left out:
|
|
231
|
+
// pullNumber: 33,
|
|
232
|
+
// pullUrl: 'https://www.github.com/foo/bar/pull/123',
|
|
233
|
+
committedDate: '10',
|
|
234
|
+
expectedTargetPullRequests: [],
|
|
235
|
+
originalMessage: 'First commit (#1)',
|
|
236
|
+
sha: 'xyz',
|
|
237
|
+
sourceBranch: 'main',
|
|
238
|
+
},
|
|
239
|
+
]);
|
|
240
|
+
// simulate commit is definitely not backported
|
|
241
|
+
jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
|
|
242
|
+
const commitsWithoutBackports = await (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
|
|
243
|
+
options: {},
|
|
244
|
+
commit: {
|
|
245
|
+
pullUrl: 'https://www.github.com/foo/bar/pull/123',
|
|
246
|
+
pullNumber: 123,
|
|
247
|
+
committedDate: '100',
|
|
248
|
+
expectedTargetPullRequests: [],
|
|
249
|
+
originalMessage: 'Second commit (#2)',
|
|
250
|
+
sha: 'abc',
|
|
251
|
+
sourceBranch: 'main',
|
|
252
|
+
},
|
|
253
|
+
targetBranch: '7.x',
|
|
254
|
+
conflictingFiles: ['/foo/bar/baz.ts'],
|
|
255
|
+
});
|
|
256
|
+
expect(commitsWithoutBackports.length).toEqual(0);
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
});
|