backport 5.6.6 → 6.1.2
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 +186 -50
- package/dist/entrypoint.cli.js +3 -1
- package/dist/entrypoint.module.d.ts +18 -5
- package/dist/entrypoint.module.js +42 -12
- package/dist/entrypoint.module.private.test.d.ts +1 -0
- package/dist/entrypoint.module.private.test.js +34 -0
- 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 -25
- package/dist/options/ConfigOptions.d.ts +28 -13
- package/dist/options/cliArgs.d.ts +36 -35
- package/dist/options/cliArgs.js +91 -52
- package/dist/options/cliArgs.test.js +35 -43
- package/dist/options/config/config.d.ts +35 -57
- package/dist/options/config/config.js +5 -39
- package/dist/options/config/config.test.js +11 -27
- package/dist/options/config/getOptionsFromGit.d.ts +3 -2
- package/dist/options/config/getOptionsFromGit.js +1 -3
- package/dist/options/config/globalConfig.d.ts +2 -51
- package/dist/options/config/globalConfig.js +9 -12
- package/dist/options/config/globalConfig.test.js +7 -5
- package/dist/options/config/projectConfig.d.ts +2 -51
- package/dist/options/config/projectConfig.js +2 -2
- package/dist/options/config/projectConfig.test.js +53 -16
- package/dist/options/config/readConfigFile.d.ts +44 -41
- package/dist/options/config/readConfigFile.js +30 -4
- package/dist/options/options.d.ts +59 -31
- package/dist/options/options.js +103 -10
- package/dist/options/options.test.js +266 -79
- package/dist/options/parseRequiredOptions.d.ts +19 -14
- package/dist/options/parseRequiredOptions.js +9 -15
- package/dist/options/parseRequiredOptions.test.js +30 -26
- 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 +196 -0
- package/dist/runWithOptions.js +7 -14
- package/dist/runWithOptions.test.js +138 -17
- 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 +1 -1
- 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 +20 -6
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +168 -0
- package/dist/services/git.js +93 -67
- package/dist/services/git.test.js +68 -68
- 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 +3 -8
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +6 -8
- 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 +31 -25
- package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/createPullRequest.test.js +110 -0
- package/dist/services/github/v3/createStatusComment.d.ts +11 -0
- package/dist/services/github/v3/createStatusComment.js +95 -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.js +1 -1
- package/dist/services/github/v4/apiRequestV4.d.ts +2 -2
- package/dist/services/github/v4/apiRequestV4.js +6 -8
- package/dist/services/github/v4/apiRequestV4.test.js +7 -7
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +3 -4
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +9 -8
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +93 -33
- package/dist/services/github/v4/fetchAuthorId.d.ts +5 -2
- package/dist/services/github/v4/fetchAuthorId.js +6 -7
- package/dist/services/github/v4/fetchAuthorId.private.test.js +6 -9
- package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
- package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +4 -4
- package/dist/services/github/v4/fetchCommitBySha.js +14 -12
- package/dist/services/github/v4/fetchCommitBySha.private.test.js +4 -4
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +12 -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 +70 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +12 -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 +27 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +88 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +128 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +125 -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/fetchProjectConfig.d.ts +3 -0
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -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 +77 -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 +2 -1
- package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
- package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +78 -5
- package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
- package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
- package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -5
- package/dist/services/github/v4/fetchMergedPullRequests.d.ts +18 -19
- package/dist/services/github/v4/fetchMergedPullRequests.js +22 -69
- package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
- package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
- package/dist/services/github/v4/fetchProjectConfig.js +56 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
- package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +2 -3
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +3 -3
- 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/getOptionsFromGithub.d.ts +67 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +19 -11
- package/dist/services/github/v4/getOptionsFromGithub/index.js +52 -22
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +46 -7
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +16 -16
- package/dist/services/github/v4/getOptionsFromGithub/query.js +16 -15
- 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 +1 -1
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +1 -1
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +2 -0
- 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.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 +16 -15
- 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 +413 -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 +82 -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 +229 -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 +55 -51
- package/dist/test/integration/createSpies.js +6 -6
- 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 +327 -0
- package/dist/test/integration/integration.test.js +28 -29
- package/dist/test/mockConfigFiles.d.ts +5 -0
- package/dist/test/mockConfigFiles.js +37 -0
- package/dist/test/nockHelpers.d.ts +1 -1
- package/dist/test/nockHelpers.js +7 -11
- package/dist/test/private/getDevAccessToken.js +1 -1
- package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
- package/dist/test/setupFiles/automatic-mocks.js +1 -51
- 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 +346 -76
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +2 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +95 -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/getCommitsWithoutBackports.d.ts +11 -0
- package/dist/ui/getCommitsWithoutBackports.js +53 -0
- package/dist/ui/getTargetBranches.d.ts +3 -2
- package/dist/ui/getTargetBranches.js +33 -18
- 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 +11 -10
- package/dist/ui/maybeSetupRepo.test.js +54 -4
- package/dist/utils/excludeUndefined.d.ts +6 -0
- package/dist/utils/excludeUndefined.js +7 -0
- package/dist/utils/excludeUndefined.test.d.ts +1 -0
- package/dist/utils/excludeUndefined.test.js +24 -0
- package/package.json +37 -51
- package/yarn.lock +2414 -2993
|
@@ -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 }',
|
|
@@ -4,9 +4,8 @@ exports.disablePullRequestAutoMerge = void 0;
|
|
|
4
4
|
const FetchPullRequestId_1 = require("./FetchPullRequestId");
|
|
5
5
|
const apiRequestV4_1 = require("./apiRequestV4");
|
|
6
6
|
async function disablePullRequestAutoMerge(options, pullNumber) {
|
|
7
|
-
var _a;
|
|
8
7
|
const { accessToken, githubApiBaseUrlV4 } = options;
|
|
9
|
-
const pullRequestId = await FetchPullRequestId_1.fetchPullRequestId(options, pullNumber);
|
|
8
|
+
const pullRequestId = await (0, FetchPullRequestId_1.fetchPullRequestId)(options, pullNumber);
|
|
10
9
|
const query = /* GraphQL */ `
|
|
11
10
|
mutation DisablePullRequestAutoMerge($pullRequestId: ID!) {
|
|
12
11
|
disablePullRequestAutoMerge(input: { pullRequestId: $pullRequestId }) {
|
|
@@ -16,7 +15,7 @@ async function disablePullRequestAutoMerge(options, pullNumber) {
|
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
17
|
`;
|
|
19
|
-
const res = await apiRequestV4_1.apiRequestV4({
|
|
18
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
20
19
|
githubApiBaseUrlV4,
|
|
21
20
|
accessToken,
|
|
22
21
|
query,
|
|
@@ -24,6 +23,6 @@ async function disablePullRequestAutoMerge(options, pullNumber) {
|
|
|
24
23
|
pullRequestId,
|
|
25
24
|
},
|
|
26
25
|
});
|
|
27
|
-
return
|
|
26
|
+
return res.disablePullRequestAutoMerge.pullRequest?.number;
|
|
28
27
|
}
|
|
29
28
|
exports.disablePullRequestAutoMerge = disablePullRequestAutoMerge;
|
|
@@ -9,12 +9,11 @@ const logger_1 = require("../../logger");
|
|
|
9
9
|
const FetchPullRequestId_1 = require("./FetchPullRequestId");
|
|
10
10
|
const apiRequestV4_1 = require("./apiRequestV4");
|
|
11
11
|
async function enablePullRequestAutoMerge(options, targetPullRequestNumber) {
|
|
12
|
-
|
|
13
|
-
const { accessToken, githubApiBaseUrlV4, autoMergeMethod } = options;
|
|
12
|
+
const { accessToken, githubApiBaseUrlV4, autoMergeMethod = 'merge', } = options;
|
|
14
13
|
const text = `Enabling auto merging via ${options.autoMergeMethod}`;
|
|
15
14
|
logger_1.logger.info(text);
|
|
16
|
-
const spinner = ora_1.default(text).start();
|
|
17
|
-
const pullRequestId = await FetchPullRequestId_1.fetchPullRequestId(options, targetPullRequestNumber);
|
|
15
|
+
const spinner = (0, ora_1.default)(text).start();
|
|
16
|
+
const pullRequestId = await (0, FetchPullRequestId_1.fetchPullRequestId)(options, targetPullRequestNumber);
|
|
18
17
|
const query = /* GraphQL */ `
|
|
19
18
|
mutation EnablePullRequestAutoMerge(
|
|
20
19
|
$pullRequestId: ID!
|
|
@@ -30,7 +29,7 @@ async function enablePullRequestAutoMerge(options, targetPullRequestNumber) {
|
|
|
30
29
|
}
|
|
31
30
|
`;
|
|
32
31
|
try {
|
|
33
|
-
const res = await apiRequestV4_1.apiRequestV4({
|
|
32
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
34
33
|
githubApiBaseUrlV4,
|
|
35
34
|
accessToken,
|
|
36
35
|
query,
|
|
@@ -40,11 +39,13 @@ async function enablePullRequestAutoMerge(options, targetPullRequestNumber) {
|
|
|
40
39
|
},
|
|
41
40
|
});
|
|
42
41
|
spinner.succeed();
|
|
43
|
-
return
|
|
42
|
+
return res.enablePullRequestAutoMerge.pullRequest?.number;
|
|
44
43
|
}
|
|
45
44
|
catch (e) {
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
if (e instanceof Error) {
|
|
46
|
+
spinner.fail();
|
|
47
|
+
logger_1.logger.info(`Could not enable auto merging for ${targetPullRequestNumber}`, e.stack);
|
|
48
|
+
}
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
exports.enablePullRequestAutoMerge = enablePullRequestAutoMerge;
|
|
@@ -1,52 +1,112 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
7
|
+
const rest_1 = require("@octokit/rest");
|
|
3
8
|
const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
|
|
9
|
+
const createPullRequest_1 = require("../v3/createPullRequest");
|
|
4
10
|
const disablePullRequestAutoMerge_1 = require("./disablePullRequestAutoMerge");
|
|
5
11
|
const enablePullRequestAutoMerge_1 = require("./enablePullRequestAutoMerge");
|
|
12
|
+
const fetchPullRequestAutoMergeMethod_1 = require("./fetchPullRequestAutoMergeMethod");
|
|
6
13
|
// The test repo requires auto-merge being enabled in options, as well as all merge types enabled (merge, squash, rebase)
|
|
7
|
-
// The test pull
|
|
14
|
+
// The test pull requests should be open, and not currently able to be merged (e.g. because it requires an approval),
|
|
8
15
|
// otherwise it will be merged when auto-merge is turned on
|
|
9
|
-
const TEST_REPO_OWNER = '';
|
|
10
|
-
const TEST_REPO_NAME = '';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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',
|
|
20
38
|
};
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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;
|
|
28
65
|
beforeAll(async () => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
66
|
+
const accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
67
|
+
const randomString = crypto_1.default.randomBytes(4).toString('hex');
|
|
68
|
+
branchName = `test-${randomString}`;
|
|
69
|
+
options = {
|
|
70
|
+
accessToken,
|
|
71
|
+
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);
|
|
33
77
|
});
|
|
34
|
-
|
|
35
|
-
|
|
78
|
+
// cleanup
|
|
79
|
+
afterAll(async () => {
|
|
80
|
+
await closePr(octokit, pullNumber);
|
|
81
|
+
await deleteBranch(octokit, branchName);
|
|
36
82
|
});
|
|
83
|
+
// reset auto-merge state between runs
|
|
37
84
|
afterEach(async () => {
|
|
38
|
-
await disablePullRequestAutoMerge_1.disablePullRequestAutoMerge(options,
|
|
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);
|
|
39
90
|
});
|
|
40
91
|
it('should enable auto-merge via merge', async () => {
|
|
41
|
-
|
|
42
|
-
|
|
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');
|
|
43
97
|
});
|
|
44
|
-
it('should enable auto-merge via rebase', async () => {
|
|
45
|
-
|
|
46
|
-
|
|
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);
|
|
47
104
|
});
|
|
48
105
|
it('should enable auto-merge via squash', async () => {
|
|
49
|
-
|
|
50
|
-
|
|
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');
|
|
51
111
|
});
|
|
52
112
|
});
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { ValidConfigOptions } from '../../../options/options';
|
|
2
1
|
export interface AuthorIdResponse {
|
|
3
2
|
user: {
|
|
4
3
|
id: string;
|
|
5
4
|
};
|
|
6
5
|
}
|
|
7
|
-
export declare function fetchAuthorId(
|
|
6
|
+
export declare function fetchAuthorId({ accessToken, author, githubApiBaseUrlV4, }: {
|
|
7
|
+
accessToken: string;
|
|
8
|
+
author: string | null;
|
|
9
|
+
githubApiBaseUrlV4?: string;
|
|
10
|
+
}): Promise<string | null>;
|
|
@@ -2,23 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fetchAuthorId = void 0;
|
|
4
4
|
const apiRequestV4_1 = require("./apiRequestV4");
|
|
5
|
-
async function fetchAuthorId(
|
|
6
|
-
|
|
7
|
-
if (all) {
|
|
5
|
+
async function fetchAuthorId({ accessToken, author, githubApiBaseUrlV4 = 'https://api.github.com/graphql', }) {
|
|
6
|
+
if (author === null) {
|
|
8
7
|
return null;
|
|
9
8
|
}
|
|
10
9
|
const query = /* GraphQL */ `
|
|
11
|
-
query AuthorId($
|
|
12
|
-
user(login: $
|
|
10
|
+
query AuthorId($author: String!) {
|
|
11
|
+
user(login: $author) {
|
|
13
12
|
id
|
|
14
13
|
}
|
|
15
14
|
}
|
|
16
15
|
`;
|
|
17
|
-
const res = await apiRequestV4_1.apiRequestV4({
|
|
16
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
18
17
|
githubApiBaseUrlV4,
|
|
19
18
|
accessToken,
|
|
20
19
|
query,
|
|
21
|
-
variables: {
|
|
20
|
+
variables: { author },
|
|
22
21
|
});
|
|
23
22
|
return res.user.id;
|
|
24
23
|
}
|
|
@@ -5,27 +5,24 @@ const fetchAuthorId_1 = require("./fetchAuthorId");
|
|
|
5
5
|
describe('fetchAuthorId', () => {
|
|
6
6
|
let devAccessToken;
|
|
7
7
|
beforeAll(async () => {
|
|
8
|
-
devAccessToken = await getDevAccessToken_1.getDevAccessToken();
|
|
8
|
+
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
9
|
});
|
|
10
|
-
describe('
|
|
10
|
+
describe('author = null', () => {
|
|
11
11
|
it('returns null', async () => {
|
|
12
12
|
const options = {
|
|
13
13
|
accessToken: devAccessToken,
|
|
14
|
-
|
|
15
|
-
all: true,
|
|
14
|
+
author: null,
|
|
16
15
|
};
|
|
17
|
-
expect(await fetchAuthorId_1.fetchAuthorId(options)).toEqual(null);
|
|
16
|
+
expect(await (0, fetchAuthorId_1.fetchAuthorId)(options)).toEqual(null);
|
|
18
17
|
});
|
|
19
18
|
});
|
|
20
|
-
describe('
|
|
19
|
+
describe('author is "sqren"', () => {
|
|
21
20
|
it('returns author id', async () => {
|
|
22
21
|
const options = {
|
|
23
22
|
accessToken: devAccessToken,
|
|
24
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
25
|
-
all: false,
|
|
26
23
|
author: 'sqren',
|
|
27
24
|
};
|
|
28
|
-
expect(await fetchAuthorId_1.fetchAuthorId(options)).toEqual('MDQ6VXNlcjIwOTk2Ng==');
|
|
25
|
+
expect(await (0, fetchAuthorId_1.fetchAuthorId)(options)).toEqual('MDQ6VXNlcjIwOTk2Ng==');
|
|
29
26
|
});
|
|
30
27
|
});
|
|
31
28
|
});
|
|
@@ -12,7 +12,7 @@ const apiRequestV4_1 = require("./apiRequestV4");
|
|
|
12
12
|
const getExistingTargetPullRequests_1 = require("./getExistingTargetPullRequests");
|
|
13
13
|
const getTargetBranchesFromLabels_1 = require("./getTargetBranchesFromLabels");
|
|
14
14
|
async function fetchCommitByPullNumber(options) {
|
|
15
|
-
const { accessToken, githubApiBaseUrlV4, pullNumber, repoName, repoOwner
|
|
15
|
+
const { accessToken, githubApiBaseUrlV4, pullNumber, repoName, repoOwner } = options;
|
|
16
16
|
const query = /* GraphQL */ `
|
|
17
17
|
query CommitByPullNumber(
|
|
18
18
|
$repoOwner: String!
|
|
@@ -21,17 +21,17 @@ async function fetchCommitByPullNumber(options) {
|
|
|
21
21
|
) {
|
|
22
22
|
repository(owner: $repoOwner, name: $repoName) {
|
|
23
23
|
pullRequest(number: $pullNumber) {
|
|
24
|
-
...${getExistingTargetPullRequests_1.
|
|
24
|
+
...${getExistingTargetPullRequests_1.pullRequestFragment.name}
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
${getExistingTargetPullRequests_1.pullRequestFragment}
|
|
29
|
+
${getExistingTargetPullRequests_1.pullRequestFragment.source}
|
|
30
30
|
`;
|
|
31
|
-
const spinner = ora_1.default(`Loading merge commit from pull request #${options.pullNumber}`).start();
|
|
31
|
+
const spinner = (0, ora_1.default)(`Loading merge commit from pull request #${options.pullNumber}`).start();
|
|
32
32
|
let res;
|
|
33
33
|
try {
|
|
34
|
-
res = await apiRequestV4_1.apiRequestV4({
|
|
34
|
+
res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
35
35
|
githubApiBaseUrlV4,
|
|
36
36
|
accessToken,
|
|
37
37
|
query,
|
|
@@ -51,10 +51,11 @@ async function fetchCommitByPullNumber(options) {
|
|
|
51
51
|
if (pullRequestNode.mergeCommit === null) {
|
|
52
52
|
throw new HandledError_1.HandledError(`The PR #${pullNumber} is not merged`);
|
|
53
53
|
}
|
|
54
|
+
const committedDate = pullRequestNode.mergeCommit.committedDate;
|
|
54
55
|
const sourceBranch = pullRequestNode.baseRefName;
|
|
55
56
|
const sha = pullRequestNode.mergeCommit.oid;
|
|
56
57
|
const commitMessage = pullRequestNode.mergeCommit.message;
|
|
57
|
-
const formattedMessage = commitFormatters_1.getFormattedCommitMessage({
|
|
58
|
+
const formattedMessage = (0, commitFormatters_1.getFormattedCommitMessage)({
|
|
58
59
|
message: commitMessage,
|
|
59
60
|
sha,
|
|
60
61
|
pullNumber,
|
|
@@ -64,14 +65,15 @@ async function fetchCommitByPullNumber(options) {
|
|
|
64
65
|
symbol: chalk_1.default.green('?'),
|
|
65
66
|
text: `${chalk_1.default.bold('Select pull request')} ${chalk_1.default.cyan(formattedMessage)}`,
|
|
66
67
|
});
|
|
67
|
-
const existingTargetPullRequests = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
|
|
68
|
-
const targetBranchesFromLabels = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
|
|
68
|
+
const existingTargetPullRequests = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
|
|
69
|
+
const targetBranchesFromLabels = (0, getTargetBranchesFromLabels_1.getTargetBranchesFromLabels)({
|
|
69
70
|
sourceBranch: pullRequestNode.baseRefName,
|
|
70
71
|
existingTargetPullRequests,
|
|
71
72
|
branchLabelMapping: options.branchLabelMapping,
|
|
72
|
-
labels: getExistingTargetPullRequests_1.getPullRequestLabels(pullRequestNode),
|
|
73
|
+
labels: (0, getExistingTargetPullRequests_1.getPullRequestLabels)(pullRequestNode),
|
|
73
74
|
});
|
|
74
75
|
return {
|
|
76
|
+
committedDate,
|
|
75
77
|
sourceBranch,
|
|
76
78
|
targetBranchesFromLabels,
|
|
77
79
|
sha,
|
|
@@ -5,7 +5,7 @@ const fetchCommitByPullNumber_1 = require("./fetchCommitByPullNumber");
|
|
|
5
5
|
describe('fetchCommitByPullNumber', () => {
|
|
6
6
|
let devAccessToken;
|
|
7
7
|
beforeAll(async () => {
|
|
8
|
-
devAccessToken = await getDevAccessToken_1.getDevAccessToken();
|
|
8
|
+
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
9
|
});
|
|
10
10
|
describe('when PR was merged', () => {
|
|
11
11
|
it('is returned', async () => {
|
|
@@ -16,7 +16,7 @@ describe('fetchCommitByPullNumber', () => {
|
|
|
16
16
|
repoName: 'backport-e2e',
|
|
17
17
|
repoOwner: 'backport-org',
|
|
18
18
|
};
|
|
19
|
-
expect(await fetchCommitByPullNumber_1.fetchCommitByPullNumber(options)).toEqual({
|
|
19
|
+
expect(await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).toEqual({
|
|
20
20
|
formattedMessage: 'Add 🍏 emoji (#5)',
|
|
21
21
|
originalMessage: 'Add 🍏 emoji (#5)',
|
|
22
22
|
pullNumber: 5,
|
|
@@ -39,7 +39,7 @@ describe('fetchCommitByPullNumber', () => {
|
|
|
39
39
|
repoName: 'backport-e2e',
|
|
40
40
|
repoOwner: 'backport-org',
|
|
41
41
|
};
|
|
42
|
-
await expect(fetchCommitByPullNumber_1.fetchCommitByPullNumber(options)).rejects.toThrowError(`The PR #11 is not merged`);
|
|
42
|
+
await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`The PR #11 is not merged`);
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
45
|
describe('when PR does not exist', () => {
|
|
@@ -51,7 +51,7 @@ describe('fetchCommitByPullNumber', () => {
|
|
|
51
51
|
repoName: 'backport-e2e',
|
|
52
52
|
repoOwner: 'backport-org',
|
|
53
53
|
};
|
|
54
|
-
await expect(fetchCommitByPullNumber_1.fetchCommitByPullNumber(options)).rejects.toThrowError(`Could not resolve to a PullRequest with the number of 9999999999999. (Github v4)`);
|
|
54
|
+
await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`Could not resolve to a PullRequest with the number of 9999999999999. (Unhandled Github v4 error)`);
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
57
|
});
|
|
@@ -12,19 +12,19 @@ const apiRequestV4_1 = require("./apiRequestV4");
|
|
|
12
12
|
const getExistingTargetPullRequests_1 = require("./getExistingTargetPullRequests");
|
|
13
13
|
const getTargetBranchesFromLabels_1 = require("./getTargetBranchesFromLabels");
|
|
14
14
|
async function fetchCommitBySha(options) {
|
|
15
|
-
var _a, _b;
|
|
16
15
|
const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
|
|
17
16
|
const query = /* GraphQL */ `
|
|
18
17
|
query CommitsBySha($repoOwner: String!, $repoName: String!, $oid: String!) {
|
|
19
18
|
repository(owner: $repoOwner, name: $repoName) {
|
|
20
19
|
object(expression: $oid) {
|
|
21
20
|
... on Commit {
|
|
21
|
+
committedDate
|
|
22
22
|
message
|
|
23
23
|
oid
|
|
24
24
|
associatedPullRequests(first: 1) {
|
|
25
25
|
edges {
|
|
26
26
|
node {
|
|
27
|
-
...${getExistingTargetPullRequests_1.
|
|
27
|
+
...${getExistingTargetPullRequests_1.pullRequestFragment.name}
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -33,12 +33,12 @@ async function fetchCommitBySha(options) {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
${getExistingTargetPullRequests_1.pullRequestFragment}
|
|
36
|
+
${getExistingTargetPullRequests_1.pullRequestFragment.source}
|
|
37
37
|
`;
|
|
38
|
-
const spinner = ora_1.default(`Loading commit "${commitFormatters_1.getShortSha(options.sha)}"`).start();
|
|
38
|
+
const spinner = (0, ora_1.default)(`Loading commit "${(0, commitFormatters_1.getShortSha)(options.sha)}"`).start();
|
|
39
39
|
let res;
|
|
40
40
|
try {
|
|
41
|
-
res = await apiRequestV4_1.apiRequestV4({
|
|
41
|
+
res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
42
42
|
githubApiBaseUrlV4,
|
|
43
43
|
accessToken,
|
|
44
44
|
query,
|
|
@@ -57,12 +57,13 @@ async function fetchCommitBySha(options) {
|
|
|
57
57
|
if (!res.repository.object) {
|
|
58
58
|
throw new HandledError_1.HandledError(`No commit found on branch "${options.sourceBranch}" with sha "${options.sha}"`);
|
|
59
59
|
}
|
|
60
|
+
const committedDate = res.repository.object.committedDate;
|
|
60
61
|
const sha = res.repository.object.oid;
|
|
61
62
|
const commitMessage = res.repository.object.message;
|
|
62
|
-
const pullRequestNode =
|
|
63
|
-
const pullNumber =
|
|
64
|
-
const sourceBranch =
|
|
65
|
-
const formattedMessage = commitFormatters_1.getFormattedCommitMessage({
|
|
63
|
+
const pullRequestNode = res.repository.object.associatedPullRequests.edges?.[0]?.node;
|
|
64
|
+
const pullNumber = pullRequestNode?.number || (0, commitFormatters_1.getPullNumberFromMessage)(commitMessage);
|
|
65
|
+
const sourceBranch = pullRequestNode?.baseRefName || options.sourceBranch;
|
|
66
|
+
const formattedMessage = (0, commitFormatters_1.getFormattedCommitMessage)({
|
|
66
67
|
message: commitMessage,
|
|
67
68
|
pullNumber,
|
|
68
69
|
sha,
|
|
@@ -71,16 +72,17 @@ async function fetchCommitBySha(options) {
|
|
|
71
72
|
symbol: chalk_1.default.green('?'),
|
|
72
73
|
text: `${chalk_1.default.bold('Select commit')} ${chalk_1.default.cyan(formattedMessage)}`,
|
|
73
74
|
});
|
|
74
|
-
const existingTargetPullRequests = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
|
|
75
|
+
const existingTargetPullRequests = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
|
|
75
76
|
const targetBranchesFromLabels = pullRequestNode
|
|
76
|
-
? getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
|
|
77
|
+
? (0, getTargetBranchesFromLabels_1.getTargetBranchesFromLabels)({
|
|
77
78
|
sourceBranch: pullRequestNode.baseRefName,
|
|
78
79
|
existingTargetPullRequests,
|
|
79
80
|
branchLabelMapping: options.branchLabelMapping,
|
|
80
|
-
labels: getExistingTargetPullRequests_1.getPullRequestLabels(pullRequestNode),
|
|
81
|
+
labels: (0, getExistingTargetPullRequests_1.getPullRequestLabels)(pullRequestNode),
|
|
81
82
|
})
|
|
82
83
|
: [];
|
|
83
84
|
return {
|
|
85
|
+
committedDate,
|
|
84
86
|
sourceBranch,
|
|
85
87
|
targetBranchesFromLabels,
|
|
86
88
|
sha,
|
|
@@ -5,10 +5,10 @@ const fetchCommitBySha_1 = require("./fetchCommitBySha");
|
|
|
5
5
|
describe('fetchCommitBySha', () => {
|
|
6
6
|
let devAccessToken;
|
|
7
7
|
beforeEach(async () => {
|
|
8
|
-
devAccessToken = await getDevAccessToken_1.getDevAccessToken();
|
|
8
|
+
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
9
|
});
|
|
10
10
|
it('should return single commit with pull request', async () => {
|
|
11
|
-
await expect(await fetchCommitBySha_1.fetchCommitBySha({
|
|
11
|
+
await expect(await (0, fetchCommitBySha_1.fetchCommitBySha)({
|
|
12
12
|
repoOwner: 'elastic',
|
|
13
13
|
repoName: 'kibana',
|
|
14
14
|
accessToken: devAccessToken,
|
|
@@ -28,7 +28,7 @@ describe('fetchCommitBySha', () => {
|
|
|
28
28
|
});
|
|
29
29
|
});
|
|
30
30
|
it('throws if sha does not exist', async () => {
|
|
31
|
-
await expect(fetchCommitBySha_1.fetchCommitBySha({
|
|
31
|
+
await expect((0, fetchCommitBySha_1.fetchCommitBySha)({
|
|
32
32
|
repoOwner: 'elastic',
|
|
33
33
|
repoName: 'kibana',
|
|
34
34
|
accessToken: devAccessToken,
|
|
@@ -38,7 +38,7 @@ describe('fetchCommitBySha', () => {
|
|
|
38
38
|
})).rejects.toThrowError('No commit found on branch "main" with sha "fc22f59"');
|
|
39
39
|
});
|
|
40
40
|
it('throws if sha is invalid', async () => {
|
|
41
|
-
await expect(fetchCommitBySha_1.fetchCommitBySha({
|
|
41
|
+
await expect((0, fetchCommitBySha_1.fetchCommitBySha)({
|
|
42
42
|
repoOwner: 'elastic',
|
|
43
43
|
repoName: 'kibana',
|
|
44
44
|
accessToken: devAccessToken,
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
historicalBranchLabelMappings: ValidConfigOptions['historicalBranchLabelMappings'];
|
|
8
|
+
pullNumber: number;
|
|
9
|
+
repoName: string;
|
|
10
|
+
repoOwner: string;
|
|
11
|
+
sourceBranch: string;
|
|
12
|
+
}): Promise<Commit>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchCommitByPullNumber = void 0;
|
|
4
|
+
const HandledError_1 = require("../../../HandledError");
|
|
5
|
+
const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
|
|
6
|
+
const apiRequestV4_1 = require("../apiRequestV4");
|
|
7
|
+
async function fetchCommitByPullNumber(options) {
|
|
8
|
+
const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', pullNumber, repoName, repoOwner, } = options;
|
|
9
|
+
const query = /* GraphQL */ `
|
|
10
|
+
query CommitByPullNumber(
|
|
11
|
+
$repoOwner: String!
|
|
12
|
+
$repoName: String!
|
|
13
|
+
$pullNumber: Int!
|
|
14
|
+
) {
|
|
15
|
+
repository(owner: $repoOwner, name: $repoName) {
|
|
16
|
+
pullRequest(number: $pullNumber) {
|
|
17
|
+
mergeCommit {
|
|
18
|
+
...${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.name}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
|
|
25
|
+
`;
|
|
26
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
27
|
+
githubApiBaseUrlV4,
|
|
28
|
+
accessToken,
|
|
29
|
+
query,
|
|
30
|
+
variables: {
|
|
31
|
+
repoOwner,
|
|
32
|
+
repoName,
|
|
33
|
+
pullNumber,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
const pullRequestNode = res.repository.pullRequest;
|
|
37
|
+
if (!pullRequestNode) {
|
|
38
|
+
throw new HandledError_1.HandledError(`The PR #${pullNumber} does not exist`);
|
|
39
|
+
}
|
|
40
|
+
const sourceCommit = pullRequestNode.mergeCommit;
|
|
41
|
+
if (sourceCommit === null) {
|
|
42
|
+
throw new HandledError_1.HandledError(`The PR #${pullNumber} is not merged`);
|
|
43
|
+
}
|
|
44
|
+
return (0, parseSourceCommit_1.parseSourceCommit)({ options, sourceCommit });
|
|
45
|
+
}
|
|
46
|
+
exports.fetchCommitByPullNumber = fetchCommitByPullNumber;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|