backport 5.6.3 → 6.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 +48 -39
- package/dist/entrypoint.cli.js +1 -1
- package/dist/entrypoint.module.d.ts +6 -5
- package/dist/entrypoint.module.js +8 -6
- package/dist/ink.d.ts +1 -0
- package/dist/ink.js +49 -0
- package/dist/main.d.ts +11 -6
- package/dist/main.js +40 -24
- package/dist/options/ConfigOptions.d.ts +47 -39
- package/dist/options/cliArgs.d.ts +28 -34
- package/dist/options/cliArgs.js +113 -94
- package/dist/options/cliArgs.test.js +103 -119
- package/dist/options/config/config.d.ts +81 -2
- package/dist/options/config/config.js +46 -6
- package/dist/options/config/config.test.js +24 -2
- package/dist/options/config/getOptionsFromGit.d.ts +3 -0
- package/dist/options/config/getOptionsFromGit.js +10 -0
- package/dist/options/config/globalConfig.d.ts +2 -1
- package/dist/options/config/globalConfig.js +8 -8
- package/dist/options/config/globalConfig.test.js +7 -3
- package/dist/options/config/projectConfig.d.ts +2 -1
- package/dist/options/config/projectConfig.js +3 -3
- package/dist/options/config/projectConfig.test.js +4 -4
- package/dist/options/config/readConfigFile.d.ts +2 -2
- package/dist/options/config/readConfigFile.js +3 -3
- package/dist/options/options.d.ts +40 -27
- package/dist/options/options.js +8 -16
- package/dist/options/options.test.js +66 -26
- package/dist/options/parseRequiredOptions.d.ts +71 -0
- package/dist/options/parseRequiredOptions.js +70 -0
- package/dist/options/parseRequiredOptions.test.d.ts +1 -0
- package/dist/options/parseRequiredOptions.test.js +127 -0
- package/dist/runSequentially.d.ts +20 -0
- package/dist/runSequentially.js +41 -0
- package/dist/runSequentially.test.d.ts +1 -0
- package/dist/runSequentially.test.js +235 -0
- package/dist/runWithOptions.js +7 -14
- package/dist/runWithOptions.test.js +142 -16
- package/dist/scripts/generate-gql.d.ts +1 -0
- package/dist/scripts/generate-gql.js +15 -0
- package/dist/scripts/postinstall.js +4 -4
- package/dist/scripts/postinstall.test.js +9 -2
- package/dist/scripts/runPostinstall.js +1 -1
- package/dist/services/HandledError.d.ts +11 -1
- package/dist/services/HandledError.js +2 -1
- package/dist/services/child-process-promisified.d.ts +1 -1
- package/dist/services/child-process-promisified.js +2 -2
- package/dist/services/env.js +5 -5
- package/dist/services/env.test.js +11 -4
- package/dist/services/fs-promisified.js +4 -4
- package/dist/services/getExpectedTarget.d.ts +9 -0
- package/dist/services/getExpectedTarget.js +77 -0
- package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
- package/dist/services/getExpectedTargetPullRequests.js +77 -0
- package/dist/services/git.d.ts +19 -4
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +168 -0
- package/dist/services/git.js +129 -57
- package/dist/services/git.test.js +155 -51
- package/dist/services/github/commitFormatters.d.ts +3 -7
- package/dist/services/github/commitFormatters.js +10 -19
- package/dist/services/github/commitFormatters.test.js +2 -24
- package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -6
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +2 -3
- package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
- package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
- package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
- package/dist/services/github/v3/createPullRequest.d.ts +3 -2
- package/dist/services/github/v3/createPullRequest.js +33 -24
- package/dist/services/github/v3/createStatusComment.d.ts +11 -0
- package/dist/services/github/v3/createStatusComment.js +97 -0
- package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/services/github/v3/createStatusComment.test.js +209 -0
- package/dist/services/github/v4/FetchPullRequestId.d.ts +9 -0
- package/dist/services/github/v4/FetchPullRequestId.js +32 -0
- package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
- package/dist/services/github/v4/apiRequestV4.js +8 -10
- package/dist/services/github/v4/apiRequestV4.test.js +7 -7
- package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +9 -0
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +28 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +9 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +51 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +113 -0
- package/dist/services/github/v4/fetchAuthorId.d.ts +5 -0
- package/dist/services/github/v4/fetchAuthorId.js +1 -1
- package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -3
- package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
- package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +6 -6
- package/dist/services/github/v4/fetchCommitBySha.js +14 -12
- package/dist/services/github/v4/fetchCommitBySha.private.test.js +7 -5
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +5 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +67 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +5 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +16 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +90 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +130 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +127 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +81 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
- package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +3 -2
- package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
- package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +81 -8
- package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
- package/dist/services/github/v4/fetchDefaultBranch.d.ts +1 -1
- package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +4 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.js +52 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +32 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.d.ts +4 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.js +72 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.js +34 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.d.ts +40 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.js +72 -0
- package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -3
- package/dist/services/github/v4/fetchMergedPullRequests.d.ts +19 -20
- package/dist/services/github/v4/fetchMergedPullRequests.js +22 -68
- package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +11 -0
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +35 -0
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.d.ts +1 -1
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +8 -6
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
- package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
- package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
- package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +61 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.js +139 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +126 -0
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +34 -0
- package/dist/services/github/v4/getOptionsFromGithub/query.js +44 -0
- package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
- package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
- package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
- package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +2 -2
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +2 -2
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +4 -1
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +1 -1
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
- package/dist/services/logger.d.ts +3 -3
- package/dist/services/logger.js +24 -24
- package/dist/services/prompt.test.d.ts +1 -0
- package/dist/services/prompt.test.js +87 -0
- package/dist/services/prompts.d.ts +10 -4
- package/dist/services/prompts.js +85 -22
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +396 -0
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +78 -0
- package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.js +114 -0
- package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
- package/dist/services/sourceCommit/sourceCommit.js +86 -0
- package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
- package/dist/services/sourceCommit.d.ts +78 -0
- package/dist/services/sourceCommit.js +86 -0
- package/dist/services/sourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit.test.js +280 -0
- package/dist/test/inquirer.private.test.js +81 -45
- package/dist/test/integration/createSpies.d.ts +1 -1
- package/dist/test/integration/createSpies.js +21 -9
- package/dist/test/integration/envConstants.js +5 -6
- package/dist/test/integration/helpers.js +1 -1
- package/dist/test/integration/integration.private.test.d.ts +1 -0
- package/dist/test/integration/integration.private.test.js +308 -0
- package/dist/test/integration/integration.test.js +30 -31
- package/dist/test/nockHelpers.d.ts +2 -2
- package/dist/test/nockHelpers.js +3 -7
- package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
- package/dist/test/setupFiles/automatic-mocks.js +0 -22
- package/dist/types/Commit.d.ts +85 -0
- package/dist/types/Commit.js +139 -0
- package/dist/types/commitNode.d.ts +89 -0
- package/dist/types/commitNode.js +139 -0
- package/dist/types/commitNode.test.d.ts +1 -0
- package/dist/types/commitNode.test.js +255 -0
- package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
- package/dist/types/commitWithAssociatedPullRequests.js +145 -0
- package/dist/ui/cherrypickAndCreatePullRequest.test.js +277 -59
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +135 -67
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
- package/dist/ui/getCommits.d.ts +1 -1
- package/dist/ui/getCommits.js +55 -25
- package/dist/ui/getTargetBranches.d.ts +2 -2
- package/dist/ui/getTargetBranches.js +16 -17
- package/dist/ui/getTargetBranches.test.js +75 -99
- package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
- package/dist/ui/getTargetBranchesFromLabels.js +40 -0
- package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
- package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
- package/dist/ui/maybeSetupRepo.js +9 -9
- package/dist/ui/maybeSetupRepo.test.js +5 -1
- package/package.json +36 -51
- package/yarn.lock +2387 -2979
|
@@ -0,0 +1,51 @@
|
|
|
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.enablePullRequestAutoMerge = void 0;
|
|
7
|
+
const ora_1 = __importDefault(require("ora"));
|
|
8
|
+
const logger_1 = require("../../logger");
|
|
9
|
+
const FetchPullRequestId_1 = require("./FetchPullRequestId");
|
|
10
|
+
const apiRequestV4_1 = require("./apiRequestV4");
|
|
11
|
+
async function enablePullRequestAutoMerge(options, targetPullRequestNumber) {
|
|
12
|
+
const { accessToken, githubApiBaseUrlV4, autoMergeMethod } = options;
|
|
13
|
+
const text = `Enabling auto merging via ${options.autoMergeMethod}`;
|
|
14
|
+
logger_1.logger.info(text);
|
|
15
|
+
const spinner = (0, ora_1.default)(text).start();
|
|
16
|
+
const pullRequestId = await (0, FetchPullRequestId_1.fetchPullRequestId)(options, targetPullRequestNumber);
|
|
17
|
+
const query = /* GraphQL */ `
|
|
18
|
+
mutation EnablePullRequestAutoMerge(
|
|
19
|
+
$pullRequestId: ID!
|
|
20
|
+
$mergeMethod: PullRequestMergeMethod!
|
|
21
|
+
) {
|
|
22
|
+
enablePullRequestAutoMerge(
|
|
23
|
+
input: { pullRequestId: $pullRequestId, mergeMethod: $mergeMethod }
|
|
24
|
+
) {
|
|
25
|
+
pullRequest {
|
|
26
|
+
number
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
try {
|
|
32
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
33
|
+
githubApiBaseUrlV4,
|
|
34
|
+
accessToken,
|
|
35
|
+
query,
|
|
36
|
+
variables: {
|
|
37
|
+
pullRequestId,
|
|
38
|
+
mergeMethod: autoMergeMethod.toUpperCase(),
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
spinner.succeed();
|
|
42
|
+
return res.enablePullRequestAutoMerge.pullRequest?.number;
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
if (e instanceof Error) {
|
|
46
|
+
spinner.fail();
|
|
47
|
+
logger_1.logger.info(`Could not enable auto merging for ${targetPullRequestNumber}`, e.stack);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.enablePullRequestAutoMerge = enablePullRequestAutoMerge;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
// commit to create new branch from
|
|
19
|
+
// https://github.com/backport-org/repo-with-auto-merge-enabled/commit/1a88d210f90a22e2a06253c5760909833dc820e9
|
|
20
|
+
const COMMIT_SHA = '1a88d210f90a22e2a06253c5760909833dc820e9';
|
|
21
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
22
|
+
async function closePr(octokit, pullNumber) {
|
|
23
|
+
await octokit.pulls.update({
|
|
24
|
+
owner: TEST_REPO_OWNER,
|
|
25
|
+
repo: TEST_REPO_NAME,
|
|
26
|
+
pull_number: pullNumber,
|
|
27
|
+
state: 'closed',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async function createPr(options, branchName) {
|
|
31
|
+
const prPayload = {
|
|
32
|
+
base: 'main',
|
|
33
|
+
head: branchName,
|
|
34
|
+
body: 'testing...',
|
|
35
|
+
owner: TEST_REPO_OWNER,
|
|
36
|
+
repo: TEST_REPO_NAME,
|
|
37
|
+
title: 'my pr title',
|
|
38
|
+
};
|
|
39
|
+
const { number } = await (0, createPullRequest_1.createPullRequest)({ options, prPayload });
|
|
40
|
+
return number;
|
|
41
|
+
}
|
|
42
|
+
async function deleteBranch(octokit, branchName) {
|
|
43
|
+
await octokit.git.deleteRef({
|
|
44
|
+
owner: TEST_REPO_OWNER,
|
|
45
|
+
repo: TEST_REPO_NAME,
|
|
46
|
+
ref: `heads/${branchName}`,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async function createBranch(octokit, branchName, sha) {
|
|
50
|
+
await octokit.git.createRef({
|
|
51
|
+
owner: TEST_REPO_OWNER,
|
|
52
|
+
repo: TEST_REPO_NAME,
|
|
53
|
+
ref: `refs/heads/${branchName}`,
|
|
54
|
+
sha,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
// causes flaky test runs on CI because parallel builds are racing each other
|
|
58
|
+
// might also be an issue with Github's API being slow at updating after a mutation happens
|
|
59
|
+
// eslint-disable-next-line jest/no-disabled-tests
|
|
60
|
+
describe.skip('enablePullRequestAutoMerge', () => {
|
|
61
|
+
let pullNumber;
|
|
62
|
+
let branchName;
|
|
63
|
+
let octokit;
|
|
64
|
+
let options;
|
|
65
|
+
beforeAll(async () => {
|
|
66
|
+
const accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
67
|
+
const randomString = crypto_1.default.randomBytes(4).toString('hex');
|
|
68
|
+
branchName = `test-${randomString}`;
|
|
69
|
+
options = {
|
|
70
|
+
accessToken,
|
|
71
|
+
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
72
|
+
repoOwner: TEST_REPO_OWNER,
|
|
73
|
+
repoName: TEST_REPO_NAME,
|
|
74
|
+
};
|
|
75
|
+
octokit = new rest_1.Octokit({ auth: accessToken });
|
|
76
|
+
await createBranch(octokit, branchName, COMMIT_SHA);
|
|
77
|
+
pullNumber = await createPr(options, branchName);
|
|
78
|
+
});
|
|
79
|
+
// cleanup
|
|
80
|
+
afterAll(async () => {
|
|
81
|
+
await closePr(octokit, pullNumber);
|
|
82
|
+
await deleteBranch(octokit, branchName);
|
|
83
|
+
});
|
|
84
|
+
// reset auto-merge state between runs
|
|
85
|
+
afterEach(async () => {
|
|
86
|
+
await (0, disablePullRequestAutoMerge_1.disablePullRequestAutoMerge)(options, pullNumber);
|
|
87
|
+
});
|
|
88
|
+
it('should initially have auto-merge disabled', async () => {
|
|
89
|
+
const autoMergeMethod = await (0, fetchPullRequestAutoMergeMethod_1.fetchPullRequestAutoMergeMethod)(options, pullNumber);
|
|
90
|
+
expect(autoMergeMethod).toBe(undefined);
|
|
91
|
+
});
|
|
92
|
+
it('should enable auto-merge via merge', async () => {
|
|
93
|
+
await (0, enablePullRequestAutoMerge_1.enablePullRequestAutoMerge)({ ...options, autoMergeMethod: 'merge' }, pullNumber);
|
|
94
|
+
// ensure Github API reflects the change before querying
|
|
95
|
+
await sleep(100);
|
|
96
|
+
const autoMergeMethod = await (0, fetchPullRequestAutoMergeMethod_1.fetchPullRequestAutoMergeMethod)(options, pullNumber);
|
|
97
|
+
expect(autoMergeMethod).toBe('MERGE');
|
|
98
|
+
});
|
|
99
|
+
it('should not enable auto-merge via rebase because it is disallowed', async () => {
|
|
100
|
+
await (0, enablePullRequestAutoMerge_1.enablePullRequestAutoMerge)({ ...options, autoMergeMethod: 'rebase' }, pullNumber);
|
|
101
|
+
// ensure Github API reflects the change before querying
|
|
102
|
+
await sleep(100);
|
|
103
|
+
const autoMergeMethod = await (0, fetchPullRequestAutoMergeMethod_1.fetchPullRequestAutoMergeMethod)(options, pullNumber);
|
|
104
|
+
expect(autoMergeMethod).toBe(undefined);
|
|
105
|
+
});
|
|
106
|
+
it('should enable auto-merge via squash', async () => {
|
|
107
|
+
await (0, enablePullRequestAutoMerge_1.enablePullRequestAutoMerge)({ ...options, autoMergeMethod: 'squash' }, pullNumber);
|
|
108
|
+
// ensure Github API reflects the change before querying
|
|
109
|
+
await sleep(100);
|
|
110
|
+
const autoMergeMethod = await (0, fetchPullRequestAutoMergeMethod_1.fetchPullRequestAutoMergeMethod)(options, pullNumber);
|
|
111
|
+
expect(autoMergeMethod).toBe('SQUASH');
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -5,7 +5,7 @@ const fetchAuthorId_1 = require("./fetchAuthorId");
|
|
|
5
5
|
describe('fetchAuthorId', () => {
|
|
6
6
|
let devAccessToken;
|
|
7
7
|
beforeAll(async () => {
|
|
8
|
-
devAccessToken = await getDevAccessToken_1.getDevAccessToken();
|
|
8
|
+
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
9
|
});
|
|
10
10
|
describe('all = true', () => {
|
|
11
11
|
it('returns null', async () => {
|
|
@@ -14,7 +14,7 @@ describe('fetchAuthorId', () => {
|
|
|
14
14
|
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
15
15
|
all: true,
|
|
16
16
|
};
|
|
17
|
-
expect(await fetchAuthorId_1.fetchAuthorId(options)).toEqual(null);
|
|
17
|
+
expect(await (0, fetchAuthorId_1.fetchAuthorId)(options)).toEqual(null);
|
|
18
18
|
});
|
|
19
19
|
});
|
|
20
20
|
describe('all = false', () => {
|
|
@@ -25,7 +25,7 @@ describe('fetchAuthorId', () => {
|
|
|
25
25
|
all: false,
|
|
26
26
|
author: 'sqren',
|
|
27
27
|
};
|
|
28
|
-
expect(await fetchAuthorId_1.fetchAuthorId(options)).toEqual('MDQ6VXNlcjIwOTk2Ng==');
|
|
28
|
+
expect(await (0, fetchAuthorId_1.fetchAuthorId)(options)).toEqual('MDQ6VXNlcjIwOTk2Ng==');
|
|
29
29
|
});
|
|
30
30
|
});
|
|
31
31
|
});
|
|
@@ -12,7 +12,7 @@ const apiRequestV4_1 = require("./apiRequestV4");
|
|
|
12
12
|
const getExistingTargetPullRequests_1 = require("./getExistingTargetPullRequests");
|
|
13
13
|
const getTargetBranchesFromLabels_1 = require("./getTargetBranchesFromLabels");
|
|
14
14
|
async function fetchCommitByPullNumber(options) {
|
|
15
|
-
const { accessToken, githubApiBaseUrlV4, pullNumber, repoName, repoOwner
|
|
15
|
+
const { accessToken, githubApiBaseUrlV4, pullNumber, repoName, repoOwner } = options;
|
|
16
16
|
const query = /* GraphQL */ `
|
|
17
17
|
query CommitByPullNumber(
|
|
18
18
|
$repoOwner: String!
|
|
@@ -21,17 +21,17 @@ async function fetchCommitByPullNumber(options) {
|
|
|
21
21
|
) {
|
|
22
22
|
repository(owner: $repoOwner, name: $repoName) {
|
|
23
23
|
pullRequest(number: $pullNumber) {
|
|
24
|
-
...${getExistingTargetPullRequests_1.
|
|
24
|
+
...${getExistingTargetPullRequests_1.pullRequestFragment.name}
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
${getExistingTargetPullRequests_1.pullRequestFragment}
|
|
29
|
+
${getExistingTargetPullRequests_1.pullRequestFragment.source}
|
|
30
30
|
`;
|
|
31
|
-
const spinner = ora_1.default(`Loading merge commit from pull request #${options.pullNumber}`).start();
|
|
31
|
+
const spinner = (0, ora_1.default)(`Loading merge commit from pull request #${options.pullNumber}`).start();
|
|
32
32
|
let res;
|
|
33
33
|
try {
|
|
34
|
-
res = await apiRequestV4_1.apiRequestV4({
|
|
34
|
+
res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
35
35
|
githubApiBaseUrlV4,
|
|
36
36
|
accessToken,
|
|
37
37
|
query,
|
|
@@ -51,10 +51,11 @@ async function fetchCommitByPullNumber(options) {
|
|
|
51
51
|
if (pullRequestNode.mergeCommit === null) {
|
|
52
52
|
throw new HandledError_1.HandledError(`The PR #${pullNumber} is not merged`);
|
|
53
53
|
}
|
|
54
|
+
const committedDate = pullRequestNode.mergeCommit.committedDate;
|
|
54
55
|
const sourceBranch = pullRequestNode.baseRefName;
|
|
55
56
|
const sha = pullRequestNode.mergeCommit.oid;
|
|
56
57
|
const commitMessage = pullRequestNode.mergeCommit.message;
|
|
57
|
-
const formattedMessage = commitFormatters_1.getFormattedCommitMessage({
|
|
58
|
+
const formattedMessage = (0, commitFormatters_1.getFormattedCommitMessage)({
|
|
58
59
|
message: commitMessage,
|
|
59
60
|
sha,
|
|
60
61
|
pullNumber,
|
|
@@ -64,14 +65,15 @@ async function fetchCommitByPullNumber(options) {
|
|
|
64
65
|
symbol: chalk_1.default.green('?'),
|
|
65
66
|
text: `${chalk_1.default.bold('Select pull request')} ${chalk_1.default.cyan(formattedMessage)}`,
|
|
66
67
|
});
|
|
67
|
-
const existingTargetPullRequests = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
|
|
68
|
-
const targetBranchesFromLabels = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
|
|
68
|
+
const existingTargetPullRequests = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
|
|
69
|
+
const targetBranchesFromLabels = (0, getTargetBranchesFromLabels_1.getTargetBranchesFromLabels)({
|
|
69
70
|
sourceBranch: pullRequestNode.baseRefName,
|
|
70
71
|
existingTargetPullRequests,
|
|
71
72
|
branchLabelMapping: options.branchLabelMapping,
|
|
72
|
-
labels: getExistingTargetPullRequests_1.getPullRequestLabels(pullRequestNode),
|
|
73
|
+
labels: (0, getExistingTargetPullRequests_1.getPullRequestLabels)(pullRequestNode),
|
|
73
74
|
});
|
|
74
75
|
return {
|
|
76
|
+
committedDate,
|
|
75
77
|
sourceBranch,
|
|
76
78
|
targetBranchesFromLabels,
|
|
77
79
|
sha,
|
|
@@ -5,7 +5,7 @@ const fetchCommitByPullNumber_1 = require("./fetchCommitByPullNumber");
|
|
|
5
5
|
describe('fetchCommitByPullNumber', () => {
|
|
6
6
|
let devAccessToken;
|
|
7
7
|
beforeAll(async () => {
|
|
8
|
-
devAccessToken = await getDevAccessToken_1.getDevAccessToken();
|
|
8
|
+
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
9
|
});
|
|
10
10
|
describe('when PR was merged', () => {
|
|
11
11
|
it('is returned', async () => {
|
|
@@ -16,7 +16,7 @@ describe('fetchCommitByPullNumber', () => {
|
|
|
16
16
|
repoName: 'backport-e2e',
|
|
17
17
|
repoOwner: 'backport-org',
|
|
18
18
|
};
|
|
19
|
-
expect(await fetchCommitByPullNumber_1.fetchCommitByPullNumber(options)).toEqual({
|
|
19
|
+
expect(await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).toEqual({
|
|
20
20
|
formattedMessage: 'Add 🍏 emoji (#5)',
|
|
21
21
|
originalMessage: 'Add 🍏 emoji (#5)',
|
|
22
22
|
pullNumber: 5,
|
|
@@ -24,8 +24,8 @@ describe('fetchCommitByPullNumber', () => {
|
|
|
24
24
|
sourceBranch: 'master',
|
|
25
25
|
targetBranchesFromLabels: [],
|
|
26
26
|
existingTargetPullRequests: [
|
|
27
|
-
{ branch: '7.x', state: 'MERGED' },
|
|
28
|
-
{ branch: '7.8', state: 'MERGED' },
|
|
27
|
+
{ branch: '7.x', state: 'MERGED', number: 6 },
|
|
28
|
+
{ branch: '7.8', state: 'MERGED', number: 7 },
|
|
29
29
|
],
|
|
30
30
|
});
|
|
31
31
|
});
|
|
@@ -39,7 +39,7 @@ describe('fetchCommitByPullNumber', () => {
|
|
|
39
39
|
repoName: 'backport-e2e',
|
|
40
40
|
repoOwner: 'backport-org',
|
|
41
41
|
};
|
|
42
|
-
await expect(fetchCommitByPullNumber_1.fetchCommitByPullNumber(options)).rejects.toThrowError(`The PR #11 is not merged`);
|
|
42
|
+
await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`The PR #11 is not merged`);
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
45
|
describe('when PR does not exist', () => {
|
|
@@ -51,7 +51,7 @@ describe('fetchCommitByPullNumber', () => {
|
|
|
51
51
|
repoName: 'backport-e2e',
|
|
52
52
|
repoOwner: 'backport-org',
|
|
53
53
|
};
|
|
54
|
-
await expect(fetchCommitByPullNumber_1.fetchCommitByPullNumber(options)).rejects.toThrowError(`Could not resolve to a PullRequest with the number of 9999999999999. (Github v4)`);
|
|
54
|
+
await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`Could not resolve to a PullRequest with the number of 9999999999999. (Unhandled Github v4 error)`);
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
57
|
});
|
|
@@ -12,19 +12,19 @@ const apiRequestV4_1 = require("./apiRequestV4");
|
|
|
12
12
|
const getExistingTargetPullRequests_1 = require("./getExistingTargetPullRequests");
|
|
13
13
|
const getTargetBranchesFromLabels_1 = require("./getTargetBranchesFromLabels");
|
|
14
14
|
async function fetchCommitBySha(options) {
|
|
15
|
-
var _a, _b;
|
|
16
15
|
const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
|
|
17
16
|
const query = /* GraphQL */ `
|
|
18
17
|
query CommitsBySha($repoOwner: String!, $repoName: String!, $oid: String!) {
|
|
19
18
|
repository(owner: $repoOwner, name: $repoName) {
|
|
20
19
|
object(expression: $oid) {
|
|
21
20
|
... on Commit {
|
|
21
|
+
committedDate
|
|
22
22
|
message
|
|
23
23
|
oid
|
|
24
24
|
associatedPullRequests(first: 1) {
|
|
25
25
|
edges {
|
|
26
26
|
node {
|
|
27
|
-
...${getExistingTargetPullRequests_1.
|
|
27
|
+
...${getExistingTargetPullRequests_1.pullRequestFragment.name}
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -33,12 +33,12 @@ async function fetchCommitBySha(options) {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
${getExistingTargetPullRequests_1.pullRequestFragment}
|
|
36
|
+
${getExistingTargetPullRequests_1.pullRequestFragment.source}
|
|
37
37
|
`;
|
|
38
|
-
const spinner = ora_1.default(`Loading commit "${commitFormatters_1.getShortSha(options.sha)}"`).start();
|
|
38
|
+
const spinner = (0, ora_1.default)(`Loading commit "${(0, commitFormatters_1.getShortSha)(options.sha)}"`).start();
|
|
39
39
|
let res;
|
|
40
40
|
try {
|
|
41
|
-
res = await apiRequestV4_1.apiRequestV4({
|
|
41
|
+
res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
42
42
|
githubApiBaseUrlV4,
|
|
43
43
|
accessToken,
|
|
44
44
|
query,
|
|
@@ -57,12 +57,13 @@ async function fetchCommitBySha(options) {
|
|
|
57
57
|
if (!res.repository.object) {
|
|
58
58
|
throw new HandledError_1.HandledError(`No commit found on branch "${options.sourceBranch}" with sha "${options.sha}"`);
|
|
59
59
|
}
|
|
60
|
+
const committedDate = res.repository.object.committedDate;
|
|
60
61
|
const sha = res.repository.object.oid;
|
|
61
62
|
const commitMessage = res.repository.object.message;
|
|
62
|
-
const pullRequestNode =
|
|
63
|
-
const pullNumber =
|
|
64
|
-
const sourceBranch =
|
|
65
|
-
const formattedMessage = commitFormatters_1.getFormattedCommitMessage({
|
|
63
|
+
const pullRequestNode = res.repository.object.associatedPullRequests.edges?.[0]?.node;
|
|
64
|
+
const pullNumber = pullRequestNode?.number || (0, commitFormatters_1.getPullNumberFromMessage)(commitMessage);
|
|
65
|
+
const sourceBranch = pullRequestNode?.baseRefName || options.sourceBranch;
|
|
66
|
+
const formattedMessage = (0, commitFormatters_1.getFormattedCommitMessage)({
|
|
66
67
|
message: commitMessage,
|
|
67
68
|
pullNumber,
|
|
68
69
|
sha,
|
|
@@ -71,16 +72,17 @@ async function fetchCommitBySha(options) {
|
|
|
71
72
|
symbol: chalk_1.default.green('?'),
|
|
72
73
|
text: `${chalk_1.default.bold('Select commit')} ${chalk_1.default.cyan(formattedMessage)}`,
|
|
73
74
|
});
|
|
74
|
-
const existingTargetPullRequests = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
|
|
75
|
+
const existingTargetPullRequests = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
|
|
75
76
|
const targetBranchesFromLabels = pullRequestNode
|
|
76
|
-
? getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
|
|
77
|
+
? (0, getTargetBranchesFromLabels_1.getTargetBranchesFromLabels)({
|
|
77
78
|
sourceBranch: pullRequestNode.baseRefName,
|
|
78
79
|
existingTargetPullRequests,
|
|
79
80
|
branchLabelMapping: options.branchLabelMapping,
|
|
80
|
-
labels: getExistingTargetPullRequests_1.getPullRequestLabels(pullRequestNode),
|
|
81
|
+
labels: (0, getExistingTargetPullRequests_1.getPullRequestLabels)(pullRequestNode),
|
|
81
82
|
})
|
|
82
83
|
: [];
|
|
83
84
|
return {
|
|
85
|
+
committedDate,
|
|
84
86
|
sourceBranch,
|
|
85
87
|
targetBranchesFromLabels,
|
|
86
88
|
sha,
|
|
@@ -5,10 +5,10 @@ const fetchCommitBySha_1 = require("./fetchCommitBySha");
|
|
|
5
5
|
describe('fetchCommitBySha', () => {
|
|
6
6
|
let devAccessToken;
|
|
7
7
|
beforeEach(async () => {
|
|
8
|
-
devAccessToken = await getDevAccessToken_1.getDevAccessToken();
|
|
8
|
+
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
9
|
});
|
|
10
10
|
it('should return single commit with pull request', async () => {
|
|
11
|
-
await expect(await fetchCommitBySha_1.fetchCommitBySha({
|
|
11
|
+
await expect(await (0, fetchCommitBySha_1.fetchCommitBySha)({
|
|
12
12
|
repoOwner: 'elastic',
|
|
13
13
|
repoName: 'kibana',
|
|
14
14
|
accessToken: devAccessToken,
|
|
@@ -22,11 +22,13 @@ describe('fetchCommitBySha', () => {
|
|
|
22
22
|
sha: 'cb6fbc0e1b406675724181a3e9f59459b5f8f892',
|
|
23
23
|
sourceBranch: 'master',
|
|
24
24
|
targetBranchesFromLabels: [],
|
|
25
|
-
existingTargetPullRequests: [
|
|
25
|
+
existingTargetPullRequests: [
|
|
26
|
+
{ branch: '7.x', state: 'MERGED', number: 71014 },
|
|
27
|
+
],
|
|
26
28
|
});
|
|
27
29
|
});
|
|
28
30
|
it('throws if sha does not exist', async () => {
|
|
29
|
-
await expect(fetchCommitBySha_1.fetchCommitBySha({
|
|
31
|
+
await expect((0, fetchCommitBySha_1.fetchCommitBySha)({
|
|
30
32
|
repoOwner: 'elastic',
|
|
31
33
|
repoName: 'kibana',
|
|
32
34
|
accessToken: devAccessToken,
|
|
@@ -36,7 +38,7 @@ describe('fetchCommitBySha', () => {
|
|
|
36
38
|
})).rejects.toThrowError('No commit found on branch "main" with sha "fc22f59"');
|
|
37
39
|
});
|
|
38
40
|
it('throws if sha is invalid', async () => {
|
|
39
|
-
await expect(fetchCommitBySha_1.fetchCommitBySha({
|
|
41
|
+
await expect((0, fetchCommitBySha_1.fetchCommitBySha)({
|
|
40
42
|
repoOwner: 'elastic',
|
|
41
43
|
repoName: 'kibana',
|
|
42
44
|
accessToken: devAccessToken,
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchCommitByPullNumber = void 0;
|
|
4
|
+
const HandledError_1 = require("../../../HandledError");
|
|
5
|
+
const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
|
|
6
|
+
const apiRequestV4_1 = require("../apiRequestV4");
|
|
7
|
+
async function fetchCommitByPullNumber(options) {
|
|
8
|
+
const { accessToken, githubApiBaseUrlV4, pullNumber, repoName, repoOwner } = options;
|
|
9
|
+
const query = /* GraphQL */ `
|
|
10
|
+
query CommitByPullNumber(
|
|
11
|
+
$repoOwner: String!
|
|
12
|
+
$repoName: String!
|
|
13
|
+
$pullNumber: Int!
|
|
14
|
+
) {
|
|
15
|
+
repository(owner: $repoOwner, name: $repoName) {
|
|
16
|
+
pullRequest(number: $pullNumber) {
|
|
17
|
+
mergeCommit {
|
|
18
|
+
...${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.name}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
|
|
25
|
+
`;
|
|
26
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
27
|
+
githubApiBaseUrlV4,
|
|
28
|
+
accessToken,
|
|
29
|
+
query,
|
|
30
|
+
variables: {
|
|
31
|
+
repoOwner,
|
|
32
|
+
repoName,
|
|
33
|
+
pullNumber,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
const pullRequestNode = res.repository.pullRequest;
|
|
37
|
+
if (!pullRequestNode) {
|
|
38
|
+
throw new HandledError_1.HandledError(`The PR #${pullNumber} does not exist`);
|
|
39
|
+
}
|
|
40
|
+
const sourceCommit = pullRequestNode.mergeCommit;
|
|
41
|
+
if (sourceCommit === null) {
|
|
42
|
+
throw new HandledError_1.HandledError(`The PR #${pullNumber} is not merged`);
|
|
43
|
+
}
|
|
44
|
+
return (0, parseSourceCommit_1.parseSourceCommit)({ options, sourceCommit });
|
|
45
|
+
}
|
|
46
|
+
exports.fetchCommitByPullNumber = fetchCommitByPullNumber;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
|
|
4
|
+
const fetchCommitByPullNumber_1 = require("./fetchCommitByPullNumber");
|
|
5
|
+
describe('fetchCommitByPullNumber', () => {
|
|
6
|
+
let devAccessToken;
|
|
7
|
+
beforeAll(async () => {
|
|
8
|
+
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
|
+
});
|
|
10
|
+
describe('when PR was merged', () => {
|
|
11
|
+
it('is returned', async () => {
|
|
12
|
+
const options = {
|
|
13
|
+
accessToken: devAccessToken,
|
|
14
|
+
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
15
|
+
pullNumber: 5,
|
|
16
|
+
repoName: 'backport-e2e',
|
|
17
|
+
repoOwner: 'backport-org',
|
|
18
|
+
};
|
|
19
|
+
expect(await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).toEqual({
|
|
20
|
+
committedDate: '2020-08-15T12:40:19Z',
|
|
21
|
+
originalMessage: 'Add 🍏 emoji (#5)',
|
|
22
|
+
pullNumber: 5,
|
|
23
|
+
pullUrl: 'https://github.com/backport-org/backport-e2e/pull/5',
|
|
24
|
+
sha: 'ee8c492334cef1ca077a56addb79a26f79821d2f',
|
|
25
|
+
sourceBranch: 'master',
|
|
26
|
+
expectedTargetPullRequests: [
|
|
27
|
+
{
|
|
28
|
+
branch: '7.x',
|
|
29
|
+
state: 'MERGED',
|
|
30
|
+
number: 6,
|
|
31
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/6',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
branch: '7.8',
|
|
35
|
+
state: 'MERGED',
|
|
36
|
+
number: 7,
|
|
37
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/7',
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe('when PR is still open', () => {
|
|
44
|
+
it('throws an error', async () => {
|
|
45
|
+
const options = {
|
|
46
|
+
accessToken: devAccessToken,
|
|
47
|
+
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
48
|
+
pullNumber: 11,
|
|
49
|
+
repoName: 'backport-e2e',
|
|
50
|
+
repoOwner: 'backport-org',
|
|
51
|
+
};
|
|
52
|
+
await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`The PR #11 is not merged`);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
describe('when PR does not exist', () => {
|
|
56
|
+
it('throws an error', async () => {
|
|
57
|
+
const options = {
|
|
58
|
+
accessToken: devAccessToken,
|
|
59
|
+
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
60
|
+
pullNumber: 9999999999999,
|
|
61
|
+
repoName: 'backport-e2e',
|
|
62
|
+
repoOwner: 'backport-org',
|
|
63
|
+
};
|
|
64
|
+
await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`Could not resolve to a PullRequest with the number of 9999999999999. (Unhandled Github v4 error)`);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchCommitBySha = void 0;
|
|
4
|
+
const HandledError_1 = require("../../../HandledError");
|
|
5
|
+
const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
|
|
6
|
+
const apiRequestV4_1 = require("../apiRequestV4");
|
|
7
|
+
async function fetchCommitBySha(options) {
|
|
8
|
+
const { accessToken, githubApiBaseUrlV4, repoName, repoOwner, sha, sourceBranch, } = options;
|
|
9
|
+
const query = /* GraphQL */ `
|
|
10
|
+
query CommitsBySha($repoOwner: String!, $repoName: String!, $oid: String!) {
|
|
11
|
+
repository(owner: $repoOwner, name: $repoName) {
|
|
12
|
+
object(expression: $oid) {
|
|
13
|
+
...${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.name}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
|
|
19
|
+
`;
|
|
20
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
21
|
+
githubApiBaseUrlV4,
|
|
22
|
+
accessToken,
|
|
23
|
+
query,
|
|
24
|
+
variables: {
|
|
25
|
+
repoOwner,
|
|
26
|
+
repoName,
|
|
27
|
+
oid: sha,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const sourceCommit = res.repository.object;
|
|
31
|
+
if (!sourceCommit) {
|
|
32
|
+
throw new HandledError_1.HandledError(`No commit found on branch "${sourceBranch}" with sha "${sha}"`);
|
|
33
|
+
}
|
|
34
|
+
return (0, parseSourceCommit_1.parseSourceCommit)({ options, sourceCommit });
|
|
35
|
+
}
|
|
36
|
+
exports.fetchCommitBySha = fetchCommitBySha;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|