backport 7.4.0 → 8.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -16
- package/dist/backportRun.d.ts +12 -6
- package/dist/backportRun.js +64 -62
- package/dist/entrypoint.cli.js +4 -8
- package/dist/entrypoint.module.d.ts +13 -6
- package/dist/entrypoint.module.js +14 -20
- package/dist/entrypoint.module.private.test.js +47 -346
- package/dist/errors/BackportError.d.ts +19 -0
- package/dist/errors/BackportError.js +29 -0
- package/dist/lib/BackportError.d.ts +19 -0
- package/dist/lib/BackportError.js +29 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.d.ts +11 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +242 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +321 -0
- package/dist/lib/child-process-promisified.d.ts +25 -0
- package/dist/lib/child-process-promisified.js +60 -0
- package/dist/lib/env.d.ts +9 -0
- package/dist/lib/env.js +33 -0
- package/dist/lib/env.test.d.ts +1 -0
- package/dist/lib/env.test.js +26 -0
- package/dist/lib/getCommits.d.ts +2 -0
- package/dist/lib/getCommits.js +75 -0
- package/dist/lib/getCommitsWithoutBackports.d.ts +11 -0
- package/dist/lib/getCommitsWithoutBackports.js +68 -0
- package/dist/lib/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/lib/getCommitsWithoutBackports.test.js +335 -0
- package/dist/lib/getGitConfigAuthor.d.ts +6 -0
- package/dist/lib/getGitConfigAuthor.js +15 -0
- package/dist/lib/getTargetBranches.d.ts +5 -0
- package/dist/lib/getTargetBranches.js +67 -0
- package/dist/lib/getTargetBranches.test.d.ts +1 -0
- package/dist/lib/getTargetBranches.test.js +210 -0
- package/dist/lib/git.d.ts +77 -0
- package/dist/lib/git.js +439 -0
- package/dist/lib/git.private.test.d.ts +1 -0
- package/dist/lib/git.private.test.js +618 -0
- package/dist/lib/git.test.d.ts +1 -0
- package/dist/lib/git.test.js +580 -0
- package/dist/lib/github/commitFormatters.d.ts +3 -0
- package/dist/lib/github/commitFormatters.js +17 -0
- package/dist/lib/github/commitFormatters.test.d.ts +1 -0
- package/dist/lib/github/commitFormatters.test.js +11 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.d.ts +2 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.js +32 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.test.js +27 -0
- package/dist/lib/github/v3/addLabelsToPullRequest.d.ts +2 -0
- package/dist/lib/github/v3/addLabelsToPullRequest.js +30 -0
- package/dist/lib/github/v3/addReviewersToPullRequest.d.ts +2 -0
- package/dist/lib/github/v3/addReviewersToPullRequest.js +32 -0
- package/dist/lib/github/v3/createPullRequest.d.ts +29 -0
- package/dist/lib/github/v3/createPullRequest.js +91 -0
- package/dist/lib/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/lib/github/v3/createPullRequest.test.js +377 -0
- package/dist/lib/github/v3/createStatusComment.d.ts +11 -0
- package/dist/lib/github/v3/createStatusComment.js +138 -0
- package/dist/lib/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/lib/github/v3/createStatusComment.test.js +566 -0
- package/dist/lib/github/v3/getGithubV3ErrorMessage.d.ts +14 -0
- package/dist/lib/github/v3/getGithubV3ErrorMessage.js +16 -0
- package/dist/lib/github/v4/FetchPullRequestId.d.ts +2 -0
- package/dist/lib/github/v4/FetchPullRequestId.js +36 -0
- package/dist/lib/github/v4/apiRequestV4.d.ts +31 -0
- package/dist/lib/github/v4/apiRequestV4.js +71 -0
- package/dist/lib/github/v4/apiRequestV4.test.d.ts +1 -0
- package/dist/lib/github/v4/apiRequestV4.test.js +109 -0
- package/dist/lib/github/v4/disablePullRequestAutoMerge.d.ts +2 -0
- package/dist/lib/github/v4/disablePullRequestAutoMerge.js +32 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.d.ts +2 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.js +50 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
- package/dist/lib/github/v4/fetchAuthorId.d.ts +10 -0
- package/dist/lib/github/v4/fetchAuthorId.js +28 -0
- package/dist/lib/github/v4/fetchAuthorId.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchAuthorId.private.test.js +25 -0
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +93 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +11 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +58 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +136 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.d.ts +11 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +48 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +118 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +29 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +110 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +196 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +157 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +107 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +12 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +69 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.d.ts +9 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.js +64 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.private.test.js +44 -0
- package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.d.ts +2 -0
- package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.js +39 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.js +49 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.js +49 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +72 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +78 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +116 -0
- package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +16 -0
- package/dist/lib/github/v4/getOptionsFromGithub/query.js +29 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +29 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.js +61 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +72 -0
- package/dist/lib/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
- package/dist/lib/github/v4/mocks/commitsByAuthorMock.js +176 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.d.ts +7 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.js +45 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.test.js +87 -0
- package/dist/lib/github/v4/validateTargetBranches.d.ts +14 -0
- package/dist/lib/github/v4/validateTargetBranches.js +46 -0
- package/dist/lib/github/v4/validateTargetBranches.private.test.d.ts +1 -0
- package/dist/lib/github/v4/validateTargetBranches.private.test.js +51 -0
- package/dist/lib/logger.d.ts +11 -0
- package/dist/lib/logger.js +80 -0
- package/dist/lib/ora.d.ts +2 -0
- package/dist/lib/ora.js +21 -0
- package/dist/lib/prompt.test.d.ts +1 -0
- package/dist/lib/prompt.test.js +139 -0
- package/dist/lib/prompts.d.ts +17 -0
- package/dist/lib/prompts.js +132 -0
- package/dist/lib/remoteConfig.d.ts +20 -0
- package/dist/lib/remoteConfig.js +52 -0
- package/dist/lib/sequentially.d.ts +1 -0
- package/dist/lib/sequentially.js +10 -0
- package/dist/lib/setupRepo.d.ts +2 -0
- package/dist/lib/setupRepo.js +56 -0
- package/dist/lib/setupRepo.test.d.ts +1 -0
- package/dist/lib/setupRepo.test.js +278 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +16 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.js +102 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
- package/dist/lib/sourceCommit/getMockSourceCommit.d.ts +26 -0
- package/dist/lib/sourceCommit/getMockSourceCommit.js +103 -0
- package/dist/lib/sourceCommit/parseSourceCommit.d.ts +108 -0
- package/dist/lib/sourceCommit/parseSourceCommit.js +123 -0
- package/dist/lib/sourceCommit/parseSourceCommit.test.d.ts +1 -0
- package/dist/lib/sourceCommit/parseSourceCommit.test.js +226 -0
- package/dist/options/ConfigOptions.d.ts +4 -2
- package/dist/options/cliArgs.d.ts +14 -6
- package/dist/options/cliArgs.js +50 -22
- package/dist/options/cliArgs.test.js +128 -4
- package/dist/options/config/config.d.ts +5 -4
- package/dist/options/config/config.js +3 -5
- package/dist/options/config/config.test.js +0 -1
- package/dist/options/config/globalConfig.d.ts +5 -3
- package/dist/options/config/globalConfig.js +17 -14
- package/dist/options/config/readConfigFile.d.ts +5 -3
- package/dist/options/config/readConfigFile.js +2 -2
- package/dist/options/options.d.ts +41 -5
- package/dist/options/options.js +24 -24
- package/dist/options/options.test.js +117 -55
- package/dist/runSequentially.d.ts +14 -9
- package/dist/runSequentially.js +27 -12
- package/dist/scripts/postinstall.js +4 -3
- package/dist/scripts/postinstall.test.js +6 -2
- package/dist/services/BackportError.d.ts +19 -0
- package/dist/services/BackportError.js +29 -0
- package/dist/services/HandledBackportError.d.ts +19 -0
- package/dist/services/HandledBackportError.js +29 -0
- package/dist/services/HandledError.d.ts +2 -2
- package/dist/services/HandledError.js +7 -7
- package/dist/services/child-process-promisified.d.ts +19 -3
- package/dist/services/child-process-promisified.js +46 -17
- package/dist/services/git.d.ts +6 -7
- package/dist/services/git.integration.test.js +381 -65
- package/dist/services/git.js +189 -123
- package/dist/services/git.private.test.d.ts +1 -0
- package/dist/services/git.private.test.js +618 -0
- package/dist/services/git.test.js +167 -124
- package/dist/services/github/v3/addAssigneesToPullRequest.js +1 -1
- package/dist/services/github/v3/addLabelsToPullRequest.js +1 -1
- package/dist/services/github/v3/addReviewersToPullRequest.js +2 -1
- package/dist/services/github/v3/createPullRequest.js +4 -2
- package/dist/services/github/v3/createStatusComment.js +16 -17
- package/dist/services/github/v3/createStatusComment.test.js +20 -9
- package/dist/services/github/v4/apiRequestV4.js +2 -2
- package/dist/services/github/v4/apiRequestV4.test.js +2 -2
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +4 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +3 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +4 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +3 -2
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +5 -1
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
- package/dist/services/logger.js +5 -1
- package/dist/services/test.d.ts +1 -0
- package/dist/services/test.js +23 -0
- package/dist/state.d.ts +0 -0
- package/dist/state.js +1 -0
- package/dist/test/e2e/cli/commit-author.private.test.js +4 -4
- package/dist/test/e2e/cli/different-merge-strategies.private.test.js +27 -25
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +53 -75
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +80 -0
- package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +199 -0
- package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/interactive-error-handling.private.test.js +80 -0
- package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +198 -0
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +28 -29
- package/dist/test/e2e/cli/runBackportViaCli.d.ts +6 -2
- package/dist/test/e2e/cli/runBackportViaCli.js +44 -23
- package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +22 -14
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +28 -21
- package/dist/test/handleUnbackportedPullRequests.private.test.js +11 -8
- package/dist/test/sandbox.js +5 -1
- package/dist/test/setupFiles/automatic-mocks.js +6 -2
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +4 -4
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +7 -159
- package/dist/ui/getCommits.js +2 -2
- package/dist/ui/getCommitsWithoutBackports.test.js +5 -1
- package/dist/ui/getGitConfigAuthor.js +1 -1
- package/dist/ui/getTargetBranches.js +3 -3
- package/dist/ui/getTargetBranches.test.js +5 -1
- package/dist/ui/ora.d.ts +1 -8
- package/dist/ui/setupRepo.js +3 -3
- package/dist/ui/setupRepo.test.js +98 -61
- package/dist/utils/isErrnoError.d.ts +2 -0
- package/dist/utils/isErrnoError.js +7 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +19 -19
- package/yarn.lock +472 -701
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const graphql_1 = require("graphql");
|
|
27
|
+
const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
|
|
28
|
+
const apiRequestV4Module = __importStar(require("../apiRequestV4"));
|
|
29
|
+
const fetchCommitByPullNumber_1 = require("./fetchCommitByPullNumber");
|
|
30
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
31
|
+
describe('fetchCommitByPullNumber', () => {
|
|
32
|
+
describe('snapshot request/response', () => {
|
|
33
|
+
let spy;
|
|
34
|
+
let commit;
|
|
35
|
+
beforeEach(async () => {
|
|
36
|
+
spy = jest.spyOn(apiRequestV4Module, 'apiRequestV4');
|
|
37
|
+
commit = await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
|
|
38
|
+
repoOwner: 'elastic',
|
|
39
|
+
repoName: 'kibana',
|
|
40
|
+
accessToken,
|
|
41
|
+
pullNumber: 121633,
|
|
42
|
+
sourceBranch: 'master',
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
it('makes the right queries', () => {
|
|
46
|
+
const queries = spy.mock.calls.reduce((acc, call) => {
|
|
47
|
+
const query = call[0].query;
|
|
48
|
+
const name = apiRequestV4Module.getQueryName(query);
|
|
49
|
+
return { ...acc, [name]: (0, graphql_1.print)(query) };
|
|
50
|
+
}, {});
|
|
51
|
+
const queryNames = Object.keys(queries);
|
|
52
|
+
expect(queryNames).toEqual(['CommitByPullNumber']);
|
|
53
|
+
queryNames.forEach((name) => {
|
|
54
|
+
expect(queries[name]).toMatchSnapshot(`Query: ${name}`);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
it('returns the correct response', async () => {
|
|
58
|
+
expect(commit).toMatchSnapshot();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
describe('when PR was merged', () => {
|
|
62
|
+
it('is returned', async () => {
|
|
63
|
+
const options = {
|
|
64
|
+
accessToken,
|
|
65
|
+
pullNumber: 5,
|
|
66
|
+
repoName: 'backport-e2e',
|
|
67
|
+
repoOwner: 'backport-org',
|
|
68
|
+
sourceBranch: 'main',
|
|
69
|
+
};
|
|
70
|
+
const expectedCommit = {
|
|
71
|
+
author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
|
|
72
|
+
sourceCommit: {
|
|
73
|
+
committedDate: '2020-08-15T12:40:19Z',
|
|
74
|
+
message: 'Add 🍏 emoji (#5)',
|
|
75
|
+
sha: 'ee8c492334cef1ca077a56addb79a26f79821d2f',
|
|
76
|
+
},
|
|
77
|
+
sourcePullRequest: {
|
|
78
|
+
number: 5,
|
|
79
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/5',
|
|
80
|
+
mergeCommit: {
|
|
81
|
+
message: 'Add 🍏 emoji (#5)',
|
|
82
|
+
sha: 'ee8c492334cef1ca077a56addb79a26f79821d2f',
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
sourceBranch: 'master',
|
|
86
|
+
expectedTargetPullRequests: [
|
|
87
|
+
{
|
|
88
|
+
branch: '7.x',
|
|
89
|
+
state: 'MERGED',
|
|
90
|
+
number: 6,
|
|
91
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/6',
|
|
92
|
+
mergeCommit: {
|
|
93
|
+
message: 'Add 🍏 emoji (#5) (#6)',
|
|
94
|
+
sha: '4bcd876d4ceaa73cf437bfc89b74d1a4e704c0a6',
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
branch: '7.8',
|
|
99
|
+
state: 'MERGED',
|
|
100
|
+
number: 7,
|
|
101
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/7',
|
|
102
|
+
mergeCommit: {
|
|
103
|
+
message: 'Add 🍏 emoji (#5) (#7)',
|
|
104
|
+
sha: '46cd6f9999effdf894a36dbc7db90e890f4be840',
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
};
|
|
109
|
+
expect(await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).toEqual(expectedCommit);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
describe('when PR is still open', () => {
|
|
113
|
+
it('throws an error', async () => {
|
|
114
|
+
const options = {
|
|
115
|
+
accessToken,
|
|
116
|
+
pullNumber: 11,
|
|
117
|
+
repoName: 'backport-e2e',
|
|
118
|
+
repoOwner: 'backport-org',
|
|
119
|
+
sourceBranch: 'main',
|
|
120
|
+
};
|
|
121
|
+
await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`The PR #11 is not merged`);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
describe('when PR does not exist', () => {
|
|
125
|
+
it('throws an error', async () => {
|
|
126
|
+
const options = {
|
|
127
|
+
accessToken,
|
|
128
|
+
pullNumber: 9999999999999,
|
|
129
|
+
repoName: 'backport-e2e',
|
|
130
|
+
repoOwner: 'backport-org',
|
|
131
|
+
sourceBranch: 'main',
|
|
132
|
+
};
|
|
133
|
+
await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`Could not resolve to a PullRequest with the number of 9999999999999. (Github API v4)`);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
repoName: string;
|
|
8
|
+
repoOwner: string;
|
|
9
|
+
sha: string;
|
|
10
|
+
sourceBranch: string;
|
|
11
|
+
}): Promise<Commit>;
|
|
@@ -0,0 +1,48 @@
|
|
|
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.fetchCommitBySha = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const BackportError_1 = require("../../../BackportError");
|
|
9
|
+
const remoteConfig_1 = require("../../../remoteConfig");
|
|
10
|
+
const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
|
|
11
|
+
const apiRequestV4_1 = require("../apiRequestV4");
|
|
12
|
+
async function fetchCommitBySha(options) {
|
|
13
|
+
const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', repoName, repoOwner, sha, sourceBranch, } = options;
|
|
14
|
+
const query = (0, graphql_tag_1.default) `
|
|
15
|
+
query CommitsBySha($repoOwner: String!, $repoName: String!, $sha: String!) {
|
|
16
|
+
repository(owner: $repoOwner, name: $repoName) {
|
|
17
|
+
object(expression: $sha) {
|
|
18
|
+
...SourceCommitWithTargetPullRequestFragment
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
|
|
24
|
+
`;
|
|
25
|
+
let res;
|
|
26
|
+
try {
|
|
27
|
+
res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
28
|
+
githubApiBaseUrlV4,
|
|
29
|
+
accessToken,
|
|
30
|
+
query,
|
|
31
|
+
variables: {
|
|
32
|
+
repoOwner,
|
|
33
|
+
repoName,
|
|
34
|
+
sha,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
//@ts-expect-error
|
|
40
|
+
res = (0, remoteConfig_1.swallowMissingConfigFileException)(e);
|
|
41
|
+
}
|
|
42
|
+
const sourceCommit = res.repository.object;
|
|
43
|
+
if (!sourceCommit) {
|
|
44
|
+
throw new BackportError_1.BackportError(`No commit found on branch "${sourceBranch}" with sha "${sha}"`);
|
|
45
|
+
}
|
|
46
|
+
return (0, parseSourceCommit_1.parseSourceCommit)({ options, sourceCommit });
|
|
47
|
+
}
|
|
48
|
+
exports.fetchCommitBySha = fetchCommitBySha;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const graphql_1 = require("graphql");
|
|
27
|
+
const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
|
|
28
|
+
const apiRequestV4Module = __importStar(require("../apiRequestV4"));
|
|
29
|
+
const fetchCommitBySha_1 = require("./fetchCommitBySha");
|
|
30
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
31
|
+
describe('fetchCommitBySha', () => {
|
|
32
|
+
describe('snapshot request/response', () => {
|
|
33
|
+
let spy;
|
|
34
|
+
let commit;
|
|
35
|
+
beforeEach(async () => {
|
|
36
|
+
spy = jest.spyOn(apiRequestV4Module, 'apiRequestV4');
|
|
37
|
+
commit = await (0, fetchCommitBySha_1.fetchCommitBySha)({
|
|
38
|
+
repoOwner: 'elastic',
|
|
39
|
+
repoName: 'kibana',
|
|
40
|
+
accessToken,
|
|
41
|
+
sha: 'd421ddcf6157150596581c7885afa3690cec6339',
|
|
42
|
+
sourceBranch: 'main',
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
it('makes the right queries', () => {
|
|
46
|
+
const queries = spy.mock.calls.reduce((acc, call) => {
|
|
47
|
+
const query = call[0].query;
|
|
48
|
+
//@ts-expect-error
|
|
49
|
+
const name = query.definitions[0].name.value;
|
|
50
|
+
return { ...acc, [name]: (0, graphql_1.print)(query) };
|
|
51
|
+
}, {});
|
|
52
|
+
const queryNames = Object.keys(queries);
|
|
53
|
+
expect(queryNames).toEqual(['CommitsBySha']);
|
|
54
|
+
queryNames.forEach((name) => {
|
|
55
|
+
expect(queries[name]).toMatchSnapshot(`Query: ${name}`);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
it('returns the correct response', async () => {
|
|
59
|
+
expect(commit).toMatchSnapshot();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
it('should return single commit with pull request', async () => {
|
|
63
|
+
const expectedCommit = {
|
|
64
|
+
author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
|
|
65
|
+
sourceCommit: {
|
|
66
|
+
committedDate: '2020-07-07T20:40:28Z',
|
|
67
|
+
message: '[APM] Add API tests (#70740)',
|
|
68
|
+
sha: 'cb6fbc0e1b406675724181a3e9f59459b5f8f892',
|
|
69
|
+
},
|
|
70
|
+
sourcePullRequest: {
|
|
71
|
+
number: 70740,
|
|
72
|
+
url: 'https://github.com/elastic/kibana/pull/70740',
|
|
73
|
+
mergeCommit: {
|
|
74
|
+
message: '[APM] Add API tests (#70740)',
|
|
75
|
+
sha: 'cb6fbc0e1b406675724181a3e9f59459b5f8f892',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
sourceBranch: 'master',
|
|
79
|
+
expectedTargetPullRequests: [
|
|
80
|
+
{
|
|
81
|
+
branch: '7.x',
|
|
82
|
+
state: 'MERGED',
|
|
83
|
+
number: 71014,
|
|
84
|
+
url: 'https://github.com/elastic/kibana/pull/71014',
|
|
85
|
+
mergeCommit: {
|
|
86
|
+
message: '[APM] Add API tests (#70740) (#71014)',
|
|
87
|
+
sha: 'd15242be682582e58cd69f6b7707565434e99293',
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
};
|
|
92
|
+
await expect(await (0, fetchCommitBySha_1.fetchCommitBySha)({
|
|
93
|
+
repoOwner: 'elastic',
|
|
94
|
+
repoName: 'kibana',
|
|
95
|
+
accessToken,
|
|
96
|
+
sha: 'cb6fbc0',
|
|
97
|
+
sourceBranch: 'master',
|
|
98
|
+
})).toEqual(expectedCommit);
|
|
99
|
+
});
|
|
100
|
+
it('throws if sha does not exist', async () => {
|
|
101
|
+
await expect((0, fetchCommitBySha_1.fetchCommitBySha)({
|
|
102
|
+
repoOwner: 'elastic',
|
|
103
|
+
repoName: 'kibana',
|
|
104
|
+
accessToken,
|
|
105
|
+
sha: 'fc22f59',
|
|
106
|
+
sourceBranch: 'main',
|
|
107
|
+
})).rejects.toThrowError('No commit found on branch "main" with sha "fc22f59"');
|
|
108
|
+
});
|
|
109
|
+
it('throws if sha is invalid', async () => {
|
|
110
|
+
await expect((0, fetchCommitBySha_1.fetchCommitBySha)({
|
|
111
|
+
repoOwner: 'elastic',
|
|
112
|
+
repoName: 'kibana',
|
|
113
|
+
accessToken,
|
|
114
|
+
sha: 'myCommitSha',
|
|
115
|
+
sourceBranch: 'main',
|
|
116
|
+
})).rejects.toThrowError('No commit found on branch "main" with sha "myCommitSha"');
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
dateSince: string | null;
|
|
9
|
+
dateUntil: string | null;
|
|
10
|
+
githubApiBaseUrlV4?: string;
|
|
11
|
+
maxNumber?: number;
|
|
12
|
+
onlyMissing?: boolean;
|
|
13
|
+
repoName: string;
|
|
14
|
+
repoOwner: string;
|
|
15
|
+
sourceBranch: string;
|
|
16
|
+
}): Promise<Commit[]>;
|
|
17
|
+
export interface CommitByAuthorResponse {
|
|
18
|
+
repository: {
|
|
19
|
+
ref: {
|
|
20
|
+
target: {
|
|
21
|
+
history: {
|
|
22
|
+
edges: Array<{
|
|
23
|
+
node: SourceCommitWithTargetPullRequest;
|
|
24
|
+
}>;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
} | null;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
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.fetchCommitsByAuthor = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
9
|
+
const filterEmpty_1 = require("../../../../utils/filterEmpty");
|
|
10
|
+
const filterUnmergedCommits_1 = require("../../../../utils/filterUnmergedCommits");
|
|
11
|
+
const BackportError_1 = require("../../../BackportError");
|
|
12
|
+
const remoteConfig_1 = require("../../../remoteConfig");
|
|
13
|
+
const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
|
|
14
|
+
const apiRequestV4_1 = require("../apiRequestV4");
|
|
15
|
+
const fetchAuthorId_1 = require("../fetchAuthorId");
|
|
16
|
+
async function fetchByCommitPath({ options, authorId, commitPath, }) {
|
|
17
|
+
const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', maxNumber = 10, repoName, repoOwner, sourceBranch, dateSince, dateUntil, } = options;
|
|
18
|
+
const query = (0, graphql_tag_1.default) `
|
|
19
|
+
query CommitsByAuthor(
|
|
20
|
+
$repoOwner: String!
|
|
21
|
+
$repoName: String!
|
|
22
|
+
$maxNumber: Int!
|
|
23
|
+
$sourceBranch: String!
|
|
24
|
+
$authorId: ID
|
|
25
|
+
$commitPath: String
|
|
26
|
+
$dateSince: GitTimestamp
|
|
27
|
+
$dateUntil: GitTimestamp
|
|
28
|
+
) {
|
|
29
|
+
repository(owner: $repoOwner, name: $repoName) {
|
|
30
|
+
ref(qualifiedName: $sourceBranch) {
|
|
31
|
+
target {
|
|
32
|
+
... on Commit {
|
|
33
|
+
history(
|
|
34
|
+
first: $maxNumber
|
|
35
|
+
author: { id: $authorId }
|
|
36
|
+
path: $commitPath
|
|
37
|
+
since: $dateSince
|
|
38
|
+
until: $dateUntil
|
|
39
|
+
) {
|
|
40
|
+
edges {
|
|
41
|
+
node {
|
|
42
|
+
...SourceCommitWithTargetPullRequestFragment
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
|
|
53
|
+
`;
|
|
54
|
+
const variables = {
|
|
55
|
+
repoOwner,
|
|
56
|
+
repoName,
|
|
57
|
+
sourceBranch,
|
|
58
|
+
maxNumber,
|
|
59
|
+
authorId,
|
|
60
|
+
commitPath,
|
|
61
|
+
dateSince,
|
|
62
|
+
dateUntil,
|
|
63
|
+
};
|
|
64
|
+
try {
|
|
65
|
+
return await (0, apiRequestV4_1.apiRequestV4)({
|
|
66
|
+
githubApiBaseUrlV4,
|
|
67
|
+
accessToken,
|
|
68
|
+
query,
|
|
69
|
+
variables,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
//@ts-expect-error
|
|
74
|
+
return (0, remoteConfig_1.swallowMissingConfigFileException)(e);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async function fetchCommitsByAuthor(options) {
|
|
78
|
+
const { sourceBranch, commitPaths = [] } = options;
|
|
79
|
+
const authorId = await (0, fetchAuthorId_1.fetchAuthorId)(options);
|
|
80
|
+
const responses = await Promise.all((0, lodash_1.isEmpty)(commitPaths)
|
|
81
|
+
? [fetchByCommitPath({ options, authorId, commitPath: null })]
|
|
82
|
+
: commitPaths.map((commitPath) => fetchByCommitPath({ options, authorId, commitPath })));
|
|
83
|
+
// we only need to check if the first item is `null` (if the first is `null` they all are)
|
|
84
|
+
if (responses[0].repository.ref === null) {
|
|
85
|
+
throw new BackportError_1.BackportError(`The upstream branch "${sourceBranch}" does not exist. Try specifying a different branch with "--source-branch <your-branch>"`);
|
|
86
|
+
}
|
|
87
|
+
const commits = responses
|
|
88
|
+
.flatMap((res) => {
|
|
89
|
+
return res.repository.ref?.target.history.edges.map((edge) => {
|
|
90
|
+
const sourceCommit = edge.node;
|
|
91
|
+
return (0, parseSourceCommit_1.parseSourceCommit)({ options, sourceCommit });
|
|
92
|
+
});
|
|
93
|
+
})
|
|
94
|
+
.filter(filterEmpty_1.filterNil);
|
|
95
|
+
// terminate if not commits were found
|
|
96
|
+
if ((0, lodash_1.isEmpty)(commits)) {
|
|
97
|
+
const pathText = commitPaths.length > 0 ? ` touching files in path: "${commitPaths}"` : '';
|
|
98
|
+
const errorText = options.author
|
|
99
|
+
? `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`
|
|
100
|
+
: `There are no commits in this repository${pathText}`;
|
|
101
|
+
throw new BackportError_1.BackportError(errorText);
|
|
102
|
+
}
|
|
103
|
+
const commitsUnique = (0, lodash_1.uniqBy)(commits, (c) => c.sourceCommit.sha);
|
|
104
|
+
const commitsSorted = (0, lodash_1.orderBy)(commitsUnique, (c) => c.sourceCommit.committedDate, 'desc');
|
|
105
|
+
if (options.onlyMissing) {
|
|
106
|
+
return commitsSorted.filter(filterUnmergedCommits_1.filterUnmergedCommits);
|
|
107
|
+
}
|
|
108
|
+
return commitsSorted;
|
|
109
|
+
}
|
|
110
|
+
exports.fetchCommitsByAuthor = fetchCommitsByAuthor;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const graphql_1 = require("graphql");
|
|
27
|
+
const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
|
|
28
|
+
const apiRequestV4Module = __importStar(require("../apiRequestV4"));
|
|
29
|
+
const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
|
|
30
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
31
|
+
describe('fetchCommitsByAuthor', () => {
|
|
32
|
+
describe('snapshot request/response', () => {
|
|
33
|
+
let spy;
|
|
34
|
+
let commits;
|
|
35
|
+
beforeEach(async () => {
|
|
36
|
+
spy = jest.spyOn(apiRequestV4Module, 'apiRequestV4');
|
|
37
|
+
commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
38
|
+
accessToken,
|
|
39
|
+
author: 'sqren',
|
|
40
|
+
maxNumber: 10,
|
|
41
|
+
repoName: 'kibana',
|
|
42
|
+
repoOwner: 'elastic',
|
|
43
|
+
sourceBranch: 'main',
|
|
44
|
+
dateSince: '2021-01-10T00:00:00Z',
|
|
45
|
+
dateUntil: '2022-01-01T00:00:00Z',
|
|
46
|
+
commitPaths: [],
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
it('makes the right queries', () => {
|
|
50
|
+
const queries = spy.mock.calls.reduce((acc, call) => {
|
|
51
|
+
const query = call[0].query;
|
|
52
|
+
//@ts-expect-error
|
|
53
|
+
const name = query.definitions[0].name.value;
|
|
54
|
+
return { ...acc, [name]: (0, graphql_1.print)(query) };
|
|
55
|
+
}, {});
|
|
56
|
+
const queryNames = Object.keys(queries);
|
|
57
|
+
expect(queryNames).toEqual(['AuthorId', 'CommitsByAuthor']);
|
|
58
|
+
queryNames.forEach((name) => {
|
|
59
|
+
expect(queries[name]).toMatchSnapshot(`Query: ${name}`);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
it('returns the correct response', async () => {
|
|
63
|
+
expect(commits).toMatchSnapshot();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
describe('commitPaths', () => {
|
|
67
|
+
const getOptions = () => ({
|
|
68
|
+
accessToken,
|
|
69
|
+
author: 'sqren',
|
|
70
|
+
maxNumber: 10,
|
|
71
|
+
repoName: 'repo-with-different-commit-paths',
|
|
72
|
+
repoOwner: 'backport-org',
|
|
73
|
+
sourceBranch: 'main',
|
|
74
|
+
dateSince: null,
|
|
75
|
+
dateUntil: null,
|
|
76
|
+
});
|
|
77
|
+
const getCommitMessages = (commits) => {
|
|
78
|
+
return commits.map((c) => c.sourceCommit.message.replace(/(\r\n|\n|\r)/gm, ''));
|
|
79
|
+
};
|
|
80
|
+
it('returns all commits', async () => {
|
|
81
|
+
const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
82
|
+
...getOptions(),
|
|
83
|
+
commitPaths: [],
|
|
84
|
+
});
|
|
85
|
+
const commitMessages = getCommitMessages(commits);
|
|
86
|
+
expect(commitMessages).toEqual([
|
|
87
|
+
'Edit all lyrics',
|
|
88
|
+
'Update .backportrc.json',
|
|
89
|
+
'Edit "Take on me"',
|
|
90
|
+
'Add backportrc.json',
|
|
91
|
+
'Add "Bohemian Rhapsody""',
|
|
92
|
+
'Add "99 Luftballons"',
|
|
93
|
+
'Add "Take on me"',
|
|
94
|
+
]);
|
|
95
|
+
});
|
|
96
|
+
it('only returns commits related to "99-luftballons.txt"', async () => {
|
|
97
|
+
const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
98
|
+
...getOptions(),
|
|
99
|
+
commitPaths: ['lyrics/99-luftballons.txt'],
|
|
100
|
+
});
|
|
101
|
+
const commitMessages = getCommitMessages(commits);
|
|
102
|
+
expect(commitMessages).toEqual([
|
|
103
|
+
'Edit all lyrics',
|
|
104
|
+
'Add "99 Luftballons"',
|
|
105
|
+
]);
|
|
106
|
+
});
|
|
107
|
+
it('only returns commits related to "take-on-me.txt"', async () => {
|
|
108
|
+
const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
109
|
+
...getOptions(),
|
|
110
|
+
commitPaths: ['lyrics/take-on-me.txt'],
|
|
111
|
+
});
|
|
112
|
+
const commitMessages = getCommitMessages(commits);
|
|
113
|
+
expect(commitMessages).toEqual([
|
|
114
|
+
'Edit all lyrics',
|
|
115
|
+
'Edit "Take on me"',
|
|
116
|
+
'Add "Take on me"',
|
|
117
|
+
]);
|
|
118
|
+
});
|
|
119
|
+
it('removes duplicates and order by `committedDate`', async () => {
|
|
120
|
+
const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
121
|
+
...getOptions(),
|
|
122
|
+
commitPaths: [
|
|
123
|
+
'lyrics/99-luftballons.txt',
|
|
124
|
+
'lyrics/take-on-me.txt',
|
|
125
|
+
'lyrics/bohemian-rhapsody.txt',
|
|
126
|
+
],
|
|
127
|
+
});
|
|
128
|
+
const commitMessages = getCommitMessages(commits);
|
|
129
|
+
expect(commitMessages).toEqual([
|
|
130
|
+
'Edit all lyrics',
|
|
131
|
+
'Edit "Take on me"',
|
|
132
|
+
'Add "Bohemian Rhapsody""',
|
|
133
|
+
'Add "99 Luftballons"',
|
|
134
|
+
'Add "Take on me"',
|
|
135
|
+
]);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
describe('expectedTargetPullRequests', () => {
|
|
139
|
+
let res;
|
|
140
|
+
beforeEach(async () => {
|
|
141
|
+
res = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
142
|
+
accessToken,
|
|
143
|
+
commitPaths: [],
|
|
144
|
+
maxNumber: 10,
|
|
145
|
+
repoName: 'backport-e2e',
|
|
146
|
+
repoOwner: 'backport-org',
|
|
147
|
+
sourceBranch: 'master',
|
|
148
|
+
author: null,
|
|
149
|
+
dateSince: null,
|
|
150
|
+
dateUntil: null,
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
it('returns related OPEN PRs', async () => {
|
|
154
|
+
const commitWithOpenPR = res.find((commit) => commit.sourcePullRequest?.number === 9);
|
|
155
|
+
expect(commitWithOpenPR?.expectedTargetPullRequests).toEqual([
|
|
156
|
+
{
|
|
157
|
+
branch: '7.8',
|
|
158
|
+
state: 'OPEN',
|
|
159
|
+
number: 10,
|
|
160
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/10',
|
|
161
|
+
},
|
|
162
|
+
]);
|
|
163
|
+
});
|
|
164
|
+
it('returns related MERGED PRs', async () => {
|
|
165
|
+
const commitWithMergedPRs = res.find((commit) => commit.sourcePullRequest?.number === 5);
|
|
166
|
+
expect(commitWithMergedPRs?.expectedTargetPullRequests).toEqual([
|
|
167
|
+
{
|
|
168
|
+
branch: '7.x',
|
|
169
|
+
state: 'MERGED',
|
|
170
|
+
number: 6,
|
|
171
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/6',
|
|
172
|
+
mergeCommit: {
|
|
173
|
+
message: 'Add 🍏 emoji (#5) (#6)',
|
|
174
|
+
sha: '4bcd876d4ceaa73cf437bfc89b74d1a4e704c0a6',
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
branch: '7.8',
|
|
179
|
+
state: 'MERGED',
|
|
180
|
+
number: 7,
|
|
181
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/7',
|
|
182
|
+
mergeCommit: {
|
|
183
|
+
message: 'Add 🍏 emoji (#5) (#7)',
|
|
184
|
+
sha: '46cd6f9999effdf894a36dbc7db90e890f4be840',
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
]);
|
|
188
|
+
});
|
|
189
|
+
it('returns missing pull requests', async () => {
|
|
190
|
+
const commitWithoutPRs = res.find((commit) => commit.sourcePullRequest?.number === 8);
|
|
191
|
+
expect(commitWithoutPRs?.expectedTargetPullRequests).toEqual([
|
|
192
|
+
{ branch: '7.x', state: 'NOT_CREATED' },
|
|
193
|
+
]);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|