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
|
@@ -3,27 +3,18 @@ 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.getTitle = exports.
|
|
6
|
+
exports.getTitle = exports.getPullRequestBody = exports.createPullRequest = void 0;
|
|
7
7
|
const rest_1 = require("@octokit/rest");
|
|
8
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
9
8
|
const ora_1 = __importDefault(require("ora"));
|
|
10
9
|
const HandledError_1 = require("../../HandledError");
|
|
11
10
|
const logger_1 = require("../../logger");
|
|
11
|
+
const commitFormatters_1 = require("../commitFormatters");
|
|
12
12
|
const fetchExistingPullRequest_1 = require("../v4/fetchExistingPullRequest");
|
|
13
13
|
const getGithubV3ErrorMessage_1 = require("./getGithubV3ErrorMessage");
|
|
14
14
|
async function createPullRequest({ options, prPayload, }) {
|
|
15
15
|
logger_1.logger.info(`Creating PR with title: "${prPayload.title}". ${prPayload.head} -> ${prPayload.base}`);
|
|
16
|
-
const { accessToken,
|
|
17
|
-
const spinner = ora_1.default(`Creating pull request`).start();
|
|
18
|
-
if (dryRun) {
|
|
19
|
-
spinner.succeed('Dry run: Creating pull request');
|
|
20
|
-
// output PR summary
|
|
21
|
-
logger_1.consoleLog(chalk_1.default.bold('\nPull request summary:'));
|
|
22
|
-
logger_1.consoleLog(`Branch: ${prPayload.head} -> ${prPayload.base}`);
|
|
23
|
-
logger_1.consoleLog(`Title: ${prPayload.title}`);
|
|
24
|
-
logger_1.consoleLog(`Body: ${prPayload.body}\n`);
|
|
25
|
-
return { url: 'example_url', number: 1337 };
|
|
26
|
-
}
|
|
16
|
+
const { accessToken, githubApiBaseUrlV3 } = options;
|
|
17
|
+
const spinner = (0, ora_1.default)(`Creating pull request`).start();
|
|
27
18
|
try {
|
|
28
19
|
const octokit = new rest_1.Octokit({
|
|
29
20
|
auth: accessToken,
|
|
@@ -35,42 +26,60 @@ async function createPullRequest({ options, prPayload, }) {
|
|
|
35
26
|
return {
|
|
36
27
|
url: res.data.html_url,
|
|
37
28
|
number: res.data.number,
|
|
29
|
+
didUpdate: false,
|
|
38
30
|
};
|
|
39
31
|
}
|
|
40
32
|
catch (e) {
|
|
41
33
|
// retrieve url for existing
|
|
42
34
|
try {
|
|
43
|
-
const existingPR = await fetchExistingPullRequest_1.fetchExistingPullRequest({
|
|
35
|
+
const existingPR = await (0, fetchExistingPullRequest_1.fetchExistingPullRequest)({
|
|
44
36
|
options,
|
|
45
37
|
prPayload,
|
|
46
38
|
});
|
|
47
39
|
if (existingPR) {
|
|
48
40
|
spinner.succeed('Updating existing pull request');
|
|
49
|
-
return
|
|
41
|
+
return {
|
|
42
|
+
url: existingPR.url,
|
|
43
|
+
number: existingPR.number,
|
|
44
|
+
didUpdate: true,
|
|
45
|
+
};
|
|
50
46
|
}
|
|
51
47
|
}
|
|
52
48
|
catch (e) {
|
|
53
|
-
logger_1.logger.
|
|
49
|
+
logger_1.logger.info('Could not retrieve existing pull request', e);
|
|
54
50
|
// swallow error
|
|
55
51
|
}
|
|
56
52
|
spinner.fail();
|
|
57
|
-
throw new HandledError_1.HandledError(`Could not create pull request: ${getGithubV3ErrorMessage_1.getGithubV3ErrorMessage(e)}`);
|
|
53
|
+
throw new HandledError_1.HandledError(`Could not create pull request: ${(0, getGithubV3ErrorMessage_1.getGithubV3ErrorMessage)(e)}`);
|
|
58
54
|
}
|
|
59
55
|
}
|
|
60
56
|
exports.createPullRequest = createPullRequest;
|
|
61
|
-
function
|
|
62
|
-
const commitMessages = commits
|
|
63
|
-
.map((commit) => ` - ${commit.formattedMessage}`)
|
|
64
|
-
.join('\n');
|
|
57
|
+
function getPullRequestBody({ options, commits, targetBranch, }) {
|
|
65
58
|
const bodySuffix = options.prDescription
|
|
66
59
|
? `\n\n${options.prDescription}`
|
|
67
60
|
: '';
|
|
68
|
-
|
|
61
|
+
const backportDocsNote = `\n\nPlease refer to the [Backport tool documentation](https://github.com/sqren/backport) for additional information`;
|
|
62
|
+
if (commits.length === 1) {
|
|
63
|
+
const c = commits[0];
|
|
64
|
+
const ref = c.pullNumber
|
|
65
|
+
? `pull request #${c.pullNumber}`
|
|
66
|
+
: `commit ${c.sha}`;
|
|
67
|
+
return `This is an automatic backport of ${ref} to ${targetBranch}.${backportDocsNote}${bodySuffix}`;
|
|
68
|
+
}
|
|
69
|
+
const commitMessages = commits
|
|
70
|
+
.map((c) => {
|
|
71
|
+
const message = c.pullNumber
|
|
72
|
+
? `#${c.pullNumber}`
|
|
73
|
+
: `${(0, commitFormatters_1.getFirstLine)(c.originalMessage)} (${(0, commitFormatters_1.getShortSha)(c.sha)})`;
|
|
74
|
+
return ` - ${message}`;
|
|
75
|
+
})
|
|
76
|
+
.join('\n');
|
|
77
|
+
return `This is an automatic backport of the following commits to ${targetBranch}:\n${commitMessages}${backportDocsNote}${bodySuffix}`;
|
|
69
78
|
}
|
|
70
|
-
exports.
|
|
79
|
+
exports.getPullRequestBody = getPullRequestBody;
|
|
71
80
|
function getTitle({ options, commits, targetBranch, }) {
|
|
72
81
|
const commitMessages = commits
|
|
73
|
-
.map((commit) => commit.
|
|
82
|
+
.map((commit) => (0, commitFormatters_1.getFirstLine)(commit.originalMessage))
|
|
74
83
|
.join(' | ');
|
|
75
84
|
return options.prTitle
|
|
76
85
|
.replace('{targetBranch}', targetBranch)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BackportResponse } from '../../../main';
|
|
2
|
+
import { ValidConfigOptions } from '../../../options/options';
|
|
3
|
+
export declare function createStatusComment({ options, backportResponse, }: {
|
|
4
|
+
options: ValidConfigOptions;
|
|
5
|
+
backportResponse: BackportResponse;
|
|
6
|
+
}): Promise<void>;
|
|
7
|
+
export declare function getCommentBody({ options, pullNumber, backportResponse, }: {
|
|
8
|
+
options: ValidConfigOptions;
|
|
9
|
+
pullNumber: number;
|
|
10
|
+
backportResponse: BackportResponse;
|
|
11
|
+
}): string;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCommentBody = exports.createStatusComment = void 0;
|
|
4
|
+
const rest_1 = require("@octokit/rest");
|
|
5
|
+
const logger_1 = require("../../logger");
|
|
6
|
+
const commitFormatters_1 = require("../commitFormatters");
|
|
7
|
+
async function createStatusComment({ options, backportResponse, }) {
|
|
8
|
+
const { githubApiBaseUrlV3, repoName, repoOwner, accessToken } = options;
|
|
9
|
+
try {
|
|
10
|
+
const octokit = new rest_1.Octokit({
|
|
11
|
+
auth: accessToken,
|
|
12
|
+
baseUrl: githubApiBaseUrlV3,
|
|
13
|
+
log: logger_1.logger,
|
|
14
|
+
});
|
|
15
|
+
// don't post update if there are no new pull requests created
|
|
16
|
+
if (backportResponse.status === 'success') {
|
|
17
|
+
const hasOnlyUpdates = backportResponse.results.every((result) => result.status === 'success' && result.didUpdate);
|
|
18
|
+
if (hasOnlyUpdates) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
await Promise.all(backportResponse.commits.map((commit) => {
|
|
23
|
+
if (!commit.pullNumber) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const body = getCommentBody({
|
|
27
|
+
options,
|
|
28
|
+
pullNumber: commit.pullNumber,
|
|
29
|
+
backportResponse,
|
|
30
|
+
});
|
|
31
|
+
return octokit.issues.createComment({
|
|
32
|
+
owner: repoOwner,
|
|
33
|
+
repo: repoName,
|
|
34
|
+
issue_number: commit.pullNumber,
|
|
35
|
+
body,
|
|
36
|
+
});
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
logger_1.logger.info(`Could not create status comment `, e.stack);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.createStatusComment = createStatusComment;
|
|
44
|
+
function getCommentBody({ options, pullNumber, backportResponse, }) {
|
|
45
|
+
const { repoName, repoOwner, autoMerge } = options;
|
|
46
|
+
const backportPRCommand = `To backport manually run: \`node scripts/backport --pr ${pullNumber}\`.\nFor more info read the [Backport documentation](https://github.com/sqren/backport#backport)`;
|
|
47
|
+
if (backportResponse.status === 'failure') {
|
|
48
|
+
return `## 💔 Backport failed
|
|
49
|
+
The pull request could not be backported due to the following error:
|
|
50
|
+
\`${backportResponse.errorMessage}\`
|
|
51
|
+
|
|
52
|
+
${backportPRCommand}
|
|
53
|
+
`;
|
|
54
|
+
}
|
|
55
|
+
const tableBody = backportResponse.results
|
|
56
|
+
.map((result) => {
|
|
57
|
+
if (result.status === 'success') {
|
|
58
|
+
return [
|
|
59
|
+
'✅',
|
|
60
|
+
result.targetBranch,
|
|
61
|
+
`[<img src="https://img.shields.io/github/pulls/detail/state/${repoOwner}/${repoName}/${result.pullRequestNumber}">](${result.pullRequestUrl})`,
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
if (result.error.meta?.type === 'commitsWithoutBackports') {
|
|
65
|
+
const conflictMessage = result.error.meta.commitsWithoutBackports.map((c) => {
|
|
66
|
+
if (c.commit.pullNumber) {
|
|
67
|
+
return ` - [#${c.commit.pullNumber}](${c.commit.pullUrl})`;
|
|
68
|
+
}
|
|
69
|
+
return ` - ${(0, commitFormatters_1.getFirstLine)(c.commit.originalMessage)} (${(0, commitFormatters_1.getShortSha)(c.commit.sha)})`;
|
|
70
|
+
});
|
|
71
|
+
return [
|
|
72
|
+
'❌',
|
|
73
|
+
result.targetBranch,
|
|
74
|
+
`Could not backport due to conflicts, possibly caused by the following unbackported commits:<br>${conflictMessage.join('<br>')}`,
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
return ['❌', result.targetBranch, result.errorMessage];
|
|
78
|
+
})
|
|
79
|
+
.map((line) => line.join('|'))
|
|
80
|
+
.join('|\n|');
|
|
81
|
+
const table = backportResponse.results.length
|
|
82
|
+
? `| Status | Branch | Result |\n|:------:|:------:|:------:|\n|${tableBody}|`
|
|
83
|
+
: '';
|
|
84
|
+
const didAllBackportsSucceed = backportResponse.results.every((r) => r.status === 'success');
|
|
85
|
+
const didAnyBackportsSucceed = backportResponse.results.some((r) => r.status === 'success');
|
|
86
|
+
const header = didAllBackportsSucceed
|
|
87
|
+
? '## 💚 All backports created successfully'
|
|
88
|
+
: '## 💔 Some backports could not be created';
|
|
89
|
+
const autoMergeMessage = autoMerge && didAnyBackportsSucceed
|
|
90
|
+
? 'Note: Successful backport PRs will be merged automatically after passing CI.\n'
|
|
91
|
+
: '';
|
|
92
|
+
const backportPRCommandMessage = !didAllBackportsSucceed
|
|
93
|
+
? `${backportPRCommand}\n\n`
|
|
94
|
+
: '';
|
|
95
|
+
return (0, logger_1.redactAccessToken)(`${header}\n\n${table}\n\n${backportPRCommandMessage}${autoMergeMessage}`);
|
|
96
|
+
}
|
|
97
|
+
exports.getCommentBody = getCommentBody;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const HandledError_1 = require("../../HandledError");
|
|
4
|
+
const createStatusComment_1 = require("./createStatusComment");
|
|
5
|
+
describe('getCommentBody', () => {
|
|
6
|
+
it('when an unknown error occurs', () => {
|
|
7
|
+
expect((0, createStatusComment_1.getCommentBody)({
|
|
8
|
+
options: {},
|
|
9
|
+
pullNumber: 55,
|
|
10
|
+
backportResponse: {
|
|
11
|
+
status: 'failure',
|
|
12
|
+
errorMessage: 'A terrible error occured',
|
|
13
|
+
},
|
|
14
|
+
})).toMatchInlineSnapshot(`
|
|
15
|
+
"## 💔 Backport failed
|
|
16
|
+
The pull request could not be backported due to the following error:
|
|
17
|
+
\`A terrible error occured\`
|
|
18
|
+
|
|
19
|
+
To backport manually run: \`node scripts/backport --pr 55\`.
|
|
20
|
+
For more info read the [Backport documentation](https://github.com/sqren/backport#backport)
|
|
21
|
+
"
|
|
22
|
+
`);
|
|
23
|
+
});
|
|
24
|
+
it('when all backports succeed', () => {
|
|
25
|
+
expect((0, createStatusComment_1.getCommentBody)({
|
|
26
|
+
options: {
|
|
27
|
+
repoName: 'kibana',
|
|
28
|
+
repoOwner: 'elastic',
|
|
29
|
+
autoMerge: true,
|
|
30
|
+
},
|
|
31
|
+
pullNumber: 55,
|
|
32
|
+
backportResponse: {
|
|
33
|
+
status: 'success',
|
|
34
|
+
results: [
|
|
35
|
+
{
|
|
36
|
+
status: 'success',
|
|
37
|
+
targetBranch: '7.x',
|
|
38
|
+
pullRequestNumber: 55,
|
|
39
|
+
pullRequestUrl: 'url-to-pr',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
status: 'success',
|
|
43
|
+
targetBranch: '7.1',
|
|
44
|
+
pullRequestNumber: 66,
|
|
45
|
+
pullRequestUrl: 'url-to-pr',
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
})).toMatchInlineSnapshot(`
|
|
50
|
+
"## 💚 All backports created successfully
|
|
51
|
+
|
|
52
|
+
| Status | Branch | Result |
|
|
53
|
+
|:------:|:------:|:------:|
|
|
54
|
+
|✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
|
|
55
|
+
|✅|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
|
|
56
|
+
|
|
57
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
58
|
+
"
|
|
59
|
+
`);
|
|
60
|
+
});
|
|
61
|
+
it('when all backports fail', () => {
|
|
62
|
+
expect((0, createStatusComment_1.getCommentBody)({
|
|
63
|
+
options: {
|
|
64
|
+
repoName: 'kibana',
|
|
65
|
+
repoOwner: 'elastic',
|
|
66
|
+
autoMerge: true,
|
|
67
|
+
},
|
|
68
|
+
pullNumber: 55,
|
|
69
|
+
backportResponse: {
|
|
70
|
+
status: 'success',
|
|
71
|
+
results: [
|
|
72
|
+
{
|
|
73
|
+
status: 'failure',
|
|
74
|
+
targetBranch: '7.x',
|
|
75
|
+
error: new Error('Boom!'),
|
|
76
|
+
errorMessage: 'My boom error!',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
status: 'failure',
|
|
80
|
+
targetBranch: '7.1',
|
|
81
|
+
error: new Error('Boom!'),
|
|
82
|
+
errorMessage: 'My boom error!',
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
})).toMatchInlineSnapshot(`
|
|
87
|
+
"## 💔 Some backports could not be created
|
|
88
|
+
|
|
89
|
+
| Status | Branch | Result |
|
|
90
|
+
|:------:|:------:|:------:|
|
|
91
|
+
|❌|7.x|My boom error!|
|
|
92
|
+
|❌|7.1|My boom error!|
|
|
93
|
+
|
|
94
|
+
To backport manually run: \`node scripts/backport --pr 55\`.
|
|
95
|
+
For more info read the [Backport documentation](https://github.com/sqren/backport#backport)
|
|
96
|
+
|
|
97
|
+
"
|
|
98
|
+
`);
|
|
99
|
+
});
|
|
100
|
+
it('when some backports fail', () => {
|
|
101
|
+
expect((0, createStatusComment_1.getCommentBody)({
|
|
102
|
+
options: {
|
|
103
|
+
repoName: 'kibana',
|
|
104
|
+
repoOwner: 'elastic',
|
|
105
|
+
autoMerge: true,
|
|
106
|
+
},
|
|
107
|
+
pullNumber: 55,
|
|
108
|
+
backportResponse: {
|
|
109
|
+
status: 'success',
|
|
110
|
+
results: [
|
|
111
|
+
{
|
|
112
|
+
status: 'success',
|
|
113
|
+
targetBranch: '7.x',
|
|
114
|
+
pullRequestNumber: 55,
|
|
115
|
+
pullRequestUrl: 'url-to-pr-55',
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
status: 'failure',
|
|
119
|
+
targetBranch: '7.1',
|
|
120
|
+
error: new Error('Boom!'),
|
|
121
|
+
errorMessage: 'My boom error!',
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
},
|
|
125
|
+
})).toMatchInlineSnapshot(`
|
|
126
|
+
"## 💔 Some backports could not be created
|
|
127
|
+
|
|
128
|
+
| Status | Branch | Result |
|
|
129
|
+
|:------:|:------:|:------:|
|
|
130
|
+
|✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
|
|
131
|
+
|❌|7.1|My boom error!|
|
|
132
|
+
|
|
133
|
+
To backport manually run: \`node scripts/backport --pr 55\`.
|
|
134
|
+
For more info read the [Backport documentation](https://github.com/sqren/backport#backport)
|
|
135
|
+
|
|
136
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
137
|
+
"
|
|
138
|
+
`);
|
|
139
|
+
});
|
|
140
|
+
it('when some backports fail due to conflicts', () => {
|
|
141
|
+
expect((0, createStatusComment_1.getCommentBody)({
|
|
142
|
+
options: {
|
|
143
|
+
repoName: 'kibana',
|
|
144
|
+
repoOwner: 'elastic',
|
|
145
|
+
autoMerge: true,
|
|
146
|
+
},
|
|
147
|
+
pullNumber: 55,
|
|
148
|
+
backportResponse: {
|
|
149
|
+
status: 'success',
|
|
150
|
+
results: [
|
|
151
|
+
{
|
|
152
|
+
status: 'success',
|
|
153
|
+
targetBranch: '7.x',
|
|
154
|
+
pullRequestNumber: 55,
|
|
155
|
+
pullRequestUrl: 'url-to-pr-55',
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
status: 'failure',
|
|
159
|
+
targetBranch: '7.1',
|
|
160
|
+
errorMessage: 'My boom error!',
|
|
161
|
+
error: new HandledError_1.HandledError('Boom!', {
|
|
162
|
+
type: 'commitsWithoutBackports',
|
|
163
|
+
commitsWithoutBackports: [
|
|
164
|
+
{
|
|
165
|
+
//@ts-expect-error
|
|
166
|
+
commit: {
|
|
167
|
+
pullNumber: 5,
|
|
168
|
+
pullUrl: 'url-to-pr-5',
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
}),
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
status: 'failure',
|
|
176
|
+
targetBranch: '7.2',
|
|
177
|
+
errorMessage: 'My boom error!',
|
|
178
|
+
error: new HandledError_1.HandledError('Boom!', {
|
|
179
|
+
type: 'commitsWithoutBackports',
|
|
180
|
+
commitsWithoutBackports: [
|
|
181
|
+
{
|
|
182
|
+
//@ts-expect-error
|
|
183
|
+
commit: {
|
|
184
|
+
sha: 'acdefg',
|
|
185
|
+
originalMessage: 'Some long message\nin multiple lines',
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
}),
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
},
|
|
193
|
+
})).toMatchInlineSnapshot(`
|
|
194
|
+
"## 💔 Some backports could not be created
|
|
195
|
+
|
|
196
|
+
| Status | Branch | Result |
|
|
197
|
+
|:------:|:------:|:------:|
|
|
198
|
+
|✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
|
|
199
|
+
|❌|7.1|Could not backport due to conflicts, possibly caused by the following unbackported commits:<br> - [#5](url-to-pr-5)|
|
|
200
|
+
|❌|7.2|Could not backport due to conflicts, possibly caused by the following unbackported commits:<br> - Some long message (acdefg)|
|
|
201
|
+
|
|
202
|
+
To backport manually run: \`node scripts/backport --pr 55\`.
|
|
203
|
+
For more info read the [Backport documentation](https://github.com/sqren/backport#backport)
|
|
204
|
+
|
|
205
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
206
|
+
"
|
|
207
|
+
`);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ValidConfigOptions } from '../../../options/options';
|
|
2
|
+
export interface PullRequestResponse {
|
|
3
|
+
repository: {
|
|
4
|
+
pullRequest: {
|
|
5
|
+
id: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export declare function fetchPullRequestId(options: ValidConfigOptions, pullNumber: number): Promise<string>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchPullRequestId = void 0;
|
|
4
|
+
const apiRequestV4_1 = require("./apiRequestV4");
|
|
5
|
+
async function fetchPullRequestId(options, pullNumber) {
|
|
6
|
+
const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
|
|
7
|
+
const prQuery = /* GraphQL */ `
|
|
8
|
+
query PullRequestId(
|
|
9
|
+
$repoOwner: String!
|
|
10
|
+
$repoName: String!
|
|
11
|
+
$pullNumber: Int!
|
|
12
|
+
) {
|
|
13
|
+
repository(owner: $repoOwner, name: $repoName) {
|
|
14
|
+
pullRequest(number: $pullNumber) {
|
|
15
|
+
id
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
const prResponse = await (0, apiRequestV4_1.apiRequestV4)({
|
|
21
|
+
githubApiBaseUrlV4,
|
|
22
|
+
accessToken,
|
|
23
|
+
query: prQuery,
|
|
24
|
+
variables: {
|
|
25
|
+
repoOwner,
|
|
26
|
+
repoName,
|
|
27
|
+
pullNumber,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
return prResponse.repository.pullRequest.id;
|
|
31
|
+
}
|
|
32
|
+
exports.fetchPullRequestId = fetchPullRequestId;
|
|
@@ -21,4 +21,4 @@ export declare function apiRequestV4<DataResponse>({ githubApiBaseUrlV4, accessT
|
|
|
21
21
|
};
|
|
22
22
|
handleError?: boolean;
|
|
23
23
|
}): Promise<DataResponse>;
|
|
24
|
-
export declare function handleGithubV4Error(e: AxiosError<GithubV4Response<
|
|
24
|
+
export declare function handleGithubV4Error(e: AxiosError<GithubV4Response<unknown>>): HandledError | AxiosError<GithubV4Response<unknown>, any>;
|
|
@@ -8,7 +8,6 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
8
8
|
const HandledError_1 = require("../../HandledError");
|
|
9
9
|
const logger_1 = require("../../logger");
|
|
10
10
|
async function apiRequestV4({ githubApiBaseUrlV4, accessToken, query, variables, handleError = true, }) {
|
|
11
|
-
var _a, _b, _c;
|
|
12
11
|
try {
|
|
13
12
|
const response = await axios_1.default.post(githubApiBaseUrlV4, { query, variables }, {
|
|
14
13
|
headers: {
|
|
@@ -25,16 +24,16 @@ async function apiRequestV4({ githubApiBaseUrlV4, accessToken, query, variables,
|
|
|
25
24
|
logger_1.logger.info(`POST ${githubApiBaseUrlV4} (status: ${response.status})`);
|
|
26
25
|
logger_1.logger.verbose('Query:', query);
|
|
27
26
|
logger_1.logger.verbose('Variables:', variables);
|
|
28
|
-
logger_1.logger.
|
|
27
|
+
logger_1.logger.verbose('Response headers:', response.headers);
|
|
29
28
|
logger_1.logger.verbose('Response data:', response.data);
|
|
30
29
|
return response.data.data;
|
|
31
30
|
}
|
|
32
31
|
catch (e) {
|
|
33
|
-
logger_1.logger.info(`POST ${githubApiBaseUrlV4} (status: ${
|
|
32
|
+
logger_1.logger.info(`POST ${githubApiBaseUrlV4} (status: ${e.response?.status})`);
|
|
34
33
|
logger_1.logger.info('Query:', query);
|
|
35
34
|
logger_1.logger.info('Variables:', variables);
|
|
36
|
-
logger_1.logger.
|
|
37
|
-
logger_1.logger.info('Response data:',
|
|
35
|
+
logger_1.logger.verbose('Response headers:', e.response?.headers);
|
|
36
|
+
logger_1.logger.info('Response data:', e.response?.data);
|
|
38
37
|
if (handleError) {
|
|
39
38
|
throw handleGithubV4Error(e);
|
|
40
39
|
}
|
|
@@ -43,14 +42,13 @@ async function apiRequestV4({ githubApiBaseUrlV4, accessToken, query, variables,
|
|
|
43
42
|
}
|
|
44
43
|
exports.apiRequestV4 = apiRequestV4;
|
|
45
44
|
function handleGithubV4Error(e) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (!((_a = e.response) === null || _a === void 0 ? void 0 : _a.data)) {
|
|
45
|
+
// re-throw unknown error
|
|
46
|
+
if (!e.response?.data) {
|
|
49
47
|
return e;
|
|
50
48
|
}
|
|
51
|
-
const errorMessages =
|
|
49
|
+
const errorMessages = e.response.data.errors?.map((error) => error.message);
|
|
52
50
|
if (errorMessages) {
|
|
53
|
-
return new HandledError_1.HandledError(`${errorMessages.join(', ')} (Github v4)`);
|
|
51
|
+
return new HandledError_1.HandledError(`${errorMessages.join(', ')} (Unhandled Github v4 error)`);
|
|
54
52
|
}
|
|
55
53
|
return new HandledError_1.HandledError(`Unexpected response from Github API (v4):\n${JSON.stringify(e.response.data, null, 2)}`);
|
|
56
54
|
}
|
|
@@ -15,12 +15,12 @@ describe('apiRequestV4', () => {
|
|
|
15
15
|
let res;
|
|
16
16
|
let commitsByAuthorCalls;
|
|
17
17
|
beforeEach(async () => {
|
|
18
|
-
commitsByAuthorCalls = nockHelpers_1.mockGqlRequest({
|
|
18
|
+
commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
19
19
|
name: 'MyQuery',
|
|
20
20
|
statusCode: 200,
|
|
21
21
|
body: { data: { hello: 'world' } },
|
|
22
22
|
});
|
|
23
|
-
res = await apiRequestV4_1.apiRequestV4({
|
|
23
|
+
res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
24
24
|
accessToken: 'myAccessToken',
|
|
25
25
|
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
26
26
|
query: 'query MyQuery{ foo }',
|
|
@@ -41,7 +41,7 @@ describe('apiRequestV4', () => {
|
|
|
41
41
|
});
|
|
42
42
|
describe('when request fails with error messages', () => {
|
|
43
43
|
beforeEach(() => {
|
|
44
|
-
nockHelpers_1.mockGqlRequest({
|
|
44
|
+
(0, nockHelpers_1.mockGqlRequest)({
|
|
45
45
|
name: 'MyQuery',
|
|
46
46
|
statusCode: 500,
|
|
47
47
|
body: {
|
|
@@ -50,26 +50,26 @@ describe('apiRequestV4', () => {
|
|
|
50
50
|
});
|
|
51
51
|
});
|
|
52
52
|
it('should return parsed github error', async () => {
|
|
53
|
-
return expect(apiRequestV4_1.apiRequestV4({
|
|
53
|
+
return expect((0, apiRequestV4_1.apiRequestV4)({
|
|
54
54
|
accessToken: 'myAccessToken',
|
|
55
55
|
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
56
56
|
query: 'query MyQuery{ foo }',
|
|
57
57
|
variables: {
|
|
58
58
|
foo: 'bar',
|
|
59
59
|
},
|
|
60
|
-
})).rejects.toThrowError(new HandledError_1.HandledError(`some error, some other error (Github v4)`));
|
|
60
|
+
})).rejects.toThrowError(new HandledError_1.HandledError(`some error, some other error (Unhandled Github v4 error)`));
|
|
61
61
|
});
|
|
62
62
|
});
|
|
63
63
|
describe('when request fails without error messages', () => {
|
|
64
64
|
beforeEach(() => {
|
|
65
|
-
nockHelpers_1.mockGqlRequest({
|
|
65
|
+
(0, nockHelpers_1.mockGqlRequest)({
|
|
66
66
|
name: 'MyQuery',
|
|
67
67
|
statusCode: 500,
|
|
68
68
|
body: { data: { foo: 'bar' } },
|
|
69
69
|
});
|
|
70
70
|
});
|
|
71
71
|
it('should return parsed github error', async () => {
|
|
72
|
-
return expect(apiRequestV4_1.apiRequestV4({
|
|
72
|
+
return expect((0, apiRequestV4_1.apiRequestV4)({
|
|
73
73
|
accessToken: 'myAccessToken',
|
|
74
74
|
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
75
75
|
query: 'query MyQuery{ foo }',
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ValidConfigOptions } from '../../../options/options';
|
|
2
|
+
export interface PullRequestAutoMergeResponse {
|
|
3
|
+
disablePullRequestAutoMerge: {
|
|
4
|
+
pullRequest?: {
|
|
5
|
+
number: number;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export declare function disablePullRequestAutoMerge(options: ValidConfigOptions, pullNumber: number): Promise<number | undefined>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.disablePullRequestAutoMerge = void 0;
|
|
4
|
+
const FetchPullRequestId_1 = require("./FetchPullRequestId");
|
|
5
|
+
const apiRequestV4_1 = require("./apiRequestV4");
|
|
6
|
+
async function disablePullRequestAutoMerge(options, pullNumber) {
|
|
7
|
+
const { accessToken, githubApiBaseUrlV4 } = options;
|
|
8
|
+
const pullRequestId = await (0, FetchPullRequestId_1.fetchPullRequestId)(options, pullNumber);
|
|
9
|
+
const query = /* GraphQL */ `
|
|
10
|
+
mutation DisablePullRequestAutoMerge($pullRequestId: ID!) {
|
|
11
|
+
disablePullRequestAutoMerge(input: { pullRequestId: $pullRequestId }) {
|
|
12
|
+
pullRequest {
|
|
13
|
+
number
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
19
|
+
githubApiBaseUrlV4,
|
|
20
|
+
accessToken,
|
|
21
|
+
query,
|
|
22
|
+
variables: {
|
|
23
|
+
pullRequestId,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
return res.disablePullRequestAutoMerge.pullRequest?.number;
|
|
27
|
+
}
|
|
28
|
+
exports.disablePullRequestAutoMerge = disablePullRequestAutoMerge;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ValidConfigOptions } from '../../../options/options';
|
|
2
|
+
export interface PullRequestAutoMergeResponse {
|
|
3
|
+
enablePullRequestAutoMerge: {
|
|
4
|
+
pullRequest?: {
|
|
5
|
+
number: number;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export declare function enablePullRequestAutoMerge(options: ValidConfigOptions, targetPullRequestNumber: number): Promise<number | undefined>;
|