backport 5.6.4 → 6.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 +166 -41
- 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 +33 -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 +56 -39
- package/dist/options/cliArgs.d.ts +38 -45
- package/dist/options/cliArgs.js +123 -104
- package/dist/options/cliArgs.test.js +106 -119
- package/dist/options/config/config.d.ts +56 -2
- package/dist/options/config/config.js +12 -6
- package/dist/options/config/config.test.js +11 -6
- package/dist/options/config/getOptionsFromGit.d.ts +4 -0
- package/dist/options/config/getOptionsFromGit.js +8 -0
- package/dist/options/config/globalConfig.d.ts +2 -1
- 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 -1
- package/dist/options/config/projectConfig.js +3 -3
- package/dist/options/config/projectConfig.test.js +54 -17
- package/dist/options/config/readConfigFile.d.ts +53 -2
- package/dist/options/config/readConfigFile.js +31 -5
- package/dist/options/options.d.ts +67 -35
- package/dist/options/options.js +99 -16
- package/dist/options/options.test.js +214 -67
- package/dist/options/parseRequiredOptions.d.ts +71 -0
- package/dist/options/parseRequiredOptions.js +68 -0
- package/dist/options/parseRequiredOptions.test.d.ts +1 -0
- package/dist/options/parseRequiredOptions.test.js +122 -0
- package/dist/runSequentially.d.ts +20 -0
- package/dist/runSequentially.js +41 -0
- package/dist/runSequentially.test.d.ts +1 -0
- package/dist/runSequentially.test.js +192 -0
- package/dist/runWithOptions.js +7 -14
- package/dist/runWithOptions.test.js +142 -16
- package/dist/scripts/generate-gql.d.ts +1 -0
- package/dist/scripts/generate-gql.js +15 -0
- package/dist/scripts/postinstall.js +4 -4
- package/dist/scripts/postinstall.test.js +9 -2
- package/dist/scripts/runPostinstall.js +1 -1
- package/dist/services/HandledError.d.ts +11 -1
- package/dist/services/HandledError.js +2 -1
- package/dist/services/child-process-promisified.d.ts +1 -1
- package/dist/services/child-process-promisified.js +2 -2
- package/dist/services/env.js +5 -5
- package/dist/services/env.test.js +11 -4
- package/dist/services/fs-promisified.js +4 -4
- package/dist/services/getExpectedTarget.d.ts +9 -0
- package/dist/services/getExpectedTarget.js +77 -0
- package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
- package/dist/services/getExpectedTargetPullRequests.js +77 -0
- package/dist/services/git.d.ts +23 -5
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +168 -0
- package/dist/services/git.js +133 -60
- package/dist/services/git.test.js +160 -53
- 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 +32 -26
- package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/createPullRequest.test.js +78 -0
- package/dist/services/github/v3/createStatusComment.d.ts +11 -0
- package/dist/services/github/v3/createStatusComment.js +97 -0
- package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/services/github/v3/createStatusComment.test.js +209 -0
- package/dist/services/github/v4/FetchPullRequestId.d.ts +9 -0
- package/dist/services/github/v4/FetchPullRequestId.js +32 -0
- package/dist/services/github/v4/apiRequestV4.d.ts +2 -2
- package/dist/services/github/v4/apiRequestV4.js +9 -11
- package/dist/services/github/v4/apiRequestV4.test.js +7 -7
- package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +9 -0
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +28 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +9 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +51 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
- package/dist/services/github/v4/fetchAuthorId.d.ts +10 -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 +6 -6
- package/dist/services/github/v4/fetchCommitBySha.js +14 -12
- package/dist/services/github/v4/fetchCommitBySha.private.test.js +7 -5
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +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 +3 -2
- package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
- package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +81 -8
- package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
- package/dist/services/github/v4/fetchDefaultBranch.d.ts +1 -1
- package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +4 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.js +52 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +32 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.d.ts +4 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.js +72 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.js +34 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.d.ts +40 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.js +72 -0
- package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -5
- package/dist/services/github/v4/fetchMergedPullRequests.d.ts +19 -20
- package/dist/services/github/v4/fetchMergedPullRequests.js +22 -68
- package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
- package/dist/services/github/v4/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.d.ts +11 -0
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +35 -0
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.d.ts +1 -1
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +8 -6
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
- package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
- package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +66 -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 +63 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.js +139 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +147 -0
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +37 -0
- package/dist/services/github/v4/getOptionsFromGithub/query.js +47 -0
- package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
- package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
- package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
- package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +2 -2
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +2 -2
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +4 -1
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +1 -1
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
- package/dist/services/logger.d.ts +3 -3
- package/dist/services/logger.js +24 -24
- package/dist/services/prompt.test.d.ts +1 -0
- package/dist/services/prompt.test.js +87 -0
- package/dist/services/prompts.d.ts +10 -4
- package/dist/services/prompts.js +85 -22
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +396 -0
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +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 +105 -61
- package/dist/test/integration/createSpies.d.ts +1 -1
- package/dist/test/integration/createSpies.js +21 -9
- package/dist/test/integration/envConstants.js +5 -6
- package/dist/test/integration/helpers.js +1 -1
- package/dist/test/integration/integration.private.test.d.ts +1 -0
- package/dist/test/integration/integration.private.test.js +317 -0
- package/dist/test/integration/integration.test.js +30 -31
- package/dist/test/mockConfigFiles.d.ts +5 -0
- package/dist/test/mockConfigFiles.js +37 -0
- package/dist/test/nockHelpers.d.ts +3 -3
- 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 +333 -76
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +138 -67
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
- package/dist/ui/getCommits.d.ts +1 -1
- package/dist/ui/getCommits.js +55 -25
- package/dist/ui/getTargetBranches.d.ts +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 +2416 -2987
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ValidConfigOptions } from '../../../options/options';
|
|
2
|
+
export interface PullRequestAutoMergeResponse {
|
|
3
|
+
repository: {
|
|
4
|
+
pullRequest?: {
|
|
5
|
+
autoMergeRequest?: {
|
|
6
|
+
mergeMethod: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare function fetchPullRequestAutoMergeMethod(options: ValidConfigOptions, pullNumber: number): Promise<string | undefined>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchPullRequestAutoMergeMethod = void 0;
|
|
4
|
+
const apiRequestV4_1 = require("./apiRequestV4");
|
|
5
|
+
async function fetchPullRequestAutoMergeMethod(options, pullNumber) {
|
|
6
|
+
const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
|
|
7
|
+
const query = /* GraphQL */ `
|
|
8
|
+
query PullRequestAutoMergeMethod(
|
|
9
|
+
$repoOwner: String!
|
|
10
|
+
$repoName: String!
|
|
11
|
+
$pullNumber: Int!
|
|
12
|
+
) {
|
|
13
|
+
repository(owner: $repoOwner, name: $repoName) {
|
|
14
|
+
pullRequest(number: $pullNumber) {
|
|
15
|
+
autoMergeRequest {
|
|
16
|
+
enabledAt
|
|
17
|
+
mergeMethod
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
23
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
24
|
+
githubApiBaseUrlV4,
|
|
25
|
+
accessToken,
|
|
26
|
+
query,
|
|
27
|
+
variables: {
|
|
28
|
+
repoOwner,
|
|
29
|
+
repoName,
|
|
30
|
+
pullNumber,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
return res.repository.pullRequest?.autoMergeRequest?.mergeMethod;
|
|
34
|
+
}
|
|
35
|
+
exports.fetchPullRequestAutoMergeMethod = fetchPullRequestAutoMergeMethod;
|
|
@@ -2,7 +2,7 @@ import { ValidConfigOptions } from '../../../options/options';
|
|
|
2
2
|
import { Commit } from '../../../types/Commit';
|
|
3
3
|
import { PullRequestNode } from './getExistingTargetPullRequests';
|
|
4
4
|
export declare function fetchPullRequestBySearchQuery(options: ValidConfigOptions): Promise<Commit[]>;
|
|
5
|
-
export interface
|
|
5
|
+
export interface PullRequestBySearchQueryResponse {
|
|
6
6
|
search: {
|
|
7
7
|
nodes: PullRequestNode[];
|
|
8
8
|
};
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.fetchPullRequestBySearchQuery = void 0;
|
|
7
|
-
const
|
|
7
|
+
const lodash_1 = require("lodash");
|
|
8
8
|
const ora_1 = __importDefault(require("ora"));
|
|
9
9
|
const HandledError_1 = require("../../HandledError");
|
|
10
10
|
const commitFormatters_1 = require("../commitFormatters");
|
|
@@ -18,20 +18,20 @@ async function fetchPullRequestBySearchQuery(options) {
|
|
|
18
18
|
search(query: $query, type: ISSUE, first: $maxNumber) {
|
|
19
19
|
nodes {
|
|
20
20
|
... on PullRequest {
|
|
21
|
-
...${getExistingTargetPullRequests_1.
|
|
21
|
+
...${getExistingTargetPullRequests_1.pullRequestFragment.name}
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
${getExistingTargetPullRequests_1.pullRequestFragment}
|
|
27
|
+
${getExistingTargetPullRequests_1.pullRequestFragment.source}
|
|
28
28
|
`;
|
|
29
29
|
const authorFilter = all ? '' : `author:${author}`;
|
|
30
30
|
const searchQuery = `type:pr is:merged sort:updated-desc repo:${repoOwner}/${repoName} ${authorFilter} ${prFilter} base:${sourceBranch}`;
|
|
31
|
-
const spinner = ora_1.default('Loading pull requests...').start();
|
|
31
|
+
const spinner = (0, ora_1.default)('Loading pull requests...').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,
|
|
@@ -52,22 +52,24 @@ async function fetchPullRequestBySearchQuery(options) {
|
|
|
52
52
|
if (pullRequestNode.mergeCommit == null) {
|
|
53
53
|
throw new Error('Pull Request is not merged');
|
|
54
54
|
}
|
|
55
|
+
const committedDate = pullRequestNode.mergeCommit.committedDate;
|
|
55
56
|
const sha = pullRequestNode.mergeCommit.oid;
|
|
56
57
|
const pullNumber = pullRequestNode.number;
|
|
57
58
|
const commitMessage = pullRequestNode.mergeCommit.message;
|
|
58
|
-
const formattedMessage = commitFormatters_1.getFormattedCommitMessage({
|
|
59
|
+
const formattedMessage = (0, commitFormatters_1.getFormattedCommitMessage)({
|
|
59
60
|
message: commitMessage,
|
|
60
61
|
sha,
|
|
61
62
|
pullNumber,
|
|
62
63
|
});
|
|
63
|
-
const existingTargetPullRequests = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
|
|
64
|
-
const targetBranchesFromLabels = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
|
|
64
|
+
const existingTargetPullRequests = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
|
|
65
|
+
const targetBranchesFromLabels = (0, getTargetBranchesFromLabels_1.getTargetBranchesFromLabels)({
|
|
65
66
|
sourceBranch: pullRequestNode.baseRefName,
|
|
66
67
|
existingTargetPullRequests,
|
|
67
68
|
branchLabelMapping: options.branchLabelMapping,
|
|
68
|
-
labels: getExistingTargetPullRequests_1.getPullRequestLabels(pullRequestNode),
|
|
69
|
+
labels: (0, getExistingTargetPullRequests_1.getPullRequestLabels)(pullRequestNode),
|
|
69
70
|
});
|
|
70
71
|
const choice = {
|
|
72
|
+
committedDate,
|
|
71
73
|
sourceBranch,
|
|
72
74
|
targetBranchesFromLabels,
|
|
73
75
|
sha,
|
|
@@ -79,7 +81,7 @@ async function fetchPullRequestBySearchQuery(options) {
|
|
|
79
81
|
return choice;
|
|
80
82
|
});
|
|
81
83
|
// terminate if not commits were found
|
|
82
|
-
if (
|
|
84
|
+
if ((0, lodash_1.isEmpty)(commits)) {
|
|
83
85
|
const errorText = options.all
|
|
84
86
|
? `There are no pull requests matching the filter "${prFilter}"`
|
|
85
87
|
: `There are no commits by "${options.author}" matching the filter "${prFilter}". Try with \`--all\` for commits by all users or \`--author=<username>\` for commits from a specific user`;
|
|
@@ -5,7 +5,7 @@ const fetchPullRequestBySearchQuery_1 = require("./fetchPullRequestBySearchQuery
|
|
|
5
5
|
describe('fetchPullRequestBySearchQuery', () => {
|
|
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 filter does not match any PRs', () => {
|
|
11
11
|
it('throws an error', async () => {
|
|
@@ -20,7 +20,7 @@ describe('fetchPullRequestBySearchQuery', () => {
|
|
|
20
20
|
repoOwner: 'backport-org',
|
|
21
21
|
sourceBranch: 'master',
|
|
22
22
|
};
|
|
23
|
-
await expect(fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery(options)).rejects.toThrowError('There are no commits by "sqren" matching the filter "label:non-existing". Try with `--all` for commits by all users or `--author=<username>` for commits from a specific user');
|
|
23
|
+
await expect((0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)(options)).rejects.toThrowError('There are no commits by "sqren" matching the filter "label:non-existing". Try with `--all` for commits by all users or `--author=<username>` for commits from a specific user');
|
|
24
24
|
});
|
|
25
25
|
});
|
|
26
26
|
describe('when filter matches PRs', () => {
|
|
@@ -36,9 +36,11 @@ describe('fetchPullRequestBySearchQuery', () => {
|
|
|
36
36
|
repoOwner: 'backport-org',
|
|
37
37
|
sourceBranch: 'master',
|
|
38
38
|
};
|
|
39
|
-
expect(await fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery(options)).toEqual([
|
|
39
|
+
expect(await (0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)(options)).toEqual([
|
|
40
40
|
{
|
|
41
|
-
existingTargetPullRequests: [
|
|
41
|
+
existingTargetPullRequests: [
|
|
42
|
+
{ branch: '7.8', state: 'OPEN', number: 10 },
|
|
43
|
+
],
|
|
42
44
|
formattedMessage: 'Add sheep emoji (#9)',
|
|
43
45
|
originalMessage: 'Add sheep emoji (#9)',
|
|
44
46
|
pullNumber: 9,
|
|
@@ -48,8 +50,8 @@ describe('fetchPullRequestBySearchQuery', () => {
|
|
|
48
50
|
},
|
|
49
51
|
{
|
|
50
52
|
existingTargetPullRequests: [
|
|
51
|
-
{ branch: '7.x', state: 'MERGED' },
|
|
52
|
-
{ branch: '7.8', state: 'MERGED' },
|
|
53
|
+
{ branch: '7.x', state: 'MERGED', number: 6 },
|
|
54
|
+
{ branch: '7.8', state: 'MERGED', number: 7 },
|
|
53
55
|
],
|
|
54
56
|
formattedMessage: 'Add 🍏 emoji (#5)',
|
|
55
57
|
originalMessage: 'Add 🍏 emoji (#5)',
|
|
@@ -11,12 +11,12 @@ describe('fetchPullRequestBySearchQuery', () => {
|
|
|
11
11
|
let res;
|
|
12
12
|
let mockCalls;
|
|
13
13
|
beforeEach(async () => {
|
|
14
|
-
mockCalls = nockHelpers_1.mockGqlRequest({
|
|
14
|
+
mockCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
15
15
|
name: 'PullRequestBySearchQuery',
|
|
16
16
|
statusCode: 200,
|
|
17
17
|
body: { data: fetchPullRequestBySearchQueryMock_1.fetchPullRequestBySearchQueryMock },
|
|
18
18
|
});
|
|
19
|
-
res = await fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery({
|
|
19
|
+
res = await (0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)({
|
|
20
20
|
accessToken: 'myAccessToken',
|
|
21
21
|
all: false,
|
|
22
22
|
author: 'sqren',
|
|
@@ -1,61 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const pullRequestFragment: string;
|
|
3
|
-
export interface PullRequestNode {
|
|
4
|
-
baseRefName: string;
|
|
5
|
-
number: number;
|
|
6
|
-
mergeCommit: {
|
|
7
|
-
oid: string;
|
|
8
|
-
message: string;
|
|
9
|
-
} | null;
|
|
10
|
-
labels: {
|
|
11
|
-
nodes: {
|
|
12
|
-
name: string;
|
|
13
|
-
}[];
|
|
14
|
-
};
|
|
15
|
-
repository: {
|
|
16
|
-
owner: {
|
|
17
|
-
login: string;
|
|
18
|
-
};
|
|
19
|
-
name: string;
|
|
20
|
-
};
|
|
21
|
-
timelineItems: {
|
|
22
|
-
edges: TimelineItemEdge[];
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
interface TimeLinePullRequestItem {
|
|
26
|
-
node: {
|
|
27
|
-
source: {
|
|
28
|
-
__typename: 'PullRequest';
|
|
29
|
-
title: string;
|
|
30
|
-
state: 'OPEN' | 'CLOSED' | 'MERGED';
|
|
31
|
-
baseRefName: string;
|
|
32
|
-
number: number;
|
|
33
|
-
commits: {
|
|
34
|
-
edges: CommitEdge[];
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
interface IssueTimelineItem {
|
|
40
|
-
node: {
|
|
41
|
-
source: {
|
|
42
|
-
__typename: 'Issue';
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
declare type TimelineItemEdge = TimeLinePullRequestItem | IssueTimelineItem;
|
|
47
|
-
interface CommitEdge {
|
|
48
|
-
node: {
|
|
49
|
-
commit: {
|
|
50
|
-
message: string;
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
export declare function getPullRequestLabels(pullRequestNode?: PullRequestNode): string[] | undefined;
|
|
1
|
+
import { PullRequestNode } from '../../../types/Commit';
|
|
55
2
|
export declare type ExistingTargetPullRequests = ReturnType<typeof getExistingTargetPullRequests>;
|
|
56
3
|
export declare function getExistingTargetPullRequests(sourcePullRequest?: PullRequestNode): {
|
|
57
|
-
number:
|
|
58
|
-
branch:
|
|
59
|
-
state:
|
|
4
|
+
number: any;
|
|
5
|
+
branch: any;
|
|
6
|
+
state: any;
|
|
60
7
|
}[];
|
|
61
|
-
export {};
|
|
@@ -1,68 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getExistingTargetPullRequests =
|
|
3
|
+
exports.getExistingTargetPullRequests = void 0;
|
|
4
4
|
const filterEmpty_1 = require("../../../utils/filterEmpty");
|
|
5
5
|
const commitFormatters_1 = require("../commitFormatters");
|
|
6
|
-
exports.pullRequestFragmentName = 'ExistingTargetPullRequests';
|
|
7
|
-
exports.pullRequestFragment = `
|
|
8
|
-
fragment ${exports.pullRequestFragmentName} on PullRequest {
|
|
9
|
-
# Source PR
|
|
10
|
-
number
|
|
11
|
-
repository {
|
|
12
|
-
name
|
|
13
|
-
owner {
|
|
14
|
-
login
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
mergeCommit {
|
|
18
|
-
oid
|
|
19
|
-
message
|
|
20
|
-
}
|
|
21
|
-
labels(first: 50) {
|
|
22
|
-
nodes {
|
|
23
|
-
name
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
baseRefName
|
|
27
|
-
timelineItems(last: 20, itemTypes: CROSS_REFERENCED_EVENT) {
|
|
28
|
-
edges {
|
|
29
|
-
node {
|
|
30
|
-
... on CrossReferencedEvent {
|
|
31
|
-
source {
|
|
32
|
-
__typename
|
|
33
|
-
|
|
34
|
-
# Target PRs
|
|
35
|
-
... on PullRequest {
|
|
36
|
-
title
|
|
37
|
-
state
|
|
38
|
-
baseRefName
|
|
39
|
-
number
|
|
40
|
-
commits(first: 20) {
|
|
41
|
-
edges {
|
|
42
|
-
node {
|
|
43
|
-
commit {
|
|
44
|
-
message
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
`;
|
|
57
|
-
function getPullRequestLabels(pullRequestNode) {
|
|
58
|
-
return pullRequestNode === null || pullRequestNode === void 0 ? void 0 : pullRequestNode.labels.nodes.map((label) => label.name);
|
|
59
|
-
}
|
|
60
|
-
exports.getPullRequestLabels = getPullRequestLabels;
|
|
61
6
|
function getExistingTargetPullRequests(sourcePullRequest) {
|
|
62
7
|
if (!sourcePullRequest || !sourcePullRequest.mergeCommit) {
|
|
63
8
|
return [];
|
|
64
9
|
}
|
|
65
|
-
const sourcePRMergeCommitMessage = commitFormatters_1.getFirstCommitMessageLine(sourcePullRequest.mergeCommit.message);
|
|
10
|
+
const sourcePRMergeCommitMessage = (0, commitFormatters_1.getFirstCommitMessageLine)(sourcePullRequest.mergeCommit.message);
|
|
66
11
|
return sourcePullRequest.timelineItems.edges
|
|
67
12
|
.filter(filterEmpty_1.filterNil)
|
|
68
13
|
.filter(filterPullRequests)
|
|
@@ -73,7 +18,7 @@ function getExistingTargetPullRequests(sourcePullRequest) {
|
|
|
73
18
|
}
|
|
74
19
|
// at least one of the commits in the target pull request should match the merge commit from the source pull request
|
|
75
20
|
const commitMatch = source.commits.edges.some((commit) => {
|
|
76
|
-
const targetPRCommitMessage = commitFormatters_1.getFirstCommitMessageLine(commit.node.commit.message);
|
|
21
|
+
const targetPRCommitMessage = (0, commitFormatters_1.getFirstCommitMessageLine)(commit.node.commit.message);
|
|
77
22
|
return targetPRCommitMessage === sourcePRMergeCommitMessage;
|
|
78
23
|
});
|
|
79
24
|
const prTitleMatch = source.title.includes(sourcePRMergeCommitMessage);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export declare type OptionsFromGithub = Awaited<ReturnType<typeof getOptionsFromGithub>>;
|
|
2
|
+
export declare function getOptionsFromGithub(options: {
|
|
3
|
+
accessToken: string;
|
|
4
|
+
githubApiBaseUrlV4?: string;
|
|
5
|
+
repoName: string;
|
|
6
|
+
repoOwner: string;
|
|
7
|
+
skipRemoteConfig?: boolean;
|
|
8
|
+
}): Promise<{
|
|
9
|
+
historicalBranchLabelMappings: {
|
|
10
|
+
branchLabelMapping: Record<string, string>;
|
|
11
|
+
committedDate: string;
|
|
12
|
+
}[];
|
|
13
|
+
accessToken?: string | undefined;
|
|
14
|
+
assignees?: string[] | undefined;
|
|
15
|
+
author?: string | null | undefined;
|
|
16
|
+
autoAssign?: boolean | undefined;
|
|
17
|
+
autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
|
|
18
|
+
files: string[];
|
|
19
|
+
directory: string;
|
|
20
|
+
logger: {
|
|
21
|
+
error: (message: string, meta?: unknown) => void;
|
|
22
|
+
warn: (message: string, meta?: unknown) => void;
|
|
23
|
+
info: (message: string, meta?: unknown) => void;
|
|
24
|
+
verbose: (message: string, meta?: unknown) => void;
|
|
25
|
+
debug: (message: string, meta?: unknown) => void;
|
|
26
|
+
};
|
|
27
|
+
targetBranch: string;
|
|
28
|
+
}) => boolean | Promise<boolean>) | undefined;
|
|
29
|
+
autoMerge?: boolean | undefined;
|
|
30
|
+
autoMergeMethod?: string | undefined;
|
|
31
|
+
cherrypickRef?: boolean | undefined;
|
|
32
|
+
ci?: boolean | undefined;
|
|
33
|
+
commitPaths?: string[] | undefined;
|
|
34
|
+
details?: boolean | undefined;
|
|
35
|
+
editor?: string | undefined;
|
|
36
|
+
fork?: boolean | undefined;
|
|
37
|
+
gitHostname?: string | undefined;
|
|
38
|
+
githubApiBaseUrlV3?: string | undefined;
|
|
39
|
+
githubApiBaseUrlV4?: string | undefined;
|
|
40
|
+
maxNumber?: number | undefined;
|
|
41
|
+
multiple?: boolean | undefined;
|
|
42
|
+
multipleBranches?: boolean | undefined;
|
|
43
|
+
multipleCommits?: boolean | undefined;
|
|
44
|
+
noVerify?: boolean | undefined;
|
|
45
|
+
prDescription?: string | undefined;
|
|
46
|
+
prFilter?: string | undefined;
|
|
47
|
+
prTitle?: string | undefined;
|
|
48
|
+
pullNumber?: number | undefined;
|
|
49
|
+
repoName?: string | undefined;
|
|
50
|
+
repoOwner?: string | undefined;
|
|
51
|
+
resetAuthor?: boolean | undefined;
|
|
52
|
+
reviewers?: string[] | undefined;
|
|
53
|
+
sha?: string | undefined;
|
|
54
|
+
skipRemoteConfig?: boolean | undefined;
|
|
55
|
+
sourceBranch: string;
|
|
56
|
+
sourcePRLabels?: string[] | undefined;
|
|
57
|
+
targetBranchChoices?: import("../../../../options/ConfigOptions").TargetBranchChoiceOrString[] | undefined;
|
|
58
|
+
targetBranches?: string[] | undefined;
|
|
59
|
+
targetPRLabels?: string[] | undefined;
|
|
60
|
+
verbose?: boolean | undefined;
|
|
61
|
+
branchLabelMapping?: Record<string, string> | undefined;
|
|
62
|
+
upstream?: string | undefined;
|
|
63
|
+
branches?: import("../../../../options/ConfigOptions").TargetBranchChoiceOrString[] | undefined;
|
|
64
|
+
labels?: string[] | undefined;
|
|
65
|
+
authenticatedUsername: string;
|
|
66
|
+
}>;
|
|
@@ -0,0 +1,130 @@
|
|
|
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.getOptionsFromGithub = void 0;
|
|
7
|
+
const ora_1 = __importDefault(require("ora"));
|
|
8
|
+
const readConfigFile_1 = require("../../../../options/config/readConfigFile");
|
|
9
|
+
const filterEmpty_1 = require("../../../../utils/filterEmpty");
|
|
10
|
+
const HandledError_1 = require("../../../HandledError");
|
|
11
|
+
const git_1 = require("../../../git");
|
|
12
|
+
const logger_1 = require("../../../logger");
|
|
13
|
+
const apiRequestV4_1 = require("../apiRequestV4");
|
|
14
|
+
const throwOnInvalidAccessToken_1 = require("../throwOnInvalidAccessToken");
|
|
15
|
+
const query_1 = require("./query");
|
|
16
|
+
async function getOptionsFromGithub(options) {
|
|
17
|
+
const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
|
|
18
|
+
let res;
|
|
19
|
+
const spinner = (0, ora_1.default)().start('Initializing...');
|
|
20
|
+
try {
|
|
21
|
+
res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
22
|
+
githubApiBaseUrlV4,
|
|
23
|
+
accessToken,
|
|
24
|
+
query: query_1.query,
|
|
25
|
+
variables: { repoOwner, repoName },
|
|
26
|
+
handleError: false,
|
|
27
|
+
});
|
|
28
|
+
spinner.stop();
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
spinner.stop();
|
|
32
|
+
const error = e;
|
|
33
|
+
(0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
|
|
34
|
+
error,
|
|
35
|
+
repoName,
|
|
36
|
+
repoOwner,
|
|
37
|
+
});
|
|
38
|
+
res = handleMissingConfigFile(error);
|
|
39
|
+
}
|
|
40
|
+
// get the original repo (not the fork)
|
|
41
|
+
const repo = res.repository.isFork ? res.repository.parent : res.repository;
|
|
42
|
+
// it is not possible to have a branch named "backport"
|
|
43
|
+
if (repo.ref?.name === 'backport') {
|
|
44
|
+
throw new HandledError_1.HandledError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
|
|
45
|
+
}
|
|
46
|
+
const historicalRemoteConfigs = repo.defaultBranchRef.target.history.edges;
|
|
47
|
+
const latestRemoteConfig = historicalRemoteConfigs[0]?.remoteConfig;
|
|
48
|
+
const skipRemoteConfig = await getSkipRemoteConfigFile(options.skipRemoteConfig, latestRemoteConfig);
|
|
49
|
+
return {
|
|
50
|
+
authenticatedUsername: res.viewer.login,
|
|
51
|
+
sourceBranch: repo.defaultBranchRef.name,
|
|
52
|
+
...(skipRemoteConfig ? {} : parseRemoteConfig(latestRemoteConfig)),
|
|
53
|
+
historicalBranchLabelMappings: skipRemoteConfig
|
|
54
|
+
? []
|
|
55
|
+
: getHistoricalBranchLabelMappings(historicalRemoteConfigs),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
exports.getOptionsFromGithub = getOptionsFromGithub;
|
|
59
|
+
async function getSkipRemoteConfigFile(skipRemoteConfig, remoteConfig) {
|
|
60
|
+
if (skipRemoteConfig) {
|
|
61
|
+
logger_1.logger.info('Skipping remote config: `--skip-remote-config` specified via config file or cli');
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
if (!remoteConfig) {
|
|
65
|
+
logger_1.logger.info("Skipping remote config: remote config doesn't exist");
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
const [isLocalConfigModified, isLocalConfigUntracked, localCommitDate] = await Promise.all([
|
|
69
|
+
(0, git_1.isLocalConfigFileModified)(),
|
|
70
|
+
(0, git_1.isLocalConfigFileUntracked)(),
|
|
71
|
+
(0, git_1.getLocalConfigFileCommitDate)(),
|
|
72
|
+
]);
|
|
73
|
+
if (isLocalConfigUntracked) {
|
|
74
|
+
logger_1.logger.info('Skipping remote config: local config is new');
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
if (isLocalConfigModified) {
|
|
78
|
+
logger_1.logger.info('Skipping remote config: local config is modified');
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
if (localCommitDate &&
|
|
82
|
+
localCommitDate > Date.parse(remoteConfig.committedDate)) {
|
|
83
|
+
logger_1.logger.info(`Skipping remote config: local config is newer: ${new Date(localCommitDate).toISOString()} > ${remoteConfig.committedDate}`);
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
function parseRemoteConfig(remoteConfig) {
|
|
89
|
+
if (!remoteConfig) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
logger_1.logger.info('Using remote config');
|
|
94
|
+
return (0, readConfigFile_1.withConfigMigrations)(JSON.parse(remoteConfig.file.object.text));
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
logger_1.logger.info('Parsing remote config failed', e);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function getHistoricalBranchLabelMappings(historicalRemoteConfigs) {
|
|
102
|
+
return historicalRemoteConfigs
|
|
103
|
+
.map((edge) => {
|
|
104
|
+
try {
|
|
105
|
+
const remoteConfig = JSON.parse(edge.remoteConfig.file.object.text);
|
|
106
|
+
if (!remoteConfig.branchLabelMapping) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
branchLabelMapping: remoteConfig.branchLabelMapping,
|
|
111
|
+
committedDate: edge.remoteConfig.committedDate,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
logger_1.logger.info('Could not get historical remote config', e);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
.filter(filterEmpty_1.filterNil);
|
|
120
|
+
}
|
|
121
|
+
function handleMissingConfigFile(error) {
|
|
122
|
+
const wasMissingConfigError = error.response?.data.errors?.some((error) => error.type === 'NOT_FOUND' &&
|
|
123
|
+
error.path.join('.') ===
|
|
124
|
+
'repository.defaultBranchRef.target.history.edges.0.remoteConfig.file');
|
|
125
|
+
// Throw unexpected error
|
|
126
|
+
if (!wasMissingConfigError || !error.response?.data.data) {
|
|
127
|
+
throw (0, apiRequestV4_1.handleGithubV4Error)(error);
|
|
128
|
+
}
|
|
129
|
+
return error.response.data.data;
|
|
130
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,130 @@
|
|
|
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 os_1 = __importDefault(require("os"));
|
|
7
|
+
const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
|
|
8
|
+
const getOptionsFromGithub_1 = require("./getOptionsFromGithub");
|
|
9
|
+
describe('getOptionsFromGithub', () => {
|
|
10
|
+
let devAccessToken;
|
|
11
|
+
beforeAll(async () => {
|
|
12
|
+
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
13
|
+
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
14
|
+
});
|
|
15
|
+
describe('access token', () => {
|
|
16
|
+
describe('is invalid', () => {
|
|
17
|
+
it('throws an error', async () => {
|
|
18
|
+
const combinedOptions = {
|
|
19
|
+
author: 'sqren',
|
|
20
|
+
accessToken: 'foo',
|
|
21
|
+
repoOwner: 'backport-org',
|
|
22
|
+
repoName: 'backport-e2e',
|
|
23
|
+
};
|
|
24
|
+
await expect((0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions)).rejects.toThrowError('Please check your access token and make sure it is valid.\nConfig: /myHomeDir/.backport/config.json');
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe('is valid', () => {
|
|
28
|
+
it('returns the options', async () => {
|
|
29
|
+
const combinedOptions = {
|
|
30
|
+
author: 'sqren',
|
|
31
|
+
accessToken: devAccessToken,
|
|
32
|
+
repoOwner: 'backport-org',
|
|
33
|
+
repoName: 'backport-e2e',
|
|
34
|
+
};
|
|
35
|
+
expect(await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions)).toEqual({
|
|
36
|
+
authenticatedUsername: 'sqren',
|
|
37
|
+
branchLabelMapping: {
|
|
38
|
+
'^v(\\d+).(\\d+).\\d+$': '$1.$2',
|
|
39
|
+
'^v7.9.0$': '7.x',
|
|
40
|
+
'^v8.0.0$': 'master',
|
|
41
|
+
},
|
|
42
|
+
historicalBranchLabelMappings: [
|
|
43
|
+
{
|
|
44
|
+
branchLabelMapping: {
|
|
45
|
+
'^v(\\d+).(\\d+).\\d+$': '$1.$2',
|
|
46
|
+
'^v7.9.0$': '7.x',
|
|
47
|
+
'^v8.0.0$': 'master',
|
|
48
|
+
},
|
|
49
|
+
committedDate: '2020-08-15T10:33:06Z',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
branchLabelMapping: { '6.1': '6.1', '6.3': '6.3' },
|
|
53
|
+
committedDate: '2020-08-15T10:20:23Z',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
branchLabelMapping: { '6.1': '6.1', '6.3': '6.3' },
|
|
57
|
+
committedDate: '2020-08-15T10:17:57Z',
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
sourceBranch: 'master',
|
|
61
|
+
targetBranchChoices: [
|
|
62
|
+
{ checked: true, name: 'master' },
|
|
63
|
+
{ checked: true, name: '7.x' },
|
|
64
|
+
'7.8',
|
|
65
|
+
],
|
|
66
|
+
targetPRLabels: ['backport'],
|
|
67
|
+
repoOwner: 'backport-org',
|
|
68
|
+
repoName: 'backport-e2e',
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe('when `repoOwner` is fork', () => {
|
|
74
|
+
it('returns original repoOwner', async () => {
|
|
75
|
+
const combinedOptions = {
|
|
76
|
+
author: 'sqren',
|
|
77
|
+
accessToken: devAccessToken,
|
|
78
|
+
repoOwner: 'sqren',
|
|
79
|
+
repoName: 'backport-e2e',
|
|
80
|
+
};
|
|
81
|
+
const options = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
|
|
82
|
+
await expect(options.repoOwner).toEqual('backport-org');
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe('sourceBranch', () => {
|
|
86
|
+
describe('when no sourceBranch is specified', () => {
|
|
87
|
+
it('uses the default branch of the repo', async () => {
|
|
88
|
+
const combinedOptions = {
|
|
89
|
+
author: 'sqren',
|
|
90
|
+
accessToken: devAccessToken,
|
|
91
|
+
repoOwner: 'backport-org',
|
|
92
|
+
repoName: 'repo-with-non-standard-main-branch',
|
|
93
|
+
};
|
|
94
|
+
const options = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
|
|
95
|
+
await expect(options.sourceBranch).toEqual('my-custom-default-branch');
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
describe('when a branch named "backport"', () => {
|
|
100
|
+
describe('exists', () => {
|
|
101
|
+
it('shows a warning', async () => {
|
|
102
|
+
const combinedOptions = {
|
|
103
|
+
author: 'sqren',
|
|
104
|
+
accessToken: devAccessToken,
|
|
105
|
+
repoOwner: 'backport-org',
|
|
106
|
+
repoName: 'repo-with-branch-named-backport',
|
|
107
|
+
};
|
|
108
|
+
await expect(async () => {
|
|
109
|
+
await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
|
|
110
|
+
}).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
describe('when a backportrc.json config was deleted from repo', () => {
|
|
115
|
+
it('does not throw', async () => {
|
|
116
|
+
const combinedOptions = {
|
|
117
|
+
author: 'sqren',
|
|
118
|
+
accessToken: devAccessToken,
|
|
119
|
+
repoOwner: 'backport-org',
|
|
120
|
+
repoName: 'repo-with-backportrc-removed',
|
|
121
|
+
};
|
|
122
|
+
const options = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
|
|
123
|
+
expect(options).toEqual({
|
|
124
|
+
authenticatedUsername: 'sqren',
|
|
125
|
+
sourceBranch: 'main',
|
|
126
|
+
historicalBranchLabelMappings: [],
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|