backport 7.4.0 → 8.2.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 +15 -16
- package/dist/backportRun.d.ts +12 -6
- package/dist/backportRun.js +64 -62
- package/dist/entrypoint.cli.js +4 -8
- package/dist/entrypoint.module.d.ts +13 -6
- package/dist/entrypoint.module.js +14 -20
- package/dist/entrypoint.module.private.test.js +47 -346
- 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 +11 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +242 -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 +60 -0
- package/dist/lib/env.d.ts +9 -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 +210 -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 +138 -0
- package/dist/lib/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/lib/github/v3/createStatusComment.test.js +566 -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/github/v4/validateTargetBranches.d.ts +14 -0
- package/dist/lib/github/v4/validateTargetBranches.js +46 -0
- package/dist/lib/github/v4/validateTargetBranches.private.test.d.ts +1 -0
- package/dist/lib/github/v4/validateTargetBranches.private.test.js +51 -0
- package/dist/lib/logger.d.ts +11 -0
- package/dist/lib/logger.js +80 -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 +14 -6
- package/dist/options/cliArgs.js +50 -22
- package/dist/options/cliArgs.test.js +128 -4
- 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 +5 -3
- package/dist/options/config/globalConfig.js +17 -14
- package/dist/options/config/readConfigFile.d.ts +5 -3
- package/dist/options/config/readConfigFile.js +2 -2
- package/dist/options/options.d.ts +41 -5
- package/dist/options/options.js +24 -24
- package/dist/options/options.test.js +117 -55
- package/dist/runSequentially.d.ts +14 -9
- package/dist/runSequentially.js +27 -12
- package/dist/scripts/postinstall.js +4 -3
- package/dist/scripts/postinstall.test.js +6 -2
- 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 +2 -2
- package/dist/services/HandledError.js +7 -7
- package/dist/services/child-process-promisified.d.ts +19 -3
- package/dist/services/child-process-promisified.js +46 -17
- package/dist/services/git.d.ts +6 -7
- package/dist/services/git.integration.test.js +381 -65
- package/dist/services/git.js +189 -123
- package/dist/services/git.private.test.d.ts +1 -0
- package/dist/services/git.private.test.js +618 -0
- package/dist/services/git.test.js +167 -124
- package/dist/services/github/v3/addAssigneesToPullRequest.js +1 -1
- package/dist/services/github/v3/addLabelsToPullRequest.js +1 -1
- package/dist/services/github/v3/addReviewersToPullRequest.js +2 -1
- package/dist/services/github/v3/createPullRequest.js +4 -2
- package/dist/services/github/v3/createStatusComment.js +16 -17
- package/dist/services/github/v3/createStatusComment.test.js +20 -9
- package/dist/services/github/v4/apiRequestV4.js +2 -2
- package/dist/services/github/v4/apiRequestV4.test.js +2 -2
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +4 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +3 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +4 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +3 -2
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +5 -1
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
- package/dist/services/logger.js +5 -1
- package/dist/services/test.d.ts +1 -0
- package/dist/services/test.js +23 -0
- 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 +27 -25
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +53 -75
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +80 -0
- package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +199 -0
- package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/interactive-error-handling.private.test.js +80 -0
- package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +198 -0
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +28 -29
- package/dist/test/e2e/cli/runBackportViaCli.d.ts +6 -2
- package/dist/test/e2e/cli/runBackportViaCli.js +44 -23
- 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 +28 -21
- package/dist/test/handleUnbackportedPullRequests.private.test.js +11 -8
- package/dist/test/sandbox.js +5 -1
- package/dist/test/setupFiles/automatic-mocks.js +6 -2
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +4 -4
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +7 -159
- package/dist/ui/getCommits.js +2 -2
- package/dist/ui/getCommitsWithoutBackports.test.js +5 -1
- package/dist/ui/getGitConfigAuthor.js +1 -1
- package/dist/ui/getTargetBranches.js +3 -3
- package/dist/ui/getTargetBranches.test.js +5 -1
- package/dist/ui/ora.d.ts +1 -8
- package/dist/ui/setupRepo.js +3 -3
- package/dist/ui/setupRepo.test.js +98 -61
- package/dist/utils/isErrnoError.d.ts +2 -0
- package/dist/utils/isErrnoError.js +7 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +19 -19
- package/yarn.lock +472 -701
|
@@ -0,0 +1,71 @@
|
|
|
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.getQueryName = exports.GithubV4Exception = exports.apiRequestV4 = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const printer_1 = require("graphql/language/printer");
|
|
9
|
+
const BackportError_1 = require("../../BackportError");
|
|
10
|
+
const logger_1 = require("../../logger");
|
|
11
|
+
async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graphql', accessToken, query, variables, }) {
|
|
12
|
+
try {
|
|
13
|
+
const response = await axios_1.default.post(githubApiBaseUrlV4, { query: (0, printer_1.print)(query), variables }, {
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-Type': 'application/json',
|
|
16
|
+
Authorization: `bearer ${accessToken}`,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
if (response.data.errors) {
|
|
20
|
+
throw new GithubV4Exception(response);
|
|
21
|
+
}
|
|
22
|
+
addDebugLogs({
|
|
23
|
+
githubApiBaseUrlV4,
|
|
24
|
+
query,
|
|
25
|
+
variables,
|
|
26
|
+
githubResponse: response,
|
|
27
|
+
});
|
|
28
|
+
return response.data.data;
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
if (axios_1.default.isAxiosError(e) && e.response) {
|
|
32
|
+
addDebugLogs({
|
|
33
|
+
githubApiBaseUrlV4,
|
|
34
|
+
query,
|
|
35
|
+
variables,
|
|
36
|
+
githubResponse: e.response,
|
|
37
|
+
didThrow: true,
|
|
38
|
+
});
|
|
39
|
+
throw new GithubV4Exception(e.response, e.message);
|
|
40
|
+
}
|
|
41
|
+
throw e;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.apiRequestV4 = apiRequestV4;
|
|
45
|
+
function addDebugLogs({ githubApiBaseUrlV4, query, variables, githubResponse, didThrow = false, }) {
|
|
46
|
+
const gqlQueryName = getQueryName(query);
|
|
47
|
+
logger_1.logger.info(`POST ${githubApiBaseUrlV4} (name:${gqlQueryName}, status: ${githubResponse.status}${didThrow ? ', EXCEPTION THROWN' : ''})`);
|
|
48
|
+
logger_1.logger.verbose(`Query: ${query}`);
|
|
49
|
+
logger_1.logger.verbose('Variables:', variables);
|
|
50
|
+
logger_1.logger.verbose('Response headers:', githubResponse.headers);
|
|
51
|
+
logger_1.logger.verbose('Response data:', githubResponse.data);
|
|
52
|
+
}
|
|
53
|
+
class GithubV4Exception extends Error {
|
|
54
|
+
constructor(githubResponse, errorMessage) {
|
|
55
|
+
const githubMessage = githubResponse.data.errors
|
|
56
|
+
?.map((error) => error.message)
|
|
57
|
+
.join(',');
|
|
58
|
+
const message = `${errorMessage ?? githubMessage ?? 'Unknown error'} (Github API v4)`;
|
|
59
|
+
super(message);
|
|
60
|
+
Error.captureStackTrace(this, BackportError_1.BackportError);
|
|
61
|
+
this.name = 'GithubV4Exception';
|
|
62
|
+
this.message = message;
|
|
63
|
+
this.githubResponse = { ...githubResponse, request: undefined };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.GithubV4Exception = GithubV4Exception;
|
|
67
|
+
function getQueryName(query) {
|
|
68
|
+
//@ts-expect-error
|
|
69
|
+
return query.definitions[0].name?.value;
|
|
70
|
+
}
|
|
71
|
+
exports.getQueryName = getQueryName;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
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 graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
7
|
+
const nock_1 = __importDefault(require("nock"));
|
|
8
|
+
const nockHelpers_1 = require("../../../test/nockHelpers");
|
|
9
|
+
const BackportError_1 = require("../../BackportError");
|
|
10
|
+
const apiRequestV4_1 = require("./apiRequestV4");
|
|
11
|
+
describe('apiRequestV4', () => {
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
nock_1.default.cleanAll();
|
|
14
|
+
});
|
|
15
|
+
describe('when request succeeds', () => {
|
|
16
|
+
let res;
|
|
17
|
+
let commitsByAuthorCalls;
|
|
18
|
+
beforeEach(async () => {
|
|
19
|
+
commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
20
|
+
name: 'MyQuery',
|
|
21
|
+
statusCode: 200,
|
|
22
|
+
body: { data: { viewer: { login: 'sqren' } } },
|
|
23
|
+
});
|
|
24
|
+
res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
25
|
+
accessToken: 'myAccessToken',
|
|
26
|
+
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
27
|
+
query: (0, graphql_tag_1.default) `
|
|
28
|
+
query MyQuery {
|
|
29
|
+
viewer {
|
|
30
|
+
login
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`,
|
|
34
|
+
variables: { foo: 'bar' },
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
it('should return correct response', async () => {
|
|
38
|
+
expect(res).toEqual({ viewer: { login: 'sqren' } });
|
|
39
|
+
});
|
|
40
|
+
it('should call with correct args', async () => {
|
|
41
|
+
expect(commitsByAuthorCalls).toMatchInlineSnapshot(`
|
|
42
|
+
Array [
|
|
43
|
+
Object {
|
|
44
|
+
"query": "query MyQuery {
|
|
45
|
+
viewer {
|
|
46
|
+
login
|
|
47
|
+
}
|
|
48
|
+
}",
|
|
49
|
+
"variables": Object {
|
|
50
|
+
"foo": "bar",
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
]
|
|
54
|
+
`);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
describe('when request fails with error messages', () => {
|
|
58
|
+
beforeEach(() => {
|
|
59
|
+
(0, nockHelpers_1.mockGqlRequest)({
|
|
60
|
+
name: 'MyQuery',
|
|
61
|
+
statusCode: 200,
|
|
62
|
+
body: {
|
|
63
|
+
errors: [{ message: 'some error' }, { message: 'some other error' }],
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
it('should return error containing the error messages', async () => {
|
|
68
|
+
return expect((0, apiRequestV4_1.apiRequestV4)({
|
|
69
|
+
accessToken: 'myAccessToken',
|
|
70
|
+
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
71
|
+
query: (0, graphql_tag_1.default) `
|
|
72
|
+
query MyQuery {
|
|
73
|
+
viewer {
|
|
74
|
+
login
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
`,
|
|
78
|
+
variables: {
|
|
79
|
+
foo: 'bar',
|
|
80
|
+
},
|
|
81
|
+
})).rejects.toThrowError(new BackportError_1.BackportError(`some error,some other error (Github API v4)`));
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
describe('when request fails without error messages', () => {
|
|
85
|
+
beforeEach(() => {
|
|
86
|
+
(0, nockHelpers_1.mockGqlRequest)({
|
|
87
|
+
name: 'MyQuery',
|
|
88
|
+
statusCode: 500,
|
|
89
|
+
body: { data: { foo: 'bar' } },
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
it('should return parsed github error', async () => {
|
|
93
|
+
return expect((0, apiRequestV4_1.apiRequestV4)({
|
|
94
|
+
accessToken: 'myAccessToken',
|
|
95
|
+
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
96
|
+
query: (0, graphql_tag_1.default) `
|
|
97
|
+
query MyQuery {
|
|
98
|
+
viewer {
|
|
99
|
+
login
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
`,
|
|
103
|
+
variables: {
|
|
104
|
+
foo: 'bar',
|
|
105
|
+
},
|
|
106
|
+
})).rejects.toThrowError('Request failed with status code 500');
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
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.disablePullRequestAutoMerge = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const FetchPullRequestId_1 = require("./FetchPullRequestId");
|
|
9
|
+
const apiRequestV4_1 = require("./apiRequestV4");
|
|
10
|
+
async function disablePullRequestAutoMerge(options, pullNumber) {
|
|
11
|
+
const { accessToken, githubApiBaseUrlV4 } = options;
|
|
12
|
+
const pullRequestId = await (0, FetchPullRequestId_1.fetchPullRequestId)(options, pullNumber);
|
|
13
|
+
const query = (0, graphql_tag_1.default) `
|
|
14
|
+
mutation DisablePullRequestAutoMerge($pullRequestId: ID!) {
|
|
15
|
+
disablePullRequestAutoMerge(input: { pullRequestId: $pullRequestId }) {
|
|
16
|
+
pullRequest {
|
|
17
|
+
number
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
23
|
+
githubApiBaseUrlV4,
|
|
24
|
+
accessToken,
|
|
25
|
+
query,
|
|
26
|
+
variables: {
|
|
27
|
+
pullRequestId,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
return res.disablePullRequestAutoMerge.pullRequest?.number;
|
|
31
|
+
}
|
|
32
|
+
exports.disablePullRequestAutoMerge = disablePullRequestAutoMerge;
|
|
@@ -0,0 +1,50 @@
|
|
|
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 graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const ora_1 = require("../../../lib/ora");
|
|
9
|
+
const logger_1 = require("../../logger");
|
|
10
|
+
const FetchPullRequestId_1 = require("./FetchPullRequestId");
|
|
11
|
+
const apiRequestV4_1 = require("./apiRequestV4");
|
|
12
|
+
async function enablePullRequestAutoMerge(options, targetPullRequestNumber) {
|
|
13
|
+
const { accessToken, githubApiBaseUrlV4, autoMergeMethod = 'merge', } = options;
|
|
14
|
+
const text = `Enabling auto merging via ${options.autoMergeMethod}`;
|
|
15
|
+
logger_1.logger.info(text);
|
|
16
|
+
const spinner = (0, ora_1.ora)(options.interactive, text).start();
|
|
17
|
+
const pullRequestId = await (0, FetchPullRequestId_1.fetchPullRequestId)(options, targetPullRequestNumber);
|
|
18
|
+
const query = (0, graphql_tag_1.default) `
|
|
19
|
+
mutation EnablePullRequestAutoMerge(
|
|
20
|
+
$pullRequestId: ID!
|
|
21
|
+
$mergeMethod: PullRequestMergeMethod!
|
|
22
|
+
) {
|
|
23
|
+
enablePullRequestAutoMerge(
|
|
24
|
+
input: { pullRequestId: $pullRequestId, mergeMethod: $mergeMethod }
|
|
25
|
+
) {
|
|
26
|
+
pullRequest {
|
|
27
|
+
number
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
try {
|
|
33
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
34
|
+
githubApiBaseUrlV4,
|
|
35
|
+
accessToken,
|
|
36
|
+
query,
|
|
37
|
+
variables: {
|
|
38
|
+
pullRequestId,
|
|
39
|
+
mergeMethod: autoMergeMethod.toUpperCase(),
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
spinner.succeed();
|
|
43
|
+
return res.enablePullRequestAutoMerge.pullRequest?.number;
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
spinner.fail();
|
|
47
|
+
logger_1.logger.info(`Could not enable auto merging for ${targetPullRequestNumber}`, e);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.enablePullRequestAutoMerge = enablePullRequestAutoMerge;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
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 = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
67
|
+
const randomString = crypto_1.default.randomBytes(4).toString('hex');
|
|
68
|
+
branchName = `test-${randomString}`;
|
|
69
|
+
options = {
|
|
70
|
+
accessToken,
|
|
71
|
+
repoOwner: TEST_REPO_OWNER,
|
|
72
|
+
repoName: TEST_REPO_NAME,
|
|
73
|
+
};
|
|
74
|
+
octokit = new rest_1.Octokit({ auth: accessToken });
|
|
75
|
+
await createBranch(octokit, branchName, COMMIT_SHA);
|
|
76
|
+
pullNumber = await createPr(options, branchName);
|
|
77
|
+
});
|
|
78
|
+
// cleanup
|
|
79
|
+
afterAll(async () => {
|
|
80
|
+
await closePr(octokit, pullNumber);
|
|
81
|
+
await deleteBranch(octokit, branchName);
|
|
82
|
+
});
|
|
83
|
+
// reset auto-merge state between runs
|
|
84
|
+
afterEach(async () => {
|
|
85
|
+
await (0, disablePullRequestAutoMerge_1.disablePullRequestAutoMerge)(options, pullNumber);
|
|
86
|
+
});
|
|
87
|
+
it('should initially have auto-merge disabled', async () => {
|
|
88
|
+
const autoMergeMethod = await (0, fetchPullRequestAutoMergeMethod_1.fetchPullRequestAutoMergeMethod)(options, pullNumber);
|
|
89
|
+
expect(autoMergeMethod).toBe(undefined);
|
|
90
|
+
});
|
|
91
|
+
it('should enable auto-merge via merge', async () => {
|
|
92
|
+
await (0, enablePullRequestAutoMerge_1.enablePullRequestAutoMerge)({ ...options, autoMergeMethod: 'merge' }, pullNumber);
|
|
93
|
+
// ensure Github API reflects the change before querying
|
|
94
|
+
await sleep(100);
|
|
95
|
+
const autoMergeMethod = await (0, fetchPullRequestAutoMergeMethod_1.fetchPullRequestAutoMergeMethod)(options, pullNumber);
|
|
96
|
+
expect(autoMergeMethod).toBe('MERGE');
|
|
97
|
+
});
|
|
98
|
+
it('should not enable auto-merge via rebase because it is disallowed', async () => {
|
|
99
|
+
await (0, enablePullRequestAutoMerge_1.enablePullRequestAutoMerge)({ ...options, autoMergeMethod: 'rebase' }, pullNumber);
|
|
100
|
+
// ensure Github API reflects the change before querying
|
|
101
|
+
await sleep(100);
|
|
102
|
+
const autoMergeMethod = await (0, fetchPullRequestAutoMergeMethod_1.fetchPullRequestAutoMergeMethod)(options, pullNumber);
|
|
103
|
+
expect(autoMergeMethod).toBe(undefined);
|
|
104
|
+
});
|
|
105
|
+
it('should enable auto-merge via squash', async () => {
|
|
106
|
+
await (0, enablePullRequestAutoMerge_1.enablePullRequestAutoMerge)({ ...options, autoMergeMethod: 'squash' }, pullNumber);
|
|
107
|
+
// ensure Github API reflects the change before querying
|
|
108
|
+
await sleep(100);
|
|
109
|
+
const autoMergeMethod = await (0, fetchPullRequestAutoMergeMethod_1.fetchPullRequestAutoMergeMethod)(options, pullNumber);
|
|
110
|
+
expect(autoMergeMethod).toBe('SQUASH');
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface AuthorIdResponse {
|
|
2
|
+
user: {
|
|
3
|
+
id: string;
|
|
4
|
+
};
|
|
5
|
+
}
|
|
6
|
+
export declare function fetchAuthorId({ accessToken, author, githubApiBaseUrlV4, }: {
|
|
7
|
+
accessToken: string;
|
|
8
|
+
author: string | null;
|
|
9
|
+
githubApiBaseUrlV4?: string;
|
|
10
|
+
}): Promise<string | null>;
|
|
@@ -0,0 +1,28 @@
|
|
|
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.fetchAuthorId = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const apiRequestV4_1 = require("./apiRequestV4");
|
|
9
|
+
async function fetchAuthorId({ accessToken, author, githubApiBaseUrlV4 = 'https://api.github.com/graphql', }) {
|
|
10
|
+
if (author === null) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const query = (0, graphql_tag_1.default) `
|
|
14
|
+
query AuthorId($author: String!) {
|
|
15
|
+
user(login: $author) {
|
|
16
|
+
id
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
21
|
+
githubApiBaseUrlV4,
|
|
22
|
+
accessToken,
|
|
23
|
+
query,
|
|
24
|
+
variables: { author },
|
|
25
|
+
});
|
|
26
|
+
return res.user.id;
|
|
27
|
+
}
|
|
28
|
+
exports.fetchAuthorId = fetchAuthorId;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
|
|
4
|
+
const fetchAuthorId_1 = require("./fetchAuthorId");
|
|
5
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
6
|
+
describe('fetchAuthorId', () => {
|
|
7
|
+
describe('author = null', () => {
|
|
8
|
+
it('returns null', async () => {
|
|
9
|
+
const options = {
|
|
10
|
+
accessToken,
|
|
11
|
+
author: null,
|
|
12
|
+
};
|
|
13
|
+
expect(await (0, fetchAuthorId_1.fetchAuthorId)(options)).toEqual(null);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
describe('author is "sqren"', () => {
|
|
17
|
+
it('returns author id', async () => {
|
|
18
|
+
const options = {
|
|
19
|
+
accessToken,
|
|
20
|
+
author: 'sqren',
|
|
21
|
+
};
|
|
22
|
+
expect(await (0, fetchAuthorId_1.fetchAuthorId)(options)).toEqual('MDQ6VXNlcjIwOTk2Ng==');
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
const fetchCommitBySha_1 = require("./fetchCommitBySha");
|
|
6
|
+
const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
|
|
7
|
+
const fetchPullRequestsBySearchQuery_1 = require("./fetchPullRequestsBySearchQuery");
|
|
8
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
|
+
describe('allFetchers', () => {
|
|
10
|
+
let commitByAuthor;
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
const commitsByAuthor = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
13
|
+
accessToken,
|
|
14
|
+
author: 'sqren',
|
|
15
|
+
maxNumber: 1,
|
|
16
|
+
repoName: 'kibana',
|
|
17
|
+
repoOwner: 'elastic',
|
|
18
|
+
sourceBranch: 'main',
|
|
19
|
+
dateSince: '2021-01-10T00:00:00Z',
|
|
20
|
+
dateUntil: '2022-01-01T00:00:00Z',
|
|
21
|
+
commitPaths: [],
|
|
22
|
+
});
|
|
23
|
+
commitByAuthor = commitsByAuthor[0];
|
|
24
|
+
});
|
|
25
|
+
it('matches commitByAuthor with commitByPullNumber', async () => {
|
|
26
|
+
if (!commitByAuthor.sourcePullRequest) {
|
|
27
|
+
throw new Error('Missing pull number!');
|
|
28
|
+
}
|
|
29
|
+
const commitByPullNumber = await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
|
|
30
|
+
repoOwner: 'elastic',
|
|
31
|
+
repoName: 'kibana',
|
|
32
|
+
accessToken,
|
|
33
|
+
pullNumber: commitByAuthor.sourcePullRequest.number,
|
|
34
|
+
sourceBranch: 'master',
|
|
35
|
+
});
|
|
36
|
+
expect(commitByAuthor).toEqual(commitByPullNumber);
|
|
37
|
+
});
|
|
38
|
+
it('matches commitByAuthor with commitBySha', async () => {
|
|
39
|
+
const commitBySha = await (0, fetchCommitBySha_1.fetchCommitBySha)({
|
|
40
|
+
repoOwner: 'elastic',
|
|
41
|
+
repoName: 'kibana',
|
|
42
|
+
accessToken,
|
|
43
|
+
sha: commitByAuthor.sourceCommit.sha,
|
|
44
|
+
sourceBranch: 'main',
|
|
45
|
+
});
|
|
46
|
+
expect(commitByAuthor).toEqual(commitBySha);
|
|
47
|
+
});
|
|
48
|
+
it('matches commitByAuthor with commitBySearchQuery', async () => {
|
|
49
|
+
const commitsBySearchQuery = await (0, fetchPullRequestsBySearchQuery_1.fetchPullRequestsBySearchQuery)({
|
|
50
|
+
repoOwner: 'elastic',
|
|
51
|
+
repoName: 'kibana',
|
|
52
|
+
accessToken,
|
|
53
|
+
maxNumber: 1,
|
|
54
|
+
prFilter: `created:2021-12-20..2021-12-20`,
|
|
55
|
+
sourceBranch: 'main',
|
|
56
|
+
author: 'sqren',
|
|
57
|
+
});
|
|
58
|
+
const commitBySearchQuery = commitsBySearchQuery[0];
|
|
59
|
+
expect(commitByAuthor).toEqual(commitBySearchQuery);
|
|
60
|
+
});
|
|
61
|
+
it('returns correct response for commitByAuthor', async () => {
|
|
62
|
+
const expectedCommit = {
|
|
63
|
+
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
64
|
+
sourceCommit: {
|
|
65
|
+
committedDate: '2021-12-20T14:20:16Z',
|
|
66
|
+
message: '[APM] Add note about synthtrace to APM docs (#121633)',
|
|
67
|
+
sha: 'd421ddcf6157150596581c7885afa3690cec6339',
|
|
68
|
+
},
|
|
69
|
+
sourcePullRequest: {
|
|
70
|
+
number: 121633,
|
|
71
|
+
url: 'https://github.com/elastic/kibana/pull/121633',
|
|
72
|
+
mergeCommit: {
|
|
73
|
+
message: '[APM] Add note about synthtrace to APM docs (#121633)',
|
|
74
|
+
sha: 'd421ddcf6157150596581c7885afa3690cec6339',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
sourceBranch: 'main',
|
|
78
|
+
expectedTargetPullRequests: [
|
|
79
|
+
{
|
|
80
|
+
branch: '8.0',
|
|
81
|
+
mergeCommit: {
|
|
82
|
+
message: '[APM] Add note about synthtrace to APM docs (#121633) (#121643)\n\nCo-authored-by: Søren Louv-Jansen <soren.louv@elastic.co>',
|
|
83
|
+
sha: '842adfdeb5541b059231857522f9009771a46107',
|
|
84
|
+
},
|
|
85
|
+
number: 121643,
|
|
86
|
+
state: 'MERGED',
|
|
87
|
+
url: 'https://github.com/elastic/kibana/pull/121643',
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
};
|
|
91
|
+
expect(commitByAuthor).toEqual(expectedCommit);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ValidConfigOptions } from '../../../../options/options';
|
|
2
|
+
import { Commit } from '../../../sourceCommit/parseSourceCommit';
|
|
3
|
+
export declare function fetchCommitByPullNumber(options: {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
|
|
6
|
+
githubApiBaseUrlV4?: string;
|
|
7
|
+
pullNumber: number;
|
|
8
|
+
repoName: string;
|
|
9
|
+
repoOwner: string;
|
|
10
|
+
sourceBranch: string;
|
|
11
|
+
}): Promise<Commit>;
|
|
@@ -0,0 +1,58 @@
|
|
|
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.fetchCommitByPullNumber = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const BackportError_1 = require("../../../BackportError");
|
|
9
|
+
const remoteConfig_1 = require("../../../remoteConfig");
|
|
10
|
+
const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
|
|
11
|
+
const apiRequestV4_1 = require("../apiRequestV4");
|
|
12
|
+
async function fetchCommitByPullNumber(options) {
|
|
13
|
+
const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', pullNumber, repoName, repoOwner, } = options;
|
|
14
|
+
const query = (0, graphql_tag_1.default) `
|
|
15
|
+
query CommitByPullNumber(
|
|
16
|
+
$repoOwner: String!
|
|
17
|
+
$repoName: String!
|
|
18
|
+
$pullNumber: Int!
|
|
19
|
+
) {
|
|
20
|
+
repository(owner: $repoOwner, name: $repoName) {
|
|
21
|
+
pullRequest(number: $pullNumber) {
|
|
22
|
+
mergeCommit {
|
|
23
|
+
...SourceCommitWithTargetPullRequestFragment
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
|
|
30
|
+
`;
|
|
31
|
+
let res;
|
|
32
|
+
try {
|
|
33
|
+
res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
34
|
+
githubApiBaseUrlV4,
|
|
35
|
+
accessToken,
|
|
36
|
+
query,
|
|
37
|
+
variables: {
|
|
38
|
+
repoOwner,
|
|
39
|
+
repoName,
|
|
40
|
+
pullNumber,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
//@ts-expect-error
|
|
46
|
+
res = (0, remoteConfig_1.swallowMissingConfigFileException)(e);
|
|
47
|
+
}
|
|
48
|
+
const pullRequestNode = res.repository.pullRequest;
|
|
49
|
+
if (!pullRequestNode) {
|
|
50
|
+
throw new BackportError_1.BackportError(`The PR #${pullNumber} does not exist`);
|
|
51
|
+
}
|
|
52
|
+
const sourceCommit = pullRequestNode.mergeCommit;
|
|
53
|
+
if (sourceCommit === null) {
|
|
54
|
+
throw new BackportError_1.BackportError(`The PR #${pullNumber} is not merged`);
|
|
55
|
+
}
|
|
56
|
+
return (0, parseSourceCommit_1.parseSourceCommit)({ options, sourceCommit });
|
|
57
|
+
}
|
|
58
|
+
exports.fetchCommitByPullNumber = fetchCommitByPullNumber;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|