backport 5.6.3 → 6.0.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 +48 -39
- package/dist/entrypoint.cli.js +1 -1
- package/dist/entrypoint.module.d.ts +6 -5
- package/dist/entrypoint.module.js +8 -6
- 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 -24
- package/dist/options/ConfigOptions.d.ts +47 -39
- package/dist/options/cliArgs.d.ts +28 -34
- package/dist/options/cliArgs.js +113 -94
- package/dist/options/cliArgs.test.js +103 -119
- package/dist/options/config/config.d.ts +81 -2
- package/dist/options/config/config.js +46 -6
- package/dist/options/config/config.test.js +24 -2
- package/dist/options/config/getOptionsFromGit.d.ts +3 -0
- package/dist/options/config/getOptionsFromGit.js +10 -0
- package/dist/options/config/globalConfig.d.ts +2 -1
- package/dist/options/config/globalConfig.js +8 -8
- package/dist/options/config/globalConfig.test.js +7 -3
- package/dist/options/config/projectConfig.d.ts +2 -1
- package/dist/options/config/projectConfig.js +3 -3
- package/dist/options/config/projectConfig.test.js +4 -4
- package/dist/options/config/readConfigFile.d.ts +2 -2
- package/dist/options/config/readConfigFile.js +3 -3
- package/dist/options/options.d.ts +40 -27
- package/dist/options/options.js +8 -16
- package/dist/options/options.test.js +66 -26
- package/dist/options/parseRequiredOptions.d.ts +71 -0
- package/dist/options/parseRequiredOptions.js +70 -0
- package/dist/options/parseRequiredOptions.test.d.ts +1 -0
- package/dist/options/parseRequiredOptions.test.js +127 -0
- package/dist/runSequentially.d.ts +20 -0
- package/dist/runSequentially.js +41 -0
- package/dist/runSequentially.test.d.ts +1 -0
- package/dist/runSequentially.test.js +235 -0
- package/dist/runWithOptions.js +7 -14
- package/dist/runWithOptions.test.js +142 -16
- package/dist/scripts/generate-gql.d.ts +1 -0
- package/dist/scripts/generate-gql.js +15 -0
- package/dist/scripts/postinstall.js +4 -4
- package/dist/scripts/postinstall.test.js +9 -2
- package/dist/scripts/runPostinstall.js +1 -1
- package/dist/services/HandledError.d.ts +11 -1
- package/dist/services/HandledError.js +2 -1
- package/dist/services/child-process-promisified.d.ts +1 -1
- package/dist/services/child-process-promisified.js +2 -2
- package/dist/services/env.js +5 -5
- package/dist/services/env.test.js +11 -4
- package/dist/services/fs-promisified.js +4 -4
- package/dist/services/getExpectedTarget.d.ts +9 -0
- package/dist/services/getExpectedTarget.js +77 -0
- package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
- package/dist/services/getExpectedTargetPullRequests.js +77 -0
- package/dist/services/git.d.ts +19 -4
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +168 -0
- package/dist/services/git.js +129 -57
- package/dist/services/git.test.js +155 -51
- 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 +2 -6
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +2 -3
- 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 +33 -24
- 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 +1 -1
- 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 +9 -0
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +28 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +9 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +51 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +113 -0
- package/dist/services/github/v4/fetchAuthorId.d.ts +5 -0
- package/dist/services/github/v4/fetchAuthorId.js +1 -1
- package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -3
- package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
- package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +6 -6
- package/dist/services/github/v4/fetchCommitBySha.js +14 -12
- package/dist/services/github/v4/fetchCommitBySha.private.test.js +7 -5
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +5 -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 +67 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +5 -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 +16 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +90 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +130 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +127 -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/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 +81 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
- package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +3 -2
- package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
- package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +81 -8
- package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
- package/dist/services/github/v4/fetchDefaultBranch.d.ts +1 -1
- package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +4 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.js +52 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +32 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.d.ts +4 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.js +72 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.js +34 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.d.ts +40 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.js +72 -0
- package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -3
- package/dist/services/github/v4/fetchMergedPullRequests.d.ts +19 -20
- package/dist/services/github/v4/fetchMergedPullRequests.js +22 -68
- package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +11 -0
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +35 -0
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.d.ts +1 -1
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +8 -6
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
- package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
- package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
- package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +61 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.js +139 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +126 -0
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +34 -0
- package/dist/services/github/v4/getOptionsFromGithub/query.js +44 -0
- package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
- package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
- package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
- package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +2 -2
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +2 -2
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +4 -1
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +1 -1
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
- package/dist/services/logger.d.ts +3 -3
- package/dist/services/logger.js +24 -24
- package/dist/services/prompt.test.d.ts +1 -0
- package/dist/services/prompt.test.js +87 -0
- package/dist/services/prompts.d.ts +10 -4
- package/dist/services/prompts.js +85 -22
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +396 -0
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +78 -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 +114 -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 +81 -45
- package/dist/test/integration/createSpies.d.ts +1 -1
- package/dist/test/integration/createSpies.js +21 -9
- package/dist/test/integration/envConstants.js +5 -6
- package/dist/test/integration/helpers.js +1 -1
- package/dist/test/integration/integration.private.test.d.ts +1 -0
- package/dist/test/integration/integration.private.test.js +308 -0
- package/dist/test/integration/integration.test.js +30 -31
- package/dist/test/nockHelpers.d.ts +2 -2
- package/dist/test/nockHelpers.js +3 -7
- package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
- package/dist/test/setupFiles/automatic-mocks.js +0 -22
- 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 +277 -59
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +135 -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 +2 -2
- package/dist/ui/getTargetBranches.js +16 -17
- 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 +9 -9
- package/dist/ui/maybeSetupRepo.test.js +5 -1
- package/package.json +36 -51
- package/yarn.lock +2387 -2979
|
@@ -22,13 +22,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const os_1 = __importDefault(require("os"));
|
|
25
26
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
27
|
+
const lodash_1 = require("lodash");
|
|
26
28
|
const nock_1 = __importDefault(require("nock"));
|
|
27
29
|
const runWithOptions_1 = require("./runWithOptions");
|
|
28
30
|
const childProcess = __importStar(require("./services/child-process-promisified"));
|
|
29
31
|
const fs = __importStar(require("./services/fs-promisified"));
|
|
30
32
|
const commitsByAuthorMock_1 = require("./services/github/v4/mocks/commitsByAuthorMock");
|
|
31
33
|
const nockHelpers_1 = require("./test/nockHelpers");
|
|
34
|
+
jest.mock('./services/child-process-promisified', () => {
|
|
35
|
+
return {
|
|
36
|
+
exec: jest.fn(async (cmd) => {
|
|
37
|
+
throw new Error(`Mock required for exec with cmd: "${cmd}"`);
|
|
38
|
+
}),
|
|
39
|
+
execAsCallback: jest.fn((...args) => {
|
|
40
|
+
(0, lodash_1.last)(args)();
|
|
41
|
+
return {
|
|
42
|
+
stderr: {
|
|
43
|
+
on: () => null,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}),
|
|
47
|
+
};
|
|
48
|
+
});
|
|
32
49
|
describe('runWithOptions', () => {
|
|
33
50
|
let rpcExecMock;
|
|
34
51
|
let rpcExecOriginalMock;
|
|
@@ -42,16 +59,23 @@ describe('runWithOptions', () => {
|
|
|
42
59
|
nock_1.default.cleanAll();
|
|
43
60
|
});
|
|
44
61
|
beforeEach(async () => {
|
|
62
|
+
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
45
63
|
const options = {
|
|
46
64
|
accessToken: 'myAccessToken',
|
|
47
65
|
all: false,
|
|
48
66
|
assignees: [],
|
|
49
67
|
author: 'sqren',
|
|
68
|
+
autoAssign: false,
|
|
50
69
|
autoFixConflicts: undefined,
|
|
70
|
+
autoMerge: false,
|
|
71
|
+
autoMergeMethod: 'merge',
|
|
51
72
|
branchLabelMapping: undefined,
|
|
52
73
|
ci: false,
|
|
53
|
-
|
|
74
|
+
cherrypickRef: true,
|
|
75
|
+
commitPaths: [],
|
|
76
|
+
details: false,
|
|
54
77
|
editor: 'code',
|
|
78
|
+
forceLocalConfig: undefined,
|
|
55
79
|
fork: true,
|
|
56
80
|
gitHostname: 'github.com',
|
|
57
81
|
githubApiBaseUrlV3: 'https://api.github.com',
|
|
@@ -61,18 +85,18 @@ describe('runWithOptions', () => {
|
|
|
61
85
|
multipleBranches: false,
|
|
62
86
|
multipleCommits: false,
|
|
63
87
|
noVerify: true,
|
|
64
|
-
path: undefined,
|
|
65
88
|
prDescription: 'myPrDescription',
|
|
89
|
+
prFilter: undefined,
|
|
66
90
|
prTitle: 'myPrTitle {targetBranch} {commitMessages}',
|
|
67
91
|
pullNumber: undefined,
|
|
68
92
|
repoName: 'kibana',
|
|
69
93
|
repoOwner: 'elastic',
|
|
70
94
|
resetAuthor: false,
|
|
71
95
|
sha: undefined,
|
|
72
|
-
sourceBranch: '
|
|
96
|
+
sourceBranch: 'my-source-branch-from-options',
|
|
73
97
|
sourcePRLabels: [],
|
|
74
|
-
prFilter: undefined,
|
|
75
98
|
targetBranches: [],
|
|
99
|
+
upstream: 'elastic/kibana',
|
|
76
100
|
targetBranchChoices: [
|
|
77
101
|
{ name: '6.x' },
|
|
78
102
|
{ name: '6.0' },
|
|
@@ -97,21 +121,21 @@ describe('runWithOptions', () => {
|
|
|
97
121
|
.mockImplementationOnce((async (args) => {
|
|
98
122
|
return { promptResult: args[0].choices[0].name };
|
|
99
123
|
}));
|
|
100
|
-
authorIdCalls = nockHelpers_1.mockGqlRequest({
|
|
124
|
+
authorIdCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
101
125
|
name: 'AuthorId',
|
|
102
126
|
statusCode: 200,
|
|
103
127
|
body: { data: { user: { id: 'sqren_author_id' } } },
|
|
104
128
|
});
|
|
105
|
-
commitsByAuthorCalls = nockHelpers_1.mockGqlRequest({
|
|
129
|
+
commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
106
130
|
name: 'CommitsByAuthor',
|
|
107
131
|
statusCode: 200,
|
|
108
|
-
body: { data: commitsByAuthorMock_1.
|
|
132
|
+
body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
|
|
109
133
|
});
|
|
110
|
-
const scope = nock_1.default('https://api.github.com')
|
|
134
|
+
const scope = (0, nock_1.default)('https://api.github.com')
|
|
111
135
|
.post('/repos/elastic/kibana/pulls')
|
|
112
136
|
.reply(200, { html_url: 'pull request url', number: 1337 });
|
|
113
|
-
createPullRequestCalls = nockHelpers_1.getNockCallsForScope(scope);
|
|
114
|
-
res = await runWithOptions_1.runWithOptions(options);
|
|
137
|
+
createPullRequestCalls = (0, nockHelpers_1.getNockCallsForScope)(scope);
|
|
138
|
+
res = await (0, runWithOptions_1.runWithOptions)(options);
|
|
115
139
|
scope.done();
|
|
116
140
|
});
|
|
117
141
|
it('returns pull request', () => {
|
|
@@ -129,7 +153,7 @@ describe('runWithOptions', () => {
|
|
|
129
153
|
base: '6.x',
|
|
130
154
|
body: 'Backports the following commits to 6.x:\n - Add 👻 (2e63475c)\n\nmyPrDescription',
|
|
131
155
|
head: 'sqren:backport/6.x/commit-2e63475c',
|
|
132
|
-
title: 'myPrTitle 6.x Add 👻
|
|
156
|
+
title: 'myPrTitle 6.x Add 👻',
|
|
133
157
|
},
|
|
134
158
|
]);
|
|
135
159
|
});
|
|
@@ -155,24 +179,126 @@ describe('runWithOptions', () => {
|
|
|
155
179
|
expect(commitsByAuthorCalls.map((body) => body.variables)).toEqual([
|
|
156
180
|
{
|
|
157
181
|
authorId: 'sqren_author_id',
|
|
158
|
-
historyPath: null,
|
|
159
182
|
maxNumber: 10,
|
|
183
|
+
commitPath: null,
|
|
160
184
|
repoName: 'kibana',
|
|
161
185
|
repoOwner: 'elastic',
|
|
162
|
-
sourceBranch: '
|
|
186
|
+
sourceBranch: 'my-source-branch-from-options',
|
|
163
187
|
},
|
|
164
188
|
]);
|
|
165
189
|
});
|
|
166
190
|
it('prompt calls should match snapshot', () => {
|
|
167
191
|
expect(inquirer_1.default.prompt).toHaveBeenCalledTimes(2);
|
|
168
|
-
expect(
|
|
192
|
+
expect(
|
|
193
|
+
// @ts-expect-error
|
|
194
|
+
inquirerPromptMock.mock.calls[0][0][0].choices.map(({ name, short }) => ({
|
|
195
|
+
name,
|
|
196
|
+
short,
|
|
197
|
+
}))).toMatchInlineSnapshot(`
|
|
198
|
+
Array [
|
|
199
|
+
Object {
|
|
200
|
+
"name": "1. Add 👻 ",
|
|
201
|
+
"short": "2e63475c",
|
|
202
|
+
},
|
|
203
|
+
Object {
|
|
204
|
+
"name": "2. Add witch (#85) ",
|
|
205
|
+
"short": "#85 (f3b618b9)",
|
|
206
|
+
},
|
|
207
|
+
Object {
|
|
208
|
+
"name": "3. Add SF mention (#80) 6.3",
|
|
209
|
+
"short": "#80 (79cf1845)",
|
|
210
|
+
},
|
|
211
|
+
Object {
|
|
212
|
+
"name": "4. Add backport config ",
|
|
213
|
+
"short": "3827bbba",
|
|
214
|
+
},
|
|
215
|
+
Object {
|
|
216
|
+
"name": "5. Initial commit ",
|
|
217
|
+
"short": "5ea0da55",
|
|
218
|
+
},
|
|
219
|
+
]
|
|
220
|
+
`);
|
|
169
221
|
});
|
|
170
222
|
it('exec should be called with correct args', () => {
|
|
171
223
|
expect(rpcExecMock).toHaveBeenCalledTimes(10);
|
|
172
|
-
expect(rpcExecMock.mock.calls).
|
|
224
|
+
expect(rpcExecMock.mock.calls).toMatchInlineSnapshot(`
|
|
225
|
+
Array [
|
|
226
|
+
Array [
|
|
227
|
+
"git remote rm origin",
|
|
228
|
+
Object {
|
|
229
|
+
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
Array [
|
|
233
|
+
"git remote rm sqren",
|
|
234
|
+
Object {
|
|
235
|
+
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
Array [
|
|
239
|
+
"git remote add sqren https://x-access-token:myAccessToken@github.com/sqren/kibana.git",
|
|
240
|
+
Object {
|
|
241
|
+
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
242
|
+
},
|
|
243
|
+
],
|
|
244
|
+
Array [
|
|
245
|
+
"git remote rm elastic",
|
|
246
|
+
Object {
|
|
247
|
+
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
Array [
|
|
251
|
+
"git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git",
|
|
252
|
+
Object {
|
|
253
|
+
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
Array [
|
|
257
|
+
"git reset --hard && git clean -d --force && git fetch elastic 6.x && git checkout -B backport/6.x/commit-2e63475c elastic/6.x --no-track",
|
|
258
|
+
Object {
|
|
259
|
+
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
260
|
+
},
|
|
261
|
+
],
|
|
262
|
+
Array [
|
|
263
|
+
"git fetch elastic my-source-branch-from-options:my-source-branch-from-options --force",
|
|
264
|
+
Object {
|
|
265
|
+
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
Array [
|
|
269
|
+
"git cherry-pick 2e63475c483f7844b0f2833bc57fdee32095bacb",
|
|
270
|
+
Object {
|
|
271
|
+
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
Array [
|
|
275
|
+
"git push sqren backport/6.x/commit-2e63475c:backport/6.x/commit-2e63475c --force",
|
|
276
|
+
Object {
|
|
277
|
+
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
278
|
+
},
|
|
279
|
+
],
|
|
280
|
+
Array [
|
|
281
|
+
"git reset --hard && git checkout my-source-branch-from-options && git branch -D backport/6.x/commit-2e63475c",
|
|
282
|
+
Object {
|
|
283
|
+
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
]
|
|
287
|
+
`);
|
|
173
288
|
});
|
|
174
289
|
it('git clone should be called with correct args', () => {
|
|
175
290
|
expect(rpcExecOriginalMock).toHaveBeenCalledTimes(1);
|
|
176
|
-
expect(rpcExecOriginalMock.mock.calls).
|
|
291
|
+
expect(rpcExecOriginalMock.mock.calls).toMatchInlineSnapshot(`
|
|
292
|
+
Array [
|
|
293
|
+
Array [
|
|
294
|
+
"git clone https://x-access-token:myAccessToken@github.com/elastic/kibana.git --progress",
|
|
295
|
+
Object {
|
|
296
|
+
"cwd": "/myHomeDir/.backport/repositories/elastic",
|
|
297
|
+
"maxBuffer": 104857600,
|
|
298
|
+
},
|
|
299
|
+
[Function],
|
|
300
|
+
],
|
|
301
|
+
]
|
|
302
|
+
`);
|
|
177
303
|
});
|
|
178
304
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fetchCommitBySha_1 = require("../services/github/v4/fetchCommits/fetchCommitBySha");
|
|
4
|
+
const getDevAccessToken_1 = require("../test/private/getDevAccessToken");
|
|
5
|
+
async function init() {
|
|
6
|
+
const accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
7
|
+
const res = (0, fetchCommitBySha_1.fetchCommitBySha)({
|
|
8
|
+
accessToken,
|
|
9
|
+
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
10
|
+
repoName: 'backport-org',
|
|
11
|
+
repoOwner: 'backport-e2e',
|
|
12
|
+
sha: 'b484e161b705b39dbbfc5005e67ca24d05b23c37',
|
|
13
|
+
sourceBranch: 'main',
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -6,14 +6,14 @@ const env_1 = require("../services/env");
|
|
|
6
6
|
const logger_1 = require("../services/logger");
|
|
7
7
|
async function postinstall() {
|
|
8
8
|
try {
|
|
9
|
-
const didCreate = await globalConfig_1.createGlobalConfigAndFolderIfNotExist();
|
|
9
|
+
const didCreate = await (0, globalConfig_1.createGlobalConfigAndFolderIfNotExist)();
|
|
10
10
|
if (didCreate) {
|
|
11
|
-
const GLOBAL_CONFIG_PATH = env_1.getGlobalConfigPath();
|
|
12
|
-
logger_1.consoleLog(`Global config successfully created in ${GLOBAL_CONFIG_PATH}`);
|
|
11
|
+
const GLOBAL_CONFIG_PATH = (0, env_1.getGlobalConfigPath)();
|
|
12
|
+
(0, logger_1.consoleLog)(`Global config successfully created in ${GLOBAL_CONFIG_PATH}`);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
catch (e) {
|
|
16
|
-
logger_1.consoleLog(`Global config could not be created:\n${e.stack}`);
|
|
16
|
+
(0, logger_1.consoleLog)(`Global config could not be created:\n${e.stack}`);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.postinstall = postinstall;
|
|
@@ -18,19 +18,26 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
18
18
|
__setModuleDefault(result, mod);
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
21
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const os_1 = __importDefault(require("os"));
|
|
22
26
|
const globalConfig = __importStar(require("../options/config/globalConfig"));
|
|
23
27
|
const logger = __importStar(require("../services/logger"));
|
|
24
28
|
const postinstall_1 = require("./postinstall");
|
|
25
29
|
describe('postinstall', () => {
|
|
26
30
|
beforeEach(() => {
|
|
31
|
+
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
32
|
+
});
|
|
33
|
+
afterEach(() => {
|
|
27
34
|
jest.clearAllMocks();
|
|
28
35
|
});
|
|
29
36
|
it("should create global config if it doesn't exist", async () => {
|
|
30
37
|
const createGlobalConfigAndFolderIfNotExistSpy = jest
|
|
31
38
|
.spyOn(globalConfig, 'createGlobalConfigAndFolderIfNotExist')
|
|
32
39
|
.mockResolvedValueOnce(true);
|
|
33
|
-
await postinstall_1.postinstall();
|
|
40
|
+
await (0, postinstall_1.postinstall)();
|
|
34
41
|
expect(createGlobalConfigAndFolderIfNotExistSpy).toBeCalledTimes(1);
|
|
35
42
|
expect(logger.consoleLog).toBeCalledWith('Global config successfully created in /myHomeDir/.backport/config.json');
|
|
36
43
|
});
|
|
@@ -39,7 +46,7 @@ describe('postinstall', () => {
|
|
|
39
46
|
const createGlobalConfigAndFolderIfNotExistSpy = jest
|
|
40
47
|
.spyOn(globalConfig, 'createGlobalConfigAndFolderIfNotExist')
|
|
41
48
|
.mockResolvedValueOnce(false);
|
|
42
|
-
await postinstall_1.postinstall();
|
|
49
|
+
await (0, postinstall_1.postinstall)();
|
|
43
50
|
expect(createGlobalConfigAndFolderIfNotExistSpy).toBeCalledTimes(1);
|
|
44
51
|
expect(consoleSpy).toBeCalledTimes(0);
|
|
45
52
|
});
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import { Commit } from './sourceCommit/parseSourceCommit';
|
|
2
|
+
declare type Meta = {
|
|
3
|
+
type: 'commitsWithoutBackports';
|
|
4
|
+
commitsWithoutBackports: {
|
|
5
|
+
formatted: string;
|
|
6
|
+
commit: Commit;
|
|
7
|
+
}[];
|
|
8
|
+
};
|
|
1
9
|
export declare class HandledError extends Error {
|
|
2
|
-
|
|
10
|
+
meta?: Meta;
|
|
11
|
+
constructor(message: string, meta?: Meta);
|
|
3
12
|
}
|
|
13
|
+
export {};
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HandledError = void 0;
|
|
4
4
|
class HandledError extends Error {
|
|
5
|
-
constructor(message) {
|
|
5
|
+
constructor(message, meta) {
|
|
6
6
|
super(message);
|
|
7
7
|
Error.captureStackTrace(this, HandledError);
|
|
8
8
|
this.name = 'HandledError';
|
|
9
|
+
this.meta = meta;
|
|
9
10
|
}
|
|
10
11
|
}
|
|
11
12
|
exports.HandledError = HandledError;
|
|
@@ -4,4 +4,4 @@ export declare function exec(cmd: string, options: child_process.ExecOptions): P
|
|
|
4
4
|
stdout: string;
|
|
5
5
|
stderr: string;
|
|
6
6
|
}>;
|
|
7
|
-
export declare const execAsCallback: (command: string, options: (import("fs").
|
|
7
|
+
export declare const execAsCallback: (command: string, options: (import("fs").ObjectEncodingOptions & child_process.ExecOptions) | null | undefined, callback?: ((error: child_process.ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void) | undefined) => child_process.ChildProcess;
|
|
@@ -8,7 +8,7 @@ const child_process_1 = __importDefault(require("child_process"));
|
|
|
8
8
|
const util_1 = require("util");
|
|
9
9
|
const logger_1 = require("./logger");
|
|
10
10
|
async function exec(cmd, options) {
|
|
11
|
-
const execPromisified = util_1.promisify(child_process_1.default.exec);
|
|
11
|
+
const execPromisified = (0, util_1.promisify)(child_process_1.default.exec);
|
|
12
12
|
try {
|
|
13
13
|
const res = await execPromisified(cmd, {
|
|
14
14
|
maxBuffer: 100 * 1024 * 1024,
|
|
@@ -18,7 +18,7 @@ async function exec(cmd, options) {
|
|
|
18
18
|
return res;
|
|
19
19
|
}
|
|
20
20
|
catch (e) {
|
|
21
|
-
logger_1.logger.info(`exec error '${cmd}'
|
|
21
|
+
logger_1.logger.info(`exec error '${cmd}': ${JSON.stringify(e, null, 2)}`);
|
|
22
22
|
throw e;
|
|
23
23
|
}
|
|
24
24
|
}
|
package/dist/services/env.js
CHANGED
|
@@ -7,22 +7,22 @@ exports.getRepoPath = exports.getRepoOwnerPath = exports.getReposPath = exports.
|
|
|
7
7
|
const os_1 = require("os");
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
function getLogfilePath() {
|
|
10
|
-
return path_1.default.join(os_1.homedir(), '.backport', 'backport.log');
|
|
10
|
+
return path_1.default.join((0, os_1.homedir)(), '.backport', 'backport.log');
|
|
11
11
|
}
|
|
12
12
|
exports.getLogfilePath = getLogfilePath;
|
|
13
13
|
function getGlobalConfigPath() {
|
|
14
|
-
return path_1.default.join(os_1.homedir(), '.backport', 'config.json');
|
|
14
|
+
return path_1.default.join((0, os_1.homedir)(), '.backport', 'config.json');
|
|
15
15
|
}
|
|
16
16
|
exports.getGlobalConfigPath = getGlobalConfigPath;
|
|
17
17
|
function getReposPath() {
|
|
18
|
-
return path_1.default.join(os_1.homedir(), '.backport', 'repositories');
|
|
18
|
+
return path_1.default.join((0, os_1.homedir)(), '.backport', 'repositories');
|
|
19
19
|
}
|
|
20
20
|
exports.getReposPath = getReposPath;
|
|
21
21
|
function getRepoOwnerPath({ repoOwner }) {
|
|
22
|
-
return path_1.default.join(os_1.homedir(), '.backport', 'repositories', repoOwner);
|
|
22
|
+
return path_1.default.join((0, os_1.homedir)(), '.backport', 'repositories', repoOwner);
|
|
23
23
|
}
|
|
24
24
|
exports.getRepoOwnerPath = getRepoOwnerPath;
|
|
25
25
|
function getRepoPath({ repoOwner, repoName }) {
|
|
26
|
-
return path_1.default.join(os_1.homedir(), '.backport', 'repositories', repoOwner, repoName);
|
|
26
|
+
return path_1.default.join((0, os_1.homedir)(), '.backport', 'repositories', repoOwner, repoName);
|
|
27
27
|
}
|
|
28
28
|
exports.getRepoPath = getRepoPath;
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const os_1 = __importDefault(require("os"));
|
|
3
7
|
const env_1 = require("../services/env");
|
|
4
8
|
describe('env', () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
11
|
+
});
|
|
5
12
|
test('getGlobalConfigPath', () => {
|
|
6
|
-
expect(env_1.getGlobalConfigPath()).toBe('/myHomeDir/.backport/config.json');
|
|
13
|
+
expect((0, env_1.getGlobalConfigPath)()).toBe('/myHomeDir/.backport/config.json');
|
|
7
14
|
});
|
|
8
15
|
test('getReposPath', () => {
|
|
9
|
-
expect(env_1.getReposPath()).toBe('/myHomeDir/.backport/repositories');
|
|
16
|
+
expect((0, env_1.getReposPath)()).toBe('/myHomeDir/.backport/repositories');
|
|
10
17
|
});
|
|
11
18
|
test('getRepoOwnerPath', () => {
|
|
12
|
-
expect(env_1.getRepoOwnerPath({ repoOwner: 'elastic' })).toBe('/myHomeDir/.backport/repositories/elastic');
|
|
19
|
+
expect((0, env_1.getRepoOwnerPath)({ repoOwner: 'elastic' })).toBe('/myHomeDir/.backport/repositories/elastic');
|
|
13
20
|
});
|
|
14
21
|
test('getRepoPath', () => {
|
|
15
|
-
expect(env_1.getRepoPath({
|
|
22
|
+
expect((0, env_1.getRepoPath)({
|
|
16
23
|
repoOwner: 'elastic',
|
|
17
24
|
repoName: 'kibana',
|
|
18
25
|
})).toBe('/myHomeDir/.backport/repositories/elastic/kibana');
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.chmod = exports.stat = exports.readFile = exports.writeFile = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const util_1 = require("util");
|
|
9
|
-
exports.writeFile = util_1.promisify(fs_1.default.writeFile);
|
|
10
|
-
exports.readFile = util_1.promisify(fs_1.default.readFile);
|
|
11
|
-
exports.stat = util_1.promisify(fs_1.default.stat);
|
|
12
|
-
exports.chmod = util_1.promisify(fs_1.default.chmod);
|
|
9
|
+
exports.writeFile = (0, util_1.promisify)(fs_1.default.writeFile);
|
|
10
|
+
exports.readFile = (0, util_1.promisify)(fs_1.default.readFile);
|
|
11
|
+
exports.stat = (0, util_1.promisify)(fs_1.default.stat);
|
|
12
|
+
exports.chmod = (0, util_1.promisify)(fs_1.default.chmod);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ValidConfigOptions } from '../options/options';
|
|
2
|
+
import { SourceCommitWithTargetPullRequest } from './sourceCommit';
|
|
3
|
+
export declare type ExpectedTargetPullRequest = {
|
|
4
|
+
url?: string;
|
|
5
|
+
number?: number;
|
|
6
|
+
branch: string;
|
|
7
|
+
state: 'OPEN' | 'CLOSED' | 'MERGED' | 'MISSING';
|
|
8
|
+
};
|
|
9
|
+
export declare function getExpectedTargetPullRequests(sourceCommit: SourceCommitWithTargetPullRequest, branchLabelMapping: ValidConfigOptions['branchLabelMapping']): ExpectedTargetPullRequest[];
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getExpectedTargetPullRequests = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const getTargetBranchesFromLabels_1 = require("../services/github/v4/getTargetBranchesFromLabels");
|
|
6
|
+
const filterEmpty_1 = require("../utils/filterEmpty");
|
|
7
|
+
const commitFormatters_1 = require("./github/commitFormatters");
|
|
8
|
+
function getExpectedTargetPullRequests(sourceCommit, branchLabelMapping) {
|
|
9
|
+
const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
|
|
10
|
+
// if there is no source pull request the commit was pushed directly to the source branch
|
|
11
|
+
// in that case there will be no labels, and thus not possible to deduce the expected target branches
|
|
12
|
+
if (!sourcePullRequest) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
const existingTargetPullRequests = getExistingTargetPullRequests(sourceCommit, sourcePullRequest);
|
|
16
|
+
// if there's no `branchLabelMapping`, it's not possible to deduce the missing target branches
|
|
17
|
+
if (!branchLabelMapping) {
|
|
18
|
+
return existingTargetPullRequests;
|
|
19
|
+
}
|
|
20
|
+
const missingTargetPullRequests = getMissingTargetPullRequests(sourcePullRequest, existingTargetPullRequests, branchLabelMapping);
|
|
21
|
+
return [...existingTargetPullRequests, ...missingTargetPullRequests];
|
|
22
|
+
}
|
|
23
|
+
exports.getExpectedTargetPullRequests = getExpectedTargetPullRequests;
|
|
24
|
+
function getExistingTargetPullRequests(sourceCommit, sourcePullRequest) {
|
|
25
|
+
const sourceCommitMessage = (0, commitFormatters_1.getFirstLine)(sourceCommit.message);
|
|
26
|
+
return sourcePullRequest.timelineItems.edges
|
|
27
|
+
.filter(filterEmpty_1.filterNil)
|
|
28
|
+
.filter(filterPullRequests)
|
|
29
|
+
.filter((item) => {
|
|
30
|
+
const { targetPullRequest } = item.node;
|
|
31
|
+
// ignore closed PRs
|
|
32
|
+
if (targetPullRequest.state === 'CLOSED') {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
// at least one of the commits in `targetPullRequest` should match the merge commit from the source pull request
|
|
36
|
+
const didCommitMatch = targetPullRequest.commits.edges.some((commitEdge) => {
|
|
37
|
+
const { targetCommit } = commitEdge.node;
|
|
38
|
+
const matchingRepoName = sourceCommit.repository.name === targetCommit.repository.name;
|
|
39
|
+
const matchingRepoOwner = sourceCommit.repository.owner.login ===
|
|
40
|
+
targetCommit.repository.owner.login;
|
|
41
|
+
const targetCommitMessage = (0, commitFormatters_1.getFirstLine)(targetCommit.message);
|
|
42
|
+
const matchingMessage = targetCommitMessage === sourceCommitMessage;
|
|
43
|
+
return matchingRepoName && matchingRepoOwner && matchingMessage;
|
|
44
|
+
});
|
|
45
|
+
const titleIncludesMessage = targetPullRequest.title.includes(sourceCommitMessage);
|
|
46
|
+
const titleIncludesNumber = targetPullRequest.title.includes(sourcePullRequest.number.toString());
|
|
47
|
+
return didCommitMatch || (titleIncludesMessage && titleIncludesNumber);
|
|
48
|
+
})
|
|
49
|
+
.map((item) => {
|
|
50
|
+
const { targetPullRequest } = item.node;
|
|
51
|
+
return {
|
|
52
|
+
url: targetPullRequest.url,
|
|
53
|
+
number: targetPullRequest.number,
|
|
54
|
+
branch: targetPullRequest.baseRefName,
|
|
55
|
+
state: targetPullRequest.state,
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function getMissingTargetPullRequests(sourcePullRequest, existingTargetPullRequests, branchLabelMapping) {
|
|
60
|
+
const labels = sourcePullRequest.labels.nodes.map((label) => label.name);
|
|
61
|
+
const targetBranchesFromLabels = labels
|
|
62
|
+
.map((label) => (0, getTargetBranchesFromLabels_1.getTargetBranchForLabel)({ branchLabelMapping, label }))
|
|
63
|
+
.filter(filterEmpty_1.filterNil)
|
|
64
|
+
.filter((targetBranch) => targetBranch !== sourcePullRequest.baseRefName);
|
|
65
|
+
const expectedTargetBranches = existingTargetPullRequests.map((pr) => pr.branch);
|
|
66
|
+
const expected = (0, lodash_1.uniq)(targetBranchesFromLabels);
|
|
67
|
+
return expected
|
|
68
|
+
.filter((targetBranch) => !expectedTargetBranches.includes(targetBranch))
|
|
69
|
+
.map((branch) => {
|
|
70
|
+
return { branch, state: 'MISSING' };
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
// narrow TimelineEdge to TimelinePullRequestEdge
|
|
74
|
+
function filterPullRequests(item) {
|
|
75
|
+
const { targetPullRequest } = item.node;
|
|
76
|
+
return targetPullRequest.__typename === 'PullRequest';
|
|
77
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ValidConfigOptions } from '../options/options';
|
|
2
|
+
import { SourceCommitWithTargetPullRequest } from './sourceCommit';
|
|
3
|
+
export declare type ExpectedTargetPullRequest = {
|
|
4
|
+
url?: string;
|
|
5
|
+
number?: number;
|
|
6
|
+
branch: string;
|
|
7
|
+
state: 'OPEN' | 'CLOSED' | 'MERGED' | 'MISSING';
|
|
8
|
+
};
|
|
9
|
+
export declare function getExpectedTargetPullRequests(sourceCommit: SourceCommitWithTargetPullRequest, branchLabelMapping: ValidConfigOptions['branchLabelMapping']): ExpectedTargetPullRequest[];
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getExpectedTargetPullRequests = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const getTargetBranchesFromLabels_1 = require("../services/github/v4/getTargetBranchesFromLabels");
|
|
6
|
+
const filterEmpty_1 = require("../utils/filterEmpty");
|
|
7
|
+
const commitFormatters_1 = require("./github/commitFormatters");
|
|
8
|
+
function getExpectedTargetPullRequests(sourceCommit, branchLabelMapping) {
|
|
9
|
+
const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
|
|
10
|
+
// if there is no source pull request the commit was pushed directly to the source branch
|
|
11
|
+
// in that case there will be no labels, and thus not possible to deduce the expected target branches
|
|
12
|
+
if (!sourcePullRequest) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
const existingTargetPullRequests = getExistingTargetPullRequests(sourceCommit, sourcePullRequest);
|
|
16
|
+
// if there's no `branchLabelMapping`, it's not possible to deduce the missing target branches
|
|
17
|
+
if (!branchLabelMapping) {
|
|
18
|
+
return existingTargetPullRequests;
|
|
19
|
+
}
|
|
20
|
+
const missingTargetPullRequests = getMissingTargetPullRequests(sourcePullRequest, existingTargetPullRequests, branchLabelMapping);
|
|
21
|
+
return [...existingTargetPullRequests, ...missingTargetPullRequests];
|
|
22
|
+
}
|
|
23
|
+
exports.getExpectedTargetPullRequests = getExpectedTargetPullRequests;
|
|
24
|
+
function getExistingTargetPullRequests(sourceCommit, sourcePullRequest) {
|
|
25
|
+
const sourceCommitMessage = (0, commitFormatters_1.getFirstLine)(sourceCommit.message);
|
|
26
|
+
return sourcePullRequest.timelineItems.edges
|
|
27
|
+
.filter(filterEmpty_1.filterNil)
|
|
28
|
+
.filter(filterPullRequests)
|
|
29
|
+
.filter((item) => {
|
|
30
|
+
const { targetPullRequest } = item.node;
|
|
31
|
+
// ignore closed PRs
|
|
32
|
+
if (targetPullRequest.state === 'CLOSED') {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
// at least one of the commits in `targetPullRequest` should match the merge commit from the source pull request
|
|
36
|
+
const didCommitMatch = targetPullRequest.commits.edges.some((commitEdge) => {
|
|
37
|
+
const { targetCommit } = commitEdge.node;
|
|
38
|
+
const matchingRepoName = sourceCommit.repository.name === targetCommit.repository.name;
|
|
39
|
+
const matchingRepoOwner = sourceCommit.repository.owner.login ===
|
|
40
|
+
targetCommit.repository.owner.login;
|
|
41
|
+
const targetCommitMessage = (0, commitFormatters_1.getFirstLine)(targetCommit.message);
|
|
42
|
+
const matchingMessage = targetCommitMessage === sourceCommitMessage;
|
|
43
|
+
return matchingRepoName && matchingRepoOwner && matchingMessage;
|
|
44
|
+
});
|
|
45
|
+
const titleIncludesMessage = targetPullRequest.title.includes(sourceCommitMessage);
|
|
46
|
+
const titleIncludesNumber = targetPullRequest.title.includes(sourcePullRequest.number.toString());
|
|
47
|
+
return didCommitMatch || (titleIncludesMessage && titleIncludesNumber);
|
|
48
|
+
})
|
|
49
|
+
.map((item) => {
|
|
50
|
+
const { targetPullRequest } = item.node;
|
|
51
|
+
return {
|
|
52
|
+
url: targetPullRequest.url,
|
|
53
|
+
number: targetPullRequest.number,
|
|
54
|
+
branch: targetPullRequest.baseRefName,
|
|
55
|
+
state: targetPullRequest.state,
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function getMissingTargetPullRequests(sourcePullRequest, existingTargetPullRequests, branchLabelMapping) {
|
|
60
|
+
const labels = sourcePullRequest.labels.nodes.map((label) => label.name);
|
|
61
|
+
const targetBranchesFromLabels = labels
|
|
62
|
+
.map((label) => (0, getTargetBranchesFromLabels_1.getTargetBranchForLabel)({ branchLabelMapping, label }))
|
|
63
|
+
.filter(filterEmpty_1.filterNil)
|
|
64
|
+
.filter((targetBranch) => targetBranch !== sourcePullRequest.baseRefName);
|
|
65
|
+
const expectedTargetBranches = existingTargetPullRequests.map((pr) => pr.branch);
|
|
66
|
+
const expected = (0, lodash_1.uniq)(targetBranchesFromLabels);
|
|
67
|
+
return expected
|
|
68
|
+
.filter((targetBranch) => !expectedTargetBranches.includes(targetBranch))
|
|
69
|
+
.map((branch) => {
|
|
70
|
+
return { branch, state: 'MISSING' };
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
// narrow TimelineEdge to TimelinePullRequestEdge
|
|
74
|
+
function filterPullRequests(item) {
|
|
75
|
+
const { targetPullRequest } = item.node;
|
|
76
|
+
return targetPullRequest.__typename === 'PullRequest';
|
|
77
|
+
}
|