backport 5.6.5 → 6.1.1
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 +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 -12
- package/dist/options/cliArgs.d.ts +36 -35
- package/dist/options/cliArgs.js +91 -52
- package/dist/options/cliArgs.test.js +41 -42
- package/dist/options/config/config.d.ts +34 -57
- package/dist/options/config/config.js +5 -39
- package/dist/options/config/config.test.js +11 -25
- 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 -49
- 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 -49
- package/dist/options/config/projectConfig.js +2 -2
- package/dist/options/config/projectConfig.test.js +53 -16
- package/dist/options/config/readConfigFile.d.ts +43 -39
- package/dist/options/config/readConfigFile.js +30 -4
- package/dist/options/options.d.ts +57 -31
- package/dist/options/options.js +102 -10
- package/dist/options/options.test.js +263 -61
- 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 +140 -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 -29
- 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 +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 +8 -10
- package/dist/services/github/v4/apiRequestV4.test.js +7 -7
- package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +1 -8
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +6 -32
- package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +1 -8
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +31 -40
- 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 +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.d.ts +11 -0
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +35 -0
- 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 +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 +19 -9
- package/dist/services/github/v4/getOptionsFromGithub/index.js +59 -19
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +119 -32
- 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.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 +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 +64 -49
- 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 +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 +2414 -2993
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.fetchCommitsByAuthor = 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");
|
|
@@ -12,8 +12,34 @@ const apiRequestV4_1 = require("./apiRequestV4");
|
|
|
12
12
|
const fetchAuthorId_1 = require("./fetchAuthorId");
|
|
13
13
|
const getExistingTargetPullRequests_1 = require("./getExistingTargetPullRequests");
|
|
14
14
|
const getTargetBranchesFromLabels_1 = require("./getTargetBranchesFromLabels");
|
|
15
|
+
function getCommitHistoryFragment(commitPath, index = 0) {
|
|
16
|
+
return /* GraphQL */ `
|
|
17
|
+
_${index}: history(
|
|
18
|
+
first: $maxNumber
|
|
19
|
+
author: { id: $authorId }
|
|
20
|
+
${commitPath ? `path: "${commitPath}"` : ''}
|
|
21
|
+
) {
|
|
22
|
+
edges {
|
|
23
|
+
node {
|
|
24
|
+
oid
|
|
25
|
+
message
|
|
26
|
+
committedDate
|
|
27
|
+
associatedPullRequests(first: 1) {
|
|
28
|
+
edges {
|
|
29
|
+
node {
|
|
30
|
+
...${getExistingTargetPullRequests_1.pullRequestFragment.name}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}`;
|
|
37
|
+
}
|
|
15
38
|
async function fetchCommitsByAuthor(options) {
|
|
16
|
-
const { accessToken, githubApiBaseUrlV4, maxNumber,
|
|
39
|
+
const { accessToken, githubApiBaseUrlV4, maxNumber, commitPaths, repoName, repoOwner, sourceBranch, } = options;
|
|
40
|
+
const commitHistoryFragment = commitPaths.length > 0
|
|
41
|
+
? commitPaths.map(getCommitHistoryFragment).join('\n')
|
|
42
|
+
: getCommitHistoryFragment(null);
|
|
17
43
|
const query = /* GraphQL */ `
|
|
18
44
|
query CommitsByAuthor(
|
|
19
45
|
$repoOwner: String!
|
|
@@ -21,44 +47,25 @@ async function fetchCommitsByAuthor(options) {
|
|
|
21
47
|
$maxNumber: Int!
|
|
22
48
|
$sourceBranch: String!
|
|
23
49
|
$authorId: ID
|
|
24
|
-
$historyPath: String
|
|
25
50
|
) {
|
|
26
51
|
repository(owner: $repoOwner, name: $repoName) {
|
|
27
52
|
ref(qualifiedName: $sourceBranch) {
|
|
28
53
|
target {
|
|
29
54
|
... on Commit {
|
|
30
|
-
|
|
31
|
-
first: $maxNumber
|
|
32
|
-
author: { id: $authorId }
|
|
33
|
-
path: $historyPath
|
|
34
|
-
) {
|
|
35
|
-
edges {
|
|
36
|
-
node {
|
|
37
|
-
oid
|
|
38
|
-
message
|
|
39
|
-
associatedPullRequests(first: 1) {
|
|
40
|
-
edges {
|
|
41
|
-
node {
|
|
42
|
-
...${getExistingTargetPullRequests_1.pullRequestFragmentName}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
55
|
+
${commitHistoryFragment}
|
|
49
56
|
}
|
|
50
57
|
}
|
|
51
58
|
}
|
|
52
59
|
}
|
|
53
60
|
}
|
|
54
61
|
|
|
55
|
-
${getExistingTargetPullRequests_1.pullRequestFragment}
|
|
62
|
+
${getExistingTargetPullRequests_1.pullRequestFragment.source}
|
|
56
63
|
`;
|
|
57
|
-
const spinner = ora_1.default(`Loading commits from branch "${sourceBranch}"...`).start();
|
|
64
|
+
const spinner = (0, ora_1.default)(`Loading commits from branch "${sourceBranch}"...`).start();
|
|
58
65
|
let res;
|
|
59
66
|
try {
|
|
60
|
-
const authorId = await fetchAuthorId_1.fetchAuthorId(options);
|
|
61
|
-
res = await apiRequestV4_1.apiRequestV4({
|
|
67
|
+
const authorId = await (0, fetchAuthorId_1.fetchAuthorId)(options);
|
|
68
|
+
res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
62
69
|
githubApiBaseUrlV4,
|
|
63
70
|
accessToken,
|
|
64
71
|
query,
|
|
@@ -68,7 +75,6 @@ async function fetchCommitsByAuthor(options) {
|
|
|
68
75
|
sourceBranch,
|
|
69
76
|
maxNumber,
|
|
70
77
|
authorId,
|
|
71
|
-
historyPath: path || null,
|
|
72
78
|
},
|
|
73
79
|
});
|
|
74
80
|
spinner.stop();
|
|
@@ -80,71 +86,76 @@ async function fetchCommitsByAuthor(options) {
|
|
|
80
86
|
if (res.repository.ref === null) {
|
|
81
87
|
throw new HandledError_1.HandledError(`The upstream branch "${sourceBranch}" does not exist. Try specifying a different branch with "--source-branch <your-branch>"`);
|
|
82
88
|
}
|
|
83
|
-
const commits = res.repository.ref.target.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
const commits = Object.values(res.repository.ref.target).flatMap((historyResponse) => {
|
|
90
|
+
return historyResponse.edges.map((edge) => {
|
|
91
|
+
const commitMessage = edge.node.message;
|
|
92
|
+
const sha = edge.node.oid;
|
|
93
|
+
const committedDate = edge.node.committedDate;
|
|
94
|
+
// it is assumed that there can only be a single PR associated with a commit
|
|
95
|
+
// that assumption might not hold true forever but for now it works out
|
|
96
|
+
const pullRequestNode = edge.node.associatedPullRequests.edges[0]?.node;
|
|
97
|
+
// the source pull request for the commit cannot be retrieved
|
|
98
|
+
// This happens if the commits was pushed directly to a branch (not merging via a PR)
|
|
99
|
+
if (!isSourcePullRequest({ pullRequestNode, options, sha })) {
|
|
100
|
+
const pullNumber = (0, commitFormatters_1.getPullNumberFromMessage)(commitMessage);
|
|
101
|
+
const formattedMessage = (0, commitFormatters_1.getFormattedCommitMessage)({
|
|
102
|
+
message: commitMessage,
|
|
103
|
+
pullNumber,
|
|
104
|
+
sha,
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
committedDate,
|
|
108
|
+
sourceBranch,
|
|
109
|
+
targetBranchesFromLabels: [],
|
|
110
|
+
sha,
|
|
111
|
+
formattedMessage,
|
|
112
|
+
originalMessage: commitMessage,
|
|
113
|
+
pullNumber,
|
|
114
|
+
existingTargetPullRequests: [],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const pullNumber = pullRequestNode.number;
|
|
118
|
+
const formattedMessage = (0, commitFormatters_1.getFormattedCommitMessage)({
|
|
95
119
|
message: commitMessage,
|
|
96
120
|
pullNumber,
|
|
97
121
|
sha,
|
|
98
122
|
});
|
|
123
|
+
const existingTargetPullRequests = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
|
|
124
|
+
const targetBranchesFromLabels = (0, getTargetBranchesFromLabels_1.getTargetBranchesFromLabels)({
|
|
125
|
+
sourceBranch: pullRequestNode.baseRefName,
|
|
126
|
+
existingTargetPullRequests,
|
|
127
|
+
branchLabelMapping: options.branchLabelMapping,
|
|
128
|
+
labels: (0, getExistingTargetPullRequests_1.getPullRequestLabels)(pullRequestNode),
|
|
129
|
+
});
|
|
99
130
|
return {
|
|
131
|
+
committedDate,
|
|
100
132
|
sourceBranch,
|
|
101
|
-
targetBranchesFromLabels
|
|
133
|
+
targetBranchesFromLabels,
|
|
102
134
|
sha,
|
|
103
135
|
formattedMessage,
|
|
104
136
|
originalMessage: commitMessage,
|
|
105
137
|
pullNumber,
|
|
106
|
-
existingTargetPullRequests
|
|
138
|
+
existingTargetPullRequests,
|
|
107
139
|
};
|
|
108
|
-
}
|
|
109
|
-
const pullNumber = pullRequestNode.number;
|
|
110
|
-
const formattedMessage = commitFormatters_1.getFormattedCommitMessage({
|
|
111
|
-
message: commitMessage,
|
|
112
|
-
pullNumber,
|
|
113
|
-
sha,
|
|
114
|
-
});
|
|
115
|
-
const existingTargetPullRequests = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
|
|
116
|
-
const targetBranchesFromLabels = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
|
|
117
|
-
sourceBranch: pullRequestNode.baseRefName,
|
|
118
|
-
existingTargetPullRequests,
|
|
119
|
-
branchLabelMapping: options.branchLabelMapping,
|
|
120
|
-
labels: getExistingTargetPullRequests_1.getPullRequestLabels(pullRequestNode),
|
|
121
140
|
});
|
|
122
|
-
return {
|
|
123
|
-
sourceBranch,
|
|
124
|
-
targetBranchesFromLabels,
|
|
125
|
-
sha,
|
|
126
|
-
formattedMessage,
|
|
127
|
-
originalMessage: commitMessage,
|
|
128
|
-
pullNumber,
|
|
129
|
-
existingTargetPullRequests,
|
|
130
|
-
};
|
|
131
141
|
});
|
|
132
142
|
// terminate if not commits were found
|
|
133
|
-
if (
|
|
134
|
-
const pathText = options.
|
|
135
|
-
? ` touching files in path: "${options.
|
|
143
|
+
if ((0, lodash_1.isEmpty)(commits)) {
|
|
144
|
+
const pathText = options.commitPaths.length > 0
|
|
145
|
+
? ` touching files in path: "${options.commitPaths}"`
|
|
136
146
|
: '';
|
|
137
147
|
const errorText = options.all
|
|
138
148
|
? `There are no commits in this repository${pathText}`
|
|
139
149
|
: `There are no commits by "${options.author}" in this repository${pathText}. Try with \`--all\` for commits by all users or \`--author=<username>\` for commits from a specific user`;
|
|
140
150
|
throw new HandledError_1.HandledError(errorText);
|
|
141
151
|
}
|
|
142
|
-
|
|
152
|
+
const commitsUnique = (0, lodash_1.uniqBy)(commits, 'sha');
|
|
153
|
+
const commitsSorted = (0, lodash_1.orderBy)(commitsUnique, 'committedDate', 'desc');
|
|
154
|
+
return commitsSorted;
|
|
143
155
|
}
|
|
144
156
|
exports.fetchCommitsByAuthor = fetchCommitsByAuthor;
|
|
145
157
|
function isSourcePullRequest({ pullRequestNode, options, sha, }) {
|
|
146
|
-
|
|
147
|
-
return ((pullRequestNode === null || pullRequestNode === void 0 ? void 0 : pullRequestNode.repository.name) === options.repoName &&
|
|
158
|
+
return (pullRequestNode?.repository.name === options.repoName &&
|
|
148
159
|
pullRequestNode.repository.owner.login === options.repoOwner &&
|
|
149
|
-
|
|
160
|
+
pullRequestNode.mergeCommit?.oid === sha);
|
|
150
161
|
}
|
|
@@ -5,12 +5,84 @@ const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
|
|
|
5
5
|
describe('fetchCommitsByAuthor', () => {
|
|
6
6
|
let devAccessToken;
|
|
7
7
|
beforeAll(async () => {
|
|
8
|
-
devAccessToken = await getDevAccessToken_1.getDevAccessToken();
|
|
8
|
+
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
|
+
});
|
|
10
|
+
describe('commitPaths', () => {
|
|
11
|
+
const getOptions = () => ({
|
|
12
|
+
repoOwner: 'backport-org',
|
|
13
|
+
repoName: 'repo-with-different-commit-paths',
|
|
14
|
+
sourceBranch: 'main',
|
|
15
|
+
accessToken: devAccessToken,
|
|
16
|
+
username: 'sqren',
|
|
17
|
+
author: 'sqren',
|
|
18
|
+
maxNumber: 10,
|
|
19
|
+
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
20
|
+
});
|
|
21
|
+
const getCommitMessages = (commits) => {
|
|
22
|
+
return commits.map((c) => c.originalMessage.replace(/(\r\n|\n|\r)/gm, ''));
|
|
23
|
+
};
|
|
24
|
+
it('returns all commits', async () => {
|
|
25
|
+
const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
26
|
+
...getOptions(),
|
|
27
|
+
commitPaths: [],
|
|
28
|
+
});
|
|
29
|
+
const commitMessages = getCommitMessages(commits);
|
|
30
|
+
expect(commitMessages).toEqual([
|
|
31
|
+
'Edit all lyrics',
|
|
32
|
+
'Update .backportrc.json',
|
|
33
|
+
'Edit "Take on me"',
|
|
34
|
+
'Add backportrc.json',
|
|
35
|
+
'Add "Bohemian Rhapsody""',
|
|
36
|
+
'Add "99 Luftballons"',
|
|
37
|
+
'Add "Take on me"',
|
|
38
|
+
]);
|
|
39
|
+
});
|
|
40
|
+
it('only returns commits related to "99-luftballons.txt"', async () => {
|
|
41
|
+
const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
42
|
+
...getOptions(),
|
|
43
|
+
commitPaths: ['lyrics/99-luftballons.txt'],
|
|
44
|
+
});
|
|
45
|
+
const commitMessages = getCommitMessages(commits);
|
|
46
|
+
expect(commitMessages).toEqual([
|
|
47
|
+
'Edit all lyrics',
|
|
48
|
+
'Add "99 Luftballons"',
|
|
49
|
+
]);
|
|
50
|
+
});
|
|
51
|
+
it('only returns commits related to "take-on-me.txt"', async () => {
|
|
52
|
+
const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
53
|
+
...getOptions(),
|
|
54
|
+
commitPaths: ['lyrics/take-on-me.txt'],
|
|
55
|
+
});
|
|
56
|
+
const commitMessages = getCommitMessages(commits);
|
|
57
|
+
expect(commitMessages).toEqual([
|
|
58
|
+
'Edit all lyrics',
|
|
59
|
+
'Edit "Take on me"',
|
|
60
|
+
'Add "Take on me"',
|
|
61
|
+
]);
|
|
62
|
+
});
|
|
63
|
+
it('removes duplicates and order by `committedDate`', async () => {
|
|
64
|
+
const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
65
|
+
...getOptions(),
|
|
66
|
+
commitPaths: [
|
|
67
|
+
'lyrics/99-luftballons.txt',
|
|
68
|
+
'lyrics/take-on-me.txt',
|
|
69
|
+
'lyrics/bohemian-rhapsody.txt',
|
|
70
|
+
],
|
|
71
|
+
});
|
|
72
|
+
const commitMessages = getCommitMessages(commits);
|
|
73
|
+
expect(commitMessages).toEqual([
|
|
74
|
+
'Edit all lyrics',
|
|
75
|
+
'Edit "Take on me"',
|
|
76
|
+
'Add "Bohemian Rhapsody""',
|
|
77
|
+
'Add "99 Luftballons"',
|
|
78
|
+
'Add "Take on me"',
|
|
79
|
+
]);
|
|
80
|
+
});
|
|
9
81
|
});
|
|
10
82
|
describe('existingTargetPullRequests', () => {
|
|
11
83
|
let res;
|
|
12
84
|
beforeEach(async () => {
|
|
13
|
-
res = await fetchCommitsByAuthor_1.fetchCommitsByAuthor({
|
|
85
|
+
res = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
14
86
|
repoOwner: 'backport-org',
|
|
15
87
|
repoName: 'backport-e2e',
|
|
16
88
|
sourceBranch: 'master',
|
|
@@ -19,24 +91,25 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
19
91
|
author: 'sqren',
|
|
20
92
|
maxNumber: 10,
|
|
21
93
|
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
94
|
+
commitPaths: [],
|
|
22
95
|
});
|
|
23
96
|
});
|
|
24
97
|
it('returns related OPEN PRs', async () => {
|
|
25
98
|
const commitWithOpenPR = res.find((commit) => commit.pullNumber === 9);
|
|
26
|
-
expect(commitWithOpenPR
|
|
99
|
+
expect(commitWithOpenPR?.existingTargetPullRequests).toEqual([
|
|
27
100
|
{ branch: '7.8', state: 'OPEN', number: 10 },
|
|
28
101
|
]);
|
|
29
102
|
});
|
|
30
103
|
it('returns related MERGED PRs', async () => {
|
|
31
104
|
const commitWithMergedPRs = res.find((commit) => commit.pullNumber === 5);
|
|
32
|
-
expect(commitWithMergedPRs
|
|
105
|
+
expect(commitWithMergedPRs?.existingTargetPullRequests).toEqual([
|
|
33
106
|
{ branch: '7.x', state: 'MERGED', number: 6 },
|
|
34
107
|
{ branch: '7.8', state: 'MERGED', number: 7 },
|
|
35
108
|
]);
|
|
36
109
|
});
|
|
37
110
|
it('returns empty if there are no related PRs', async () => {
|
|
38
111
|
const commitWithoutPRs = res.find((commit) => commit.pullNumber === 8);
|
|
39
|
-
expect(commitWithoutPRs
|
|
112
|
+
expect(commitWithoutPRs?.existingTargetPullRequests).toEqual([]);
|
|
40
113
|
});
|
|
41
114
|
});
|
|
42
115
|
});
|
|
@@ -20,6 +20,7 @@ const defaultOptions = {
|
|
|
20
20
|
maxNumber: 10,
|
|
21
21
|
githubApiBaseUrlV3: 'https://api.github.com',
|
|
22
22
|
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
23
|
+
commitPaths: [],
|
|
23
24
|
};
|
|
24
25
|
const authorIdMockData = { user: { id: 'myUserId' } };
|
|
25
26
|
describe('fetchCommitsByAuthor', () => {
|
|
@@ -34,21 +35,22 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
34
35
|
let authorIdCalls;
|
|
35
36
|
let commitsByAuthorCalls;
|
|
36
37
|
beforeEach(async () => {
|
|
37
|
-
authorIdCalls = nockHelpers_1.mockGqlRequest({
|
|
38
|
+
authorIdCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
38
39
|
name: 'AuthorId',
|
|
39
40
|
statusCode: 200,
|
|
40
41
|
body: { data: authorIdMockData },
|
|
41
42
|
});
|
|
42
|
-
commitsByAuthorCalls = nockHelpers_1.mockGqlRequest({
|
|
43
|
+
commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
43
44
|
name: 'CommitsByAuthor',
|
|
44
45
|
statusCode: 200,
|
|
45
46
|
body: { data: commitsByAuthorMock_1.commitsWithPullRequestsMock },
|
|
46
47
|
});
|
|
47
|
-
res = await fetchCommitsByAuthor_1.fetchCommitsByAuthor(defaultOptions);
|
|
48
|
+
res = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)(defaultOptions);
|
|
48
49
|
});
|
|
49
|
-
it('
|
|
50
|
+
it('should return a list of commits with pullNumber and existing backports', () => {
|
|
50
51
|
const expectedCommits = [
|
|
51
52
|
{
|
|
53
|
+
committedDate: '2021-12-24T00:00:00Z',
|
|
52
54
|
sha: '2e63475c483f7844b0f2833bc57fdee32095bacb',
|
|
53
55
|
formattedMessage: 'Add 👻 (2e63475c)',
|
|
54
56
|
originalMessage: 'Add 👻',
|
|
@@ -57,6 +59,7 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
57
59
|
sourceBranch: 'master',
|
|
58
60
|
},
|
|
59
61
|
{
|
|
62
|
+
committedDate: '2021-12-23T00:00:00Z',
|
|
60
63
|
sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
|
|
61
64
|
formattedMessage: 'Add witch (#85)',
|
|
62
65
|
originalMessage: 'Add witch (#85)',
|
|
@@ -66,6 +69,7 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
66
69
|
sourceBranch: 'master',
|
|
67
70
|
},
|
|
68
71
|
{
|
|
72
|
+
committedDate: '2021-12-22T00:00:00Z',
|
|
69
73
|
sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
|
|
70
74
|
formattedMessage: 'Add SF mention (#80)',
|
|
71
75
|
originalMessage: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
@@ -77,6 +81,7 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
77
81
|
sourceBranch: 'master',
|
|
78
82
|
},
|
|
79
83
|
{
|
|
84
|
+
committedDate: '2021-12-21T00:00:00Z',
|
|
80
85
|
sha: '3827bbbaf39914eda4f02f6940189844375fd097',
|
|
81
86
|
formattedMessage: 'Add backport config (3827bbba)',
|
|
82
87
|
originalMessage: 'Add backport config',
|
|
@@ -85,6 +90,7 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
85
90
|
sourceBranch: 'master',
|
|
86
91
|
},
|
|
87
92
|
{
|
|
93
|
+
committedDate: '2021-12-20T00:00:00Z',
|
|
88
94
|
sha: '5ea0da550ac191029459289d67f99ad7d310812b',
|
|
89
95
|
formattedMessage: 'Initial commit (5ea0da55)',
|
|
90
96
|
originalMessage: 'Initial commit',
|
|
@@ -107,6 +113,7 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
107
113
|
const res = await getExistingBackportsByRepoName('kibana', 'kibana');
|
|
108
114
|
const expectedCommits = [
|
|
109
115
|
{
|
|
116
|
+
committedDate: '2021-12-13T22:46:29Z',
|
|
110
117
|
existingTargetPullRequests: [
|
|
111
118
|
{ branch: '6.3', state: 'MERGED', number: 99 },
|
|
112
119
|
],
|
|
@@ -124,6 +131,7 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
124
131
|
const res = await getExistingBackportsByRepoName('kibana', 'kibana2');
|
|
125
132
|
const expectedCommits = [
|
|
126
133
|
{
|
|
134
|
+
committedDate: '2021-12-13T22:46:29Z',
|
|
127
135
|
existingTargetPullRequests: [],
|
|
128
136
|
formattedMessage: 'Add SF mention (#80)',
|
|
129
137
|
originalMessage: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
@@ -138,19 +146,19 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
138
146
|
});
|
|
139
147
|
describe('when a custom github api hostname is supplied', () => {
|
|
140
148
|
it('should be used in gql requests', async () => {
|
|
141
|
-
const authorIdCalls = nockHelpers_1.mockGqlRequest({
|
|
149
|
+
const authorIdCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
142
150
|
name: 'AuthorId',
|
|
143
151
|
statusCode: 200,
|
|
144
152
|
body: { data: authorIdMockData },
|
|
145
153
|
apiBaseUrl: 'http://localhost/my-custom-api',
|
|
146
154
|
});
|
|
147
|
-
const commitsByAuthorCalls = nockHelpers_1.mockGqlRequest({
|
|
155
|
+
const commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
148
156
|
name: 'CommitsByAuthor',
|
|
149
157
|
statusCode: 200,
|
|
150
158
|
body: { data: commitsByAuthorMock_1.commitsWithPullRequestsMock },
|
|
151
159
|
apiBaseUrl: 'http://localhost/my-custom-api',
|
|
152
160
|
});
|
|
153
|
-
await fetchCommitsByAuthor_1.fetchCommitsByAuthor({
|
|
161
|
+
await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
154
162
|
...defaultOptions,
|
|
155
163
|
githubApiBaseUrlV4: 'http://localhost/my-custom-api',
|
|
156
164
|
});
|
|
@@ -164,7 +172,7 @@ describe('getExistingTargetPullRequests', () => {
|
|
|
164
172
|
nock_1.default.cleanAll();
|
|
165
173
|
});
|
|
166
174
|
it('should return a result when commit messages match', () => {
|
|
167
|
-
const pullRequestNode = getPullRequestNodeMock_1.getPullRequestNodeMock({
|
|
175
|
+
const pullRequestNode = (0, getPullRequestNodeMock_1.getPullRequestNodeMock)({
|
|
168
176
|
sourcePullRequest: {
|
|
169
177
|
number: 1234,
|
|
170
178
|
commitMessage: 'my message (#1234)',
|
|
@@ -175,13 +183,13 @@ describe('getExistingTargetPullRequests', () => {
|
|
|
175
183
|
commitMessages: ['my message (#1234)'],
|
|
176
184
|
},
|
|
177
185
|
});
|
|
178
|
-
const existingPRs = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
|
|
186
|
+
const existingPRs = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
|
|
179
187
|
expect(existingPRs).toEqual([
|
|
180
188
|
{ branch: '7.x', state: 'MERGED', number: 10 },
|
|
181
189
|
]);
|
|
182
190
|
});
|
|
183
191
|
it('should not return a result when commit messages do not match', () => {
|
|
184
|
-
const pullRequestNode = getPullRequestNodeMock_1.getPullRequestNodeMock({
|
|
192
|
+
const pullRequestNode = (0, getPullRequestNodeMock_1.getPullRequestNodeMock)({
|
|
185
193
|
sourcePullRequest: {
|
|
186
194
|
number: 1234,
|
|
187
195
|
commitMessage: 'the initial message',
|
|
@@ -192,11 +200,11 @@ describe('getExistingTargetPullRequests', () => {
|
|
|
192
200
|
commitMessages: ['my changed message (#1234)'],
|
|
193
201
|
},
|
|
194
202
|
});
|
|
195
|
-
const existingPRs = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
|
|
203
|
+
const existingPRs = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
|
|
196
204
|
expect(existingPRs).toEqual([]);
|
|
197
205
|
});
|
|
198
206
|
it('should return a result when commit message matches pull request title and number', () => {
|
|
199
|
-
const pullRequestNode = getPullRequestNodeMock_1.getPullRequestNodeMock({
|
|
207
|
+
const pullRequestNode = (0, getPullRequestNodeMock_1.getPullRequestNodeMock)({
|
|
200
208
|
sourcePullRequest: {
|
|
201
209
|
number: 1234,
|
|
202
210
|
commitMessage: 'the initial message',
|
|
@@ -207,13 +215,13 @@ describe('getExistingTargetPullRequests', () => {
|
|
|
207
215
|
commitMessages: ['the actual message'],
|
|
208
216
|
},
|
|
209
217
|
});
|
|
210
|
-
const existingPRs = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
|
|
218
|
+
const existingPRs = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
|
|
211
219
|
expect(existingPRs).toEqual([
|
|
212
220
|
{ branch: '7.x', state: 'MERGED', number: 40 },
|
|
213
221
|
]);
|
|
214
222
|
});
|
|
215
223
|
it('should not return a result when only pull request title (but not pull number) matches', () => {
|
|
216
|
-
const pullRequestNode = getPullRequestNodeMock_1.getPullRequestNodeMock({
|
|
224
|
+
const pullRequestNode = (0, getPullRequestNodeMock_1.getPullRequestNodeMock)({
|
|
217
225
|
sourcePullRequest: {
|
|
218
226
|
number: 1234,
|
|
219
227
|
commitMessage: 'my message',
|
|
@@ -224,11 +232,11 @@ describe('getExistingTargetPullRequests', () => {
|
|
|
224
232
|
commitMessages: ['the actual message'],
|
|
225
233
|
},
|
|
226
234
|
});
|
|
227
|
-
const existingPRs = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
|
|
235
|
+
const existingPRs = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
|
|
228
236
|
expect(existingPRs).toEqual([]);
|
|
229
237
|
});
|
|
230
238
|
it('should return a result when first line of a multiline commit message matches', () => {
|
|
231
|
-
const pullRequestNode = getPullRequestNodeMock_1.getPullRequestNodeMock({
|
|
239
|
+
const pullRequestNode = (0, getPullRequestNodeMock_1.getPullRequestNodeMock)({
|
|
232
240
|
sourcePullRequest: {
|
|
233
241
|
number: 1234,
|
|
234
242
|
commitMessage: 'my message (#1234)',
|
|
@@ -239,25 +247,25 @@ describe('getExistingTargetPullRequests', () => {
|
|
|
239
247
|
commitMessages: ['my message (#1234)\n\nsomething else'],
|
|
240
248
|
},
|
|
241
249
|
});
|
|
242
|
-
const existingPRs = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
|
|
250
|
+
const existingPRs = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
|
|
243
251
|
expect(existingPRs).toEqual([
|
|
244
252
|
{ branch: '7.x', state: 'MERGED', number: 20 },
|
|
245
253
|
]);
|
|
246
254
|
});
|
|
247
255
|
});
|
|
248
256
|
async function getExistingBackportsByRepoName(repoName1, repoName2) {
|
|
249
|
-
const commitsMock = getCommitsByAuthorMock_1.getCommitsByAuthorMock(repoName1);
|
|
250
|
-
nockHelpers_1.mockGqlRequest({
|
|
257
|
+
const commitsMock = (0, getCommitsByAuthorMock_1.getCommitsByAuthorMock)(repoName1);
|
|
258
|
+
(0, nockHelpers_1.mockGqlRequest)({
|
|
251
259
|
name: 'AuthorId',
|
|
252
260
|
statusCode: 200,
|
|
253
261
|
body: { data: authorIdMockData },
|
|
254
262
|
});
|
|
255
|
-
nockHelpers_1.mockGqlRequest({
|
|
263
|
+
(0, nockHelpers_1.mockGqlRequest)({
|
|
256
264
|
name: 'CommitsByAuthor',
|
|
257
265
|
statusCode: 200,
|
|
258
266
|
body: { data: commitsMock },
|
|
259
267
|
});
|
|
260
|
-
return fetchCommitsByAuthor_1.fetchCommitsByAuthor({
|
|
268
|
+
return (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
261
269
|
...defaultOptions,
|
|
262
270
|
repoName: repoName2,
|
|
263
271
|
});
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.splitHead = exports.fetchExistingPullRequest = void 0;
|
|
4
4
|
const apiRequestV4_1 = require("./apiRequestV4");
|
|
5
5
|
async function fetchExistingPullRequest({ options, prPayload, }) {
|
|
6
|
-
var _a;
|
|
7
6
|
const { githubApiBaseUrlV4, accessToken } = options;
|
|
8
7
|
const query = /* GraphQL */ `
|
|
9
8
|
query ExistingPullRequest(
|
|
@@ -34,7 +33,7 @@ async function fetchExistingPullRequest({ options, prPayload, }) {
|
|
|
34
33
|
}
|
|
35
34
|
`;
|
|
36
35
|
const { repoForkOwner, head } = splitHead(prPayload);
|
|
37
|
-
const res = await apiRequestV4_1.apiRequestV4({
|
|
36
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
38
37
|
githubApiBaseUrlV4,
|
|
39
38
|
accessToken,
|
|
40
39
|
query,
|
|
@@ -45,7 +44,7 @@ async function fetchExistingPullRequest({ options, prPayload, }) {
|
|
|
45
44
|
head: head,
|
|
46
45
|
},
|
|
47
46
|
});
|
|
48
|
-
const existingPullRequest =
|
|
47
|
+
const existingPullRequest = res.repository.ref?.associatedPullRequests.edges[0];
|
|
49
48
|
if (!existingPullRequest) {
|
|
50
49
|
return;
|
|
51
50
|
}
|
|
@@ -5,13 +5,12 @@ const fetchExistingPullRequest_1 = require("./fetchExistingPullRequest");
|
|
|
5
5
|
describe('fetchExistingPullRequest', () => {
|
|
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 does not exist', () => {
|
|
11
11
|
it('returns undefined', async () => {
|
|
12
12
|
const options = {
|
|
13
13
|
accessToken: devAccessToken,
|
|
14
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
15
14
|
};
|
|
16
15
|
const prPayload = {
|
|
17
16
|
owner: 'backport-org',
|
|
@@ -21,7 +20,7 @@ describe('fetchExistingPullRequest', () => {
|
|
|
21
20
|
head: 'sqren:backport/7.8/pr-foo',
|
|
22
21
|
base: '7.8',
|
|
23
22
|
};
|
|
24
|
-
const res = await fetchExistingPullRequest_1.fetchExistingPullRequest({ options, prPayload });
|
|
23
|
+
const res = await (0, fetchExistingPullRequest_1.fetchExistingPullRequest)({ options, prPayload });
|
|
25
24
|
expect(res).toBe(undefined);
|
|
26
25
|
});
|
|
27
26
|
});
|
|
@@ -29,7 +28,6 @@ describe('fetchExistingPullRequest', () => {
|
|
|
29
28
|
it('returns the PR number and url', async () => {
|
|
30
29
|
const options = {
|
|
31
30
|
accessToken: devAccessToken,
|
|
32
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
33
31
|
};
|
|
34
32
|
const prPayload = {
|
|
35
33
|
owner: 'backport-org',
|
|
@@ -39,7 +37,7 @@ describe('fetchExistingPullRequest', () => {
|
|
|
39
37
|
head: 'sqren:backport/7.8/pr-9',
|
|
40
38
|
base: '7.8',
|
|
41
39
|
};
|
|
42
|
-
const res = await fetchExistingPullRequest_1.fetchExistingPullRequest({ options, prPayload });
|
|
40
|
+
const res = await (0, fetchExistingPullRequest_1.fetchExistingPullRequest)({ options, prPayload });
|
|
43
41
|
expect(res).toEqual({
|
|
44
42
|
url: 'https://github.com/backport-org/backport-e2e/pull/10',
|
|
45
43
|
number: 10,
|