backport 7.4.0 → 8.0.0
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 +12 -13
- package/dist/backportRun.d.ts +8 -3
- package/dist/backportRun.js +54 -42
- package/dist/entrypoint.cli.js +1 -1
- package/dist/entrypoint.module.d.ts +8 -3
- package/dist/entrypoint.module.js +3 -11
- package/dist/entrypoint.module.private.test.js +47 -346
- package/dist/options/cliArgs.d.ts +9 -4
- package/dist/options/cliArgs.js +28 -15
- package/dist/options/cliArgs.test.js +3 -3
- package/dist/options/config/globalConfig.d.ts +2 -2
- package/dist/options/config/globalConfig.js +13 -10
- package/dist/options/config/readConfigFile.d.ts +2 -2
- package/dist/options/options.d.ts +3 -3
- package/dist/options/options.test.js +5 -1
- package/dist/runSequentially.d.ts +6 -2
- package/dist/runSequentially.js +23 -7
- package/dist/scripts/postinstall.js +1 -0
- package/dist/scripts/postinstall.test.js +5 -1
- package/dist/services/HandledError.d.ts +1 -1
- package/dist/services/HandledError.js +2 -2
- package/dist/services/child-process-promisified.d.ts +19 -3
- package/dist/services/child-process-promisified.js +46 -17
- package/dist/services/git.d.ts +6 -7
- package/dist/services/git.integration.test.js +381 -65
- package/dist/services/git.js +188 -122
- package/dist/services/git.private.test.d.ts +1 -0
- package/dist/services/git.private.test.js +618 -0
- package/dist/services/git.test.js +167 -124
- package/dist/services/github/v3/addAssigneesToPullRequest.js +1 -1
- package/dist/services/github/v3/addLabelsToPullRequest.js +1 -1
- package/dist/services/github/v3/addReviewersToPullRequest.js +2 -1
- package/dist/services/github/v3/createPullRequest.js +3 -1
- package/dist/services/github/v3/createStatusComment.js +14 -15
- package/dist/services/github/v3/createStatusComment.test.js +15 -5
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +1 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +5 -1
- package/dist/services/logger.js +5 -1
- package/dist/services/test.d.ts +1 -0
- package/dist/services/test.js +23 -0
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +194 -12
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +17 -16
- package/dist/test/e2e/cli/runBackportViaCli.d.ts +2 -1
- package/dist/test/e2e/cli/runBackportViaCli.js +10 -2
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +26 -19
- package/dist/test/handleUnbackportedPullRequests.private.test.js +10 -8
- package/dist/test/sandbox.js +5 -1
- package/dist/test/setupFiles/automatic-mocks.js +5 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +1 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +7 -159
- package/dist/ui/getCommitsWithoutBackports.test.js +5 -1
- package/dist/ui/getGitConfigAuthor.js +1 -1
- package/dist/ui/getTargetBranches.test.js +5 -1
- package/dist/ui/ora.d.ts +1 -8
- package/dist/ui/setupRepo.js +1 -1
- package/dist/ui/setupRepo.test.js +98 -61
- package/dist/utils/isErrnoError.d.ts +2 -0
- package/dist/utils/isErrnoError.js +7 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +13 -13
- package/yarn.lock +414 -695
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -23,6 +27,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
27
|
};
|
|
24
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
29
|
const promises_1 = require("fs/promises");
|
|
30
|
+
const promises_2 = __importDefault(require("fs/promises"));
|
|
31
|
+
const path_1 = __importDefault(require("path"));
|
|
26
32
|
const make_dir_1 = __importDefault(require("make-dir"));
|
|
27
33
|
const sandbox_1 = require("../test/sandbox");
|
|
28
34
|
const childProcess = __importStar(require("./child-process-promisified"));
|
|
@@ -35,90 +41,182 @@ describe('git.integration', () => {
|
|
|
35
41
|
describe('getIsCommitInBranch', () => {
|
|
36
42
|
let firstSha;
|
|
37
43
|
let secondSha;
|
|
38
|
-
const
|
|
44
|
+
const cwd = (0, sandbox_1.getSandboxPath)({
|
|
39
45
|
filename: __filename,
|
|
40
46
|
specname: 'getIsCommitInBranch',
|
|
41
47
|
});
|
|
42
48
|
beforeEach(async () => {
|
|
43
|
-
await (0, sandbox_1.resetSandbox)(
|
|
44
|
-
const execOpts = { cwd: sandboxPath };
|
|
49
|
+
await (0, sandbox_1.resetSandbox)(cwd);
|
|
45
50
|
// create and commit first file
|
|
46
|
-
await
|
|
51
|
+
await gitInit(cwd);
|
|
47
52
|
firstSha = await createAndCommitFile({
|
|
48
53
|
filename: 'foo.md',
|
|
49
54
|
content: 'My first file',
|
|
50
|
-
|
|
55
|
+
cwd,
|
|
51
56
|
});
|
|
52
57
|
// create 7.x branch (but stay on `main` branch)
|
|
53
|
-
await childProcess.
|
|
58
|
+
await childProcess.spawnPromise('git', ['branch', '7.x'], cwd);
|
|
54
59
|
// create and commit second file
|
|
55
60
|
secondSha = await createAndCommitFile({
|
|
56
61
|
filename: 'bar.md',
|
|
57
62
|
content: 'My second file',
|
|
58
|
-
|
|
63
|
+
cwd,
|
|
59
64
|
});
|
|
60
65
|
// checkout 7.x
|
|
61
|
-
await childProcess.
|
|
66
|
+
await childProcess.spawnPromise('git', ['checkout', '7.x'], cwd);
|
|
62
67
|
});
|
|
63
68
|
it('should contain the first commit', async () => {
|
|
64
|
-
const isFirstCommitInBranch = await (0, git_1.getIsCommitInBranch)({ dir:
|
|
69
|
+
const isFirstCommitInBranch = await (0, git_1.getIsCommitInBranch)({ dir: cwd }, firstSha);
|
|
65
70
|
expect(isFirstCommitInBranch).toEqual(true);
|
|
66
71
|
});
|
|
67
72
|
it('should not contain the second commit', async () => {
|
|
68
|
-
const isSecondCommitInBranch = await (0, git_1.getIsCommitInBranch)({ dir:
|
|
73
|
+
const isSecondCommitInBranch = await (0, git_1.getIsCommitInBranch)({ dir: cwd }, secondSha);
|
|
69
74
|
expect(isSecondCommitInBranch).toEqual(false);
|
|
70
75
|
});
|
|
71
76
|
it('should not contain a random commit', async () => {
|
|
72
|
-
const isSecondCommitInBranch = await (0, git_1.getIsCommitInBranch)({ dir:
|
|
77
|
+
const isSecondCommitInBranch = await (0, git_1.getIsCommitInBranch)({ dir: cwd }, 'abcdefg');
|
|
73
78
|
expect(isSecondCommitInBranch).toEqual(false);
|
|
74
79
|
});
|
|
75
80
|
});
|
|
81
|
+
describe('getGitConfig', () => {
|
|
82
|
+
const cwd = (0, sandbox_1.getSandboxPath)({
|
|
83
|
+
filename: __filename,
|
|
84
|
+
specname: 'getGitConfig',
|
|
85
|
+
});
|
|
86
|
+
beforeEach(async () => {
|
|
87
|
+
await (0, sandbox_1.resetSandbox)(cwd);
|
|
88
|
+
await gitInit(cwd);
|
|
89
|
+
await childProcess.exec(`git config user.name "John Doe"`, { cwd });
|
|
90
|
+
await childProcess.exec(`git config user.email "john@jubii.dk"`, { cwd });
|
|
91
|
+
});
|
|
92
|
+
it('should retrive name', async () => {
|
|
93
|
+
const name = await (0, git_1.getGitConfig)({
|
|
94
|
+
dir: cwd,
|
|
95
|
+
key: 'user.name',
|
|
96
|
+
});
|
|
97
|
+
expect(name).toEqual('John Doe');
|
|
98
|
+
});
|
|
99
|
+
it('should retrive email', async () => {
|
|
100
|
+
const email = await (0, git_1.getGitConfig)({
|
|
101
|
+
dir: cwd,
|
|
102
|
+
key: 'user.email',
|
|
103
|
+
});
|
|
104
|
+
expect(email).toEqual('john@jubii.dk');
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
describe('createBackportBranch', () => {
|
|
108
|
+
const cwd = (0, sandbox_1.getSandboxPath)({
|
|
109
|
+
filename: __filename,
|
|
110
|
+
specname: 'createBackportBranch',
|
|
111
|
+
});
|
|
112
|
+
beforeEach(async () => {
|
|
113
|
+
await (0, sandbox_1.resetSandbox)(cwd);
|
|
114
|
+
await gitClone('https://github.com/backport-org/repo-with-conflicts.git', cwd);
|
|
115
|
+
});
|
|
116
|
+
it('creates the backport branch when `targetBranch` exists', async () => {
|
|
117
|
+
await (0, git_1.createBackportBranch)({
|
|
118
|
+
options: {
|
|
119
|
+
repoOwner: 'origin',
|
|
120
|
+
dir: cwd,
|
|
121
|
+
},
|
|
122
|
+
targetBranch: '7.x',
|
|
123
|
+
backportBranch: 'my-backport-branch',
|
|
124
|
+
});
|
|
125
|
+
expect(await getCurrentBranchName(cwd)).toEqual('my-backport-branch');
|
|
126
|
+
});
|
|
127
|
+
it('throws a handled error when `targetBranch` does not exist', async () => {
|
|
128
|
+
await expect(async () => {
|
|
129
|
+
await (0, git_1.createBackportBranch)({
|
|
130
|
+
options: {
|
|
131
|
+
repoOwner: 'origin',
|
|
132
|
+
dir: cwd,
|
|
133
|
+
},
|
|
134
|
+
targetBranch: 'foo',
|
|
135
|
+
backportBranch: 'my-backport-branch',
|
|
136
|
+
});
|
|
137
|
+
}).rejects.toThrowError('The branch "foo" is invalid or doesn\'t exist');
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
describe('pushBackportBranch', () => {
|
|
141
|
+
const cwd = (0, sandbox_1.getSandboxPath)({
|
|
142
|
+
filename: __filename,
|
|
143
|
+
specname: 'pushBackportBranch',
|
|
144
|
+
});
|
|
145
|
+
beforeEach(async () => {
|
|
146
|
+
await (0, sandbox_1.resetSandbox)(cwd);
|
|
147
|
+
await gitClone('https://github.com/backport-org/repo-with-conflicts.git', cwd);
|
|
148
|
+
await (0, git_1.createBackportBranch)({
|
|
149
|
+
options: {
|
|
150
|
+
repoOwner: 'origin',
|
|
151
|
+
dir: cwd,
|
|
152
|
+
},
|
|
153
|
+
targetBranch: '7.x',
|
|
154
|
+
backportBranch: 'my-backport-branch',
|
|
155
|
+
});
|
|
156
|
+
await childProcess.exec('git remote add sqren https://github.com/sqren/repo-with-conflicts.git', { cwd });
|
|
157
|
+
});
|
|
158
|
+
it('throws error when repo does not exist', async () => {
|
|
159
|
+
await expect(async () => {
|
|
160
|
+
await (0, git_1.pushBackportBranch)({
|
|
161
|
+
options: {
|
|
162
|
+
repoOwner: 'sqren',
|
|
163
|
+
repoName: 'repo-with-conflicts',
|
|
164
|
+
dir: cwd,
|
|
165
|
+
},
|
|
166
|
+
backportBranch: 'my-backport-branch',
|
|
167
|
+
});
|
|
168
|
+
}).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
169
|
+
"Error pushing to https://github.com/sqren/repo-with-conflicts. Repository does not exist. Either fork the repository (https://github.com/sqren/repo-with-conflicts) or disable fork mode via \\"--no-fork\\".
|
|
170
|
+
Read more about fork mode in the docs: https://github.com/sqren/backport/blob/main/docs/configuration.md#fork"
|
|
171
|
+
`);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
76
174
|
describe('cherrypick', () => {
|
|
77
175
|
let firstSha;
|
|
78
176
|
let secondSha;
|
|
79
177
|
let fourthSha;
|
|
80
|
-
let
|
|
178
|
+
let cwd;
|
|
81
179
|
const sandboxPath = (0, sandbox_1.getSandboxPath)({
|
|
82
180
|
filename: __filename,
|
|
83
181
|
specname: 'cherrypick',
|
|
84
182
|
});
|
|
85
183
|
beforeEach(async () => {
|
|
86
184
|
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
87
|
-
|
|
185
|
+
cwd = sandboxPath;
|
|
88
186
|
// create and commit first file
|
|
89
|
-
await
|
|
187
|
+
await gitInit(cwd);
|
|
90
188
|
firstSha = await createAndCommitFile({
|
|
91
189
|
filename: 'foo.md',
|
|
92
190
|
content: 'Creating first file',
|
|
93
|
-
|
|
191
|
+
cwd,
|
|
94
192
|
});
|
|
95
193
|
// create 7.x branch (but stay on `main` branch)
|
|
96
|
-
await childProcess.
|
|
194
|
+
await childProcess.spawnPromise('git', ['branch', '7.x'], cwd);
|
|
97
195
|
// create and commit second file
|
|
98
196
|
secondSha = await createAndCommitFile({
|
|
99
197
|
filename: 'bar.md',
|
|
100
198
|
content: 'Creating second file\nHello',
|
|
101
|
-
|
|
199
|
+
cwd,
|
|
102
200
|
});
|
|
103
201
|
// edit first file
|
|
104
202
|
await createAndCommitFile({
|
|
105
203
|
filename: 'foo.md',
|
|
106
204
|
content: 'Changing first file',
|
|
107
|
-
|
|
205
|
+
cwd,
|
|
108
206
|
});
|
|
109
207
|
// edit first file
|
|
110
208
|
fourthSha = await createAndCommitFile({
|
|
111
209
|
filename: 'foo.md',
|
|
112
210
|
content: 'Some more changes to the first file',
|
|
113
|
-
|
|
211
|
+
cwd,
|
|
114
212
|
});
|
|
115
213
|
// checkout 7.x
|
|
116
|
-
await childProcess.
|
|
214
|
+
await childProcess.spawnPromise('git', ['checkout', '7.x'], cwd);
|
|
117
215
|
});
|
|
118
216
|
it('should not cherrypick commit that already exists', async () => {
|
|
119
217
|
const shortSha = (0, commitFormatters_1.getShortSha)(firstSha);
|
|
120
|
-
|
|
121
|
-
options: { dir:
|
|
218
|
+
await expect(() => (0, git_1.cherrypick)({
|
|
219
|
+
options: { dir: cwd },
|
|
122
220
|
sha: firstSha,
|
|
123
221
|
commitAuthor: { name: 'Soren L', email: 'soren@mail.dk' },
|
|
124
222
|
})).rejects.toThrowError(`Cherrypick failed because the selected commit (${shortSha}) is empty. Did you already backport this commit?`);
|
|
@@ -127,7 +225,7 @@ describe('git.integration', () => {
|
|
|
127
225
|
const res = await (0, git_1.cherrypick)({
|
|
128
226
|
options: {
|
|
129
227
|
cherrypickRef: false,
|
|
130
|
-
dir:
|
|
228
|
+
dir: cwd,
|
|
131
229
|
},
|
|
132
230
|
sha: secondSha,
|
|
133
231
|
commitAuthor,
|
|
@@ -137,14 +235,14 @@ describe('git.integration', () => {
|
|
|
137
235
|
needsResolving: false,
|
|
138
236
|
unstagedFiles: [],
|
|
139
237
|
});
|
|
140
|
-
const message = await
|
|
238
|
+
const message = await getMostRecentCommitMessage(cwd);
|
|
141
239
|
expect(message).toEqual(`Update bar.md`);
|
|
142
240
|
});
|
|
143
241
|
it('should cherrypick commit cleanly and append "(cherry picked from commit...)"', async () => {
|
|
144
242
|
const res = await (0, git_1.cherrypick)({
|
|
145
243
|
options: {
|
|
146
244
|
cherrypickRef: true,
|
|
147
|
-
dir:
|
|
245
|
+
dir: cwd,
|
|
148
246
|
},
|
|
149
247
|
sha: secondSha,
|
|
150
248
|
commitAuthor,
|
|
@@ -154,12 +252,12 @@ describe('git.integration', () => {
|
|
|
154
252
|
needsResolving: false,
|
|
155
253
|
unstagedFiles: [],
|
|
156
254
|
});
|
|
157
|
-
const message = await
|
|
255
|
+
const message = await getMostRecentCommitMessage(cwd);
|
|
158
256
|
expect(message).toEqual(`Update bar.md\n\n(cherry picked from commit ${secondSha})`);
|
|
159
257
|
});
|
|
160
258
|
it('should cherrypick commit with conflicts', async () => {
|
|
161
259
|
const res = await (0, git_1.cherrypick)({
|
|
162
|
-
options: { dir:
|
|
260
|
+
options: { dir: cwd },
|
|
163
261
|
sha: fourthSha,
|
|
164
262
|
commitAuthor,
|
|
165
263
|
});
|
|
@@ -172,6 +270,70 @@ describe('git.integration', () => {
|
|
|
172
270
|
});
|
|
173
271
|
});
|
|
174
272
|
});
|
|
273
|
+
describe('commitChanges', () => {
|
|
274
|
+
const cwd = (0, sandbox_1.getSandboxPath)({
|
|
275
|
+
filename: __filename,
|
|
276
|
+
specname: 'commitChanges',
|
|
277
|
+
});
|
|
278
|
+
beforeEach(async () => {
|
|
279
|
+
await (0, sandbox_1.resetSandbox)(cwd);
|
|
280
|
+
});
|
|
281
|
+
it('should return without error if user already committed manually (and there therefore is nothing to commit)', async () => {
|
|
282
|
+
const options = { dir: cwd };
|
|
283
|
+
const commit = { sourceCommit: { message: 'my message' } };
|
|
284
|
+
await gitInit(cwd);
|
|
285
|
+
await createAndCommitFile({
|
|
286
|
+
content: 'foo',
|
|
287
|
+
filename: 'my-file-1.txt',
|
|
288
|
+
cwd,
|
|
289
|
+
});
|
|
290
|
+
expect(async () => {
|
|
291
|
+
return await (0, git_1.commitChanges)(commit, options);
|
|
292
|
+
}).not.toThrowError();
|
|
293
|
+
const message = await getMostRecentCommitMessage(cwd);
|
|
294
|
+
expect(message).toBe('Update my-file-1.txt');
|
|
295
|
+
});
|
|
296
|
+
it('should return without error if user aborts the cherrypick process', async () => {
|
|
297
|
+
const options = { dir: cwd };
|
|
298
|
+
const commit = {
|
|
299
|
+
sourceCommit: { message: 'my fallback commit message' },
|
|
300
|
+
};
|
|
301
|
+
await gitInit(cwd);
|
|
302
|
+
await createAndStageFile({
|
|
303
|
+
content: 'foo',
|
|
304
|
+
filename: 'my-file-2.txt',
|
|
305
|
+
cwd,
|
|
306
|
+
});
|
|
307
|
+
await (0, git_1.commitChanges)(commit, options);
|
|
308
|
+
const message = await getMostRecentCommitMessage(cwd);
|
|
309
|
+
expect(message).toBe('my fallback commit message');
|
|
310
|
+
});
|
|
311
|
+
it('should commit cherypicked changes after conflicts have been resolved', async () => {
|
|
312
|
+
const options = { dir: cwd };
|
|
313
|
+
const commit = {
|
|
314
|
+
sourceCommit: { message: 'my fallback commit message' },
|
|
315
|
+
};
|
|
316
|
+
await gitClone('https://github.com/backport-org/repo-with-conflicts.git', cwd);
|
|
317
|
+
await childProcess.exec('git checkout 7.x', { cwd });
|
|
318
|
+
// cherry-pick file
|
|
319
|
+
try {
|
|
320
|
+
await childProcess.spawnPromise('git', ['cherry-pick', '3a0934d1f646e4a50571cb4b137ad2b08d2e7b18'], cwd);
|
|
321
|
+
}
|
|
322
|
+
catch (e) {
|
|
323
|
+
// swallow
|
|
324
|
+
}
|
|
325
|
+
// disregard conflicts and stage all files
|
|
326
|
+
await childProcess.exec('git add -A', { cwd });
|
|
327
|
+
await (0, git_1.commitChanges)(commit, options);
|
|
328
|
+
const message = await getMostRecentCommitMessage(cwd);
|
|
329
|
+
expect(message).toMatchInlineSnapshot(`
|
|
330
|
+
"Add 🇩🇰 (#12)
|
|
331
|
+
|
|
332
|
+
# Conflicts:
|
|
333
|
+
# la-liga.md"
|
|
334
|
+
`);
|
|
335
|
+
});
|
|
336
|
+
});
|
|
175
337
|
describe('cloneRepo', () => {
|
|
176
338
|
const sandboxPath = (0, sandbox_1.getSandboxPath)({
|
|
177
339
|
filename: __filename,
|
|
@@ -181,54 +343,162 @@ describe('git.integration', () => {
|
|
|
181
343
|
const backportRepo = `${sandboxPath}/backport-repo`;
|
|
182
344
|
beforeEach(async () => {
|
|
183
345
|
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
346
|
+
});
|
|
347
|
+
it('clones the repo', async () => {
|
|
184
348
|
await (0, make_dir_1.default)(sourceRepo);
|
|
185
|
-
|
|
186
|
-
await childProcess.
|
|
187
|
-
await childProcess.exec(`git remote add origin git@github.com:elastic/kibana.git`, execOpts);
|
|
349
|
+
await gitInit(sourceRepo);
|
|
350
|
+
await childProcess.spawnPromise('git', ['remote', 'add', 'origin', 'https://github.com/elastic/kibana.git'], sourceRepo);
|
|
188
351
|
await createAndCommitFile({
|
|
189
352
|
filename: 'my-file.txt',
|
|
190
353
|
content: 'Hello!',
|
|
191
|
-
|
|
354
|
+
cwd: sourceRepo,
|
|
192
355
|
});
|
|
193
|
-
});
|
|
194
|
-
it('clones the repo', async () => {
|
|
195
356
|
// file should not exist before clone
|
|
196
357
|
await expect(() => (0, promises_1.access)(`${backportRepo}/my-file.txt`)).rejects.toThrowError();
|
|
197
358
|
await (0, git_1.cloneRepo)({ sourcePath: sourceRepo, targetPath: backportRepo }, () => null);
|
|
198
359
|
//file should exist after clone
|
|
199
360
|
await expect(() => (0, promises_1.access)(`${backportRepo}/my-file.txt`)).not.toThrowError();
|
|
200
361
|
});
|
|
362
|
+
it('clones a remote repo and continously updates the progress', async () => {
|
|
363
|
+
const onProgressSpy = jest.fn();
|
|
364
|
+
await (0, git_1.cloneRepo)({
|
|
365
|
+
sourcePath: 'https://github.com/backport-org/backport-e2e.git',
|
|
366
|
+
targetPath: backportRepo,
|
|
367
|
+
}, onProgressSpy);
|
|
368
|
+
expect(onProgressSpy).toHaveBeenCalledWith(expect.any(Number));
|
|
369
|
+
});
|
|
370
|
+
it('fails to clone repo because sourcePath is incorrect', async () => {
|
|
371
|
+
await expect(() => (0, git_1.cloneRepo)({
|
|
372
|
+
sourcePath: `${sandboxPath}/source-repo-incorrect`,
|
|
373
|
+
targetPath: backportRepo,
|
|
374
|
+
}, () => null)).rejects.toThrowError('Git clone failed with exit code: 128');
|
|
375
|
+
});
|
|
201
376
|
});
|
|
202
|
-
describe('
|
|
203
|
-
let
|
|
377
|
+
describe('getLocalConfigFileCommitDate', () => {
|
|
378
|
+
let cwd;
|
|
204
379
|
beforeEach(async () => {
|
|
205
|
-
|
|
380
|
+
cwd = (0, sandbox_1.getSandboxPath)({
|
|
206
381
|
filename: __filename,
|
|
207
|
-
specname: '
|
|
382
|
+
specname: 'getLocalConfigFileCommitDate',
|
|
208
383
|
});
|
|
209
|
-
await (0, sandbox_1.resetSandbox)(
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
384
|
+
await (0, sandbox_1.resetSandbox)(cwd);
|
|
385
|
+
await gitInit(cwd);
|
|
386
|
+
});
|
|
387
|
+
it('get the commit date for project config', async () => {
|
|
388
|
+
const timeBefore = Math.floor(Date.now() / 1000) * 1000; // round to nearest second
|
|
389
|
+
await createAndCommitFile({
|
|
390
|
+
filename: '.backportrc.json',
|
|
391
|
+
content: 'foo',
|
|
392
|
+
cwd,
|
|
393
|
+
});
|
|
394
|
+
const timeAfter = Math.ceil(Date.now() / 1000) * 1000; // round to nearest second
|
|
395
|
+
const commitedDate = await (0, git_1.getLocalConfigFileCommitDate)({ cwd });
|
|
396
|
+
expect(commitedDate).toBeGreaterThanOrEqual(timeBefore);
|
|
397
|
+
expect(commitedDate).toBeLessThanOrEqual(timeAfter);
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
describe('isLocalConfigFileUntracked', () => {
|
|
401
|
+
let cwd;
|
|
402
|
+
beforeEach(async () => {
|
|
403
|
+
cwd = (0, sandbox_1.getSandboxPath)({
|
|
404
|
+
filename: __filename,
|
|
405
|
+
specname: 'isLocalConfigFileUntracked',
|
|
406
|
+
});
|
|
407
|
+
await (0, sandbox_1.resetSandbox)(cwd);
|
|
408
|
+
await gitInit(cwd);
|
|
409
|
+
});
|
|
410
|
+
it('is not untracked when committed', async () => {
|
|
411
|
+
await createAndCommitFile({
|
|
412
|
+
filename: '.backportrc.json',
|
|
413
|
+
content: 'foo',
|
|
414
|
+
cwd,
|
|
415
|
+
});
|
|
416
|
+
const isUntracked = await (0, git_1.isLocalConfigFileUntracked)({ cwd });
|
|
417
|
+
expect(isUntracked).toBe(false);
|
|
418
|
+
});
|
|
419
|
+
it('is not untracked when staged', async () => {
|
|
420
|
+
await createAndStageFile({
|
|
421
|
+
filename: '.backportrc.json',
|
|
422
|
+
content: 'foo',
|
|
423
|
+
cwd,
|
|
424
|
+
});
|
|
425
|
+
const isUntracked = await (0, git_1.isLocalConfigFileUntracked)({ cwd });
|
|
426
|
+
expect(isUntracked).toBe(false);
|
|
427
|
+
});
|
|
428
|
+
it('is untracked when neither staged nor committed', async () => {
|
|
429
|
+
await promises_2.default.writeFile(path_1.default.join(cwd, '.backportrc.json'), 'foo');
|
|
430
|
+
const isUntracked = await (0, git_1.isLocalConfigFileUntracked)({ cwd });
|
|
431
|
+
expect(isUntracked).toBe(true);
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
describe('getLocalSourceRepoPath', () => {
|
|
435
|
+
let cwd;
|
|
436
|
+
beforeEach(async () => {
|
|
437
|
+
cwd = (0, sandbox_1.getSandboxPath)({
|
|
438
|
+
filename: __filename,
|
|
439
|
+
specname: 'getLocalSourceRepoPath',
|
|
440
|
+
});
|
|
441
|
+
await (0, sandbox_1.resetSandbox)(cwd);
|
|
442
|
+
await gitInit(cwd);
|
|
443
|
+
await childProcess.spawnPromise('git', ['remote', 'add', 'sqren', 'https://github.com/sqren/kibana.git'], cwd);
|
|
444
|
+
await childProcess.spawnPromise('git', ['remote', 'add', 'elastic', 'https://github.com/elastic/kibana.git'], cwd);
|
|
214
445
|
});
|
|
215
446
|
it('returns local source repo, when one remote matches', async () => {
|
|
216
447
|
const options = {
|
|
217
448
|
repoName: 'kibana',
|
|
218
449
|
repoOwner: 'elastic',
|
|
219
|
-
cwd
|
|
450
|
+
cwd,
|
|
220
451
|
githubApiBaseUrlV4: 'http://localhost/graphql', // required to mock the response
|
|
221
452
|
};
|
|
222
|
-
expect(await (0, git_1.
|
|
453
|
+
expect(await (0, git_1.getLocalSourceRepoPath)(options)).toBe(cwd);
|
|
223
454
|
});
|
|
224
455
|
it('returns undefined when no remotes match', async () => {
|
|
225
456
|
const options = {
|
|
226
457
|
repoName: 'kibana',
|
|
227
458
|
repoOwner: 'not-a-match',
|
|
228
|
-
cwd
|
|
459
|
+
cwd,
|
|
229
460
|
githubApiBaseUrlV4: 'http://localhost/graphql', // required to mock the response
|
|
230
461
|
};
|
|
231
|
-
expect(await (0, git_1.
|
|
462
|
+
expect(await (0, git_1.getLocalSourceRepoPath)(options)).toBe(undefined);
|
|
463
|
+
});
|
|
464
|
+
});
|
|
465
|
+
describe('getGitProjectRootPath', () => {
|
|
466
|
+
let sandboxPath;
|
|
467
|
+
let subDirectory;
|
|
468
|
+
beforeEach(async () => {
|
|
469
|
+
sandboxPath = (0, sandbox_1.getSandboxPath)({
|
|
470
|
+
filename: __filename,
|
|
471
|
+
specname: 'getGitProjectRootPath',
|
|
472
|
+
});
|
|
473
|
+
subDirectory = `${sandboxPath}/foo-dir`;
|
|
474
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
475
|
+
await gitInit(sandboxPath);
|
|
476
|
+
(0, make_dir_1.default)(subDirectory);
|
|
477
|
+
});
|
|
478
|
+
it('returns the root dir', async () => {
|
|
479
|
+
const rootPath = await (0, git_1.getGitProjectRootPath)(subDirectory);
|
|
480
|
+
expect(rootPath).toBe(sandboxPath);
|
|
481
|
+
expect(rootPath).not.toBe(subDirectory);
|
|
482
|
+
});
|
|
483
|
+
});
|
|
484
|
+
describe('isLocalConfigFileModified', () => {
|
|
485
|
+
let cwd;
|
|
486
|
+
beforeEach(async () => {
|
|
487
|
+
cwd = (0, sandbox_1.getSandboxPath)({
|
|
488
|
+
filename: __filename,
|
|
489
|
+
specname: 'isLocalConfigFileModified',
|
|
490
|
+
});
|
|
491
|
+
await (0, sandbox_1.resetSandbox)(cwd);
|
|
492
|
+
await gitClone('https://github.com/backport-org/repo-with-project-config.git', cwd);
|
|
493
|
+
});
|
|
494
|
+
it('returns false when file is unchanged', async () => {
|
|
495
|
+
const isModified = await (0, git_1.isLocalConfigFileModified)({ cwd });
|
|
496
|
+
expect(isModified).toBe(false);
|
|
497
|
+
});
|
|
498
|
+
it('returns true when file is changed', async () => {
|
|
499
|
+
await promises_2.default.writeFile(path_1.default.join(cwd, '.backportrc.json'), 'foo');
|
|
500
|
+
const isModified = await (0, git_1.isLocalConfigFileModified)({ cwd });
|
|
501
|
+
expect(isModified).toBe(true);
|
|
232
502
|
});
|
|
233
503
|
});
|
|
234
504
|
describe('when cloning "backport-org/different-merge-strategies"', () => {
|
|
@@ -236,36 +506,36 @@ describe('git.integration', () => {
|
|
|
236
506
|
const MERGE_COMMIT_HASH_2 = '0db7f1ac1233461563d8708511d1c14adbab46da';
|
|
237
507
|
const SQUASH_COMMIT_HASH = '74a76fa64b34e3ffe8f2a3f73840e1b42fd07299';
|
|
238
508
|
const REBASE_COMMIT_HASH = '9059ae0ca31caa2eebc035f2542842d6c2fde83b';
|
|
239
|
-
let
|
|
509
|
+
let cwd;
|
|
240
510
|
beforeAll(async () => {
|
|
241
|
-
|
|
511
|
+
cwd = (0, sandbox_1.getSandboxPath)({
|
|
242
512
|
filename: __filename,
|
|
243
513
|
specname: 'different-merge-strategies',
|
|
244
514
|
});
|
|
245
|
-
await (0, sandbox_1.resetSandbox)(
|
|
246
|
-
await
|
|
515
|
+
await (0, sandbox_1.resetSandbox)(cwd);
|
|
516
|
+
await gitClone('https://github.com/backport-org/different-merge-strategies.git', cwd);
|
|
247
517
|
});
|
|
248
518
|
describe('getIsMergeCommit', () => {
|
|
249
519
|
it('returns true for first merge commit', async () => {
|
|
250
|
-
const res = await (0, git_1.getIsMergeCommit)({ dir:
|
|
520
|
+
const res = await (0, git_1.getIsMergeCommit)({ dir: cwd }, MERGE_COMMIT_HASH_1);
|
|
251
521
|
expect(res).toBe(true);
|
|
252
522
|
});
|
|
253
523
|
it('returns true for second merge commit', async () => {
|
|
254
|
-
const res = await (0, git_1.getIsMergeCommit)({ dir:
|
|
524
|
+
const res = await (0, git_1.getIsMergeCommit)({ dir: cwd }, MERGE_COMMIT_HASH_2);
|
|
255
525
|
expect(res).toBe(true);
|
|
256
526
|
});
|
|
257
527
|
it('returns false for rebased commits', async () => {
|
|
258
|
-
const res = await (0, git_1.getIsMergeCommit)({ dir:
|
|
528
|
+
const res = await (0, git_1.getIsMergeCommit)({ dir: cwd }, REBASE_COMMIT_HASH);
|
|
259
529
|
expect(res).toBe(false);
|
|
260
530
|
});
|
|
261
531
|
it('returns false for squashed commits', async () => {
|
|
262
|
-
const res = await (0, git_1.getIsMergeCommit)({ dir:
|
|
532
|
+
const res = await (0, git_1.getIsMergeCommit)({ dir: cwd }, SQUASH_COMMIT_HASH);
|
|
263
533
|
expect(res).toBe(false);
|
|
264
534
|
});
|
|
265
535
|
});
|
|
266
536
|
describe('getCommitsInMergeCommit', () => {
|
|
267
537
|
it('returns a list of commit hashes - excluding the merge hash itself', async () => {
|
|
268
|
-
const res = await (0, git_1.getCommitsInMergeCommit)({ dir:
|
|
538
|
+
const res = await (0, git_1.getCommitsInMergeCommit)({ dir: cwd }, MERGE_COMMIT_HASH_1);
|
|
269
539
|
expect(res).not.toContain(MERGE_COMMIT_HASH_1);
|
|
270
540
|
expect(res).toEqual([
|
|
271
541
|
'f9a760e0d9eb3ebcc64f8cb75ce885714b836496',
|
|
@@ -279,22 +549,68 @@ describe('git.integration', () => {
|
|
|
279
549
|
]);
|
|
280
550
|
});
|
|
281
551
|
it('returns empty for squash commits', async () => {
|
|
282
|
-
const res = await (0, git_1.getCommitsInMergeCommit)({ dir:
|
|
552
|
+
const res = await (0, git_1.getCommitsInMergeCommit)({ dir: cwd }, SQUASH_COMMIT_HASH);
|
|
283
553
|
expect(res).toEqual([]);
|
|
284
554
|
});
|
|
285
555
|
});
|
|
286
556
|
});
|
|
287
557
|
});
|
|
288
|
-
async function createAndCommitFile({ filename, content,
|
|
289
|
-
await
|
|
290
|
-
await childProcess.
|
|
291
|
-
return getCurrentSha(
|
|
558
|
+
async function createAndCommitFile({ filename, content, cwd, }) {
|
|
559
|
+
await createAndStageFile({ filename, content, cwd });
|
|
560
|
+
await childProcess.spawnPromise('git', ['commit', `--message=Update ${filename}`], cwd);
|
|
561
|
+
return getCurrentSha(cwd);
|
|
292
562
|
}
|
|
293
|
-
async function
|
|
294
|
-
|
|
563
|
+
async function createAndStageFile({ filename, content, cwd, }) {
|
|
564
|
+
try {
|
|
565
|
+
await promises_2.default.writeFile(path_1.default.join(cwd, filename), content);
|
|
566
|
+
await childProcess.spawnPromise('git', ['add', `${filename}`], cwd);
|
|
567
|
+
}
|
|
568
|
+
catch (e) {
|
|
569
|
+
// eslint-disable-next-line no-console
|
|
570
|
+
console.log('"createAndStageFile" threw an error', {
|
|
571
|
+
filename,
|
|
572
|
+
content,
|
|
573
|
+
cwd,
|
|
574
|
+
});
|
|
575
|
+
throw e;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
async function getCurrentSha(cwd) {
|
|
579
|
+
const { stdout } = await childProcess.spawnPromise('git', ['rev-parse', 'HEAD'], cwd);
|
|
295
580
|
return stdout.trim();
|
|
296
581
|
}
|
|
297
|
-
async function
|
|
298
|
-
const { stdout } = await childProcess.exec('git
|
|
582
|
+
async function getCurrentBranchName(cwd) {
|
|
583
|
+
const { stdout } = await childProcess.exec('git rev-parse --abbrev-ref HEAD', { cwd });
|
|
299
584
|
return stdout.trim();
|
|
300
585
|
}
|
|
586
|
+
async function getMostRecentCommitMessage(cwd) {
|
|
587
|
+
try {
|
|
588
|
+
const { stdout } = await childProcess.spawnPromise('git', ['--no-pager', 'log', '-1', '--pretty=%B'], cwd);
|
|
589
|
+
return stdout.trim();
|
|
590
|
+
}
|
|
591
|
+
catch (e) {
|
|
592
|
+
// eslint-disable-next-line no-console
|
|
593
|
+
console.log('"getMostRecentCommitMessage" threw an error', cwd);
|
|
594
|
+
throw e;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
async function gitClone(repoUrl, cwd) {
|
|
598
|
+
try {
|
|
599
|
+
return await childProcess.spawnPromise('git', ['clone', repoUrl, './'], cwd);
|
|
600
|
+
}
|
|
601
|
+
catch (e) {
|
|
602
|
+
// eslint-disable-next-line no-console
|
|
603
|
+
console.log('Git clone failed');
|
|
604
|
+
throw e;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
async function gitInit(cwd) {
|
|
608
|
+
try {
|
|
609
|
+
await childProcess.spawnPromise('git', ['init'], cwd);
|
|
610
|
+
}
|
|
611
|
+
catch (e) {
|
|
612
|
+
// eslint-disable-next-line no-console
|
|
613
|
+
console.log('Git init failed');
|
|
614
|
+
throw e;
|
|
615
|
+
}
|
|
616
|
+
}
|