backport 8.9.0 → 8.9.2
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/lib/cherrypickAndCreateTargetPullRequest/autoMergeNowOrLater.js +6 -16
- package/dist/lib/github/v3/createStatusComment.js +4 -1
- package/dist/lib/github/v4/enablePullRequestAutoMerge.d.ts +4 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.js +8 -1
- package/dist/lib/github/v4/enablePullRequestAutoMerge.mutation.test.js +96 -19
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -1
- package/dist/options/ConfigOptions.d.ts +2 -1
- package/dist/options/config/config.d.ts +2 -1
- package/dist/options/config/readConfigFile.d.ts +1 -0
- package/dist/options/options.d.ts +1 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +1 -1
|
@@ -22,25 +22,15 @@ async function autoMergeNowOrLater(options, pullNumber) {
|
|
|
22
22
|
if (!(e instanceof apiRequestV4_1.GithubV4Exception)) {
|
|
23
23
|
throw e;
|
|
24
24
|
}
|
|
25
|
-
logger_1.logger.info(`Auto merge:
|
|
26
|
-
const isMissingStatusChecks =
|
|
27
|
-
e.message.includes('Branch does not have required protected branch rules'));
|
|
28
|
-
// if auto merge cannot be enabled due to missing status checks, the PR should be merged immediately
|
|
25
|
+
logger_1.logger.info(`Auto merge: Failed to enable auto merge for PR "#${pullNumber}" due to ${e.message}`);
|
|
26
|
+
const { isMissingStatusChecks } = (0, enablePullRequestAutoMerge_1.parseGithubError)(e);
|
|
29
27
|
if (!isMissingStatusChecks) {
|
|
30
28
|
throw e;
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
catch (e) {
|
|
38
|
-
if (!(e instanceof Error)) {
|
|
39
|
-
throw new Error(`Unknown error: ${e}`);
|
|
40
|
-
}
|
|
41
|
-
logger_1.logger.error(`Auto merge: Could not merge PR "#${pullNumber}" immediately due to ${e.message}`, e);
|
|
42
|
-
throw e;
|
|
43
|
-
}
|
|
30
|
+
// if auto merge cannot be enabled due to missing status checks, the PR should be merged immediately
|
|
31
|
+
logger_1.logger.info('Auto merge: Attempting to merge immediately');
|
|
32
|
+
await (0, mergePullRequest_1.mergePullRequest)(options, pullNumber);
|
|
33
|
+
spinner.text = 'Auto-merge: Pull request was merged immediately';
|
|
44
34
|
}
|
|
45
35
|
spinner.succeed();
|
|
46
36
|
}
|
|
@@ -70,7 +70,10 @@ function getCommentBody({ options, pullNumber, backportResponse, }) {
|
|
|
70
70
|
}
|
|
71
71
|
const packageVersionSection = `\n<!--- Backport version: ${packageVersion_1.PACKAGE_VERSION} -->`;
|
|
72
72
|
const manualBackportCommand = `\n### Manual backport\nTo create the backport manually run:\n\`\`\`\n${options.backportBinary} --pr ${pullNumber}\n\`\`\`\n`;
|
|
73
|
-
const
|
|
73
|
+
const linkToGithubActionLogs = options.githubActionRunId
|
|
74
|
+
? ` and see the [Github Action logs](https://github.com/${repoOwner}/${repoName}/actions/runs/${options.githubActionRunId}) for details`
|
|
75
|
+
: '';
|
|
76
|
+
const questionsAndLinkToBackport = `\n### Questions ?\nPlease refer to the [Backport tool documentation](https://github.com/sqren/backport)${linkToGithubActionLogs}\n`;
|
|
74
77
|
if (backportResponse.status === 'aborted' &&
|
|
75
78
|
backportResponse.error.errorContext.code === 'no-branches-exception') {
|
|
76
79
|
return `## ⚪ Backport skipped
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../../../options/options';
|
|
2
|
+
import { GithubV4Exception } from './apiRequestV4';
|
|
2
3
|
export declare function enablePullRequestAutoMerge(options: ValidConfigOptions, targetPullRequestNumber: number): Promise<number | undefined>;
|
|
4
|
+
export declare function parseGithubError(e: GithubV4Exception<any>): {
|
|
5
|
+
isMissingStatusChecks: boolean | undefined;
|
|
6
|
+
};
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.enablePullRequestAutoMerge = void 0;
|
|
6
|
+
exports.parseGithubError = exports.enablePullRequestAutoMerge = void 0;
|
|
7
7
|
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
8
|
const FetchPullRequestId_1 = require("./FetchPullRequestId");
|
|
9
9
|
const apiRequestV4_1 = require("./apiRequestV4");
|
|
@@ -36,3 +36,10 @@ async function enablePullRequestAutoMerge(options, targetPullRequestNumber) {
|
|
|
36
36
|
return res.enablePullRequestAutoMerge.pullRequest?.number;
|
|
37
37
|
}
|
|
38
38
|
exports.enablePullRequestAutoMerge = enablePullRequestAutoMerge;
|
|
39
|
+
function parseGithubError(e) {
|
|
40
|
+
const isMissingStatusChecks = e.githubResponse.data.errors?.some((e) => e.type === 'UNPROCESSABLE' &&
|
|
41
|
+
(e.message.includes('Branch does not have required protected branch rules') ||
|
|
42
|
+
e.message.includes('Pull request is in clean status')));
|
|
43
|
+
return { isMissingStatusChecks };
|
|
44
|
+
}
|
|
45
|
+
exports.parseGithubError = parseGithubError;
|
|
@@ -28,7 +28,7 @@ function resetReference(octokit) {
|
|
|
28
28
|
force: true,
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
async function closePr(octokit, pullNumber) {
|
|
31
|
+
async function closePr({ octokit, pullNumber, }) {
|
|
32
32
|
await octokit.pulls.update({
|
|
33
33
|
owner: TEST_REPO_OWNER,
|
|
34
34
|
repo: TEST_REPO_NAME,
|
|
@@ -36,10 +36,10 @@ async function closePr(octokit, pullNumber) {
|
|
|
36
36
|
state: 'closed',
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
async function createPr(options,
|
|
39
|
+
async function createPr({ options, headBranch, baseBranch, }) {
|
|
40
40
|
const prPayload = {
|
|
41
41
|
base: baseBranch,
|
|
42
|
-
head:
|
|
42
|
+
head: headBranch,
|
|
43
43
|
body: 'testing...',
|
|
44
44
|
owner: TEST_REPO_OWNER,
|
|
45
45
|
repo: TEST_REPO_NAME,
|
|
@@ -48,14 +48,14 @@ async function createPr(options, branchName, baseBranch) {
|
|
|
48
48
|
const { number } = await (0, createPullRequest_1.createPullRequest)({ options, prPayload });
|
|
49
49
|
return number;
|
|
50
50
|
}
|
|
51
|
-
async function deleteBranch(octokit, branchName) {
|
|
51
|
+
async function deleteBranch({ octokit, branchName, }) {
|
|
52
52
|
await octokit.git.deleteRef({
|
|
53
53
|
owner: TEST_REPO_OWNER,
|
|
54
54
|
repo: TEST_REPO_NAME,
|
|
55
55
|
ref: `heads/${branchName}`,
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
-
async function createBranch(octokit, branchName, sha) {
|
|
58
|
+
async function createBranch({ octokit, branchName, sha, }) {
|
|
59
59
|
await octokit.git.createRef({
|
|
60
60
|
owner: TEST_REPO_OWNER,
|
|
61
61
|
repo: TEST_REPO_NAME,
|
|
@@ -80,7 +80,7 @@ async function addCommit(octokit) {
|
|
|
80
80
|
return sha;
|
|
81
81
|
}
|
|
82
82
|
describe('enablePullRequestAutoMerge', () => {
|
|
83
|
-
describe('create a PR
|
|
83
|
+
describe('create a PR and enable auto-merge against "approvals-required-branch"', () => {
|
|
84
84
|
let pullNumber;
|
|
85
85
|
let branchName;
|
|
86
86
|
let octokit;
|
|
@@ -96,13 +96,17 @@ describe('enablePullRequestAutoMerge', () => {
|
|
|
96
96
|
octokit = new rest_1.Octokit({ auth: accessToken });
|
|
97
97
|
await resetReference(octokit);
|
|
98
98
|
const sha = await addCommit(octokit);
|
|
99
|
-
await createBranch(octokit, branchName, sha);
|
|
100
|
-
pullNumber = await createPr(
|
|
99
|
+
await createBranch({ octokit, branchName, sha });
|
|
100
|
+
pullNumber = await createPr({
|
|
101
|
+
options,
|
|
102
|
+
headBranch: branchName,
|
|
103
|
+
baseBranch: 'approvals-required-branch',
|
|
104
|
+
});
|
|
101
105
|
});
|
|
102
106
|
// cleanup
|
|
103
107
|
afterAll(async () => {
|
|
104
|
-
await closePr(octokit, pullNumber);
|
|
105
|
-
await deleteBranch(octokit, branchName);
|
|
108
|
+
await closePr({ octokit, pullNumber });
|
|
109
|
+
await deleteBranch({ octokit, branchName });
|
|
106
110
|
await resetReference(octokit);
|
|
107
111
|
});
|
|
108
112
|
// reset auto-merge state between runs
|
|
@@ -120,8 +124,20 @@ describe('enablePullRequestAutoMerge', () => {
|
|
|
120
124
|
const autoMergeMethod = await (0, fetchPullRequestAutoMergeMethod_1.fetchPullRequestAutoMergeMethod)(options, pullNumber);
|
|
121
125
|
expect(autoMergeMethod).toBe('MERGE');
|
|
122
126
|
});
|
|
123
|
-
it('should
|
|
124
|
-
|
|
127
|
+
it('should fail when enabling auto-merge via rebase because it is disallowed', async () => {
|
|
128
|
+
let errorMessage;
|
|
129
|
+
let isMissingStatusChecks;
|
|
130
|
+
try {
|
|
131
|
+
await (0, enablePullRequestAutoMerge_1.enablePullRequestAutoMerge)({ ...options, autoMergeMethod: 'rebase' }, pullNumber);
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
const err = e;
|
|
135
|
+
const res = (0, enablePullRequestAutoMerge_1.parseGithubError)(err);
|
|
136
|
+
errorMessage = err.message;
|
|
137
|
+
isMissingStatusChecks = res.isMissingStatusChecks;
|
|
138
|
+
}
|
|
139
|
+
expect(isMissingStatusChecks).toBe(false);
|
|
140
|
+
expect(errorMessage).toMatchInlineSnapshot(`"[\\"Merge method rebase merging is not allowed on this repository\\"] (Github API v4)"`);
|
|
125
141
|
// ensure Github API reflects the change before querying
|
|
126
142
|
await sleep(100);
|
|
127
143
|
const autoMergeMethod = await (0, fetchPullRequestAutoMergeMethod_1.fetchPullRequestAutoMergeMethod)(options, pullNumber);
|
|
@@ -135,7 +151,7 @@ describe('enablePullRequestAutoMerge', () => {
|
|
|
135
151
|
expect(autoMergeMethod).toBe('SQUASH');
|
|
136
152
|
});
|
|
137
153
|
});
|
|
138
|
-
describe('
|
|
154
|
+
describe('when creating a PR against "no-checks-required-branch"', () => {
|
|
139
155
|
let pullNumber;
|
|
140
156
|
let branchName;
|
|
141
157
|
let octokit;
|
|
@@ -151,17 +167,78 @@ describe('enablePullRequestAutoMerge', () => {
|
|
|
151
167
|
octokit = new rest_1.Octokit({ auth: accessToken });
|
|
152
168
|
await resetReference(octokit);
|
|
153
169
|
const sha = await addCommit(octokit);
|
|
154
|
-
await createBranch(octokit, branchName, sha);
|
|
155
|
-
pullNumber = await createPr(
|
|
170
|
+
await createBranch({ octokit, branchName, sha });
|
|
171
|
+
pullNumber = await createPr({
|
|
172
|
+
options,
|
|
173
|
+
headBranch: branchName,
|
|
174
|
+
baseBranch: 'no-checks-required-branch',
|
|
175
|
+
});
|
|
156
176
|
});
|
|
157
177
|
// cleanup
|
|
158
178
|
afterAll(async () => {
|
|
159
|
-
await closePr(octokit, pullNumber);
|
|
160
|
-
await deleteBranch(octokit, branchName);
|
|
179
|
+
await closePr({ octokit, pullNumber });
|
|
180
|
+
await deleteBranch({ octokit, branchName });
|
|
161
181
|
await resetReference(octokit);
|
|
162
182
|
});
|
|
163
|
-
it('should not be
|
|
164
|
-
|
|
183
|
+
it('should not be possible to enable auto-merge', async () => {
|
|
184
|
+
let isMissingStatusChecks;
|
|
185
|
+
let errorMessage;
|
|
186
|
+
try {
|
|
187
|
+
await (0, enablePullRequestAutoMerge_1.enablePullRequestAutoMerge)({ ...options, autoMergeMethod: 'merge' }, pullNumber);
|
|
188
|
+
}
|
|
189
|
+
catch (e) {
|
|
190
|
+
const err = e;
|
|
191
|
+
const res = (0, enablePullRequestAutoMerge_1.parseGithubError)(err);
|
|
192
|
+
errorMessage = err.message;
|
|
193
|
+
isMissingStatusChecks = res.isMissingStatusChecks;
|
|
194
|
+
}
|
|
195
|
+
expect(errorMessage).toMatchInlineSnapshot(`"[\\"Pull request Pull request is in clean status\\"] (Github API v4)"`);
|
|
196
|
+
expect(isMissingStatusChecks).toBe(true);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
describe('when createing a PR against "status-checks-required-branch"', () => {
|
|
200
|
+
let pullNumber;
|
|
201
|
+
let branchName;
|
|
202
|
+
let octokit;
|
|
203
|
+
let options;
|
|
204
|
+
beforeAll(async () => {
|
|
205
|
+
const randomString = crypto_1.default.randomBytes(4).toString('hex');
|
|
206
|
+
branchName = `test-${randomString}`;
|
|
207
|
+
options = {
|
|
208
|
+
accessToken,
|
|
209
|
+
repoOwner: TEST_REPO_OWNER,
|
|
210
|
+
repoName: TEST_REPO_NAME,
|
|
211
|
+
};
|
|
212
|
+
octokit = new rest_1.Octokit({ auth: accessToken });
|
|
213
|
+
await resetReference(octokit);
|
|
214
|
+
const sha = await addCommit(octokit);
|
|
215
|
+
await createBranch({ octokit, branchName, sha });
|
|
216
|
+
pullNumber = await createPr({
|
|
217
|
+
options,
|
|
218
|
+
headBranch: branchName,
|
|
219
|
+
baseBranch: 'status-checks-required-branch',
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
// cleanup
|
|
223
|
+
afterAll(async () => {
|
|
224
|
+
await closePr({ octokit, pullNumber });
|
|
225
|
+
await deleteBranch({ octokit, branchName });
|
|
226
|
+
await resetReference(octokit);
|
|
227
|
+
});
|
|
228
|
+
it('should not be possible to enable auto-merge', async () => {
|
|
229
|
+
let isMissingStatusChecks;
|
|
230
|
+
let errorMessage;
|
|
231
|
+
try {
|
|
232
|
+
await (0, enablePullRequestAutoMerge_1.enablePullRequestAutoMerge)({ ...options, autoMergeMethod: 'merge' }, pullNumber);
|
|
233
|
+
}
|
|
234
|
+
catch (e) {
|
|
235
|
+
const err = e;
|
|
236
|
+
const res = (0, enablePullRequestAutoMerge_1.parseGithubError)(err);
|
|
237
|
+
errorMessage = err.message;
|
|
238
|
+
isMissingStatusChecks = res.isMissingStatusChecks;
|
|
239
|
+
}
|
|
240
|
+
expect(errorMessage).toMatchInlineSnapshot(`"[\\"Pull request Pull request is in clean status\\"] (Github API v4)"`);
|
|
241
|
+
expect(isMissingStatusChecks).toBe(true);
|
|
165
242
|
});
|
|
166
243
|
});
|
|
167
244
|
});
|
|
@@ -31,6 +31,7 @@ export declare function getOptionsFromGithub(options: {
|
|
|
31
31
|
gitAuthorEmail?: string | undefined;
|
|
32
32
|
gitAuthorName?: string | undefined;
|
|
33
33
|
gitHostname?: string | undefined;
|
|
34
|
+
githubActionRunId?: number | undefined;
|
|
34
35
|
githubApiBaseUrlV3?: string | undefined;
|
|
35
36
|
githubApiBaseUrlV4?: string | undefined;
|
|
36
37
|
interactive?: boolean | undefined;
|
|
@@ -55,13 +56,13 @@ export declare function getOptionsFromGithub(options: {
|
|
|
55
56
|
resetAuthor?: boolean | undefined;
|
|
56
57
|
reviewers?: string[] | undefined;
|
|
57
58
|
sha?: string | string[] | undefined;
|
|
59
|
+
signoff?: boolean | undefined;
|
|
58
60
|
skipRemoteConfig?: boolean | undefined;
|
|
59
61
|
sourceBranch: string;
|
|
60
62
|
sourcePRLabels?: string[] | undefined;
|
|
61
63
|
targetBranchChoices?: import("../../../../options/ConfigOptions").TargetBranchChoiceOrString[] | undefined;
|
|
62
64
|
targetBranches?: string[] | undefined;
|
|
63
65
|
targetPRLabels?: string[] | undefined;
|
|
64
|
-
signoff?: boolean | undefined;
|
|
65
66
|
help?: boolean | undefined;
|
|
66
67
|
version?: boolean | undefined;
|
|
67
68
|
v?: boolean | undefined;
|
|
@@ -29,6 +29,7 @@ declare type Options = Partial<{
|
|
|
29
29
|
gitAuthorEmail: string;
|
|
30
30
|
gitAuthorName: string;
|
|
31
31
|
gitHostname: string;
|
|
32
|
+
githubActionRunId: number;
|
|
32
33
|
githubApiBaseUrlV3: string;
|
|
33
34
|
githubApiBaseUrlV4: string;
|
|
34
35
|
interactive: boolean;
|
|
@@ -53,13 +54,13 @@ declare type Options = Partial<{
|
|
|
53
54
|
resetAuthor: boolean;
|
|
54
55
|
reviewers: string[];
|
|
55
56
|
sha: string | string[];
|
|
57
|
+
signoff: boolean;
|
|
56
58
|
skipRemoteConfig: boolean;
|
|
57
59
|
sourceBranch: string;
|
|
58
60
|
sourcePRLabels: string[];
|
|
59
61
|
targetBranchChoices: TargetBranchChoiceOrString[];
|
|
60
62
|
targetBranches: string[];
|
|
61
63
|
targetPRLabels: string[];
|
|
62
|
-
signoff: boolean;
|
|
63
64
|
}>;
|
|
64
65
|
export declare type ConfigFileOptions = Options & Partial<{
|
|
65
66
|
help: boolean;
|
|
@@ -28,6 +28,7 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
|
|
|
28
28
|
gitAuthorEmail?: string | undefined;
|
|
29
29
|
gitAuthorName?: string | undefined;
|
|
30
30
|
gitHostname?: string | undefined;
|
|
31
|
+
githubActionRunId?: number | undefined;
|
|
31
32
|
githubApiBaseUrlV3?: string | undefined;
|
|
32
33
|
githubApiBaseUrlV4?: string | undefined;
|
|
33
34
|
interactive?: boolean | undefined;
|
|
@@ -52,13 +53,13 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
|
|
|
52
53
|
resetAuthor?: boolean | undefined;
|
|
53
54
|
reviewers?: string[] | undefined;
|
|
54
55
|
sha?: string | string[] | undefined;
|
|
56
|
+
signoff?: boolean | undefined;
|
|
55
57
|
skipRemoteConfig?: boolean | undefined;
|
|
56
58
|
sourceBranch?: string | undefined;
|
|
57
59
|
sourcePRLabels?: string[] | undefined;
|
|
58
60
|
targetBranchChoices?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
|
|
59
61
|
targetBranches?: string[] | undefined;
|
|
60
62
|
targetPRLabels?: string[] | undefined;
|
|
61
|
-
signoff?: boolean | undefined;
|
|
62
63
|
help?: boolean | undefined;
|
|
63
64
|
version?: boolean | undefined;
|
|
64
65
|
v?: boolean | undefined;
|
|
@@ -58,5 +58,6 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
|
|
|
58
58
|
targetBranch: string;
|
|
59
59
|
}) => boolean | Promise<boolean>) | undefined;
|
|
60
60
|
backportBinary?: string | undefined;
|
|
61
|
+
githubActionRunId?: number | undefined;
|
|
61
62
|
branchLabelMapping?: Record<string, string> | undefined;
|
|
62
63
|
};
|
|
@@ -94,6 +94,7 @@ export declare function getOptions({ optionsFromCliArgs, optionsFromModule, }: {
|
|
|
94
94
|
targetBranch: string;
|
|
95
95
|
}) => boolean | Promise<boolean>) | undefined;
|
|
96
96
|
backportBinary: string;
|
|
97
|
+
githubActionRunId?: number | undefined;
|
|
97
98
|
multiple?: boolean | undefined;
|
|
98
99
|
help?: boolean | undefined;
|
|
99
100
|
version?: boolean | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "8.9.
|
|
1
|
+
export declare const PACKAGE_VERSION = "8.9.2";
|