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
|
@@ -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 {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
|
|
4
|
+
const fetchCommitByPullNumber_1 = require("./fetchCommitByPullNumber");
|
|
5
|
+
describe('fetchCommitByPullNumber', () => {
|
|
6
|
+
let devAccessToken;
|
|
7
|
+
beforeAll(async () => {
|
|
8
|
+
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
|
+
});
|
|
10
|
+
describe('when PR was merged', () => {
|
|
11
|
+
it('is returned', async () => {
|
|
12
|
+
const options = {
|
|
13
|
+
accessToken: devAccessToken,
|
|
14
|
+
pullNumber: 5,
|
|
15
|
+
repoName: 'backport-e2e',
|
|
16
|
+
repoOwner: 'backport-org',
|
|
17
|
+
sourceBranch: 'main',
|
|
18
|
+
historicalBranchLabelMappings: [],
|
|
19
|
+
};
|
|
20
|
+
expect(await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).toEqual({
|
|
21
|
+
committedDate: '2020-08-15T12:40:19Z',
|
|
22
|
+
originalMessage: 'Add 🍏 emoji (#5)',
|
|
23
|
+
pullNumber: 5,
|
|
24
|
+
pullUrl: 'https://github.com/backport-org/backport-e2e/pull/5',
|
|
25
|
+
sha: 'ee8c492334cef1ca077a56addb79a26f79821d2f',
|
|
26
|
+
sourceBranch: 'master',
|
|
27
|
+
expectedTargetPullRequests: [
|
|
28
|
+
{
|
|
29
|
+
branch: '7.x',
|
|
30
|
+
state: 'MERGED',
|
|
31
|
+
number: 6,
|
|
32
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/6',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
branch: '7.8',
|
|
36
|
+
state: 'MERGED',
|
|
37
|
+
number: 7,
|
|
38
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/7',
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
describe('when PR is still open', () => {
|
|
45
|
+
it('throws an error', async () => {
|
|
46
|
+
const options = {
|
|
47
|
+
accessToken: devAccessToken,
|
|
48
|
+
pullNumber: 11,
|
|
49
|
+
repoName: 'backport-e2e',
|
|
50
|
+
repoOwner: 'backport-org',
|
|
51
|
+
sourceBranch: 'main',
|
|
52
|
+
historicalBranchLabelMappings: [],
|
|
53
|
+
};
|
|
54
|
+
await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`The PR #11 is not merged`);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
describe('when PR does not exist', () => {
|
|
58
|
+
it('throws an error', async () => {
|
|
59
|
+
const options = {
|
|
60
|
+
accessToken: devAccessToken,
|
|
61
|
+
pullNumber: 9999999999999,
|
|
62
|
+
repoName: 'backport-e2e',
|
|
63
|
+
repoOwner: 'backport-org',
|
|
64
|
+
sourceBranch: 'main',
|
|
65
|
+
historicalBranchLabelMappings: [],
|
|
66
|
+
};
|
|
67
|
+
await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`Could not resolve to a PullRequest with the number of 9999999999999. (Unhandled Github v4 error)`);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ValidConfigOptions } from '../../../../options/options';
|
|
2
|
+
import { Commit } from '../../../sourceCommit/parseSourceCommit';
|
|
3
|
+
export declare function fetchCommitBySha(options: {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
|
|
6
|
+
githubApiBaseUrlV4?: string;
|
|
7
|
+
historicalBranchLabelMappings: ValidConfigOptions['historicalBranchLabelMappings'];
|
|
8
|
+
repoName: string;
|
|
9
|
+
repoOwner: string;
|
|
10
|
+
sha: string;
|
|
11
|
+
sourceBranch: string;
|
|
12
|
+
}): Promise<Commit>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchCommitBySha = void 0;
|
|
4
|
+
const HandledError_1 = require("../../../HandledError");
|
|
5
|
+
const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
|
|
6
|
+
const apiRequestV4_1 = require("../apiRequestV4");
|
|
7
|
+
async function fetchCommitBySha(options) {
|
|
8
|
+
const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', repoName, repoOwner, sha, sourceBranch, } = options;
|
|
9
|
+
const query = /* GraphQL */ `
|
|
10
|
+
query CommitsBySha($repoOwner: String!, $repoName: String!, $oid: String!) {
|
|
11
|
+
repository(owner: $repoOwner, name: $repoName) {
|
|
12
|
+
object(expression: $oid) {
|
|
13
|
+
...${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.name}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
|
|
19
|
+
`;
|
|
20
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
21
|
+
githubApiBaseUrlV4,
|
|
22
|
+
accessToken,
|
|
23
|
+
query,
|
|
24
|
+
variables: {
|
|
25
|
+
repoOwner,
|
|
26
|
+
repoName,
|
|
27
|
+
oid: sha,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const sourceCommit = res.repository.object;
|
|
31
|
+
if (!sourceCommit) {
|
|
32
|
+
throw new HandledError_1.HandledError(`No commit found on branch "${sourceBranch}" with sha "${sha}"`);
|
|
33
|
+
}
|
|
34
|
+
return (0, parseSourceCommit_1.parseSourceCommit)({ options, sourceCommit });
|
|
35
|
+
}
|
|
36
|
+
exports.fetchCommitBySha = fetchCommitBySha;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
|
|
4
|
+
const fetchCommitBySha_1 = require("./fetchCommitBySha");
|
|
5
|
+
describe('fetchCommitBySha', () => {
|
|
6
|
+
let devAccessToken;
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
|
+
});
|
|
10
|
+
it('should return single commit with pull request', async () => {
|
|
11
|
+
await expect(await (0, fetchCommitBySha_1.fetchCommitBySha)({
|
|
12
|
+
repoOwner: 'elastic',
|
|
13
|
+
repoName: 'kibana',
|
|
14
|
+
accessToken: devAccessToken,
|
|
15
|
+
sha: 'cb6fbc0',
|
|
16
|
+
sourceBranch: 'master',
|
|
17
|
+
historicalBranchLabelMappings: [],
|
|
18
|
+
})).toEqual({
|
|
19
|
+
committedDate: '2020-07-07T20:40:28Z',
|
|
20
|
+
originalMessage: '[APM] Add API tests (#70740)',
|
|
21
|
+
pullNumber: 70740,
|
|
22
|
+
pullUrl: 'https://github.com/elastic/kibana/pull/70740',
|
|
23
|
+
sha: 'cb6fbc0e1b406675724181a3e9f59459b5f8f892',
|
|
24
|
+
sourceBranch: 'master',
|
|
25
|
+
expectedTargetPullRequests: [
|
|
26
|
+
{
|
|
27
|
+
branch: '7.x',
|
|
28
|
+
state: 'MERGED',
|
|
29
|
+
number: 71014,
|
|
30
|
+
url: 'https://github.com/elastic/kibana/pull/71014',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
it('throws if sha does not exist', async () => {
|
|
36
|
+
await expect((0, fetchCommitBySha_1.fetchCommitBySha)({
|
|
37
|
+
repoOwner: 'elastic',
|
|
38
|
+
repoName: 'kibana',
|
|
39
|
+
accessToken: devAccessToken,
|
|
40
|
+
sha: 'fc22f59',
|
|
41
|
+
sourceBranch: 'main',
|
|
42
|
+
historicalBranchLabelMappings: [],
|
|
43
|
+
})).rejects.toThrowError('No commit found on branch "main" with sha "fc22f59"');
|
|
44
|
+
});
|
|
45
|
+
it('throws if sha is invalid', async () => {
|
|
46
|
+
await expect((0, fetchCommitBySha_1.fetchCommitBySha)({
|
|
47
|
+
repoOwner: 'elastic',
|
|
48
|
+
repoName: 'kibana',
|
|
49
|
+
accessToken: devAccessToken,
|
|
50
|
+
sha: 'myCommitSha',
|
|
51
|
+
sourceBranch: 'main',
|
|
52
|
+
historicalBranchLabelMappings: [],
|
|
53
|
+
})).rejects.toThrowError('No commit found on branch "main" with sha "myCommitSha"');
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ValidConfigOptions } from '../../../../options/options';
|
|
2
|
+
import { Commit, SourceCommitWithTargetPullRequest } from '../../../sourceCommit/parseSourceCommit';
|
|
3
|
+
export declare function fetchCommitsByAuthor(options: {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
author: string | null;
|
|
6
|
+
branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
|
|
7
|
+
commitPaths?: string[];
|
|
8
|
+
githubApiBaseUrlV4?: string;
|
|
9
|
+
historicalBranchLabelMappings: ValidConfigOptions['historicalBranchLabelMappings'];
|
|
10
|
+
maxNumber?: number;
|
|
11
|
+
repoName: string;
|
|
12
|
+
repoOwner: string;
|
|
13
|
+
sourceBranch: string;
|
|
14
|
+
}): Promise<Commit[]>;
|
|
15
|
+
export interface CommitByAuthorResponse {
|
|
16
|
+
repository: {
|
|
17
|
+
ref: {
|
|
18
|
+
target: {
|
|
19
|
+
history: {
|
|
20
|
+
edges: Array<{
|
|
21
|
+
node: SourceCommitWithTargetPullRequest;
|
|
22
|
+
}>;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
} | null;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchCommitsByAuthor = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const filterEmpty_1 = require("../../../../utils/filterEmpty");
|
|
6
|
+
const HandledError_1 = require("../../../HandledError");
|
|
7
|
+
const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
|
|
8
|
+
const apiRequestV4_1 = require("../apiRequestV4");
|
|
9
|
+
const fetchAuthorId_1 = require("../fetchAuthorId");
|
|
10
|
+
function fetchByCommitPath({ options, authorId, commitPath, }) {
|
|
11
|
+
const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', maxNumber = 10, repoName, repoOwner, sourceBranch, } = options;
|
|
12
|
+
const query = /* GraphQL */ `
|
|
13
|
+
query CommitsByAuthor(
|
|
14
|
+
$repoOwner: String!
|
|
15
|
+
$repoName: String!
|
|
16
|
+
$maxNumber: Int!
|
|
17
|
+
$sourceBranch: String!
|
|
18
|
+
$authorId: ID
|
|
19
|
+
$commitPath: String
|
|
20
|
+
) {
|
|
21
|
+
repository(owner: $repoOwner, name: $repoName) {
|
|
22
|
+
ref(qualifiedName: $sourceBranch) {
|
|
23
|
+
target {
|
|
24
|
+
... on Commit {
|
|
25
|
+
history(
|
|
26
|
+
first: $maxNumber
|
|
27
|
+
author: { id: $authorId }
|
|
28
|
+
path: $commitPath
|
|
29
|
+
) {
|
|
30
|
+
edges {
|
|
31
|
+
node {
|
|
32
|
+
...${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.name}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
|
|
43
|
+
`;
|
|
44
|
+
return (0, apiRequestV4_1.apiRequestV4)({
|
|
45
|
+
githubApiBaseUrlV4,
|
|
46
|
+
accessToken,
|
|
47
|
+
query,
|
|
48
|
+
variables: {
|
|
49
|
+
repoOwner,
|
|
50
|
+
repoName,
|
|
51
|
+
sourceBranch,
|
|
52
|
+
maxNumber,
|
|
53
|
+
authorId,
|
|
54
|
+
commitPath,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async function fetchCommitsByAuthor(options) {
|
|
59
|
+
const { sourceBranch, commitPaths = [] } = options;
|
|
60
|
+
const authorId = await (0, fetchAuthorId_1.fetchAuthorId)(options);
|
|
61
|
+
const responses = await Promise.all((0, lodash_1.isEmpty)(commitPaths)
|
|
62
|
+
? [fetchByCommitPath({ options, authorId, commitPath: null })]
|
|
63
|
+
: commitPaths.map((commitPath) => fetchByCommitPath({ options, authorId, commitPath })));
|
|
64
|
+
// we only need to check if the first item is `null` (if the first is `null` they all are)
|
|
65
|
+
if (responses[0].repository.ref === null) {
|
|
66
|
+
throw new HandledError_1.HandledError(`The upstream branch "${sourceBranch}" does not exist. Try specifying a different branch with "--source-branch <your-branch>"`);
|
|
67
|
+
}
|
|
68
|
+
const commits = responses
|
|
69
|
+
.flatMap((res) => {
|
|
70
|
+
return res.repository.ref?.target.history.edges.map((edge) => {
|
|
71
|
+
const sourceCommit = edge.node;
|
|
72
|
+
return (0, parseSourceCommit_1.parseSourceCommit)({ options, sourceCommit });
|
|
73
|
+
});
|
|
74
|
+
})
|
|
75
|
+
.filter(filterEmpty_1.filterNil);
|
|
76
|
+
// terminate if not commits were found
|
|
77
|
+
if ((0, lodash_1.isEmpty)(commits)) {
|
|
78
|
+
const pathText = commitPaths.length > 0 ? ` touching files in path: "${commitPaths}"` : '';
|
|
79
|
+
const errorText = options.author
|
|
80
|
+
? `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`
|
|
81
|
+
: `There are no commits in this repository${pathText}`;
|
|
82
|
+
throw new HandledError_1.HandledError(errorText);
|
|
83
|
+
}
|
|
84
|
+
const commitsUnique = (0, lodash_1.uniqBy)(commits, 'sha');
|
|
85
|
+
const commitsSorted = (0, lodash_1.orderBy)(commitsUnique, 'committedDate', 'desc');
|
|
86
|
+
return commitsSorted;
|
|
87
|
+
}
|
|
88
|
+
exports.fetchCommitsByAuthor = fetchCommitsByAuthor;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
|
|
4
|
+
const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
|
|
5
|
+
describe('fetchCommitsByAuthor', () => {
|
|
6
|
+
let devAccessToken;
|
|
7
|
+
beforeAll(async () => {
|
|
8
|
+
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
|
+
});
|
|
10
|
+
describe('commitPaths', () => {
|
|
11
|
+
const getOptions = () => ({
|
|
12
|
+
accessToken: devAccessToken,
|
|
13
|
+
author: 'sqren',
|
|
14
|
+
historicalBranchLabelMappings: [],
|
|
15
|
+
maxNumber: 10,
|
|
16
|
+
repoName: 'repo-with-different-commit-paths',
|
|
17
|
+
repoOwner: 'backport-org',
|
|
18
|
+
sourceBranch: 'main',
|
|
19
|
+
});
|
|
20
|
+
const getCommitMessages = (commits) => {
|
|
21
|
+
return commits.map((c) => c.originalMessage.replace(/(\r\n|\n|\r)/gm, ''));
|
|
22
|
+
};
|
|
23
|
+
it('returns all commits', async () => {
|
|
24
|
+
const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
25
|
+
...getOptions(),
|
|
26
|
+
commitPaths: [],
|
|
27
|
+
});
|
|
28
|
+
const commitMessages = getCommitMessages(commits);
|
|
29
|
+
expect(commitMessages).toEqual([
|
|
30
|
+
'Edit all lyrics',
|
|
31
|
+
'Update .backportrc.json',
|
|
32
|
+
'Edit "Take on me"',
|
|
33
|
+
'Add backportrc.json',
|
|
34
|
+
'Add "Bohemian Rhapsody""',
|
|
35
|
+
'Add "99 Luftballons"',
|
|
36
|
+
'Add "Take on me"',
|
|
37
|
+
]);
|
|
38
|
+
});
|
|
39
|
+
it('only returns commits related to "99-luftballons.txt"', async () => {
|
|
40
|
+
const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
41
|
+
...getOptions(),
|
|
42
|
+
commitPaths: ['lyrics/99-luftballons.txt'],
|
|
43
|
+
});
|
|
44
|
+
const commitMessages = getCommitMessages(commits);
|
|
45
|
+
expect(commitMessages).toEqual([
|
|
46
|
+
'Edit all lyrics',
|
|
47
|
+
'Add "99 Luftballons"',
|
|
48
|
+
]);
|
|
49
|
+
});
|
|
50
|
+
it('only returns commits related to "take-on-me.txt"', async () => {
|
|
51
|
+
const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
52
|
+
...getOptions(),
|
|
53
|
+
commitPaths: ['lyrics/take-on-me.txt'],
|
|
54
|
+
});
|
|
55
|
+
const commitMessages = getCommitMessages(commits);
|
|
56
|
+
expect(commitMessages).toEqual([
|
|
57
|
+
'Edit all lyrics',
|
|
58
|
+
'Edit "Take on me"',
|
|
59
|
+
'Add "Take on me"',
|
|
60
|
+
]);
|
|
61
|
+
});
|
|
62
|
+
it('removes duplicates and order by `committedDate`', async () => {
|
|
63
|
+
const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
64
|
+
...getOptions(),
|
|
65
|
+
commitPaths: [
|
|
66
|
+
'lyrics/99-luftballons.txt',
|
|
67
|
+
'lyrics/take-on-me.txt',
|
|
68
|
+
'lyrics/bohemian-rhapsody.txt',
|
|
69
|
+
],
|
|
70
|
+
});
|
|
71
|
+
const commitMessages = getCommitMessages(commits);
|
|
72
|
+
expect(commitMessages).toEqual([
|
|
73
|
+
'Edit all lyrics',
|
|
74
|
+
'Edit "Take on me"',
|
|
75
|
+
'Add "Bohemian Rhapsody""',
|
|
76
|
+
'Add "99 Luftballons"',
|
|
77
|
+
'Add "Take on me"',
|
|
78
|
+
]);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
describe('expectedTargetPullRequests', () => {
|
|
82
|
+
let res;
|
|
83
|
+
beforeEach(async () => {
|
|
84
|
+
res = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
85
|
+
accessToken: devAccessToken,
|
|
86
|
+
commitPaths: [],
|
|
87
|
+
historicalBranchLabelMappings: [],
|
|
88
|
+
maxNumber: 10,
|
|
89
|
+
repoName: 'backport-e2e',
|
|
90
|
+
repoOwner: 'backport-org',
|
|
91
|
+
sourceBranch: 'master',
|
|
92
|
+
author: null,
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
it('returns related OPEN PRs', async () => {
|
|
96
|
+
const commitWithOpenPR = res.find((commit) => commit.pullNumber === 9);
|
|
97
|
+
expect(commitWithOpenPR?.expectedTargetPullRequests).toEqual([
|
|
98
|
+
{
|
|
99
|
+
branch: '7.8',
|
|
100
|
+
state: 'OPEN',
|
|
101
|
+
number: 10,
|
|
102
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/10',
|
|
103
|
+
},
|
|
104
|
+
]);
|
|
105
|
+
});
|
|
106
|
+
it('returns related MERGED PRs', async () => {
|
|
107
|
+
const commitWithMergedPRs = res.find((commit) => commit.pullNumber === 5);
|
|
108
|
+
expect(commitWithMergedPRs?.expectedTargetPullRequests).toEqual([
|
|
109
|
+
{
|
|
110
|
+
branch: '7.x',
|
|
111
|
+
state: 'MERGED',
|
|
112
|
+
number: 6,
|
|
113
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/6',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
branch: '7.8',
|
|
117
|
+
state: 'MERGED',
|
|
118
|
+
number: 7,
|
|
119
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/7',
|
|
120
|
+
},
|
|
121
|
+
]);
|
|
122
|
+
});
|
|
123
|
+
it('returns empty if there are no related PRs', async () => {
|
|
124
|
+
const commitWithoutPRs = res.find((commit) => commit.pullNumber === 8);
|
|
125
|
+
expect(commitWithoutPRs?.expectedTargetPullRequests).toEqual([]);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const nock_1 = __importDefault(require("nock"));
|
|
7
|
+
const nockHelpers_1 = require("../../../../test/nockHelpers");
|
|
8
|
+
const commitsByAuthorMock_1 = require("../mocks/commitsByAuthorMock");
|
|
9
|
+
const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
|
|
10
|
+
const defaultOptions = {
|
|
11
|
+
accessToken: 'myAccessToken',
|
|
12
|
+
author: 'sqren',
|
|
13
|
+
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
14
|
+
historicalBranchLabelMappings: [],
|
|
15
|
+
maxNumber: 10,
|
|
16
|
+
repoName: 'kibana',
|
|
17
|
+
repoOwner: 'elastic',
|
|
18
|
+
sourceBranch: 'source-branch-from-options',
|
|
19
|
+
};
|
|
20
|
+
const authorIdMockData = { user: { id: 'myUserId' } };
|
|
21
|
+
describe('fetchCommitsByAuthor', () => {
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
jest.clearAllMocks();
|
|
24
|
+
});
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
nock_1.default.cleanAll();
|
|
27
|
+
});
|
|
28
|
+
describe('when commit has an associated pull request', () => {
|
|
29
|
+
let res;
|
|
30
|
+
let authorIdCalls;
|
|
31
|
+
let commitsByAuthorCalls;
|
|
32
|
+
beforeEach(async () => {
|
|
33
|
+
authorIdCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
34
|
+
name: 'AuthorId',
|
|
35
|
+
statusCode: 200,
|
|
36
|
+
body: { data: authorIdMockData },
|
|
37
|
+
});
|
|
38
|
+
commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
39
|
+
name: 'CommitsByAuthor',
|
|
40
|
+
statusCode: 200,
|
|
41
|
+
body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
|
|
42
|
+
});
|
|
43
|
+
res = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)(defaultOptions);
|
|
44
|
+
});
|
|
45
|
+
it('should return a list of commits with pullNumber and existing backports', () => {
|
|
46
|
+
const expectedCommits = [
|
|
47
|
+
{
|
|
48
|
+
committedDate: '2021-12-24T00:00:00Z',
|
|
49
|
+
sha: '2e63475c483f7844b0f2833bc57fdee32095bacb',
|
|
50
|
+
originalMessage: 'Add 👻',
|
|
51
|
+
expectedTargetPullRequests: [],
|
|
52
|
+
sourceBranch: 'source-branch-from-options',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
committedDate: '2021-12-23T00:00:00Z',
|
|
56
|
+
sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
|
|
57
|
+
originalMessage: 'Add witch (#85)',
|
|
58
|
+
pullNumber: 85,
|
|
59
|
+
pullUrl: 'https://github.com/elastic/kibana/pull/85',
|
|
60
|
+
expectedTargetPullRequests: [],
|
|
61
|
+
sourceBranch: 'master',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
committedDate: '2021-12-22T00:00:00Z',
|
|
65
|
+
sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
|
|
66
|
+
originalMessage: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
67
|
+
pullNumber: 80,
|
|
68
|
+
pullUrl: 'https://github.com/elastic/kibana/pull/80',
|
|
69
|
+
expectedTargetPullRequests: [
|
|
70
|
+
{
|
|
71
|
+
branch: '6.3',
|
|
72
|
+
state: 'MERGED',
|
|
73
|
+
number: 99,
|
|
74
|
+
url: 'https://github.com/elastic/kibana/pull/99',
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
sourceBranch: 'master',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
committedDate: '2021-12-21T00:00:00Z',
|
|
81
|
+
sha: '3827bbbaf39914eda4f02f6940189844375fd097',
|
|
82
|
+
originalMessage: 'Add backport config',
|
|
83
|
+
expectedTargetPullRequests: [],
|
|
84
|
+
sourceBranch: 'source-branch-from-options',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
committedDate: '2021-12-20T00:00:00Z',
|
|
88
|
+
sha: '5ea0da550ac191029459289d67f99ad7d310812b',
|
|
89
|
+
originalMessage: 'Initial commit',
|
|
90
|
+
expectedTargetPullRequests: [],
|
|
91
|
+
sourceBranch: 'source-branch-from-options',
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
expect(res).toEqual(expectedCommits);
|
|
95
|
+
});
|
|
96
|
+
it('should call with correct args to fetch author id', () => {
|
|
97
|
+
expect(authorIdCalls).toMatchSnapshot();
|
|
98
|
+
});
|
|
99
|
+
it('should call with correct args to fetch commits', () => {
|
|
100
|
+
expect(commitsByAuthorCalls).toMatchSnapshot();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
describe('when a custom github api hostname is supplied', () => {
|
|
104
|
+
it('should be used in gql requests', async () => {
|
|
105
|
+
const authorIdCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
106
|
+
name: 'AuthorId',
|
|
107
|
+
statusCode: 200,
|
|
108
|
+
body: { data: authorIdMockData },
|
|
109
|
+
apiBaseUrl: 'http://localhost/my-custom-api',
|
|
110
|
+
});
|
|
111
|
+
const commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
112
|
+
name: 'CommitsByAuthor',
|
|
113
|
+
statusCode: 200,
|
|
114
|
+
body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
|
|
115
|
+
apiBaseUrl: 'http://localhost/my-custom-api',
|
|
116
|
+
});
|
|
117
|
+
await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
118
|
+
...defaultOptions,
|
|
119
|
+
githubApiBaseUrlV4: 'http://localhost/my-custom-api',
|
|
120
|
+
});
|
|
121
|
+
expect(authorIdCalls.length).toBe(1);
|
|
122
|
+
expect(commitsByAuthorCalls.length).toBe(1);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ValidConfigOptions } from '../../../../options/options';
|
|
2
|
+
import { Commit, CommitNode } from '../../../../types/commitNode';
|
|
3
|
+
export declare function fetchCommitsInDateRange({ accessToken, branchLabelMapping, commitsCount, dateRange, githubApiBaseUrlV4, repoName, repoOwner, sourceBranch, }: {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
branchLabelMapping: ValidConfigOptions['branchLabelMapping'];
|
|
6
|
+
commitsCount: number;
|
|
7
|
+
dateRange: {
|
|
8
|
+
since: string;
|
|
9
|
+
until: string;
|
|
10
|
+
};
|
|
11
|
+
githubApiBaseUrlV4: string;
|
|
12
|
+
repoName: string;
|
|
13
|
+
repoOwner: string;
|
|
14
|
+
sourceBranch: string;
|
|
15
|
+
}): Promise<Commit[] | undefined>;
|
|
16
|
+
export interface CommitsSinceDateResponse {
|
|
17
|
+
repository: {
|
|
18
|
+
ref: {
|
|
19
|
+
target: {
|
|
20
|
+
history: {
|
|
21
|
+
edges: Array<{
|
|
22
|
+
node: CommitNode;
|
|
23
|
+
}>;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
} | null;
|
|
27
|
+
};
|
|
28
|
+
}
|