backport 8.0.0 → 8.1.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 +4 -4
- package/dist/backportRun.d.ts +5 -4
- package/dist/backportRun.js +41 -42
- package/dist/entrypoint.cli.js +3 -7
- package/dist/entrypoint.module.d.ts +7 -5
- package/dist/entrypoint.module.js +11 -9
- package/dist/entrypoint.module.private.test.js +4 -4
- package/dist/errors/BackportError.d.ts +19 -0
- package/dist/errors/BackportError.js +29 -0
- package/dist/lib/BackportError.d.ts +19 -0
- package/dist/lib/BackportError.js +29 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.d.ts +13 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +238 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +321 -0
- package/dist/lib/child-process-promisified.d.ts +25 -0
- package/dist/lib/child-process-promisified.js +58 -0
- package/dist/lib/env.d.ts +7 -0
- package/dist/lib/env.js +33 -0
- package/dist/lib/env.test.d.ts +1 -0
- package/dist/lib/env.test.js +26 -0
- package/dist/lib/getCommits.d.ts +2 -0
- package/dist/lib/getCommits.js +75 -0
- package/dist/lib/getCommitsWithoutBackports.d.ts +11 -0
- package/dist/lib/getCommitsWithoutBackports.js +68 -0
- package/dist/lib/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/lib/getCommitsWithoutBackports.test.js +335 -0
- package/dist/lib/getGitConfigAuthor.d.ts +6 -0
- package/dist/lib/getGitConfigAuthor.js +15 -0
- package/dist/lib/getTargetBranches.d.ts +5 -0
- package/dist/lib/getTargetBranches.js +67 -0
- package/dist/lib/getTargetBranches.test.d.ts +1 -0
- package/dist/lib/getTargetBranches.test.js +206 -0
- package/dist/lib/git.d.ts +77 -0
- package/dist/lib/git.js +439 -0
- package/dist/lib/git.private.test.d.ts +1 -0
- package/dist/lib/git.private.test.js +618 -0
- package/dist/lib/git.test.d.ts +1 -0
- package/dist/lib/git.test.js +580 -0
- package/dist/lib/github/commitFormatters.d.ts +3 -0
- package/dist/lib/github/commitFormatters.js +17 -0
- package/dist/lib/github/commitFormatters.test.d.ts +1 -0
- package/dist/lib/github/commitFormatters.test.js +11 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.d.ts +2 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.js +32 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.test.js +27 -0
- package/dist/lib/github/v3/addLabelsToPullRequest.d.ts +2 -0
- package/dist/lib/github/v3/addLabelsToPullRequest.js +30 -0
- package/dist/lib/github/v3/addReviewersToPullRequest.d.ts +2 -0
- package/dist/lib/github/v3/addReviewersToPullRequest.js +32 -0
- package/dist/lib/github/v3/createPullRequest.d.ts +29 -0
- package/dist/lib/github/v3/createPullRequest.js +91 -0
- package/dist/lib/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/lib/github/v3/createPullRequest.test.js +377 -0
- package/dist/lib/github/v3/createStatusComment.d.ts +11 -0
- package/dist/lib/github/v3/createStatusComment.js +136 -0
- package/dist/lib/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/lib/github/v3/createStatusComment.test.js +461 -0
- package/dist/lib/github/v3/getGithubV3ErrorMessage.d.ts +14 -0
- package/dist/lib/github/v3/getGithubV3ErrorMessage.js +16 -0
- package/dist/lib/github/v4/FetchPullRequestId.d.ts +2 -0
- package/dist/lib/github/v4/FetchPullRequestId.js +36 -0
- package/dist/lib/github/v4/apiRequestV4.d.ts +31 -0
- package/dist/lib/github/v4/apiRequestV4.js +71 -0
- package/dist/lib/github/v4/apiRequestV4.test.d.ts +1 -0
- package/dist/lib/github/v4/apiRequestV4.test.js +109 -0
- package/dist/lib/github/v4/disablePullRequestAutoMerge.d.ts +2 -0
- package/dist/lib/github/v4/disablePullRequestAutoMerge.js +32 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.d.ts +2 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.js +50 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
- package/dist/lib/github/v4/fetchAuthorId.d.ts +10 -0
- package/dist/lib/github/v4/fetchAuthorId.js +28 -0
- package/dist/lib/github/v4/fetchAuthorId.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchAuthorId.private.test.js +25 -0
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +93 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +11 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +58 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +136 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.d.ts +11 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +48 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +118 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +29 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +110 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +196 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +157 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +107 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +12 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +69 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.d.ts +9 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.js +64 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.private.test.js +44 -0
- package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.d.ts +2 -0
- package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.js +39 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.js +49 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.js +49 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +72 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +78 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +116 -0
- package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +16 -0
- package/dist/lib/github/v4/getOptionsFromGithub/query.js +29 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +29 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.js +61 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +72 -0
- package/dist/lib/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
- package/dist/lib/github/v4/mocks/commitsByAuthorMock.js +176 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.d.ts +7 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.js +45 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.test.js +87 -0
- package/dist/lib/logger.d.ts +9 -0
- package/dist/lib/logger.js +74 -0
- package/dist/lib/ora.d.ts +2 -0
- package/dist/lib/ora.js +21 -0
- package/dist/lib/prompt.test.d.ts +1 -0
- package/dist/lib/prompt.test.js +139 -0
- package/dist/lib/prompts.d.ts +17 -0
- package/dist/lib/prompts.js +132 -0
- package/dist/lib/remoteConfig.d.ts +20 -0
- package/dist/lib/remoteConfig.js +52 -0
- package/dist/lib/sequentially.d.ts +1 -0
- package/dist/lib/sequentially.js +10 -0
- package/dist/lib/setupRepo.d.ts +2 -0
- package/dist/lib/setupRepo.js +56 -0
- package/dist/lib/setupRepo.test.d.ts +1 -0
- package/dist/lib/setupRepo.test.js +278 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +16 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.js +102 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
- package/dist/lib/sourceCommit/getMockSourceCommit.d.ts +26 -0
- package/dist/lib/sourceCommit/getMockSourceCommit.js +103 -0
- package/dist/lib/sourceCommit/parseSourceCommit.d.ts +108 -0
- package/dist/lib/sourceCommit/parseSourceCommit.js +123 -0
- package/dist/lib/sourceCommit/parseSourceCommit.test.d.ts +1 -0
- package/dist/lib/sourceCommit/parseSourceCommit.test.js +226 -0
- package/dist/options/ConfigOptions.d.ts +4 -2
- package/dist/options/cliArgs.d.ts +15 -12
- package/dist/options/cliArgs.js +34 -19
- package/dist/options/cliArgs.test.js +125 -1
- package/dist/options/config/config.d.ts +5 -4
- package/dist/options/config/config.js +3 -5
- package/dist/options/config/config.test.js +0 -1
- package/dist/options/config/globalConfig.d.ts +3 -1
- package/dist/options/config/globalConfig.js +5 -5
- package/dist/options/config/readConfigFile.d.ts +9 -7
- package/dist/options/config/readConfigFile.js +2 -2
- package/dist/options/options.d.ts +43 -7
- package/dist/options/options.js +20 -24
- package/dist/options/options.test.js +112 -54
- package/dist/runSequentially.d.ts +10 -7
- package/dist/runSequentially.js +5 -5
- package/dist/scripts/postinstall.js +3 -3
- package/dist/scripts/postinstall.test.js +1 -1
- package/dist/services/BackportError.d.ts +19 -0
- package/dist/services/BackportError.js +29 -0
- package/dist/services/HandledBackportError.d.ts +19 -0
- package/dist/services/HandledBackportError.js +29 -0
- package/dist/services/HandledError.d.ts +1 -1
- package/dist/services/HandledError.js +5 -5
- package/dist/services/git.js +7 -7
- package/dist/services/github/v3/createPullRequest.js +2 -2
- package/dist/services/github/v3/createStatusComment.js +2 -2
- package/dist/services/github/v3/createStatusComment.test.js +5 -4
- package/dist/services/github/v4/apiRequestV4.js +2 -2
- package/dist/services/github/v4/apiRequestV4.test.js +2 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +3 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +2 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +3 -3
- package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +2 -2
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
- package/dist/state.d.ts +0 -0
- package/dist/state.js +1 -0
- package/dist/test/e2e/cli/commit-author.private.test.js +4 -4
- package/dist/test/e2e/cli/different-merge-strategies.private.test.js +26 -24
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +189 -140
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +12 -14
- package/dist/test/e2e/cli/runBackportViaCli.d.ts +5 -2
- package/dist/test/e2e/cli/runBackportViaCli.js +42 -29
- package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +22 -14
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +2 -2
- package/dist/test/handleUnbackportedPullRequests.private.test.js +3 -2
- package/dist/test/setupFiles/automatic-mocks.js +1 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +3 -3
- package/dist/ui/getCommits.js +2 -2
- package/dist/ui/getTargetBranches.js +3 -3
- package/dist/ui/setupRepo.js +2 -2
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +12 -12
- package/yarn.lock +112 -65
|
@@ -0,0 +1,136 @@
|
|
|
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 packageVersion_1 = require("../../../utils/packageVersion");
|
|
6
|
+
const redact_1 = require("../../../utils/redact");
|
|
7
|
+
const BackportError_1 = require("../../BackportError");
|
|
8
|
+
const logger_1 = require("../../logger");
|
|
9
|
+
const commitFormatters_1 = require("../commitFormatters");
|
|
10
|
+
async function createStatusComment({ options, backportResponse, }) {
|
|
11
|
+
const { githubApiBaseUrlV3, repoName, repoOwner, accessToken } = options;
|
|
12
|
+
try {
|
|
13
|
+
const octokit = new rest_1.Octokit({
|
|
14
|
+
auth: accessToken,
|
|
15
|
+
baseUrl: githubApiBaseUrlV3,
|
|
16
|
+
log: logger_1.logger,
|
|
17
|
+
});
|
|
18
|
+
await Promise.all(backportResponse.commits.map((commit) => {
|
|
19
|
+
if (!commit.sourcePullRequest) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const body = getCommentBody({
|
|
23
|
+
options,
|
|
24
|
+
pullNumber: commit.sourcePullRequest.number,
|
|
25
|
+
backportResponse,
|
|
26
|
+
});
|
|
27
|
+
// only post comment if there is a body
|
|
28
|
+
if (!body) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
return octokit.issues.createComment({
|
|
32
|
+
baseUrl: githubApiBaseUrlV3,
|
|
33
|
+
owner: repoOwner,
|
|
34
|
+
repo: repoName,
|
|
35
|
+
issue_number: commit.sourcePullRequest.number,
|
|
36
|
+
body: (0, redact_1.redact)(options.accessToken, body),
|
|
37
|
+
});
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
logger_1.logger.info(`Could not create status comment `, e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.createStatusComment = createStatusComment;
|
|
45
|
+
function getCommentBody({ options, pullNumber, backportResponse, }) {
|
|
46
|
+
const { repoName, repoOwner, autoMerge, publishStatusCommentOnAbort, publishStatusCommentOnFailure, publishStatusCommentOnSuccess, } = options;
|
|
47
|
+
// eg. in addition to `--noStatusComment` add `--noFailureStatusComment` and `--noSuccessStatusComment` where the former will overwrite the two latter
|
|
48
|
+
const didAllBackportsSucceed = backportResponse.status === 'success' &&
|
|
49
|
+
backportResponse.results.every((r) => r.status === 'success');
|
|
50
|
+
const didAllBackportsFail = backportResponse.status === 'failure' ||
|
|
51
|
+
(backportResponse.status === 'success' &&
|
|
52
|
+
backportResponse.results.every((r) => r.status !== 'success'));
|
|
53
|
+
if (
|
|
54
|
+
// don't publish on dry-run
|
|
55
|
+
options.dryRun ||
|
|
56
|
+
//
|
|
57
|
+
// don't publish comment under any circumstances
|
|
58
|
+
(!publishStatusCommentOnFailure &&
|
|
59
|
+
!publishStatusCommentOnSuccess &&
|
|
60
|
+
!publishStatusCommentOnAbort) ||
|
|
61
|
+
//
|
|
62
|
+
// dont publish comment if all backports suceeded
|
|
63
|
+
(didAllBackportsSucceed && !publishStatusCommentOnSuccess) ||
|
|
64
|
+
//
|
|
65
|
+
// dont publish comment if operation failed or all backports failed
|
|
66
|
+
(didAllBackportsFail && !publishStatusCommentOnFailure) ||
|
|
67
|
+
//
|
|
68
|
+
// dont publish comment if backport was aborted
|
|
69
|
+
(backportResponse.status === 'aborted' && !publishStatusCommentOnAbort)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const packageVersionSection = `\n<!--- Backport version: ${packageVersion_1.PACKAGE_VERSION} -->`;
|
|
73
|
+
const manualBackportCommand = `\n### Manual backport\nTo create the backport manually run:\n\`\`\`\n${options.backportBinary} --pr ${pullNumber}\n\`\`\`\n`;
|
|
74
|
+
const questionsAndLinkToBackport = '\n### Questions ?\nPlease refer to the [Backport tool documentation](https://github.com/sqren/backport)\n';
|
|
75
|
+
if (backportResponse.status === 'aborted' &&
|
|
76
|
+
backportResponse.error.errorContext.code === 'no-branches-exception') {
|
|
77
|
+
return `## ⚪ Backport skipped
|
|
78
|
+
The pull request was not backported as there were no branches to backport to. If this is a mistake, please apply the desired version labels or run the backport tool manually.
|
|
79
|
+
${manualBackportCommand}${questionsAndLinkToBackport}${packageVersionSection}`;
|
|
80
|
+
}
|
|
81
|
+
if (backportResponse.status !== 'success') {
|
|
82
|
+
return `## 💔 Backport failed
|
|
83
|
+
The pull request could not be backported due to the following error:
|
|
84
|
+
\`${backportResponse.error.message}\`
|
|
85
|
+
${manualBackportCommand}${questionsAndLinkToBackport}${packageVersionSection}`;
|
|
86
|
+
}
|
|
87
|
+
const tableBody = backportResponse.results
|
|
88
|
+
.map((result) => {
|
|
89
|
+
if (result.status === 'success') {
|
|
90
|
+
return [
|
|
91
|
+
'✅',
|
|
92
|
+
result.targetBranch,
|
|
93
|
+
`[<img src="https://img.shields.io/github/pulls/detail/state/${repoOwner}/${repoName}/${result.pullRequestNumber}">](${result.pullRequestUrl})`,
|
|
94
|
+
];
|
|
95
|
+
}
|
|
96
|
+
if (result.error instanceof BackportError_1.BackportError &&
|
|
97
|
+
result.error.errorContext.code === 'merge-conflict-exception') {
|
|
98
|
+
const unmergedBackports = result.error.errorContext.commitsWithoutBackports.map((c) => {
|
|
99
|
+
return ` - [${(0, commitFormatters_1.getFirstLine)(c.commit.sourceCommit.message)}](${c.commit.sourcePullRequest?.url})`;
|
|
100
|
+
});
|
|
101
|
+
const unmergedBackportsSection = unmergedBackports.length > 0
|
|
102
|
+
? `<br><br>You might need to backport the following PRs to ${result.targetBranch}:<br>${unmergedBackports.join('<br>')}`
|
|
103
|
+
: '';
|
|
104
|
+
return [
|
|
105
|
+
'❌',
|
|
106
|
+
result.targetBranch,
|
|
107
|
+
`**Backport failed because of merge conflicts**${unmergedBackportsSection}`,
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
return ['❌', result.targetBranch, result.error.message];
|
|
111
|
+
})
|
|
112
|
+
.map((line) => line.join('|'))
|
|
113
|
+
.join('|\n|');
|
|
114
|
+
const table = backportResponse.results.length
|
|
115
|
+
? `\n\n| Status | Branch | Result |\n|:------:|:------:|:------|\n|${tableBody}|\n`
|
|
116
|
+
: '';
|
|
117
|
+
const didAnyBackportsSucceed = backportResponse.results.some((r) => r.status === 'success');
|
|
118
|
+
let header = '';
|
|
119
|
+
if (didAllBackportsSucceed) {
|
|
120
|
+
header = '## 💚 All backports created successfully';
|
|
121
|
+
}
|
|
122
|
+
else if (didAnyBackportsSucceed) {
|
|
123
|
+
header = '## 💔 Some backports could not be created';
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
header = '## 💔 All backports failed';
|
|
127
|
+
}
|
|
128
|
+
const autoMergeMessage = autoMerge && didAnyBackportsSucceed
|
|
129
|
+
? '\nNote: Successful backport PRs will be merged automatically after passing CI.\n'
|
|
130
|
+
: '';
|
|
131
|
+
const backportPRCommandMessage = !didAllBackportsSucceed
|
|
132
|
+
? `${manualBackportCommand}`
|
|
133
|
+
: '';
|
|
134
|
+
return `${header}${table}${autoMergeMessage}${backportPRCommandMessage}${questionsAndLinkToBackport}${packageVersionSection}`;
|
|
135
|
+
}
|
|
136
|
+
exports.getCommentBody = getCommentBody;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,461 @@
|
|
|
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 nock_1 = __importDefault(require("nock"));
|
|
7
|
+
const BackportError_1 = require("../../BackportError");
|
|
8
|
+
const createStatusComment_1 = require("./createStatusComment");
|
|
9
|
+
describe('createStatusComment', () => {
|
|
10
|
+
it('redacts accessToken if it is included in the error message', async () => {
|
|
11
|
+
const accessToken = 'ghp_abcdefg';
|
|
12
|
+
const scope = (0, nock_1.default)('https://api.github.com')
|
|
13
|
+
.post('/repos/elastic/kibana/issues/100/comments')
|
|
14
|
+
.reply(200, 'some response');
|
|
15
|
+
let postedCommentBody = '';
|
|
16
|
+
scope.on('request', (req, interceptor, body) => {
|
|
17
|
+
postedCommentBody = JSON.parse(body).body;
|
|
18
|
+
});
|
|
19
|
+
await (0, createStatusComment_1.createStatusComment)({
|
|
20
|
+
options: {
|
|
21
|
+
repoName: 'kibana',
|
|
22
|
+
repoOwner: 'elastic',
|
|
23
|
+
accessToken,
|
|
24
|
+
backportBinary: 'node scripts/backport',
|
|
25
|
+
publishStatusCommentOnSuccess: true,
|
|
26
|
+
publishStatusCommentOnFailure: true,
|
|
27
|
+
githubApiBaseUrlV3: 'https://api.github.com',
|
|
28
|
+
interactive: false,
|
|
29
|
+
},
|
|
30
|
+
backportResponse: {
|
|
31
|
+
commits: [{ sourcePullRequest: { number: 100 } }],
|
|
32
|
+
status: 'failure',
|
|
33
|
+
error: new Error(`Error message containing very secret access token: ${accessToken}.`),
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
expect(postedCommentBody).toContain('Error message containing very secret access token: <REDACTED>');
|
|
37
|
+
scope.done();
|
|
38
|
+
nock_1.default.cleanAll();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe('getCommentBody', () => {
|
|
42
|
+
describe('when an unknown error occurs', () => {
|
|
43
|
+
const getParams = (opts) => ({
|
|
44
|
+
options: {
|
|
45
|
+
backportBinary: 'node scripts/backport',
|
|
46
|
+
...opts,
|
|
47
|
+
},
|
|
48
|
+
pullNumber: 55,
|
|
49
|
+
backportResponse: {
|
|
50
|
+
status: 'failure',
|
|
51
|
+
error: new Error('A terrible error occured'),
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
it('posts a comment when `publishStatusCommentOnFailure = true`', () => {
|
|
55
|
+
const params = getParams({ publishStatusCommentOnFailure: true });
|
|
56
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
57
|
+
"## 💔 Backport failed
|
|
58
|
+
The pull request could not be backported due to the following error:
|
|
59
|
+
\`A terrible error occured\`
|
|
60
|
+
|
|
61
|
+
### Manual backport
|
|
62
|
+
To create the backport manually run:
|
|
63
|
+
\`\`\`
|
|
64
|
+
node scripts/backport --pr 55
|
|
65
|
+
\`\`\`
|
|
66
|
+
|
|
67
|
+
### Questions ?
|
|
68
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
69
|
+
|
|
70
|
+
<!--- Backport version: 1.2.3-mocked -->"
|
|
71
|
+
`);
|
|
72
|
+
});
|
|
73
|
+
it('does not post a comment when `publishStatusCommentOnFailure = false`', () => {
|
|
74
|
+
const params = getParams({ publishStatusCommentOnFailure: false });
|
|
75
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
describe('when all backports succeed', () => {
|
|
79
|
+
const getParams = (opts) => ({
|
|
80
|
+
options: {
|
|
81
|
+
repoName: 'kibana',
|
|
82
|
+
repoOwner: 'elastic',
|
|
83
|
+
autoMerge: true,
|
|
84
|
+
...opts,
|
|
85
|
+
},
|
|
86
|
+
pullNumber: 55,
|
|
87
|
+
backportResponse: {
|
|
88
|
+
status: 'success',
|
|
89
|
+
results: [
|
|
90
|
+
{
|
|
91
|
+
status: 'success',
|
|
92
|
+
targetBranch: '7.x',
|
|
93
|
+
pullRequestNumber: 55,
|
|
94
|
+
pullRequestUrl: 'url-to-pr',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
status: 'success',
|
|
98
|
+
targetBranch: '7.1',
|
|
99
|
+
pullRequestNumber: 66,
|
|
100
|
+
pullRequestUrl: 'url-to-pr',
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
it('posts a comment when `publishStatusCommentOnSuccess = true`', () => {
|
|
106
|
+
const params = getParams({ publishStatusCommentOnSuccess: true });
|
|
107
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
108
|
+
"## 💚 All backports created successfully
|
|
109
|
+
|
|
110
|
+
| Status | Branch | Result |
|
|
111
|
+
|:------:|:------:|:------|
|
|
112
|
+
|✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
|
|
113
|
+
|✅|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
|
|
114
|
+
|
|
115
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
116
|
+
|
|
117
|
+
### Questions ?
|
|
118
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
119
|
+
|
|
120
|
+
<!--- Backport version: 1.2.3-mocked -->"
|
|
121
|
+
`);
|
|
122
|
+
});
|
|
123
|
+
it('does not post a comment when `publishStatusCommentOnSuccess = false`', () => {
|
|
124
|
+
const params = getParams({ interactive: true });
|
|
125
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`undefined`);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
describe('when all backports fail', () => {
|
|
129
|
+
const getParams = (opts) => ({
|
|
130
|
+
options: {
|
|
131
|
+
repoName: 'kibana',
|
|
132
|
+
repoOwner: 'elastic',
|
|
133
|
+
autoMerge: true,
|
|
134
|
+
backportBinary: 'node scripts/backport',
|
|
135
|
+
...opts,
|
|
136
|
+
},
|
|
137
|
+
pullNumber: 55,
|
|
138
|
+
backportResponse: {
|
|
139
|
+
status: 'success',
|
|
140
|
+
results: [
|
|
141
|
+
{
|
|
142
|
+
status: 'unhandled-error',
|
|
143
|
+
targetBranch: '7.x',
|
|
144
|
+
error: new Error('My boom error!'),
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
status: 'unhandled-error',
|
|
148
|
+
targetBranch: '7.1',
|
|
149
|
+
error: new Error('My boom error!'),
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
it('posts a comment when `publishStatusCommentOnFailure = true`', () => {
|
|
155
|
+
const params = getParams({ publishStatusCommentOnFailure: true });
|
|
156
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
157
|
+
"## 💔 All backports failed
|
|
158
|
+
|
|
159
|
+
| Status | Branch | Result |
|
|
160
|
+
|:------:|:------:|:------|
|
|
161
|
+
|❌|7.x|My boom error!|
|
|
162
|
+
|❌|7.1|My boom error!|
|
|
163
|
+
|
|
164
|
+
### Manual backport
|
|
165
|
+
To create the backport manually run:
|
|
166
|
+
\`\`\`
|
|
167
|
+
node scripts/backport --pr 55
|
|
168
|
+
\`\`\`
|
|
169
|
+
|
|
170
|
+
### Questions ?
|
|
171
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
172
|
+
|
|
173
|
+
<!--- Backport version: 1.2.3-mocked -->"
|
|
174
|
+
`);
|
|
175
|
+
});
|
|
176
|
+
it('does not post a comment when `publishStatusCommentOnFailure = false`', () => {
|
|
177
|
+
const params = getParams({ publishStatusCommentOnFailure: false });
|
|
178
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
describe('when some backports fail', () => {
|
|
182
|
+
const getParams = (opts) => ({
|
|
183
|
+
options: {
|
|
184
|
+
repoName: 'kibana',
|
|
185
|
+
repoOwner: 'elastic',
|
|
186
|
+
autoMerge: true,
|
|
187
|
+
backportBinary: 'node scripts/backport',
|
|
188
|
+
...opts,
|
|
189
|
+
},
|
|
190
|
+
pullNumber: 55,
|
|
191
|
+
backportResponse: {
|
|
192
|
+
status: 'success',
|
|
193
|
+
results: [
|
|
194
|
+
{
|
|
195
|
+
status: 'success',
|
|
196
|
+
targetBranch: '7.x',
|
|
197
|
+
pullRequestNumber: 55,
|
|
198
|
+
pullRequestUrl: 'url-to-pr-55',
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
status: 'failure',
|
|
202
|
+
targetBranch: '7.1',
|
|
203
|
+
error: new Error('My boom error!'),
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
it('posts a comment when `publishStatusCommentOnFailure = true`', () => {
|
|
209
|
+
const params = getParams({ publishStatusCommentOnFailure: true });
|
|
210
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
211
|
+
"## 💔 Some backports could not be created
|
|
212
|
+
|
|
213
|
+
| Status | Branch | Result |
|
|
214
|
+
|:------:|:------:|:------|
|
|
215
|
+
|✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
|
|
216
|
+
|❌|7.1|My boom error!|
|
|
217
|
+
|
|
218
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
219
|
+
|
|
220
|
+
### Manual backport
|
|
221
|
+
To create the backport manually run:
|
|
222
|
+
\`\`\`
|
|
223
|
+
node scripts/backport --pr 55
|
|
224
|
+
\`\`\`
|
|
225
|
+
|
|
226
|
+
### Questions ?
|
|
227
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
228
|
+
|
|
229
|
+
<!--- Backport version: 1.2.3-mocked -->"
|
|
230
|
+
`);
|
|
231
|
+
});
|
|
232
|
+
it('does not post a comment when running `publishStatusCommentOnFailure = false`', () => {
|
|
233
|
+
const params = getParams({ publishStatusCommentOnFailure: false });
|
|
234
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`undefined`);
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
describe('when some backports fail due to conflicts', () => {
|
|
238
|
+
const getParams = (opts) => ({
|
|
239
|
+
options: {
|
|
240
|
+
repoName: 'kibana',
|
|
241
|
+
repoOwner: 'elastic',
|
|
242
|
+
autoMerge: true,
|
|
243
|
+
backportBinary: 'node scripts/backport',
|
|
244
|
+
...opts,
|
|
245
|
+
},
|
|
246
|
+
pullNumber: 55,
|
|
247
|
+
backportResponse: {
|
|
248
|
+
status: 'success',
|
|
249
|
+
results: [
|
|
250
|
+
{
|
|
251
|
+
status: 'success',
|
|
252
|
+
targetBranch: '7.x',
|
|
253
|
+
pullRequestNumber: 55,
|
|
254
|
+
pullRequestUrl: 'url-to-pr-55',
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
status: 'failure',
|
|
258
|
+
targetBranch: '7.1',
|
|
259
|
+
error: new BackportError_1.BackportError({
|
|
260
|
+
code: 'merge-conflict-exception',
|
|
261
|
+
conflictingFiles: ['readme.md'],
|
|
262
|
+
commitsWithoutBackports: [
|
|
263
|
+
{
|
|
264
|
+
formatted: 'some-formatted-text',
|
|
265
|
+
commit: {
|
|
266
|
+
author: {
|
|
267
|
+
email: 'soren.louv@elastic.co',
|
|
268
|
+
name: 'Søren Louv-Jansen',
|
|
269
|
+
},
|
|
270
|
+
sourceBranch: 'master',
|
|
271
|
+
sourcePullRequest: {
|
|
272
|
+
number: 5,
|
|
273
|
+
url: 'url-to-pr-5',
|
|
274
|
+
mergeCommit: {
|
|
275
|
+
sha: '',
|
|
276
|
+
message: 'New Zealand commit message',
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
sourceCommit: {
|
|
280
|
+
committedDate: '',
|
|
281
|
+
sha: '',
|
|
282
|
+
message: 'New Zealand commit message',
|
|
283
|
+
},
|
|
284
|
+
expectedTargetPullRequests: [],
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
formatted: 'some-formatted-text',
|
|
289
|
+
commit: {
|
|
290
|
+
author: {
|
|
291
|
+
email: 'soren.louv@elastic.co',
|
|
292
|
+
name: 'Søren Louv-Jansen',
|
|
293
|
+
},
|
|
294
|
+
sourceBranch: 'master',
|
|
295
|
+
sourcePullRequest: {
|
|
296
|
+
number: 44,
|
|
297
|
+
url: 'url-to-pr-44',
|
|
298
|
+
mergeCommit: {
|
|
299
|
+
sha: '',
|
|
300
|
+
message: 'Australia commit',
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
sourceCommit: {
|
|
304
|
+
committedDate: '',
|
|
305
|
+
sha: '',
|
|
306
|
+
message: 'Australia commit',
|
|
307
|
+
},
|
|
308
|
+
expectedTargetPullRequests: [],
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
],
|
|
312
|
+
}),
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
status: 'failure',
|
|
316
|
+
targetBranch: '7.2',
|
|
317
|
+
error: new BackportError_1.BackportError({
|
|
318
|
+
code: 'merge-conflict-exception',
|
|
319
|
+
conflictingFiles: ['my-file.txt'],
|
|
320
|
+
commitsWithoutBackports: [],
|
|
321
|
+
}),
|
|
322
|
+
},
|
|
323
|
+
],
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
it('posts a comment when `publishStatusCommentOnFailure = true`', () => {
|
|
327
|
+
const params = getParams({ publishStatusCommentOnFailure: true });
|
|
328
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
329
|
+
"## 💔 Some backports could not be created
|
|
330
|
+
|
|
331
|
+
| Status | Branch | Result |
|
|
332
|
+
|:------:|:------:|:------|
|
|
333
|
+
|✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
|
|
334
|
+
|❌|7.1|**Backport failed because of merge conflicts**<br><br>You might need to backport the following PRs to 7.1:<br> - [New Zealand commit message](url-to-pr-5)<br> - [Australia commit](url-to-pr-44)|
|
|
335
|
+
|❌|7.2|**Backport failed because of merge conflicts**|
|
|
336
|
+
|
|
337
|
+
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
338
|
+
|
|
339
|
+
### Manual backport
|
|
340
|
+
To create the backport manually run:
|
|
341
|
+
\`\`\`
|
|
342
|
+
node scripts/backport --pr 55
|
|
343
|
+
\`\`\`
|
|
344
|
+
|
|
345
|
+
### Questions ?
|
|
346
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
347
|
+
|
|
348
|
+
<!--- Backport version: 1.2.3-mocked -->"
|
|
349
|
+
`);
|
|
350
|
+
});
|
|
351
|
+
it('does not post a comment when `publishStatusCommentOnFailure = false`', () => {
|
|
352
|
+
const params = getParams({ publishStatusCommentOnFailure: false });
|
|
353
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
describe('when backport was aborted due to missing branches', () => {
|
|
357
|
+
const getParams = (opts) => ({
|
|
358
|
+
options: {
|
|
359
|
+
repoName: 'kibana',
|
|
360
|
+
repoOwner: 'elastic',
|
|
361
|
+
autoMerge: true,
|
|
362
|
+
backportBinary: 'node scripts/backport',
|
|
363
|
+
...opts,
|
|
364
|
+
},
|
|
365
|
+
pullNumber: 55,
|
|
366
|
+
backportResponse: {
|
|
367
|
+
status: 'aborted',
|
|
368
|
+
commits: [],
|
|
369
|
+
error: new BackportError_1.BackportError({ code: 'no-branches-exception' }),
|
|
370
|
+
errorMessage: 'my message',
|
|
371
|
+
},
|
|
372
|
+
});
|
|
373
|
+
it('posts a comment when `publishStatusCommentOnAbort = true`', () => {
|
|
374
|
+
const params = getParams({
|
|
375
|
+
publishStatusCommentOnAbort: true,
|
|
376
|
+
});
|
|
377
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
378
|
+
"## ⚪ Backport skipped
|
|
379
|
+
The pull request was not backported as there were no branches to backport to. If this is a mistake, please apply the desired version labels or run the backport tool manually.
|
|
380
|
+
|
|
381
|
+
### Manual backport
|
|
382
|
+
To create the backport manually run:
|
|
383
|
+
\`\`\`
|
|
384
|
+
node scripts/backport --pr 55
|
|
385
|
+
\`\`\`
|
|
386
|
+
|
|
387
|
+
### Questions ?
|
|
388
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
389
|
+
|
|
390
|
+
<!--- Backport version: 1.2.3-mocked -->"
|
|
391
|
+
`);
|
|
392
|
+
});
|
|
393
|
+
it('does not post a comment when `publishStatusCommentOnAbort = false`', () => {
|
|
394
|
+
const params = getParams({ publishStatusCommentOnAbort: false });
|
|
395
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
describe('when backport was aborted during conflict resolution', () => {
|
|
399
|
+
const getParams = (opts) => ({
|
|
400
|
+
options: {
|
|
401
|
+
interactive: true,
|
|
402
|
+
repoName: 'kibana',
|
|
403
|
+
repoOwner: 'elastic',
|
|
404
|
+
autoMerge: true,
|
|
405
|
+
backportBinary: 'node scripts/backport',
|
|
406
|
+
...opts,
|
|
407
|
+
},
|
|
408
|
+
pullNumber: 55,
|
|
409
|
+
backportResponse: {
|
|
410
|
+
status: 'success',
|
|
411
|
+
commits: [],
|
|
412
|
+
results: [
|
|
413
|
+
{
|
|
414
|
+
targetBranch: 'staging',
|
|
415
|
+
status: 'handled-error',
|
|
416
|
+
error: new BackportError_1.BackportError({
|
|
417
|
+
code: 'abort-conflict-resolution-exception',
|
|
418
|
+
}),
|
|
419
|
+
},
|
|
420
|
+
],
|
|
421
|
+
},
|
|
422
|
+
});
|
|
423
|
+
it('posts a comment when `publishStatusCommentOnAbort = true`', () => {
|
|
424
|
+
const params = getParams({
|
|
425
|
+
publishStatusCommentOnAbort: true,
|
|
426
|
+
});
|
|
427
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`undefined`);
|
|
428
|
+
});
|
|
429
|
+
it('does not post a comment when `publishStatusCommentOnAbort = false`', () => {
|
|
430
|
+
const params = getParams({ publishStatusCommentOnAbort: false });
|
|
431
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
|
|
432
|
+
});
|
|
433
|
+
it('posts a comment when `publishStatusCommentOnFailure = true`', () => {
|
|
434
|
+
const params = getParams({
|
|
435
|
+
publishStatusCommentOnFailure: true,
|
|
436
|
+
});
|
|
437
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
|
|
438
|
+
"## 💔 All backports failed
|
|
439
|
+
|
|
440
|
+
| Status | Branch | Result |
|
|
441
|
+
|:------:|:------:|:------|
|
|
442
|
+
|❌|staging|Conflict resolution was aborted by the user|
|
|
443
|
+
|
|
444
|
+
### Manual backport
|
|
445
|
+
To create the backport manually run:
|
|
446
|
+
\`\`\`
|
|
447
|
+
node scripts/backport --pr 55
|
|
448
|
+
\`\`\`
|
|
449
|
+
|
|
450
|
+
### Questions ?
|
|
451
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
|
|
452
|
+
|
|
453
|
+
<!--- Backport version: 1.2.3-mocked -->"
|
|
454
|
+
`);
|
|
455
|
+
});
|
|
456
|
+
it('does not post a comment when `publishStatusCommentOnFailure = false`', () => {
|
|
457
|
+
const params = getParams({ publishStatusCommentOnFailure: false });
|
|
458
|
+
expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare type GithubV3Error = {
|
|
2
|
+
name: string;
|
|
3
|
+
status: number;
|
|
4
|
+
documentation_url: string;
|
|
5
|
+
message?: string;
|
|
6
|
+
errors?: Array<{
|
|
7
|
+
resource: string;
|
|
8
|
+
code: string;
|
|
9
|
+
field: string;
|
|
10
|
+
message?: string;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
export declare function getGithubV3ErrorMessage(e: GithubV3Error): string | undefined;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGithubV3ErrorMessage = void 0;
|
|
4
|
+
function getGithubV3ErrorMessage(e) {
|
|
5
|
+
if (!e.errors) {
|
|
6
|
+
return e.message;
|
|
7
|
+
}
|
|
8
|
+
const errorMessages = e.errors.map((error) => {
|
|
9
|
+
if (error.message) {
|
|
10
|
+
return error.message;
|
|
11
|
+
}
|
|
12
|
+
return JSON.stringify(error);
|
|
13
|
+
});
|
|
14
|
+
return `${errorMessages.join(', ')} (Github v3)`;
|
|
15
|
+
}
|
|
16
|
+
exports.getGithubV3ErrorMessage = getGithubV3ErrorMessage;
|
|
@@ -0,0 +1,36 @@
|
|
|
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.fetchPullRequestId = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const apiRequestV4_1 = require("./apiRequestV4");
|
|
9
|
+
async function fetchPullRequestId(options, pullNumber) {
|
|
10
|
+
const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
|
|
11
|
+
const prQuery = (0, graphql_tag_1.default) `
|
|
12
|
+
query PullRequestId(
|
|
13
|
+
$repoOwner: String!
|
|
14
|
+
$repoName: String!
|
|
15
|
+
$pullNumber: Int!
|
|
16
|
+
) {
|
|
17
|
+
repository(owner: $repoOwner, name: $repoName) {
|
|
18
|
+
pullRequest(number: $pullNumber) {
|
|
19
|
+
id
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
const prResponse = await (0, apiRequestV4_1.apiRequestV4)({
|
|
25
|
+
githubApiBaseUrlV4,
|
|
26
|
+
accessToken,
|
|
27
|
+
query: prQuery,
|
|
28
|
+
variables: {
|
|
29
|
+
repoOwner,
|
|
30
|
+
repoName,
|
|
31
|
+
pullNumber,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
return prResponse.repository.pullRequest.id;
|
|
35
|
+
}
|
|
36
|
+
exports.fetchPullRequestId = fetchPullRequestId;
|