backport 6.0.0 → 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/README.md +179 -52
- package/dist/entrypoint.cli.js +2 -0
- package/dist/entrypoint.module.d.ts +16 -4
- package/dist/entrypoint.module.js +41 -13
- package/dist/entrypoint.module.private.test.d.ts +1 -0
- package/dist/entrypoint.module.private.test.js +34 -0
- package/dist/main.js +1 -2
- package/dist/options/ConfigOptions.d.ts +16 -6
- package/dist/options/cliArgs.d.ts +36 -37
- package/dist/options/cliArgs.js +25 -24
- package/dist/options/cliArgs.test.js +6 -10
- package/dist/options/config/config.d.ts +28 -52
- package/dist/options/config/config.js +2 -36
- package/dist/options/config/config.test.js +10 -27
- package/dist/options/config/getOptionsFromGit.d.ts +3 -2
- package/dist/options/config/getOptionsFromGit.js +1 -3
- package/dist/options/config/globalConfig.js +2 -5
- package/dist/options/config/globalConfig.test.js +0 -2
- package/dist/options/config/projectConfig.test.js +51 -14
- package/dist/options/config/readConfigFile.d.ts +52 -0
- package/dist/options/config/readConfigFile.js +28 -2
- package/dist/options/options.d.ts +55 -32
- package/dist/options/options.js +101 -7
- package/dist/options/options.test.js +248 -97
- package/dist/options/parseRequiredOptions.d.ts +3 -3
- package/dist/options/parseRequiredOptions.js +2 -4
- package/dist/options/parseRequiredOptions.test.js +6 -11
- package/dist/runSequentially.test.js +40 -78
- package/dist/services/git.d.ts +5 -2
- package/dist/services/git.js +11 -10
- package/dist/services/git.test.js +12 -9
- package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -3
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +4 -5
- package/dist/services/github/v3/createPullRequest.js +10 -13
- package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/createPullRequest.test.js +110 -0
- package/dist/services/github/v3/createStatusComment.js +12 -14
- package/dist/services/github/v3/createStatusComment.test.js +58 -29
- package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
- package/dist/services/github/v4/apiRequestV4.js +1 -1
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +1 -1
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -1
- package/dist/services/github/v4/fetchAuthorId.d.ts +5 -2
- package/dist/services/github/v4/fetchAuthorId.js +5 -6
- package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +8 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +6 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +8 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +12 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +6 -8
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +10 -12
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +5 -7
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +5 -5
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +2 -6
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -2
- package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
- package/dist/services/github/v4/fetchProjectConfig.js +56 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
- package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +67 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +3 -1
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +22 -1
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +4 -1
- package/dist/services/github/v4/getOptionsFromGithub/query.js +3 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +32 -15
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +5 -1
- package/dist/services/sourceCommit/parseSourceCommit.js +2 -2
- package/dist/services/sourceCommit/parseSourceCommit.test.js +120 -5
- package/dist/test/inquirer.private.test.js +33 -36
- package/dist/test/integration/integration.private.test.js +114 -95
- package/dist/test/mockConfigFiles.d.ts +5 -0
- package/dist/test/mockConfigFiles.js +37 -0
- package/dist/test/nockHelpers.d.ts +1 -1
- package/dist/test/nockHelpers.js +4 -4
- package/dist/test/private/getDevAccessToken.js +1 -1
- package/dist/test/setupFiles/automatic-mocks.js +1 -29
- package/dist/ui/cherrypickAndCreatePullRequest.test.js +80 -28
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -9
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +13 -48
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +222 -260
- package/dist/ui/getCommits.d.ts +1 -1
- package/dist/ui/getCommitsWithoutBackports.d.ts +11 -0
- package/dist/ui/getCommitsWithoutBackports.js +53 -0
- package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/ui/getCommitsWithoutBackports.test.js +259 -0
- package/dist/ui/getTargetBranches.d.ts +2 -1
- package/dist/ui/getTargetBranches.js +17 -1
- package/dist/ui/maybeSetupRepo.js +4 -3
- package/dist/ui/maybeSetupRepo.test.js +49 -3
- package/dist/utils/excludeUndefined.d.ts +6 -0
- package/dist/utils/excludeUndefined.js +7 -0
- package/dist/utils/excludeUndefined.test.d.ts +1 -0
- package/dist/utils/excludeUndefined.test.js +24 -0
- package/package.json +9 -8
- package/yarn.lock +98 -77
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getCommitsWithoutBackports = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const commitFormatters_1 = require("../services/github/commitFormatters");
|
|
9
|
+
const fetchCommitsByAuthor_1 = require("../services/github/v4/fetchCommits/fetchCommitsByAuthor");
|
|
10
|
+
// when the user is facing a git conflict we should help them understand
|
|
11
|
+
// why the conflict occurs. In many cases it's because one or more commits haven't been backported yet
|
|
12
|
+
async function getCommitsWithoutBackports({ options,
|
|
13
|
+
// commit that is being backported
|
|
14
|
+
commit,
|
|
15
|
+
// branch the commit is being backported to
|
|
16
|
+
targetBranch,
|
|
17
|
+
// the files with conflicts on the target branch
|
|
18
|
+
conflictingFiles, }) {
|
|
19
|
+
// commits on the source branch that also touched the conflicting files
|
|
20
|
+
const commitsInConflictingPaths = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
21
|
+
...options,
|
|
22
|
+
author: null,
|
|
23
|
+
commitPaths: conflictingFiles,
|
|
24
|
+
});
|
|
25
|
+
return commitsInConflictingPaths
|
|
26
|
+
.filter((c) => {
|
|
27
|
+
// exclude the commit we are currently trying to backport
|
|
28
|
+
if (c.sha === commit.sha) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
// exclude commits that are newer than the commit we are trying to backport
|
|
32
|
+
if (c.committedDate > commit.committedDate) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
// only consider commits that have an associated pull request
|
|
36
|
+
if (!c.pullUrl) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
// only include commit if it has an unmerged PR for the given target branch
|
|
40
|
+
const hasUnmergedPr = c.expectedTargetPullRequests.some((pr) => pr.branch === targetBranch && pr.state !== 'MERGED');
|
|
41
|
+
return hasUnmergedPr;
|
|
42
|
+
})
|
|
43
|
+
.slice(0, 10) // limit to max 10 commits
|
|
44
|
+
.map((c) => {
|
|
45
|
+
// get pull request for the target branch (if it exists)
|
|
46
|
+
const pendingBackportPr = c.expectedTargetPullRequests.find((pr) => pr.branch === targetBranch && pr.state === 'OPEN');
|
|
47
|
+
const formatted = pendingBackportPr
|
|
48
|
+
? ` - ${(0, commitFormatters_1.getFirstLine)(c.originalMessage)} ${chalk_1.default.gray('(backport pending)')}\n ${pendingBackportPr.url}`
|
|
49
|
+
: ` - ${(0, commitFormatters_1.getFirstLine)(c.originalMessage)} ${chalk_1.default.red('(backport missing)')}\n ${c.pullUrl}`;
|
|
50
|
+
return { formatted, commit: c };
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
exports.getCommitsWithoutBackports = getCommitsWithoutBackports;
|
|
@@ -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
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { TargetBranchChoice } from '../options/ConfigOptions';
|
|
1
2
|
import { ValidConfigOptions } from '../options/options';
|
|
2
3
|
import { Commit } from '../services/sourceCommit/parseSourceCommit';
|
|
3
4
|
export declare function getTargetBranches(options: ValidConfigOptions, commits: Commit[]): string[] | Promise<string[]>;
|
|
4
|
-
export declare function getTargetBranchChoices(options: ValidConfigOptions, missingTargetBranches: string[], sourceBranch: string):
|
|
5
|
+
export declare function getTargetBranchChoices(options: ValidConfigOptions, missingTargetBranches: string[], sourceBranch: string): TargetBranchChoice[];
|
|
@@ -35,7 +35,7 @@ function getTargetBranches(options, commits) {
|
|
|
35
35
|
exports.getTargetBranches = getTargetBranches;
|
|
36
36
|
function getTargetBranchChoices(options, missingTargetBranches, sourceBranch) {
|
|
37
37
|
// exclude sourceBranch from targetBranchChoices
|
|
38
|
-
const targetBranchesChoices = options.targetBranchChoices.filter((choice) => choice.name !== sourceBranch);
|
|
38
|
+
const targetBranchesChoices = getTargetBranchChoicesAsObject(options.targetBranchChoices).filter((choice) => choice.name !== sourceBranch);
|
|
39
39
|
if ((0, lodash_1.isEmpty)(targetBranchesChoices)) {
|
|
40
40
|
throw new HandledError_1.HandledError('Missing target branch choices');
|
|
41
41
|
}
|
|
@@ -49,3 +49,19 @@ function getTargetBranchChoices(options, missingTargetBranches, sourceBranch) {
|
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
exports.getTargetBranchChoices = getTargetBranchChoices;
|
|
52
|
+
// `targetBranchChoices` can either be a string or an object.
|
|
53
|
+
// It must be transformed so it is always treated as an object troughout the application
|
|
54
|
+
function getTargetBranchChoicesAsObject(targetBranchChoices) {
|
|
55
|
+
if (!targetBranchChoices) {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
return targetBranchChoices.map((choice) => {
|
|
59
|
+
if ((0, lodash_1.isString)(choice)) {
|
|
60
|
+
return {
|
|
61
|
+
name: choice,
|
|
62
|
+
checked: false,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return choice;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
@@ -31,9 +31,10 @@ async function maybeSetupRepo(options) {
|
|
|
31
31
|
// delete default "origin" remote to avoid confusion
|
|
32
32
|
await (0, git_1.deleteRemote)(options, 'origin');
|
|
33
33
|
// ensure remote are setup with latest accessToken
|
|
34
|
-
await (0, git_1.deleteRemote)(options, options.
|
|
35
|
-
await (0, git_1.addRemote)(options, options.
|
|
36
|
-
|
|
34
|
+
await (0, git_1.deleteRemote)(options, options.authenticatedUsername);
|
|
35
|
+
await (0, git_1.addRemote)(options, options.authenticatedUsername);
|
|
36
|
+
// update remote for origin (if the above is a fork)
|
|
37
|
+
if (options.authenticatedUsername !== options.repoOwner) {
|
|
37
38
|
await (0, git_1.deleteRemote)(options, options.repoOwner);
|
|
38
39
|
await (0, git_1.addRemote)(options, options.repoOwner);
|
|
39
40
|
}
|
|
@@ -1,4 +1,23 @@
|
|
|
1
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
|
+
};
|
|
2
21
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
23
|
};
|
|
@@ -6,10 +25,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
25
|
const os_1 = __importDefault(require("os"));
|
|
7
26
|
const del_1 = __importDefault(require("del"));
|
|
8
27
|
const makeDir = require("make-dir");
|
|
28
|
+
const childProcess = __importStar(require("../services/child-process-promisified"));
|
|
29
|
+
const fs = __importStar(require("../services/fs-promisified"));
|
|
9
30
|
const maybeSetupRepo_1 = require("./maybeSetupRepo");
|
|
10
31
|
describe('maybeSetupRepo', () => {
|
|
32
|
+
let execSpy;
|
|
11
33
|
beforeEach(() => {
|
|
12
34
|
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
35
|
+
execSpy = jest
|
|
36
|
+
.spyOn(childProcess, 'exec')
|
|
37
|
+
.mockResolvedValue({ stderr: '', stdout: '' });
|
|
13
38
|
});
|
|
14
39
|
it('should delete repo if an error occurs', async () => {
|
|
15
40
|
expect.assertions(2);
|
|
@@ -17,12 +42,33 @@ describe('maybeSetupRepo', () => {
|
|
|
17
42
|
throw new Error('makeDir failed');
|
|
18
43
|
});
|
|
19
44
|
await expect((0, maybeSetupRepo_1.maybeSetupRepo)({
|
|
20
|
-
repoOwner: 'elastic',
|
|
21
|
-
repoName: 'kibana',
|
|
22
|
-
username: 'sqren',
|
|
23
45
|
accessToken: 'myAccessToken',
|
|
24
46
|
gitHostname: 'github.com',
|
|
47
|
+
repoName: 'kibana',
|
|
48
|
+
repoOwner: 'elastic',
|
|
25
49
|
})).rejects.toThrowError('makeDir failed');
|
|
26
50
|
expect(del_1.default).toHaveBeenCalledWith('/myHomeDir/.backport/repositories/elastic/kibana');
|
|
27
51
|
});
|
|
52
|
+
describe('if repo already exists', () => {
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
// @ts-expect-error
|
|
55
|
+
jest.spyOn(fs, 'stat').mockResolvedValue({ isDirectory: () => true });
|
|
56
|
+
});
|
|
57
|
+
it('should re-create remotes for both source repo and fork', async () => {
|
|
58
|
+
await (0, maybeSetupRepo_1.maybeSetupRepo)({
|
|
59
|
+
accessToken: 'myAccessToken',
|
|
60
|
+
authenticatedUsername: 'sqren_authenticated',
|
|
61
|
+
gitHostname: 'github.com',
|
|
62
|
+
repoName: 'kibana',
|
|
63
|
+
repoOwner: 'elastic',
|
|
64
|
+
});
|
|
65
|
+
expect(execSpy.mock.calls.map(([cmd]) => cmd)).toEqual([
|
|
66
|
+
'git remote rm origin',
|
|
67
|
+
'git remote rm sqren_authenticated',
|
|
68
|
+
'git remote add sqren_authenticated https://x-access-token:myAccessToken@github.com/sqren_authenticated/kibana.git',
|
|
69
|
+
'git remote rm elastic',
|
|
70
|
+
'git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
|
|
71
|
+
]);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
28
74
|
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Assign } from 'utility-types';
|
|
2
|
+
declare type ExcludeUndefined<T extends Record<string, any>> = Assign<T, Partial<Pick<T, {
|
|
3
|
+
[key in keyof T]-?: undefined extends T[key] ? key : never;
|
|
4
|
+
}[keyof T]>>>;
|
|
5
|
+
export declare function excludeUndefined<T extends Record<string, any>>(obj: T): ExcludeUndefined<T>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.excludeUndefined = void 0;
|
|
4
|
+
function excludeUndefined(obj) {
|
|
5
|
+
return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== undefined));
|
|
6
|
+
}
|
|
7
|
+
exports.excludeUndefined = excludeUndefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const excludeUndefined_1 = require("./excludeUndefined");
|
|
4
|
+
describe('excludeUndefined', () => {
|
|
5
|
+
it('removes undefined values', () => {
|
|
6
|
+
expect((0, excludeUndefined_1.excludeUndefined)({
|
|
7
|
+
foo: 'foo',
|
|
8
|
+
bar: undefined,
|
|
9
|
+
baz: null,
|
|
10
|
+
})).toEqual({ foo: 'foo', baz: null });
|
|
11
|
+
});
|
|
12
|
+
it('has the correct types after merging', () => {
|
|
13
|
+
const obj = (0, excludeUndefined_1.excludeUndefined)({
|
|
14
|
+
foo: 'foo',
|
|
15
|
+
bar: undefined,
|
|
16
|
+
baz: null,
|
|
17
|
+
});
|
|
18
|
+
const res = {
|
|
19
|
+
bar: 'bar',
|
|
20
|
+
...obj,
|
|
21
|
+
};
|
|
22
|
+
expect(res).toEqual({ bar: 'bar', foo: 'foo', baz: null });
|
|
23
|
+
});
|
|
24
|
+
});
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"branches",
|
|
15
15
|
"branching"
|
|
16
16
|
],
|
|
17
|
-
"version": "6.
|
|
17
|
+
"version": "6.1.3",
|
|
18
18
|
"main": "./dist/entrypoint.module.js",
|
|
19
19
|
"types": "dist/entrypoint.module.d.ts",
|
|
20
20
|
"bin": {
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
"safe-json-stringify": "^1.2.0",
|
|
71
71
|
"strip-json-comments": "^3.1.1",
|
|
72
72
|
"terminal-link": "^2.1.1",
|
|
73
|
+
"utility-types": "^3.10.0",
|
|
73
74
|
"winston": "^3.3.3",
|
|
74
75
|
"yargs": "^17.3.1"
|
|
75
76
|
},
|
|
@@ -77,18 +78,18 @@
|
|
|
77
78
|
"@types/core-js": "^2.5.5",
|
|
78
79
|
"@types/dedent": "^0.7.0",
|
|
79
80
|
"@types/inquirer": "^8.1.3",
|
|
80
|
-
"@types/jest": "^27.0
|
|
81
|
+
"@types/jest": "^27.4.0",
|
|
81
82
|
"@types/lodash": "^4.14.178",
|
|
82
83
|
"@types/node": "^16.11.17",
|
|
83
84
|
"@types/safe-json-stringify": "^1.1.2",
|
|
84
85
|
"@types/yargs": "^17.0.8",
|
|
85
86
|
"@types/yargs-parser": "^20.2.1",
|
|
86
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
87
|
-
"@typescript-eslint/parser": "^5.
|
|
88
|
-
"eslint": "^8.
|
|
87
|
+
"@typescript-eslint/eslint-plugin": "^5.9.0",
|
|
88
|
+
"@typescript-eslint/parser": "^5.9.0",
|
|
89
|
+
"eslint": "^8.6.0",
|
|
89
90
|
"eslint-config-prettier": "^8.3.0",
|
|
90
|
-
"eslint-plugin-import": "^2.25.
|
|
91
|
-
"eslint-plugin-jest": "^25.3.
|
|
91
|
+
"eslint-plugin-import": "^2.25.4",
|
|
92
|
+
"eslint-plugin-jest": "^25.3.4",
|
|
92
93
|
"eslint-plugin-prettier": "^4.0.0",
|
|
93
94
|
"graphql": "^16.2.0",
|
|
94
95
|
"graphql-config": "^4.1.0",
|
|
@@ -96,7 +97,7 @@
|
|
|
96
97
|
"husky": "^7.0.4",
|
|
97
98
|
"jest": "^27.4.5",
|
|
98
99
|
"jest-snapshot-serializer-ansi": "^1.0.0",
|
|
99
|
-
"lint-staged": "^12.1.
|
|
100
|
+
"lint-staged": "^12.1.5",
|
|
100
101
|
"nock": "^13.2.1",
|
|
101
102
|
"prettier": "^2.5.1",
|
|
102
103
|
"strip-ansi": "^6.0.1",
|