backport 8.3.0 → 8.3.1
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/backportRun.js +1 -1
- package/dist/entrypoint.module.d.ts +2 -2
- package/dist/entrypoint.module.js +2 -0
- package/dist/entrypoint.module.private.test.js +11 -10
- package/dist/lib/getCommits.js +1 -1
- package/dist/lib/git.js +2 -1
- package/dist/lib/github/v3/createStatusComment.js +3 -2
- package/dist/lib/github/v3/createStatusComment.test.js +61 -0
- package/dist/lib/github/v4/apiRequestV4.js +1 -1
- package/dist/lib/github/v4/enablePullRequestAutoMerge.js +2 -1
- package/dist/lib/github/v4/enablePullRequestAutoMerge.mutation.test.d.ts +1 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.mutation.test.js +138 -0
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +5 -3
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +0 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +0 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +5 -6
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +7 -3
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +2 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +23 -7
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +1 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +2 -0
- package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +1 -0
- package/dist/lib/github/v4/getOptionsFromGithub/query.js +1 -0
- package/dist/lib/remoteConfig.d.ts +1 -1
- package/dist/lib/remoteConfig.js +4 -0
- package/dist/options/cliArgs.d.ts +2 -2
- package/dist/options/cliArgs.js +16 -6
- package/dist/options/options.d.ts +3 -2
- package/dist/options/options.js +0 -1
- package/dist/options/options.test.js +2 -0
- package/dist/test/e2e/cli/date-filters.d.ts +1 -0
- package/dist/test/e2e/cli/date-filters.js +43 -0
- package/dist/test/e2e/cli/date-filters.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/date-filters.private.test.js +47 -0
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +2 -18
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +13 -13
- package/yarn.lock +165 -171
package/dist/backportRun.js
CHANGED
|
@@ -102,7 +102,7 @@ async function backportRun({ processArgs, optionsFromModule = {}, exitCodeOnFail
|
|
|
102
102
|
if (exitCodeOnFailure && backportResponse.status === 'failure') {
|
|
103
103
|
process.exitCode = 1;
|
|
104
104
|
}
|
|
105
|
-
logger.error('Unhandled exception', e);
|
|
105
|
+
logger.error('Unhandled exception:', e);
|
|
106
106
|
return backportResponse;
|
|
107
107
|
}
|
|
108
108
|
}
|
|
@@ -20,6 +20,8 @@ export declare function getCommits(options: {
|
|
|
20
20
|
repoOwner: string;
|
|
21
21
|
author?: string;
|
|
22
22
|
branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
|
|
23
|
+
dateSince?: string;
|
|
24
|
+
dateUntil?: string;
|
|
23
25
|
githubApiBaseUrlV4?: string;
|
|
24
26
|
maxNumber?: number;
|
|
25
27
|
onlyMissing?: boolean;
|
|
@@ -28,6 +30,4 @@ export declare function getCommits(options: {
|
|
|
28
30
|
sha?: string | string[];
|
|
29
31
|
skipRemoteConfig?: boolean;
|
|
30
32
|
sourceBranch?: string;
|
|
31
|
-
dateUntil?: string;
|
|
32
|
-
dateSince?: string;
|
|
33
33
|
}): Promise<Commit[]>;
|
|
@@ -243,7 +243,8 @@ describe('entrypoint.module', () => {
|
|
|
243
243
|
accessToken: accessToken,
|
|
244
244
|
repoName: 'kibana',
|
|
245
245
|
repoOwner: 'elastic',
|
|
246
|
-
|
|
246
|
+
dateUntil: '2021-06-02',
|
|
247
|
+
prFilter: 'label:Team:apm base:master',
|
|
247
248
|
maxNumber: 3,
|
|
248
249
|
});
|
|
249
250
|
const commitMessage = commits.map((commit) => {
|
|
@@ -255,19 +256,19 @@ describe('entrypoint.module', () => {
|
|
|
255
256
|
expect(commitMessage).toMatchInlineSnapshot(`
|
|
256
257
|
Array [
|
|
257
258
|
Object {
|
|
258
|
-
"committedDate": "2021-
|
|
259
|
-
"message": "
|
|
260
|
-
"sha": "
|
|
259
|
+
"committedDate": "2021-05-28T12:41:42Z",
|
|
260
|
+
"message": "[Observability] Fix typo in readme for new navigation (#100861)",
|
|
261
|
+
"sha": "79945fe0275b2ec9c93747e26154110133ec51fb",
|
|
261
262
|
},
|
|
262
263
|
Object {
|
|
263
|
-
"committedDate": "2021-
|
|
264
|
-
"message": "
|
|
265
|
-
"sha": "
|
|
264
|
+
"committedDate": "2021-05-28T19:43:30Z",
|
|
265
|
+
"message": "[APM] Move APM tutorial from apm_oss to x-pack/apm (#100780)",
|
|
266
|
+
"sha": "0bcd78b0e999feb95057f5e6eafdb572b9b2fe39",
|
|
266
267
|
},
|
|
267
268
|
Object {
|
|
268
|
-
"committedDate": "2021-
|
|
269
|
-
"message": "
|
|
270
|
-
"sha": "
|
|
269
|
+
"committedDate": "2021-05-18T10:33:16Z",
|
|
270
|
+
"message": "Migrate from Joi to @kbn/config-schema in \\"home\\" and \\"features\\" plugins (#100201)",
|
|
271
|
+
"sha": "574f6595ad2e5452fa90e6a3111220a599e473c0",
|
|
271
272
|
},
|
|
272
273
|
]
|
|
273
274
|
`);
|
package/dist/lib/getCommits.js
CHANGED
|
@@ -46,7 +46,7 @@ async function getCommits(options) {
|
|
|
46
46
|
spinner.text = options.prFilter
|
|
47
47
|
? 'Loading pull requests...'
|
|
48
48
|
: `Loading commits from branch "${options.sourceBranch}"...`;
|
|
49
|
-
const commitChoices = options.prFilter
|
|
49
|
+
const commitChoices = options.prFilter !== undefined
|
|
50
50
|
? await (0, fetchPullRequestsBySearchQuery_1.fetchPullRequestsBySearchQuery)({
|
|
51
51
|
...options,
|
|
52
52
|
prFilter: options.prFilter,
|
package/dist/lib/git.js
CHANGED
|
@@ -15,6 +15,7 @@ function getRemoteUrl({ repoName, accessToken, gitHostname = 'github.com' }, rep
|
|
|
15
15
|
}
|
|
16
16
|
exports.getRemoteUrl = getRemoteUrl;
|
|
17
17
|
async function cloneRepo({ sourcePath, targetPath }, onProgress) {
|
|
18
|
+
logger_1.logger.info(`Cloning repo from ${sourcePath} to ${targetPath}`);
|
|
18
19
|
return new Promise((resolve, reject) => {
|
|
19
20
|
const subprocess = (0, child_process_promisified_1.spawnOriginal)('git', [
|
|
20
21
|
'clone',
|
|
@@ -28,7 +29,7 @@ async function cloneRepo({ sourcePath, targetPath }, onProgress) {
|
|
|
28
29
|
};
|
|
29
30
|
subprocess.on('error', (err) => reject(err));
|
|
30
31
|
subprocess.stderr.on('data', (data) => {
|
|
31
|
-
logger_1.logger.verbose(
|
|
32
|
+
logger_1.logger.verbose(data.toString());
|
|
32
33
|
const [, objectReceiveProgress] = data.toString().match(/^Receiving objects:\s+(\d+)%/) || [];
|
|
33
34
|
if (objectReceiveProgress) {
|
|
34
35
|
progress.objectReceive = parseInt(objectReceiveProgress, 10);
|
|
@@ -42,7 +42,7 @@ async function createStatusComment({ options, backportResponse, }) {
|
|
|
42
42
|
}
|
|
43
43
|
exports.createStatusComment = createStatusComment;
|
|
44
44
|
function getCommentBody({ options, pullNumber, backportResponse, }) {
|
|
45
|
-
const { repoName, repoOwner, autoMerge, publishStatusCommentOnAbort, publishStatusCommentOnFailure, publishStatusCommentOnSuccess, } = options;
|
|
45
|
+
const { repoName, repoOwner, autoMerge, isRepoPrivate, publishStatusCommentOnAbort, publishStatusCommentOnFailure, publishStatusCommentOnSuccess, } = options;
|
|
46
46
|
// eg. in addition to `--noStatusComment` add `--noFailureStatusComment` and `--noSuccessStatusComment` where the former will overwrite the two latter
|
|
47
47
|
const didAllBackportsSucceed = backportResponse.status === 'success' &&
|
|
48
48
|
backportResponse.results.every((r) => r.status === 'success');
|
|
@@ -86,10 +86,11 @@ ${manualBackportCommand}${questionsAndLinkToBackport}${packageVersionSection}`;
|
|
|
86
86
|
const tableBody = backportResponse.results
|
|
87
87
|
.map((result) => {
|
|
88
88
|
if (result.status === 'success') {
|
|
89
|
+
const prShield = `[<img src="https://img.shields.io/github/pulls/detail/state/${repoOwner}/${repoName}/${result.pullRequestNumber}">](${result.pullRequestUrl})`;
|
|
89
90
|
return [
|
|
90
91
|
'✅',
|
|
91
92
|
result.targetBranch,
|
|
92
|
-
|
|
93
|
+
isRepoPrivate ? result.pullRequestUrl : prShield,
|
|
93
94
|
];
|
|
94
95
|
}
|
|
95
96
|
if (result.error instanceof BackportError_1.BackportError &&
|
|
@@ -563,4 +563,65 @@ describe('getCommentBody', () => {
|
|
|
563
563
|
expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
|
|
564
564
|
});
|
|
565
565
|
});
|
|
566
|
+
describe('shield.io badges', () => {
|
|
567
|
+
const getParams = (opts) => ({
|
|
568
|
+
options: {
|
|
569
|
+
interactive: true,
|
|
570
|
+
repoName: 'kibana',
|
|
571
|
+
repoOwner: 'elastic',
|
|
572
|
+
autoMerge: true,
|
|
573
|
+
backportBinary: 'node scripts/backport',
|
|
574
|
+
publishStatusCommentOnSuccess: true,
|
|
575
|
+
...opts,
|
|
576
|
+
},
|
|
577
|
+
pullNumber: 55,
|
|
578
|
+
backportResponse: {
|
|
579
|
+
status: 'success',
|
|
580
|
+
results: [
|
|
581
|
+
{
|
|
582
|
+
status: 'success',
|
|
583
|
+
targetBranch: '7.x',
|
|
584
|
+
pullRequestNumber: 55,
|
|
585
|
+
pullRequestUrl: 'url-to-pr',
|
|
586
|
+
},
|
|
587
|
+
],
|
|
588
|
+
},
|
|
589
|
+
});
|
|
590
|
+
it('posts a comment without shields.io badge when repo is private`', () => {
|
|
591
|
+
const params = getParams({ isRepoPrivate: true });
|
|
592
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).not.toContain('img.shields.io');
|
|
593
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
594
|
+
"## 💚 All backports created successfully
|
|
595
|
+
|
|
596
|
+
| Status | Branch | Result |
|
|
597
|
+
|:------:|:------:|:------|
|
|
598
|
+
|✅|7.x|url-to-pr|
|
|
599
|
+
|
|
600
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
601
|
+
|
|
602
|
+
### Questions ?
|
|
603
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
604
|
+
|
|
605
|
+
<!--- Backport version: 1.2.3-mocked -->"
|
|
606
|
+
`);
|
|
607
|
+
});
|
|
608
|
+
it('posts a comment with shields.io badge when repo is public`', () => {
|
|
609
|
+
const params = getParams({ isRepoPrivate: false });
|
|
610
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toContain('img.shields.io');
|
|
611
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
612
|
+
"## 💚 All backports created successfully
|
|
613
|
+
|
|
614
|
+
| Status | Branch | Result |
|
|
615
|
+
|:------:|:------:|:------|
|
|
616
|
+
|✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
|
|
617
|
+
|
|
618
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
619
|
+
|
|
620
|
+
### Questions ?
|
|
621
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
622
|
+
|
|
623
|
+
<!--- Backport version: 1.2.3-mocked -->"
|
|
624
|
+
`);
|
|
625
|
+
});
|
|
626
|
+
});
|
|
566
627
|
});
|
|
@@ -45,7 +45,7 @@ exports.apiRequestV4 = apiRequestV4;
|
|
|
45
45
|
function addDebugLogs({ githubApiBaseUrlV4, query, variables, githubResponse, didThrow = false, }) {
|
|
46
46
|
const gqlQueryName = getQueryName(query);
|
|
47
47
|
logger_1.logger.info(`POST ${githubApiBaseUrlV4} (name:${gqlQueryName}, status: ${githubResponse.status}${didThrow ? ', EXCEPTION THROWN' : ''})`);
|
|
48
|
-
logger_1.logger.verbose(`Query: ${query}`);
|
|
48
|
+
logger_1.logger.verbose(`Query: ${(0, printer_1.print)(query)}`);
|
|
49
49
|
logger_1.logger.verbose('Variables:', variables);
|
|
50
50
|
logger_1.logger.verbose('Response headers:', githubResponse.headers);
|
|
51
51
|
logger_1.logger.verbose('Response data:', githubResponse.data);
|
|
@@ -43,8 +43,9 @@ async function enablePullRequestAutoMerge(options, targetPullRequestNumber) {
|
|
|
43
43
|
return res.enablePullRequestAutoMerge.pullRequest?.number;
|
|
44
44
|
}
|
|
45
45
|
catch (e) {
|
|
46
|
+
const err = e;
|
|
46
47
|
spinner.fail();
|
|
47
|
-
logger_1.logger.info(`Could not enable auto merging for ${targetPullRequestNumber}`, e);
|
|
48
|
+
logger_1.logger.info(`Could not enable auto merging for ${targetPullRequestNumber} due to ${err.message}`, e);
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
exports.enablePullRequestAutoMerge = enablePullRequestAutoMerge;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,138 @@
|
|
|
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
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
7
|
+
const rest_1 = require("@octokit/rest");
|
|
8
|
+
const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
|
|
9
|
+
const createPullRequest_1 = require("../v3/createPullRequest");
|
|
10
|
+
const disablePullRequestAutoMerge_1 = require("./disablePullRequestAutoMerge");
|
|
11
|
+
const enablePullRequestAutoMerge_1 = require("./enablePullRequestAutoMerge");
|
|
12
|
+
const fetchPullRequestAutoMergeMethod_1 = require("./fetchPullRequestAutoMergeMethod");
|
|
13
|
+
// The test repo requires auto-merge being enabled in options, as well as all merge types enabled (merge, squash, rebase)
|
|
14
|
+
// The test pull requests should be open, and not currently able to be merged (e.g. because it requires an approval),
|
|
15
|
+
// otherwise it will be merged when auto-merge is turned on
|
|
16
|
+
const TEST_REPO_OWNER = 'backport-org';
|
|
17
|
+
const TEST_REPO_NAME = 'repo-with-auto-merge-enabled';
|
|
18
|
+
const INITIAL_SHA = '70aa879411e95b6662f8ddcb80a944fc4444579f';
|
|
19
|
+
jest.setTimeout(10000);
|
|
20
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
21
|
+
function resetReference(octokit) {
|
|
22
|
+
return octokit.rest.git.updateRef({
|
|
23
|
+
owner: TEST_REPO_OWNER,
|
|
24
|
+
repo: TEST_REPO_NAME,
|
|
25
|
+
ref: 'heads/main',
|
|
26
|
+
sha: INITIAL_SHA,
|
|
27
|
+
force: true,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async function closePr(octokit, pullNumber) {
|
|
31
|
+
await octokit.pulls.update({
|
|
32
|
+
owner: TEST_REPO_OWNER,
|
|
33
|
+
repo: TEST_REPO_NAME,
|
|
34
|
+
pull_number: pullNumber,
|
|
35
|
+
state: 'closed',
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async function createPr(options, branchName) {
|
|
39
|
+
const prPayload = {
|
|
40
|
+
base: '7.x',
|
|
41
|
+
head: branchName,
|
|
42
|
+
body: 'testing...',
|
|
43
|
+
owner: TEST_REPO_OWNER,
|
|
44
|
+
repo: TEST_REPO_NAME,
|
|
45
|
+
title: 'my pr title',
|
|
46
|
+
};
|
|
47
|
+
const { number } = await (0, createPullRequest_1.createPullRequest)({ options, prPayload });
|
|
48
|
+
return number;
|
|
49
|
+
}
|
|
50
|
+
async function deleteBranch(octokit, branchName) {
|
|
51
|
+
await octokit.git.deleteRef({
|
|
52
|
+
owner: TEST_REPO_OWNER,
|
|
53
|
+
repo: TEST_REPO_NAME,
|
|
54
|
+
ref: `heads/${branchName}`,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async function createBranch(octokit, branchName, sha) {
|
|
58
|
+
await octokit.git.createRef({
|
|
59
|
+
owner: TEST_REPO_OWNER,
|
|
60
|
+
repo: TEST_REPO_NAME,
|
|
61
|
+
ref: `refs/heads/${branchName}`,
|
|
62
|
+
sha,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async function addCommit(octokit) {
|
|
66
|
+
const randomString = Math.random().toString(36).slice(2);
|
|
67
|
+
const res = await octokit.rest.repos.createOrUpdateFileContents({
|
|
68
|
+
owner: TEST_REPO_OWNER,
|
|
69
|
+
repo: TEST_REPO_NAME,
|
|
70
|
+
path: `file-to-change-${randomString}`,
|
|
71
|
+
message: 'Automatically changed',
|
|
72
|
+
content: Buffer.from(`My new hash ${randomString}`).toString('base64'),
|
|
73
|
+
branch: 'main',
|
|
74
|
+
});
|
|
75
|
+
const sha = res.data.commit.sha;
|
|
76
|
+
return sha;
|
|
77
|
+
}
|
|
78
|
+
// Error: cannot have more than 100 pull requests with the same head_sha
|
|
79
|
+
// TODO: have unique head sha for every test run
|
|
80
|
+
// eslint-disable-next-line jest/no-disabled-tests
|
|
81
|
+
describe('enablePullRequestAutoMerge', () => {
|
|
82
|
+
let pullNumber;
|
|
83
|
+
let branchName;
|
|
84
|
+
let octokit;
|
|
85
|
+
let options;
|
|
86
|
+
beforeAll(async () => {
|
|
87
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
88
|
+
const randomString = crypto_1.default.randomBytes(4).toString('hex');
|
|
89
|
+
branchName = `test-${randomString}`;
|
|
90
|
+
options = {
|
|
91
|
+
accessToken,
|
|
92
|
+
repoOwner: TEST_REPO_OWNER,
|
|
93
|
+
repoName: TEST_REPO_NAME,
|
|
94
|
+
};
|
|
95
|
+
octokit = new rest_1.Octokit({ auth: accessToken });
|
|
96
|
+
await resetReference(octokit);
|
|
97
|
+
const sha = await addCommit(octokit);
|
|
98
|
+
if (sha) {
|
|
99
|
+
await createBranch(octokit, branchName, sha);
|
|
100
|
+
}
|
|
101
|
+
pullNumber = await createPr(options, branchName);
|
|
102
|
+
});
|
|
103
|
+
// cleanup
|
|
104
|
+
afterAll(async () => {
|
|
105
|
+
await closePr(octokit, pullNumber);
|
|
106
|
+
await deleteBranch(octokit, branchName);
|
|
107
|
+
await resetReference(octokit);
|
|
108
|
+
});
|
|
109
|
+
// reset auto-merge state between runs
|
|
110
|
+
afterEach(async () => {
|
|
111
|
+
await (0, disablePullRequestAutoMerge_1.disablePullRequestAutoMerge)(options, pullNumber);
|
|
112
|
+
});
|
|
113
|
+
it('should initially have auto-merge disabled', async () => {
|
|
114
|
+
const autoMergeMethod = await (0, fetchPullRequestAutoMergeMethod_1.fetchPullRequestAutoMergeMethod)(options, pullNumber);
|
|
115
|
+
expect(autoMergeMethod).toBe(undefined);
|
|
116
|
+
});
|
|
117
|
+
it('should enable auto-merge via merge', async () => {
|
|
118
|
+
await (0, enablePullRequestAutoMerge_1.enablePullRequestAutoMerge)({ ...options, autoMergeMethod: 'merge' }, pullNumber);
|
|
119
|
+
// ensure Github API reflects the change before querying
|
|
120
|
+
await sleep(100);
|
|
121
|
+
const autoMergeMethod = await (0, fetchPullRequestAutoMergeMethod_1.fetchPullRequestAutoMergeMethod)(options, pullNumber);
|
|
122
|
+
expect(autoMergeMethod).toBe('MERGE');
|
|
123
|
+
});
|
|
124
|
+
it('should not enable auto-merge via rebase because it is disallowed', async () => {
|
|
125
|
+
await (0, enablePullRequestAutoMerge_1.enablePullRequestAutoMerge)({ ...options, autoMergeMethod: 'rebase' }, pullNumber);
|
|
126
|
+
// ensure Github API reflects the change before querying
|
|
127
|
+
await sleep(100);
|
|
128
|
+
const autoMergeMethod = await (0, fetchPullRequestAutoMergeMethod_1.fetchPullRequestAutoMergeMethod)(options, pullNumber);
|
|
129
|
+
expect(autoMergeMethod).toBe(undefined);
|
|
130
|
+
});
|
|
131
|
+
it('should enable auto-merge via squash', async () => {
|
|
132
|
+
await (0, enablePullRequestAutoMerge_1.enablePullRequestAutoMerge)({ ...options, autoMergeMethod: 'squash' }, pullNumber);
|
|
133
|
+
// ensure Github API reflects the change before querying
|
|
134
|
+
await sleep(100);
|
|
135
|
+
const autoMergeMethod = await (0, fetchPullRequestAutoMergeMethod_1.fetchPullRequestAutoMergeMethod)(options, pullNumber);
|
|
136
|
+
expect(autoMergeMethod).toBe('SQUASH');
|
|
137
|
+
});
|
|
138
|
+
});
|
|
@@ -47,13 +47,15 @@ describe('allFetchers', () => {
|
|
|
47
47
|
});
|
|
48
48
|
it('matches commitByAuthor with commitBySearchQuery', async () => {
|
|
49
49
|
const commitsBySearchQuery = await (0, fetchPullRequestsBySearchQuery_1.fetchPullRequestsBySearchQuery)({
|
|
50
|
-
repoOwner: 'elastic',
|
|
51
|
-
repoName: 'kibana',
|
|
52
50
|
accessToken,
|
|
51
|
+
author: 'sqren',
|
|
52
|
+
dateSince: null,
|
|
53
|
+
dateUntil: null,
|
|
53
54
|
maxNumber: 1,
|
|
54
55
|
prFilter: `created:2021-12-20..2021-12-20`,
|
|
56
|
+
repoName: 'kibana',
|
|
57
|
+
repoOwner: 'elastic',
|
|
55
58
|
sourceBranch: 'main',
|
|
56
|
-
author: 'sqren',
|
|
57
59
|
});
|
|
58
60
|
const commitBySearchQuery = commitsBySearchQuery[0];
|
|
59
61
|
expect(commitByAuthor).toEqual(commitBySearchQuery);
|
|
@@ -14,17 +14,17 @@ const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
|
|
|
14
14
|
const apiRequestV4_1 = require("../apiRequestV4");
|
|
15
15
|
const fetchAuthorId_1 = require("../fetchAuthorId");
|
|
16
16
|
async function fetchByCommitPath({ options, authorId, commitPath, }) {
|
|
17
|
-
const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', maxNumber = 10, repoName, repoOwner, sourceBranch,
|
|
17
|
+
const { accessToken, dateSince, dateUntil, githubApiBaseUrlV4 = 'https://api.github.com/graphql', maxNumber = 10, repoName, repoOwner, sourceBranch, } = options;
|
|
18
18
|
const query = (0, graphql_tag_1.default) `
|
|
19
19
|
query CommitsByAuthor(
|
|
20
|
-
$repoOwner: String!
|
|
21
|
-
$repoName: String!
|
|
22
|
-
$maxNumber: Int!
|
|
23
|
-
$sourceBranch: String!
|
|
24
20
|
$authorId: ID
|
|
25
21
|
$commitPath: String
|
|
26
22
|
$dateSince: GitTimestamp
|
|
27
23
|
$dateUntil: GitTimestamp
|
|
24
|
+
$maxNumber: Int!
|
|
25
|
+
$repoName: String!
|
|
26
|
+
$repoOwner: String!
|
|
27
|
+
$sourceBranch: String!
|
|
28
28
|
) {
|
|
29
29
|
repository(owner: $repoOwner, name: $repoName) {
|
|
30
30
|
ref(qualifiedName: $sourceBranch) {
|
|
@@ -70,7 +70,6 @@ async function fetchByCommitPath({ options, authorId, commitPath, }) {
|
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
catch (e) {
|
|
73
|
-
//@ts-expect-error
|
|
74
73
|
return (0, remoteConfig_1.swallowMissingConfigFileException)(e);
|
|
75
74
|
}
|
|
76
75
|
}
|
|
@@ -8,17 +8,19 @@ describe('fetchPullRequestsBySearchQuery', () => {
|
|
|
8
8
|
it('throws an error', async () => {
|
|
9
9
|
const options = {
|
|
10
10
|
accessToken,
|
|
11
|
+
author: 'sqren',
|
|
12
|
+
dateSince: null,
|
|
13
|
+
dateUntil: null,
|
|
11
14
|
maxNumber: 10,
|
|
12
15
|
prFilter: 'label:non-existing',
|
|
13
16
|
repoName: 'backport-e2e',
|
|
14
17
|
repoOwner: 'backport-org',
|
|
15
18
|
sourceBranch: 'master',
|
|
16
|
-
author: 'sqren',
|
|
17
19
|
};
|
|
18
20
|
await expect((0, fetchPullRequestsBySearchQuery_1.fetchPullRequestsBySearchQuery)(options)).rejects
|
|
19
21
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
20
22
|
"No commits found for query:
|
|
21
|
-
type:pr is:merged sort:
|
|
23
|
+
type:pr is:merged sort:created-desc repo:backport-org/backport-e2e author:sqren base:master label:non-existing
|
|
22
24
|
|
|
23
25
|
Use \`--all\` to see commits by all users or \`--author=<username>\` for commits from a specific user"
|
|
24
26
|
`);
|
|
@@ -28,12 +30,14 @@ describe('fetchPullRequestsBySearchQuery', () => {
|
|
|
28
30
|
it('returns the merge commits for those PRs', async () => {
|
|
29
31
|
const options = {
|
|
30
32
|
accessToken,
|
|
33
|
+
author: 'sqren',
|
|
34
|
+
dateSince: null,
|
|
35
|
+
dateUntil: null,
|
|
31
36
|
maxNumber: 10,
|
|
32
37
|
prFilter: 'label:v7.8.0',
|
|
33
38
|
repoName: 'backport-e2e',
|
|
34
39
|
repoOwner: 'backport-org',
|
|
35
40
|
sourceBranch: 'master',
|
|
36
|
-
author: 'sqren',
|
|
37
41
|
};
|
|
38
42
|
const expectedCommits = [
|
|
39
43
|
{
|
|
@@ -2,6 +2,8 @@ import { Commit } from '../../../sourceCommit/parseSourceCommit';
|
|
|
2
2
|
export declare function fetchPullRequestsBySearchQuery(options: {
|
|
3
3
|
accessToken: string;
|
|
4
4
|
author: string | null;
|
|
5
|
+
dateSince: string | null;
|
|
6
|
+
dateUntil: string | null;
|
|
5
7
|
githubApiBaseUrlV4?: string;
|
|
6
8
|
maxNumber?: number;
|
|
7
9
|
onlyMissing?: boolean;
|
|
@@ -12,7 +12,7 @@ const remoteConfig_1 = require("../../../remoteConfig");
|
|
|
12
12
|
const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
|
|
13
13
|
const apiRequestV4_1 = require("../apiRequestV4");
|
|
14
14
|
async function fetchPullRequestsBySearchQuery(options) {
|
|
15
|
-
const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', maxNumber = 10, prFilter, repoName, repoOwner, sourceBranch,
|
|
15
|
+
const { accessToken, author, dateSince, dateUntil, githubApiBaseUrlV4 = 'https://api.github.com/graphql', maxNumber = 10, prFilter, repoName, repoOwner, sourceBranch, } = options;
|
|
16
16
|
const query = (0, graphql_tag_1.default) `
|
|
17
17
|
query PullRequestBySearchQuery($query: String!, $maxNumber: Int!) {
|
|
18
18
|
search(query: $query, type: ISSUE, first: $maxNumber) {
|
|
@@ -28,11 +28,28 @@ async function fetchPullRequestsBySearchQuery(options) {
|
|
|
28
28
|
|
|
29
29
|
${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
|
|
30
30
|
`;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
function dateFilter() {
|
|
32
|
+
if (dateUntil && dateSince) {
|
|
33
|
+
return [`merged:${dateSince}..${dateUntil}`];
|
|
34
|
+
}
|
|
35
|
+
if (dateUntil) {
|
|
36
|
+
return [`merged:<${dateUntil}`];
|
|
37
|
+
}
|
|
38
|
+
if (dateSince) {
|
|
39
|
+
return [`merged:>${dateSince}`];
|
|
40
|
+
}
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
const searchQuery = [
|
|
44
|
+
'type:pr',
|
|
45
|
+
'is:merged',
|
|
46
|
+
'sort:created-desc',
|
|
47
|
+
`repo:${repoOwner}/${repoName}`,
|
|
48
|
+
...(options.author ? [`author:${options.author}`] : []),
|
|
49
|
+
...(prFilter.includes('base:') ? [] : [`base:${sourceBranch}`]),
|
|
50
|
+
...dateFilter(),
|
|
51
|
+
prFilter,
|
|
52
|
+
].join(' ');
|
|
36
53
|
const variables = {
|
|
37
54
|
query: searchQuery,
|
|
38
55
|
maxNumber,
|
|
@@ -47,7 +64,6 @@ async function fetchPullRequestsBySearchQuery(options) {
|
|
|
47
64
|
});
|
|
48
65
|
}
|
|
49
66
|
catch (e) {
|
|
50
|
-
//@ts-expect-error
|
|
51
67
|
res = (0, remoteConfig_1.swallowMissingConfigFileException)(e);
|
|
52
68
|
}
|
|
53
69
|
const commits = res.search.nodes.map((pullRequestNode) => {
|
|
@@ -40,6 +40,7 @@ describe('getOptionsFromGithub', () => {
|
|
|
40
40
|
'^v7.9.0$': '7.x',
|
|
41
41
|
'^v8.0.0$': 'master',
|
|
42
42
|
},
|
|
43
|
+
isRepoPrivate: false,
|
|
43
44
|
sourceBranch: 'master',
|
|
44
45
|
targetBranchChoices: [
|
|
45
46
|
{ checked: true, name: 'master' },
|
|
@@ -109,6 +110,7 @@ describe('getOptionsFromGithub', () => {
|
|
|
109
110
|
const options = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
|
|
110
111
|
expect(options).toEqual({
|
|
111
112
|
authenticatedUsername: 'sqren',
|
|
113
|
+
isRepoPrivate: false,
|
|
112
114
|
sourceBranch: 'main',
|
|
113
115
|
});
|
|
114
116
|
});
|
|
@@ -17,4 +17,4 @@ export interface RemoteConfigHistory {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
export declare function parseRemoteConfig(remoteConfig: RemoteConfig): ConfigFileOptions | undefined;
|
|
20
|
-
export declare function swallowMissingConfigFileException<T>(error: GithubV4Exception<T>): T;
|
|
20
|
+
export declare function swallowMissingConfigFileException<T>(error: GithubV4Exception<T> | unknown): T;
|
package/dist/lib/remoteConfig.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.swallowMissingConfigFileException = exports.parseRemoteConfig = exports.RemoteConfigHistoryFragment = void 0;
|
|
7
7
|
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
8
|
const readConfigFile_1 = require("../options/config/readConfigFile");
|
|
9
|
+
const apiRequestV4_1 = require("./github/v4/apiRequestV4");
|
|
9
10
|
const logger_1 = require("./logger");
|
|
10
11
|
exports.RemoteConfigHistoryFragment = (0, graphql_tag_1.default) `
|
|
11
12
|
fragment RemoteConfigHistoryFragment on Commit {
|
|
@@ -38,6 +39,9 @@ function parseRemoteConfig(remoteConfig) {
|
|
|
38
39
|
}
|
|
39
40
|
exports.parseRemoteConfig = parseRemoteConfig;
|
|
40
41
|
function swallowMissingConfigFileException(error) {
|
|
42
|
+
if (!(error instanceof apiRequestV4_1.GithubV4Exception)) {
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
41
45
|
const { data, errors } = error.githubResponse.data;
|
|
42
46
|
const missingConfigError = errors?.some((error) => {
|
|
43
47
|
return error.path?.includes('remoteConfig') && error.type === 'NOT_FOUND';
|
|
@@ -15,6 +15,8 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[]): {
|
|
|
15
15
|
cherrypickRef?: boolean | undefined;
|
|
16
16
|
projectConfigFile?: string | undefined;
|
|
17
17
|
globalConfigFile?: string | undefined;
|
|
18
|
+
dateSince?: string | undefined;
|
|
19
|
+
dateUntil?: string | undefined;
|
|
18
20
|
details?: boolean | undefined;
|
|
19
21
|
dryRun?: boolean | undefined;
|
|
20
22
|
editor?: string | undefined;
|
|
@@ -41,8 +43,6 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[]): {
|
|
|
41
43
|
repoOwner?: string | undefined;
|
|
42
44
|
repoName?: string | undefined;
|
|
43
45
|
sourceBranch?: string | undefined;
|
|
44
|
-
dateSince?: string | undefined;
|
|
45
|
-
dateUntil?: string | undefined;
|
|
46
46
|
commitPaths?: string[] | undefined;
|
|
47
47
|
reviewers?: string[] | undefined;
|
|
48
48
|
sourcePRLabels?: string[] | undefined;
|