backport 7.3.6 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -21
- package/dist/backportRun.d.ts +18 -6
- package/dist/backportRun.js +70 -50
- package/dist/entrypoint.cli.js +4 -8
- package/dist/entrypoint.module.d.ts +13 -6
- package/dist/entrypoint.module.js +17 -19
- package/dist/entrypoint.module.private.test.js +129 -330
- 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 +13 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +238 -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 +58 -0
- package/dist/lib/env.d.ts +7 -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 +206 -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 +136 -0
- package/dist/lib/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/lib/github/v3/createStatusComment.test.js +461 -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/logger.d.ts +9 -0
- package/dist/lib/logger.js +74 -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 +6 -4
- package/dist/options/cliArgs.d.ts +16 -9
- package/dist/options/cliArgs.js +54 -28
- package/dist/options/cliArgs.test.js +128 -4
- package/dist/options/config/config.d.ts +7 -6
- package/dist/options/config/config.js +5 -7
- 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/projectConfig.d.ts +2 -2
- package/dist/options/config/projectConfig.js +3 -3
- package/dist/options/config/projectConfig.test.js +19 -7
- package/dist/options/config/readConfigFile.d.ts +9 -7
- package/dist/options/config/readConfigFile.js +2 -2
- package/dist/options/options.d.ts +44 -9
- package/dist/options/options.js +22 -27
- package/dist/options/options.test.js +119 -58
- package/dist/runSequentially.d.ts +14 -7
- package/dist/runSequentially.js +26 -11
- 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 +7 -3
- package/dist/services/HandledError.js +13 -13
- 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 -127
- 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 -158
- 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 +17 -17
- package/dist/services/github/v3/createStatusComment.test.js +22 -9
- package/dist/services/github/v4/apiRequestV4.js +8 -11
- package/dist/services/github/v4/apiRequestV4.test.js +2 -2
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
- package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +5 -6
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +4 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +10 -9
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +3 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +10 -9
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +4 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +9 -8
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +3 -6
- package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +3 -2
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -6
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +4 -7
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -2
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +6 -7
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +9 -8
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
- package/dist/services/logger.d.ts +1 -4
- package/dist/services/logger.js +14 -19
- 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 +26 -24
- package/dist/test/e2e/cli/entrypoint.cli.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +450 -0
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +27 -28
- 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.d.ts +1 -0
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +376 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +12 -10
- package/dist/test/sandbox.js +5 -1
- package/dist/test/setupFiles/automatic-mocks.js +17 -13
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +11 -7
- 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 +17 -17
- package/yarn.lock +461 -695
|
@@ -0,0 +1,157 @@
|
|
|
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
|
+
maxNumber: 10,
|
|
15
|
+
repoName: 'kibana',
|
|
16
|
+
repoOwner: 'elastic',
|
|
17
|
+
sourceBranch: 'source-branch-from-options',
|
|
18
|
+
dateSince: null,
|
|
19
|
+
dateUntil: null,
|
|
20
|
+
};
|
|
21
|
+
const authorIdMockData = { user: { id: 'myUserId' } };
|
|
22
|
+
describe('fetchCommitsByAuthor', () => {
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
jest.clearAllMocks();
|
|
25
|
+
});
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
nock_1.default.cleanAll();
|
|
28
|
+
});
|
|
29
|
+
describe('when commit has an associated pull request', () => {
|
|
30
|
+
let res;
|
|
31
|
+
let authorIdCalls;
|
|
32
|
+
let commitsByAuthorCalls;
|
|
33
|
+
beforeEach(async () => {
|
|
34
|
+
authorIdCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
35
|
+
name: 'AuthorId',
|
|
36
|
+
statusCode: 200,
|
|
37
|
+
body: { data: authorIdMockData },
|
|
38
|
+
});
|
|
39
|
+
commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
40
|
+
name: 'CommitsByAuthor',
|
|
41
|
+
statusCode: 200,
|
|
42
|
+
body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
|
|
43
|
+
});
|
|
44
|
+
res = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)(defaultOptions);
|
|
45
|
+
});
|
|
46
|
+
it('should return a list of commits with pullNumber and existing backports', () => {
|
|
47
|
+
const expectedCommits = [
|
|
48
|
+
{
|
|
49
|
+
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
50
|
+
sourceCommit: {
|
|
51
|
+
committedDate: '2021-12-24T00:00:00Z',
|
|
52
|
+
sha: '2e63475c483f7844b0f2833bc57fdee32095bacb',
|
|
53
|
+
message: 'Add 👻',
|
|
54
|
+
},
|
|
55
|
+
expectedTargetPullRequests: [],
|
|
56
|
+
sourceBranch: 'source-branch-from-options',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
60
|
+
sourceCommit: {
|
|
61
|
+
committedDate: '2021-12-23T00:00:00Z',
|
|
62
|
+
sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
|
|
63
|
+
message: 'Add witch (#85)',
|
|
64
|
+
},
|
|
65
|
+
sourcePullRequest: {
|
|
66
|
+
number: 85,
|
|
67
|
+
url: 'https://github.com/elastic/kibana/pull/85',
|
|
68
|
+
mergeCommit: {
|
|
69
|
+
sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
|
|
70
|
+
message: 'Add witch (#85)',
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
expectedTargetPullRequests: [],
|
|
74
|
+
sourceBranch: 'master',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
78
|
+
sourceCommit: {
|
|
79
|
+
committedDate: '2021-12-22T00:00:00Z',
|
|
80
|
+
sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
|
|
81
|
+
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
82
|
+
},
|
|
83
|
+
sourcePullRequest: {
|
|
84
|
+
number: 80,
|
|
85
|
+
url: 'https://github.com/elastic/kibana/pull/80',
|
|
86
|
+
mergeCommit: {
|
|
87
|
+
sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
|
|
88
|
+
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
expectedTargetPullRequests: [
|
|
92
|
+
{
|
|
93
|
+
branch: '6.3',
|
|
94
|
+
state: 'MERGED',
|
|
95
|
+
number: 99,
|
|
96
|
+
url: 'https://github.com/elastic/kibana/pull/99',
|
|
97
|
+
mergeCommit: {
|
|
98
|
+
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
99
|
+
sha: 'target-merge-commit-sha',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
sourceBranch: 'master',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
107
|
+
sourceCommit: {
|
|
108
|
+
committedDate: '2021-12-21T00:00:00Z',
|
|
109
|
+
sha: '3827bbbaf39914eda4f02f6940189844375fd097',
|
|
110
|
+
message: 'Add backport config',
|
|
111
|
+
},
|
|
112
|
+
expectedTargetPullRequests: [],
|
|
113
|
+
sourceBranch: 'source-branch-from-options',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
117
|
+
sourceCommit: {
|
|
118
|
+
committedDate: '2021-12-20T00:00:00Z',
|
|
119
|
+
sha: '5ea0da550ac191029459289d67f99ad7d310812b',
|
|
120
|
+
message: 'Initial commit',
|
|
121
|
+
},
|
|
122
|
+
expectedTargetPullRequests: [],
|
|
123
|
+
sourceBranch: 'source-branch-from-options',
|
|
124
|
+
},
|
|
125
|
+
];
|
|
126
|
+
expect(res).toEqual(expectedCommits);
|
|
127
|
+
});
|
|
128
|
+
it('should call with correct args to fetch author id', () => {
|
|
129
|
+
expect(authorIdCalls).toMatchSnapshot();
|
|
130
|
+
});
|
|
131
|
+
it('should call with correct args to fetch commits', () => {
|
|
132
|
+
expect(commitsByAuthorCalls).toMatchSnapshot();
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
describe('when a custom github api hostname is supplied', () => {
|
|
136
|
+
it('should be used in gql requests', async () => {
|
|
137
|
+
const authorIdCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
138
|
+
name: 'AuthorId',
|
|
139
|
+
statusCode: 200,
|
|
140
|
+
body: { data: authorIdMockData },
|
|
141
|
+
apiBaseUrl: 'http://localhost/my-custom-api',
|
|
142
|
+
});
|
|
143
|
+
const commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
144
|
+
name: 'CommitsByAuthor',
|
|
145
|
+
statusCode: 200,
|
|
146
|
+
body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
|
|
147
|
+
apiBaseUrl: 'http://localhost/my-custom-api',
|
|
148
|
+
});
|
|
149
|
+
await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
150
|
+
...defaultOptions,
|
|
151
|
+
githubApiBaseUrlV4: 'http://localhost/my-custom-api',
|
|
152
|
+
});
|
|
153
|
+
expect(authorIdCalls.length).toBe(1);
|
|
154
|
+
expect(commitsByAuthorCalls.length).toBe(1);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
|
|
4
|
+
const fetchPullRequestsBySearchQuery_1 = require("./fetchPullRequestsBySearchQuery");
|
|
5
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
6
|
+
describe('fetchPullRequestsBySearchQuery', () => {
|
|
7
|
+
describe('when filter does not match any PRs', () => {
|
|
8
|
+
it('throws an error', async () => {
|
|
9
|
+
const options = {
|
|
10
|
+
accessToken,
|
|
11
|
+
maxNumber: 10,
|
|
12
|
+
prFilter: 'label:non-existing',
|
|
13
|
+
repoName: 'backport-e2e',
|
|
14
|
+
repoOwner: 'backport-org',
|
|
15
|
+
sourceBranch: 'master',
|
|
16
|
+
author: 'sqren',
|
|
17
|
+
};
|
|
18
|
+
await expect((0, fetchPullRequestsBySearchQuery_1.fetchPullRequestsBySearchQuery)(options)).rejects
|
|
19
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
20
|
+
"No commits found for query:
|
|
21
|
+
type:pr is:merged sort:updated-desc repo:backport-org/backport-e2e author:sqren base:master label:non-existing
|
|
22
|
+
|
|
23
|
+
Use \`--all\` to see commits by all users or \`--author=<username>\` for commits from a specific user"
|
|
24
|
+
`);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe('when filter matches PRs', () => {
|
|
28
|
+
it('returns the merge commits for those PRs', async () => {
|
|
29
|
+
const options = {
|
|
30
|
+
accessToken,
|
|
31
|
+
maxNumber: 10,
|
|
32
|
+
prFilter: 'label:v7.8.0',
|
|
33
|
+
repoName: 'backport-e2e',
|
|
34
|
+
repoOwner: 'backport-org',
|
|
35
|
+
sourceBranch: 'master',
|
|
36
|
+
author: 'sqren',
|
|
37
|
+
};
|
|
38
|
+
const expectedCommits = [
|
|
39
|
+
{
|
|
40
|
+
author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
|
|
41
|
+
sourceCommit: {
|
|
42
|
+
committedDate: '2020-08-16T21:44:28Z',
|
|
43
|
+
message: 'Add sheep emoji (#9)',
|
|
44
|
+
sha: 'eebf165c82a4b718d95c11b3877e365b1949ff28',
|
|
45
|
+
},
|
|
46
|
+
sourcePullRequest: {
|
|
47
|
+
number: 9,
|
|
48
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/9',
|
|
49
|
+
mergeCommit: {
|
|
50
|
+
message: 'Add sheep emoji (#9)',
|
|
51
|
+
sha: 'eebf165c82a4b718d95c11b3877e365b1949ff28',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
sourceBranch: 'master',
|
|
55
|
+
expectedTargetPullRequests: [
|
|
56
|
+
{
|
|
57
|
+
branch: '7.8',
|
|
58
|
+
state: 'OPEN',
|
|
59
|
+
number: 10,
|
|
60
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/10',
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
|
|
66
|
+
sourceCommit: {
|
|
67
|
+
committedDate: '2020-08-15T12:40:19Z',
|
|
68
|
+
message: 'Add 🍏 emoji (#5)',
|
|
69
|
+
sha: 'ee8c492334cef1ca077a56addb79a26f79821d2f',
|
|
70
|
+
},
|
|
71
|
+
sourcePullRequest: {
|
|
72
|
+
number: 5,
|
|
73
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/5',
|
|
74
|
+
mergeCommit: {
|
|
75
|
+
message: 'Add 🍏 emoji (#5)',
|
|
76
|
+
sha: 'ee8c492334cef1ca077a56addb79a26f79821d2f',
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
sourceBranch: 'master',
|
|
80
|
+
expectedTargetPullRequests: [
|
|
81
|
+
{
|
|
82
|
+
branch: '7.x',
|
|
83
|
+
state: 'MERGED',
|
|
84
|
+
number: 6,
|
|
85
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/6',
|
|
86
|
+
mergeCommit: {
|
|
87
|
+
message: 'Add 🍏 emoji (#5) (#6)',
|
|
88
|
+
sha: '4bcd876d4ceaa73cf437bfc89b74d1a4e704c0a6',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
branch: '7.8',
|
|
93
|
+
state: 'MERGED',
|
|
94
|
+
number: 7,
|
|
95
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/7',
|
|
96
|
+
mergeCommit: {
|
|
97
|
+
message: 'Add 🍏 emoji (#5) (#7)',
|
|
98
|
+
sha: '46cd6f9999effdf894a36dbc7db90e890f4be840',
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
expect(await (0, fetchPullRequestsBySearchQuery_1.fetchPullRequestsBySearchQuery)(options)).toEqual(expectedCommits);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Commit } from '../../../sourceCommit/parseSourceCommit';
|
|
2
|
+
export declare function fetchPullRequestsBySearchQuery(options: {
|
|
3
|
+
accessToken: string;
|
|
4
|
+
author: string | null;
|
|
5
|
+
githubApiBaseUrlV4?: string;
|
|
6
|
+
maxNumber?: number;
|
|
7
|
+
onlyMissing?: boolean;
|
|
8
|
+
prFilter: string;
|
|
9
|
+
repoName: string;
|
|
10
|
+
repoOwner: string;
|
|
11
|
+
sourceBranch: string;
|
|
12
|
+
}): Promise<Commit[]>;
|
|
@@ -0,0 +1,69 @@
|
|
|
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.fetchPullRequestsBySearchQuery = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
9
|
+
const filterUnmergedCommits_1 = require("../../../../utils/filterUnmergedCommits");
|
|
10
|
+
const BackportError_1 = require("../../../BackportError");
|
|
11
|
+
const remoteConfig_1 = require("../../../remoteConfig");
|
|
12
|
+
const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
|
|
13
|
+
const apiRequestV4_1 = require("../apiRequestV4");
|
|
14
|
+
async function fetchPullRequestsBySearchQuery(options) {
|
|
15
|
+
const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', maxNumber = 10, prFilter, repoName, repoOwner, sourceBranch, author, } = options;
|
|
16
|
+
const query = (0, graphql_tag_1.default) `
|
|
17
|
+
query PullRequestBySearchQuery($query: String!, $maxNumber: Int!) {
|
|
18
|
+
search(query: $query, type: ISSUE, first: $maxNumber) {
|
|
19
|
+
nodes {
|
|
20
|
+
... on PullRequest {
|
|
21
|
+
mergeCommit {
|
|
22
|
+
...SourceCommitWithTargetPullRequestFragment
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
|
|
30
|
+
`;
|
|
31
|
+
const authorFilter = options.author ? ` author:${options.author}` : '';
|
|
32
|
+
const sourceBranchFilter = prFilter.includes('base:')
|
|
33
|
+
? ''
|
|
34
|
+
: ` base:${sourceBranch}`;
|
|
35
|
+
const searchQuery = `type:pr is:merged sort:updated-desc repo:${repoOwner}/${repoName}${authorFilter}${sourceBranchFilter} ${prFilter} `;
|
|
36
|
+
const variables = {
|
|
37
|
+
query: searchQuery,
|
|
38
|
+
maxNumber,
|
|
39
|
+
};
|
|
40
|
+
let res;
|
|
41
|
+
try {
|
|
42
|
+
res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
43
|
+
githubApiBaseUrlV4,
|
|
44
|
+
accessToken,
|
|
45
|
+
query,
|
|
46
|
+
variables,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
//@ts-expect-error
|
|
51
|
+
res = (0, remoteConfig_1.swallowMissingConfigFileException)(e);
|
|
52
|
+
}
|
|
53
|
+
const commits = res.search.nodes.map((pullRequestNode) => {
|
|
54
|
+
const sourceCommit = pullRequestNode.mergeCommit;
|
|
55
|
+
return (0, parseSourceCommit_1.parseSourceCommit)({ options, sourceCommit });
|
|
56
|
+
});
|
|
57
|
+
// terminate if not commits were found
|
|
58
|
+
if ((0, lodash_1.isEmpty)(commits)) {
|
|
59
|
+
const errorText = author
|
|
60
|
+
? `No commits found for query:\n ${searchQuery}\n\nUse \`--all\` to see commits by all users or \`--author=<username>\` for commits from a specific user`
|
|
61
|
+
: `No commits found for query:\n ${searchQuery}`;
|
|
62
|
+
throw new BackportError_1.BackportError(errorText);
|
|
63
|
+
}
|
|
64
|
+
if (options.onlyMissing) {
|
|
65
|
+
return commits.filter(filterUnmergedCommits_1.filterUnmergedCommits);
|
|
66
|
+
}
|
|
67
|
+
return commits;
|
|
68
|
+
}
|
|
69
|
+
exports.fetchPullRequestsBySearchQuery = fetchPullRequestsBySearchQuery;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ValidConfigOptions } from '../../../options/options';
|
|
2
|
+
import { PullRequestPayload } from '../v3/createPullRequest';
|
|
3
|
+
export declare function fetchExistingPullRequest({ options, prPayload, }: {
|
|
4
|
+
options: ValidConfigOptions;
|
|
5
|
+
prPayload: PullRequestPayload;
|
|
6
|
+
}): Promise<{
|
|
7
|
+
url: string;
|
|
8
|
+
number: number;
|
|
9
|
+
} | undefined>;
|
|
@@ -0,0 +1,64 @@
|
|
|
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.fetchExistingPullRequest = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const apiRequestV4_1 = require("./apiRequestV4");
|
|
9
|
+
async function fetchExistingPullRequest({ options, prPayload, }) {
|
|
10
|
+
const { githubApiBaseUrlV4, accessToken } = options;
|
|
11
|
+
const query = (0, graphql_tag_1.default) `
|
|
12
|
+
query ExistingPullRequest(
|
|
13
|
+
$repoOwner: String!
|
|
14
|
+
$repoName: String!
|
|
15
|
+
$base: String!
|
|
16
|
+
$head: String!
|
|
17
|
+
) {
|
|
18
|
+
repository(owner: $repoOwner, name: $repoName) {
|
|
19
|
+
name
|
|
20
|
+
ref(qualifiedName: $head) {
|
|
21
|
+
name
|
|
22
|
+
associatedPullRequests(
|
|
23
|
+
first: 1
|
|
24
|
+
states: OPEN
|
|
25
|
+
baseRefName: $base
|
|
26
|
+
headRefName: $head
|
|
27
|
+
) {
|
|
28
|
+
edges {
|
|
29
|
+
node {
|
|
30
|
+
number
|
|
31
|
+
url
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
const { repoForkOwner, head } = splitHead(prPayload);
|
|
40
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
41
|
+
githubApiBaseUrlV4,
|
|
42
|
+
accessToken,
|
|
43
|
+
query,
|
|
44
|
+
variables: {
|
|
45
|
+
repoOwner: repoForkOwner,
|
|
46
|
+
repoName: prPayload.repo,
|
|
47
|
+
base: prPayload.base,
|
|
48
|
+
head: head,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
const existingPullRequest = res.repository.ref?.associatedPullRequests.edges[0];
|
|
52
|
+
if (!existingPullRequest) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
url: existingPullRequest.node.url,
|
|
57
|
+
number: existingPullRequest.node.number,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
exports.fetchExistingPullRequest = fetchExistingPullRequest;
|
|
61
|
+
function splitHead(prPayload) {
|
|
62
|
+
const [repoForkOwner, head] = prPayload.head.split(':');
|
|
63
|
+
return { repoForkOwner, head };
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
|
|
4
|
+
const fetchExistingPullRequest_1 = require("./fetchExistingPullRequest");
|
|
5
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
6
|
+
describe('fetchExistingPullRequest', () => {
|
|
7
|
+
describe('when PR does not exist', () => {
|
|
8
|
+
it('returns undefined', async () => {
|
|
9
|
+
const options = {
|
|
10
|
+
accessToken,
|
|
11
|
+
};
|
|
12
|
+
const prPayload = {
|
|
13
|
+
owner: 'backport-org',
|
|
14
|
+
repo: 'backport-e2e',
|
|
15
|
+
title: 'My PR title',
|
|
16
|
+
body: 'My PR body',
|
|
17
|
+
head: 'sqren:backport/7.8/pr-foo',
|
|
18
|
+
base: '7.8',
|
|
19
|
+
};
|
|
20
|
+
const res = await (0, fetchExistingPullRequest_1.fetchExistingPullRequest)({ options, prPayload });
|
|
21
|
+
expect(res).toBe(undefined);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
describe('when PR exists', () => {
|
|
25
|
+
it('returns the PR number and url', async () => {
|
|
26
|
+
const options = {
|
|
27
|
+
accessToken,
|
|
28
|
+
};
|
|
29
|
+
const prPayload = {
|
|
30
|
+
owner: 'backport-org',
|
|
31
|
+
repo: 'backport-e2e',
|
|
32
|
+
title: 'My PR title',
|
|
33
|
+
body: 'My PR body',
|
|
34
|
+
head: 'sqren:backport/7.8/pr-9',
|
|
35
|
+
base: '7.8',
|
|
36
|
+
};
|
|
37
|
+
const res = await (0, fetchExistingPullRequest_1.fetchExistingPullRequest)({ options, prPayload });
|
|
38
|
+
expect(res).toEqual({
|
|
39
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/10',
|
|
40
|
+
number: 10,
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
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.fetchPullRequestAutoMergeMethod = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const apiRequestV4_1 = require("./apiRequestV4");
|
|
9
|
+
async function fetchPullRequestAutoMergeMethod(options, pullNumber) {
|
|
10
|
+
const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
|
|
11
|
+
const query = (0, graphql_tag_1.default) `
|
|
12
|
+
query PullRequestAutoMergeMethod(
|
|
13
|
+
$repoOwner: String!
|
|
14
|
+
$repoName: String!
|
|
15
|
+
$pullNumber: Int!
|
|
16
|
+
) {
|
|
17
|
+
repository(owner: $repoOwner, name: $repoName) {
|
|
18
|
+
pullRequest(number: $pullNumber) {
|
|
19
|
+
autoMergeRequest {
|
|
20
|
+
enabledAt
|
|
21
|
+
mergeMethod
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
`;
|
|
27
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
28
|
+
githubApiBaseUrlV4,
|
|
29
|
+
accessToken,
|
|
30
|
+
query,
|
|
31
|
+
variables: {
|
|
32
|
+
repoOwner,
|
|
33
|
+
repoName,
|
|
34
|
+
pullNumber,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
return res.repository.pullRequest?.autoMergeRequest?.mergeMethod;
|
|
38
|
+
}
|
|
39
|
+
exports.fetchPullRequestAutoMergeMethod = fetchPullRequestAutoMergeMethod;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ConfigFileOptions } from '../../../entrypoint.module';
|
|
2
|
+
export declare function fetchRemoteProjectConfig(options: {
|
|
3
|
+
accessToken: string;
|
|
4
|
+
githubApiBaseUrlV4?: string;
|
|
5
|
+
repoName: string;
|
|
6
|
+
repoOwner: string;
|
|
7
|
+
sourceBranch: string;
|
|
8
|
+
}): Promise<ConfigFileOptions | undefined>;
|
|
@@ -0,0 +1,49 @@
|
|
|
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.fetchRemoteProjectConfig = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const remoteConfig_1 = require("../../remoteConfig");
|
|
9
|
+
const apiRequestV4_1 = require("./apiRequestV4");
|
|
10
|
+
async function fetchRemoteProjectConfig(options) {
|
|
11
|
+
const { accessToken, githubApiBaseUrlV4, repoName, repoOwner, sourceBranch } = options;
|
|
12
|
+
const query = (0, graphql_tag_1.default) `
|
|
13
|
+
query ProjectConfig(
|
|
14
|
+
$repoOwner: String!
|
|
15
|
+
$repoName: String!
|
|
16
|
+
$sourceBranch: String!
|
|
17
|
+
) {
|
|
18
|
+
repository(owner: $repoOwner, name: $repoName) {
|
|
19
|
+
ref(qualifiedName: $sourceBranch) {
|
|
20
|
+
target {
|
|
21
|
+
...RemoteConfigHistoryFragment
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
${remoteConfig_1.RemoteConfigHistoryFragment}
|
|
28
|
+
`;
|
|
29
|
+
try {
|
|
30
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
31
|
+
githubApiBaseUrlV4,
|
|
32
|
+
accessToken,
|
|
33
|
+
query,
|
|
34
|
+
variables: {
|
|
35
|
+
repoOwner,
|
|
36
|
+
repoName,
|
|
37
|
+
sourceBranch,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
const remoteConfig = res.repository.ref.target.remoteConfigHistory.edges?.[0].remoteConfig;
|
|
41
|
+
if (remoteConfig) {
|
|
42
|
+
return (0, remoteConfig_1.parseRemoteConfig)(remoteConfig);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
throw new Error('Project config does not exist');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.fetchRemoteProjectConfig = fetchRemoteProjectConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
|
|
4
|
+
const fetchRemoteProjectConfig_1 = require("./fetchRemoteProjectConfig");
|
|
5
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
6
|
+
describe('fetchRemoteProjectConfig', () => {
|
|
7
|
+
it('returns the backport config from "main" branch', async () => {
|
|
8
|
+
const projectConfig = await (0, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
|
|
9
|
+
repoOwner: 'backport-org',
|
|
10
|
+
repoName: 'repo-with-project-config',
|
|
11
|
+
accessToken,
|
|
12
|
+
sourceBranch: 'main',
|
|
13
|
+
});
|
|
14
|
+
expect(projectConfig).toEqual({
|
|
15
|
+
autoMerge: true,
|
|
16
|
+
autoMergeMethod: 'squash',
|
|
17
|
+
branchLabelMapping: {
|
|
18
|
+
'^v(\\d+).(\\d+).\\d+$': '$1.$2',
|
|
19
|
+
'^v8.1.0$': 'main',
|
|
20
|
+
},
|
|
21
|
+
targetBranchChoices: ['main', '8.0', '7.17', '7.16'],
|
|
22
|
+
targetPRLabels: ['backport'],
|
|
23
|
+
repoOwner: 'backport-org',
|
|
24
|
+
repoName: 'repo-with-project-config',
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
it('returns the backport config from "branch-with-legacy-config" branch', async () => {
|
|
28
|
+
const projectConfig = await (0, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
|
|
29
|
+
repoOwner: 'backport-org',
|
|
30
|
+
repoName: 'repo-with-project-config',
|
|
31
|
+
accessToken,
|
|
32
|
+
sourceBranch: 'branch-with-legacy-config',
|
|
33
|
+
});
|
|
34
|
+
expect(projectConfig).toEqual({
|
|
35
|
+
targetBranchChoices: ['main', '8.0', '7.17', '7.16'],
|
|
36
|
+
repoOwner: 'backport-org',
|
|
37
|
+
repoName: 'repo-with-project-config',
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
it('throws an error if config does not exist', async () => {
|
|
41
|
+
const promise = (0, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
|
|
42
|
+
repoOwner: 'backport-org',
|
|
43
|
+
repoName: 'repo-with-project-config',
|
|
44
|
+
accessToken,
|
|
45
|
+
sourceBranch: 'branch-with-no-config',
|
|
46
|
+
});
|
|
47
|
+
await expect(promise).rejects.toThrowError('Project config does not exist');
|
|
48
|
+
});
|
|
49
|
+
});
|