backport 6.1.3 → 6.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -37
- package/dist/backportRun.d.ts +14 -0
- package/dist/backportRun.js +75 -0
- package/dist/entrypoint.api.d.ts +22 -0
- package/dist/entrypoint.api.js +57 -0
- package/dist/entrypoint.api.private.test.d.ts +1 -0
- package/dist/entrypoint.api.private.test.js +37 -0
- package/dist/entrypoint.cli.js +3 -5
- package/dist/entrypoint.module.d.ts +6 -3
- package/dist/entrypoint.module.js +13 -7
- package/dist/entrypoint.module.private.test.js +4 -1
- package/dist/main.js +5 -1
- package/dist/options/ConfigOptions.d.ts +4 -0
- package/dist/options/cliArgs.d.ts +17 -11
- package/dist/options/cliArgs.js +36 -5
- package/dist/options/config/config.d.ts +10 -1
- package/dist/options/config/config.js +9 -3
- package/dist/options/config/config.test.js +27 -1
- package/dist/options/config/getProjectConfig.d.ts +0 -0
- package/dist/options/config/getProjectConfig.js +1 -0
- package/dist/options/config/globalConfig.d.ts +2 -2
- package/dist/options/config/globalConfig.js +16 -14
- package/dist/options/config/globalConfig.test.js +10 -4
- package/dist/options/config/projectConfig.d.ts +3 -1
- package/dist/options/config/projectConfig.js +5 -2
- package/dist/options/config/projectConfig.test.js +35 -6
- package/dist/options/config/readConfigFile.d.ts +26 -22
- package/dist/options/options.d.ts +18 -9
- package/dist/options/options.js +11 -4
- package/dist/options/options.test.js +40 -35
- package/dist/react-components/0-loadOptions.d.ts +6 -0
- package/dist/react-components/0-loadOptions.js +45 -0
- package/dist/react-components/1-loadCommit.d.ts +8 -0
- package/dist/react-components/1-loadCommit.js +88 -0
- package/dist/react-components/1a-loadCommit.d.ts +5 -0
- package/dist/react-components/1a-loadCommit.js +76 -0
- package/dist/react-components/1b-commitChoices.d.ts +5 -0
- package/dist/react-components/1b-commitChoices.js +98 -0
- package/dist/react-components/2-commitChoices.d.ts +8 -0
- package/dist/react-components/2-commitChoices.js +96 -0
- package/dist/react-components/2-commitsPrompt.d.ts +8 -0
- package/dist/react-components/2-commitsPrompt.js +96 -0
- package/dist/react-components/2-targetBranchChoices.d.ts +9 -0
- package/dist/react-components/2-targetBranchChoices.js +109 -0
- package/dist/react-components/3-cherrypick.d.ts +1 -0
- package/dist/react-components/3-cherrypick.js +2 -0
- package/dist/react-components/App.d.ts +2 -0
- package/dist/react-components/App.js +35 -0
- package/dist/react-components/BackportStateContext.d.ts +33 -0
- package/dist/react-components/BackportStateContext.js +42 -0
- package/dist/react-components/CommitPrompt/2-commitsPrompt.d.ts +8 -0
- package/dist/react-components/CommitPrompt/2-commitsPrompt.js +96 -0
- package/dist/react-components/CommitPrompt/CommitPrompt.d.ts +8 -0
- package/dist/react-components/CommitPrompt/CommitPrompt.js +96 -0
- package/dist/react-components/CommitPrompt/getCommits.d.ts +2 -0
- package/dist/react-components/CommitPrompt/getCommits.js +27 -0
- package/dist/react-components/CommitPrompt.d.ts +8 -0
- package/dist/react-components/CommitPrompt.js +96 -0
- package/dist/react-components/CustomMultiSelect.d.ts +13 -0
- package/dist/react-components/CustomMultiSelect.js +21 -0
- package/dist/react-components/CustomMultiSelectItem.d.ts +5 -0
- package/dist/react-components/CustomMultiSelectItem.js +12 -0
- package/dist/react-components/CustomSelect.d.ts +14 -0
- package/dist/react-components/CustomSelect.js +34 -0
- package/dist/react-components/ErrorBoundary.d.ts +15 -0
- package/dist/react-components/ErrorBoundary.js +53 -0
- package/dist/react-components/MultiSelect.d.ts +7 -0
- package/dist/react-components/MultiSelect.js +16 -0
- package/dist/react-components/hooks/useAsync.d.ts +12 -0
- package/dist/react-components/hooks/useAsync.js +73 -0
- package/dist/runSequentially.test.js +11 -13
- package/dist/scripts/postinstall.js +3 -3
- package/dist/services/HandledError.d.ts +1 -1
- package/dist/services/backportRun/backportRun.ci.d.ts +6 -0
- package/dist/services/backportRun/backportRun.ci.js +81 -0
- package/dist/services/backportRun/backportRun.d.ts +14 -0
- package/dist/services/backportRun/backportRun.interactive.d.ts +1 -0
- package/dist/services/backportRun/backportRun.interactive.js +4 -0
- package/dist/services/backportRun/backportRun.js +14 -0
- package/dist/services/backportRun/backportState.d.ts +4 -0
- package/dist/services/backportRun/backportState.js +28 -0
- package/dist/services/backportRun/getCommits.d.ts +2 -0
- package/dist/services/backportRun/getCommits.js +20 -0
- package/dist/services/backportRun/runSequentially.d.ts +20 -0
- package/dist/services/backportRun/runSequentially.js +41 -0
- package/dist/services/backportRun/runSequentially.test.d.ts +1 -0
- package/dist/services/backportRun/runSequentially.test.js +199 -0
- package/dist/services/cherrypickAndCreateTargetPullRequest.d.ts +12 -0
- package/dist/services/cherrypickAndCreateTargetPullRequest.js +206 -0
- package/dist/services/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/services/cherrypickAndCreateTargetPullRequest.test.js +403 -0
- package/dist/services/env.d.ts +5 -4
- package/dist/services/env.js +13 -11
- package/dist/services/env.test.js +0 -6
- package/dist/services/getCommits.d.ts +2 -0
- package/dist/services/getCommits.js +38 -0
- package/dist/services/getCommitsWithoutBackports.d.ts +11 -0
- package/dist/services/getCommitsWithoutBackports.js +68 -0
- package/dist/services/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/services/getCommitsWithoutBackports.test.js +259 -0
- package/dist/services/getTargetBranches.d.ts +5 -0
- package/dist/services/getTargetBranches.js +60 -0
- package/dist/services/getTargetBranches.test.d.ts +1 -0
- package/dist/services/getTargetBranches.test.js +180 -0
- package/dist/services/git.d.ts +2 -1
- package/dist/services/git.js +5 -3
- package/dist/services/github/v3/createPullRequest.js +8 -5
- package/dist/services/github/v3/createPullRequest.test.js +60 -10
- package/dist/services/github/v3/createStatusComment.d.ts +2 -2
- package/dist/services/github/v3/createStatusComment.js +40 -15
- package/dist/services/github/v3/createStatusComment.test.js +174 -86
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +78 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +64 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +5 -5
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +60 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +2 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +17 -10
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +72 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +6 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +8 -7
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +8 -0
- package/dist/services/github/v4/fetchProjectConfig.d.ts +1 -1
- package/dist/services/github/v4/fetchProjectConfig.js +3 -3
- package/dist/services/github/v4/fetchProjectConfig.private.test.js +5 -5
- package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.js +56 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +4 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -7
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +16 -5
- package/dist/services/logger.d.ts +4 -2
- package/dist/services/logger.js +31 -32
- package/dist/services/maybeSetupRepo.d.ts +2 -0
- package/dist/services/maybeSetupRepo.js +33 -0
- package/dist/services/maybeSetupRepo.test.d.ts +1 -0
- package/dist/services/maybeSetupRepo.test.js +78 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +8 -2
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +20 -0
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +1 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +72 -46
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +22 -8
- package/dist/services/sourceCommit/parseSourceCommit.js +29 -10
- package/dist/services/sourceCommit/parseSourceCommit.test.js +10 -2
- package/dist/test/backport-e2e.private.test.d.ts +1 -0
- package/dist/test/backport-e2e.private.test.js +325 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +43 -0
- package/dist/test/inquirer.private.test.js +3 -1
- package/dist/test/integration/integration.private.test.js +2 -2
- package/dist/test/nockHelpers.js +1 -3
- package/dist/test/setupFiles/automatic-mocks.js +1 -0
- package/dist/todo-delete.d.ts +1 -0
- package/dist/todo-delete.js +17 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +4 -3
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +9 -12
- package/dist/ui/getCommits.js +1 -1
- package/dist/ui/getCommitsWithoutBackports.js +17 -2
- package/dist/ui/maybeSetupRepo.js +0 -6
- package/dist/ui/maybeSetupRepo.test.js +8 -4
- package/dist/utils/redact.d.ts +1 -0
- package/dist/utils/redact.js +7 -0
- package/dist/utils/sequentially.d.ts +1 -0
- package/dist/utils/sequentially.js +10 -0
- package/package.json +11 -11
- package/yarn.lock +570 -436
|
@@ -9,7 +9,7 @@ export interface Commit {
|
|
|
9
9
|
pullUrl?: string;
|
|
10
10
|
expectedTargetPullRequests: ExpectedTargetPullRequest[];
|
|
11
11
|
}
|
|
12
|
-
export interface
|
|
12
|
+
export interface SourcePullRequestNode {
|
|
13
13
|
baseRefName: string;
|
|
14
14
|
url: string;
|
|
15
15
|
number: number;
|
|
@@ -18,8 +18,12 @@ export interface PullRequestNode {
|
|
|
18
18
|
name: string;
|
|
19
19
|
}[];
|
|
20
20
|
};
|
|
21
|
+
sourceMergeCommit: {
|
|
22
|
+
oid: string;
|
|
23
|
+
message: string;
|
|
24
|
+
};
|
|
21
25
|
timelineItems: {
|
|
22
|
-
edges:
|
|
26
|
+
edges: TimelineEdge[];
|
|
23
27
|
};
|
|
24
28
|
}
|
|
25
29
|
export declare type TimelineEdge = TimelinePullRequestEdge | TimelineIssueEdge;
|
|
@@ -32,10 +36,23 @@ export interface TimelinePullRequestEdge {
|
|
|
32
36
|
state: 'OPEN' | 'CLOSED' | 'MERGED';
|
|
33
37
|
baseRefName: string;
|
|
34
38
|
number: number;
|
|
39
|
+
targetMergeCommit: {
|
|
40
|
+
oid: string;
|
|
41
|
+
message: string;
|
|
42
|
+
} | null;
|
|
43
|
+
repository: {
|
|
44
|
+
name: string;
|
|
45
|
+
owner: {
|
|
46
|
+
login: string;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
35
49
|
commits: {
|
|
36
50
|
edges: Array<{
|
|
37
51
|
node: {
|
|
38
|
-
targetCommit:
|
|
52
|
+
targetCommit: {
|
|
53
|
+
message: string;
|
|
54
|
+
oid: string;
|
|
55
|
+
};
|
|
39
56
|
};
|
|
40
57
|
}>;
|
|
41
58
|
};
|
|
@@ -49,7 +66,7 @@ interface TimelineIssueEdge {
|
|
|
49
66
|
};
|
|
50
67
|
};
|
|
51
68
|
}
|
|
52
|
-
declare type
|
|
69
|
+
export declare type SourceCommitWithTargetPullRequest = {
|
|
53
70
|
repository: {
|
|
54
71
|
name: string;
|
|
55
72
|
owner: {
|
|
@@ -59,11 +76,9 @@ declare type InnerCommitNode = {
|
|
|
59
76
|
oid: string;
|
|
60
77
|
message: string;
|
|
61
78
|
committedDate: string;
|
|
62
|
-
};
|
|
63
|
-
export declare type SourceCommitWithTargetPullRequest = InnerCommitNode & {
|
|
64
79
|
associatedPullRequests: {
|
|
65
80
|
edges: {
|
|
66
|
-
node:
|
|
81
|
+
node: SourcePullRequestNode;
|
|
67
82
|
}[] | null;
|
|
68
83
|
};
|
|
69
84
|
};
|
|
@@ -76,7 +91,6 @@ export declare function parseSourceCommit({ sourceCommit, options, }: {
|
|
|
76
91
|
};
|
|
77
92
|
}): Commit;
|
|
78
93
|
export declare const sourceCommitWithTargetPullRequestFragment: {
|
|
79
|
-
name: string;
|
|
80
94
|
source: string;
|
|
81
95
|
};
|
|
82
96
|
export {};
|
|
@@ -6,7 +6,9 @@ const commitFormatters_1 = require("../github/commitFormatters");
|
|
|
6
6
|
const getExpectedTargetPullRequests_1 = require("./getExpectedTargetPullRequests");
|
|
7
7
|
function parseSourceCommit({ sourceCommit, options, }) {
|
|
8
8
|
const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
|
|
9
|
-
|
|
9
|
+
// use info from associated pull request if available. Fall back to commit info
|
|
10
|
+
const commitMessage = sourcePullRequest?.sourceMergeCommit.message ?? sourceCommit.message;
|
|
11
|
+
const commitSha = sourcePullRequest?.sourceMergeCommit.oid ?? sourceCommit.oid;
|
|
10
12
|
const pullNumber = sourcePullRequest?.number ?? (0, commitFormatters_1.extractPullNumber)(commitMessage);
|
|
11
13
|
const sourceBranch = sourcePullRequest?.baseRefName ?? options.sourceBranch;
|
|
12
14
|
const branchLabelMapping = getBranchLabelMappingForCommit(sourceCommit, options.branchLabelMapping, options.historicalBranchLabelMappings);
|
|
@@ -14,7 +16,7 @@ function parseSourceCommit({ sourceCommit, options, }) {
|
|
|
14
16
|
return {
|
|
15
17
|
committedDate: sourceCommit.committedDate,
|
|
16
18
|
sourceBranch,
|
|
17
|
-
sha:
|
|
19
|
+
sha: commitSha,
|
|
18
20
|
originalMessage: commitMessage,
|
|
19
21
|
pullNumber,
|
|
20
22
|
pullUrl: sourcePullRequest?.url,
|
|
@@ -23,9 +25,9 @@ function parseSourceCommit({ sourceCommit, options, }) {
|
|
|
23
25
|
}
|
|
24
26
|
exports.parseSourceCommit = parseSourceCommit;
|
|
25
27
|
exports.sourceCommitWithTargetPullRequestFragment = {
|
|
26
|
-
name: 'SourceCommitWithTargetPullRequest',
|
|
27
28
|
source: /* GraphQL */ `
|
|
28
|
-
fragment
|
|
29
|
+
fragment SourceCommitWithTargetPullRequest on Commit {
|
|
30
|
+
# Source Commit
|
|
29
31
|
repository {
|
|
30
32
|
name
|
|
31
33
|
owner {
|
|
@@ -35,14 +37,11 @@ exports.sourceCommitWithTargetPullRequestFragment = {
|
|
|
35
37
|
oid
|
|
36
38
|
message
|
|
37
39
|
committedDate
|
|
38
|
-
}
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
...InnerCommitNode
|
|
41
|
+
# Source pull request: PR where source commit was merged in
|
|
42
42
|
associatedPullRequests(first: 1) {
|
|
43
43
|
edges {
|
|
44
44
|
node {
|
|
45
|
-
# Source PR
|
|
46
45
|
url
|
|
47
46
|
number
|
|
48
47
|
labels(first: 50) {
|
|
@@ -51,6 +50,14 @@ exports.sourceCommitWithTargetPullRequestFragment = {
|
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
baseRefName
|
|
53
|
+
|
|
54
|
+
# source merge commit (the commit that actually went into the source branch)
|
|
55
|
+
sourceMergeCommit: mergeCommit {
|
|
56
|
+
oid
|
|
57
|
+
message
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
# (possible) backport pull requests referenced in the source pull request
|
|
54
61
|
timelineItems(last: 20, itemTypes: CROSS_REFERENCED_EVENT) {
|
|
55
62
|
edges {
|
|
56
63
|
node {
|
|
@@ -58,8 +65,19 @@ exports.sourceCommitWithTargetPullRequestFragment = {
|
|
|
58
65
|
targetPullRequest: source {
|
|
59
66
|
__typename
|
|
60
67
|
|
|
61
|
-
# Target PRs
|
|
68
|
+
# Target PRs (backport PRs)
|
|
62
69
|
... on PullRequest {
|
|
70
|
+
# target merge commit: the backport commit that was merged into the target branch
|
|
71
|
+
targetMergeCommit: mergeCommit {
|
|
72
|
+
oid
|
|
73
|
+
message
|
|
74
|
+
}
|
|
75
|
+
repository {
|
|
76
|
+
name
|
|
77
|
+
owner {
|
|
78
|
+
login
|
|
79
|
+
}
|
|
80
|
+
}
|
|
63
81
|
url
|
|
64
82
|
title
|
|
65
83
|
state
|
|
@@ -69,7 +87,8 @@ exports.sourceCommitWithTargetPullRequestFragment = {
|
|
|
69
87
|
edges {
|
|
70
88
|
node {
|
|
71
89
|
targetCommit: commit {
|
|
72
|
-
|
|
90
|
+
message
|
|
91
|
+
oid
|
|
73
92
|
}
|
|
74
93
|
}
|
|
75
94
|
}
|
|
@@ -96,6 +96,10 @@ describe('parseSourceCommit', () => {
|
|
|
96
96
|
number: 5678,
|
|
97
97
|
state: 'MERGED',
|
|
98
98
|
url: 'https://github.com/elastic/kibana/pull/5678',
|
|
99
|
+
mergeCommit: {
|
|
100
|
+
message: 'My commit message (#66)',
|
|
101
|
+
sha: 'target-merge-commit-sha',
|
|
102
|
+
},
|
|
99
103
|
},
|
|
100
104
|
{
|
|
101
105
|
branch: '6.2',
|
|
@@ -170,7 +174,7 @@ describe('parseSourceCommit', () => {
|
|
|
170
174
|
});
|
|
171
175
|
it('returns the correct source commit', () => {
|
|
172
176
|
const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
|
|
173
|
-
sourceCommit: { message: 'My commit message (#1234)' },
|
|
177
|
+
sourceCommit: { message: 'My commit message (#1234)', sha: 'my-sha' },
|
|
174
178
|
sourcePullRequest: {
|
|
175
179
|
number: 1234,
|
|
176
180
|
labels: ['v6.3.0', 'v6.2.0', 'v6.1.0'],
|
|
@@ -207,6 +211,10 @@ describe('parseSourceCommit', () => {
|
|
|
207
211
|
number: 5678,
|
|
208
212
|
state: 'MERGED',
|
|
209
213
|
url: 'https://github.com/elastic/kibana/pull/5678',
|
|
214
|
+
mergeCommit: {
|
|
215
|
+
message: 'My commit message (#1234)',
|
|
216
|
+
sha: 'target-merge-commit-sha',
|
|
217
|
+
},
|
|
210
218
|
},
|
|
211
219
|
{
|
|
212
220
|
branch: '6.2',
|
|
@@ -222,7 +230,7 @@ describe('parseSourceCommit', () => {
|
|
|
222
230
|
originalMessage: 'My commit message (#1234)',
|
|
223
231
|
pullNumber: 1234,
|
|
224
232
|
pullUrl: 'https://github.com/elastic/kibana/pull/1234',
|
|
225
|
-
sha: '
|
|
233
|
+
sha: 'my-sha',
|
|
226
234
|
sourceBranch: 'source-branch-from-associated-pull-request',
|
|
227
235
|
});
|
|
228
236
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,325 @@
|
|
|
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
|
+
/* eslint-disable jest/no-commented-out-tests */
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const rest_1 = require("@octokit/rest");
|
|
10
|
+
const del = require("del");
|
|
11
|
+
const nock_1 = __importDefault(require("nock"));
|
|
12
|
+
const options_1 = require("../options/options");
|
|
13
|
+
const runSequentially_1 = require("../runSequentially");
|
|
14
|
+
const getCommits_1 = require("../ui/getCommits");
|
|
15
|
+
const mockConfigFiles_1 = require("./mockConfigFiles");
|
|
16
|
+
const nockHelpers_1 = require("./nockHelpers");
|
|
17
|
+
const getDevAccessToken_1 = require("./private/getDevAccessToken");
|
|
18
|
+
jest.unmock('make-dir');
|
|
19
|
+
jest.unmock('del');
|
|
20
|
+
jest.setTimeout(10000);
|
|
21
|
+
const E2E_TEST_DATA_PATH = (0, path_1.resolve)('./src/test/tmp-mock-environments/backport-e2e');
|
|
22
|
+
const HOMEDIR_PATH = (0, path_1.resolve)('./src/test/tmp-mock-environments/backport-e2e/homedir');
|
|
23
|
+
const REPO_OWNER = 'backport-org';
|
|
24
|
+
const REPO_NAME = 'integration-test';
|
|
25
|
+
const BRANCH_NAME = 'backport/7.x/commit-5bf29b7d';
|
|
26
|
+
const AUHTOR = 'sqren';
|
|
27
|
+
describe('backport e2e', () => {
|
|
28
|
+
afterAll(() => {
|
|
29
|
+
nock_1.default.cleanAll();
|
|
30
|
+
});
|
|
31
|
+
beforeAll(() => {
|
|
32
|
+
// set alternative homedir
|
|
33
|
+
jest.spyOn(os_1.default, 'homedir').mockReturnValue(HOMEDIR_PATH);
|
|
34
|
+
(0, mockConfigFiles_1.mockConfigFiles)({
|
|
35
|
+
globalConfig: {},
|
|
36
|
+
projectConfig: {},
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
describe('when a single commit is backported', () => {
|
|
40
|
+
let res;
|
|
41
|
+
let accessToken;
|
|
42
|
+
let createPullRequestsMockCalls;
|
|
43
|
+
beforeAll(async () => {
|
|
44
|
+
accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
45
|
+
await resetState(accessToken);
|
|
46
|
+
createPullRequestsMockCalls = mockCreatePullRequest({
|
|
47
|
+
number: 1337,
|
|
48
|
+
html_url: 'myHtmlUrl',
|
|
49
|
+
});
|
|
50
|
+
const options = await (0, options_1.getOptions)([], {
|
|
51
|
+
githubApiBaseUrlV3: 'https://api.foo.com',
|
|
52
|
+
ci: true,
|
|
53
|
+
sha: '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad',
|
|
54
|
+
author: AUHTOR,
|
|
55
|
+
accessToken,
|
|
56
|
+
repoOwner: 'backport-org',
|
|
57
|
+
repoName: 'integration-test',
|
|
58
|
+
});
|
|
59
|
+
const commits = await (0, getCommits_1.getCommits)(options);
|
|
60
|
+
const targetBranches = ['7.x'];
|
|
61
|
+
res = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
|
|
62
|
+
});
|
|
63
|
+
it('returns pull request', () => {
|
|
64
|
+
expect(res).toEqual([
|
|
65
|
+
{
|
|
66
|
+
didUpdate: false,
|
|
67
|
+
pullRequestUrl: 'myHtmlUrl',
|
|
68
|
+
pullRequestNumber: 1337,
|
|
69
|
+
status: 'success',
|
|
70
|
+
targetBranch: '7.x',
|
|
71
|
+
},
|
|
72
|
+
]);
|
|
73
|
+
});
|
|
74
|
+
it('sends the correct http body when creating pull request', () => {
|
|
75
|
+
expect(createPullRequestsMockCalls).toMatchInlineSnapshot(`
|
|
76
|
+
Array [
|
|
77
|
+
Object {
|
|
78
|
+
"base": "7.x",
|
|
79
|
+
"body": "# Backport
|
|
80
|
+
|
|
81
|
+
This is an automatic backport to \`7.x\` of:
|
|
82
|
+
- Add ❤️ emoji (5bf29b7d)
|
|
83
|
+
|
|
84
|
+
### Questions ?
|
|
85
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
|
|
86
|
+
"head": "sqren:backport/7.x/commit-5bf29b7d",
|
|
87
|
+
"title": "[7.x] Add ❤️ emoji",
|
|
88
|
+
},
|
|
89
|
+
]
|
|
90
|
+
`);
|
|
91
|
+
});
|
|
92
|
+
it('should not create new branches in origin (backport-org/integration-test)', async () => {
|
|
93
|
+
const branches = await getBranches({
|
|
94
|
+
accessToken,
|
|
95
|
+
repoOwner: REPO_OWNER,
|
|
96
|
+
repoName: REPO_NAME,
|
|
97
|
+
});
|
|
98
|
+
expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
|
|
99
|
+
});
|
|
100
|
+
it('should create branch in the fork (sqren/integration-test)', async () => {
|
|
101
|
+
const branches = await getBranches({
|
|
102
|
+
accessToken,
|
|
103
|
+
repoOwner: AUHTOR,
|
|
104
|
+
repoName: REPO_NAME,
|
|
105
|
+
});
|
|
106
|
+
expect(branches.map((b) => b.name)).toEqual([
|
|
107
|
+
'7.x',
|
|
108
|
+
BRANCH_NAME,
|
|
109
|
+
'master',
|
|
110
|
+
]);
|
|
111
|
+
});
|
|
112
|
+
it('should have cherry picked the correct commit', async () => {
|
|
113
|
+
const branches = await getBranches({
|
|
114
|
+
accessToken,
|
|
115
|
+
repoOwner: AUHTOR,
|
|
116
|
+
repoName: REPO_NAME,
|
|
117
|
+
});
|
|
118
|
+
const sha = branches.find((branch) => branch.name === '7.x')?.commit.sha;
|
|
119
|
+
expect(sha).toEqual('b68e4fcaaf4427fe1e902c718b3bb3f07b560fb5');
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
// describe.skip('when two commits are backported', () => {
|
|
123
|
+
// let createPullRequestsMockCalls: unknown[];
|
|
124
|
+
// let res: Awaited<ReturnType<typeof runSequentially>>;
|
|
125
|
+
// let accessToken: string;
|
|
126
|
+
// beforeAll(async () => {
|
|
127
|
+
// accessToken = await getDevAccessToken();
|
|
128
|
+
// await resetState(accessToken);
|
|
129
|
+
// createPullRequestsMockCalls = mockCreatePullRequest({
|
|
130
|
+
// number: 1337,
|
|
131
|
+
// html_url: 'myHtmlUrl',
|
|
132
|
+
// });
|
|
133
|
+
// const options = {
|
|
134
|
+
// githubApiBaseUrlV3: 'https://api.foo.com',
|
|
135
|
+
// ci: true,
|
|
136
|
+
// sha: '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad',
|
|
137
|
+
// author: AUHTOR,
|
|
138
|
+
// accessToken,
|
|
139
|
+
// repoOwner: 'backport-org',
|
|
140
|
+
// reponame: 'integration-test',
|
|
141
|
+
// } as ValidConfigOptions;
|
|
142
|
+
// const commits = await getCommits(options);
|
|
143
|
+
// const targetBranches: string[] = ['7.x'];
|
|
144
|
+
// res = await runSequentially({ options, commits, targetBranches });
|
|
145
|
+
// });
|
|
146
|
+
// it('sends the correct http body when creating pull request', () => {
|
|
147
|
+
// expect(createPullRequestsMockCalls).toMatchInlineSnapshot();
|
|
148
|
+
// });
|
|
149
|
+
// it('returns pull request', () => {
|
|
150
|
+
// expect(res).toEqual([
|
|
151
|
+
// { pullRequestUrl: 'myHtmlUrl', success: true, targetBranch: '6.0' },
|
|
152
|
+
// ]);
|
|
153
|
+
// });
|
|
154
|
+
// it('should not create new branches in origin (backport-org/integration-test)', async () => {
|
|
155
|
+
// const branches = await getBranches({
|
|
156
|
+
// accessToken,
|
|
157
|
+
// repoOwner: REPO_OWNER,
|
|
158
|
+
// repoName: REPO_NAME,
|
|
159
|
+
// });
|
|
160
|
+
// expect(branches.map((b) => b.name)).toEqual(['7.x', '* master']);
|
|
161
|
+
// });
|
|
162
|
+
// it('should create branch in the fork (sqren/integration-test)', async () => {
|
|
163
|
+
// const branches = await getBranches({
|
|
164
|
+
// accessToken,
|
|
165
|
+
// repoOwner: AUHTOR,
|
|
166
|
+
// repoName: REPO_NAME,
|
|
167
|
+
// });
|
|
168
|
+
// expect(branches.map((b) => b.name)).toEqual([
|
|
169
|
+
// '7.x',
|
|
170
|
+
// 'backport/6.0/pr-85_commit-2e63475c',
|
|
171
|
+
// 'master',
|
|
172
|
+
// ]);
|
|
173
|
+
// });
|
|
174
|
+
// it('should have cherry picked the correct commit', async () => {
|
|
175
|
+
// const branches = await getBranches({
|
|
176
|
+
// accessToken,
|
|
177
|
+
// repoOwner: AUHTOR,
|
|
178
|
+
// repoName: REPO_NAME,
|
|
179
|
+
// });
|
|
180
|
+
// const sha = branches.find((branch) => branch.name === '7.x')?.commit.sha;
|
|
181
|
+
// expect(sha).toEqual('foo');
|
|
182
|
+
// });
|
|
183
|
+
// });
|
|
184
|
+
describe('when disabling fork mode', () => {
|
|
185
|
+
let res;
|
|
186
|
+
let accessToken;
|
|
187
|
+
let createPullRequestsMockCalls;
|
|
188
|
+
beforeAll(async () => {
|
|
189
|
+
accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
190
|
+
await resetState(accessToken);
|
|
191
|
+
createPullRequestsMockCalls = mockCreatePullRequest({
|
|
192
|
+
number: 1337,
|
|
193
|
+
html_url: 'myHtmlUrl',
|
|
194
|
+
});
|
|
195
|
+
const options = await (0, options_1.getOptions)([], {
|
|
196
|
+
author: AUHTOR,
|
|
197
|
+
githubApiBaseUrlV3: 'https://api.foo.com',
|
|
198
|
+
ci: true,
|
|
199
|
+
sha: '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad',
|
|
200
|
+
accessToken,
|
|
201
|
+
repoOwner: 'backport-org',
|
|
202
|
+
repoName: 'integration-test',
|
|
203
|
+
fork: false,
|
|
204
|
+
});
|
|
205
|
+
const commits = await (0, getCommits_1.getCommits)(options);
|
|
206
|
+
const targetBranches = ['7.x'];
|
|
207
|
+
res = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
|
|
208
|
+
});
|
|
209
|
+
it('sends the correct http body when creating pull request', () => {
|
|
210
|
+
expect(createPullRequestsMockCalls).toMatchInlineSnapshot(`
|
|
211
|
+
Array [
|
|
212
|
+
Object {
|
|
213
|
+
"base": "7.x",
|
|
214
|
+
"body": "# Backport
|
|
215
|
+
|
|
216
|
+
This is an automatic backport to \`7.x\` of:
|
|
217
|
+
- Add ❤️ emoji (5bf29b7d)
|
|
218
|
+
|
|
219
|
+
### Questions ?
|
|
220
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
|
|
221
|
+
"head": "backport-org:backport/7.x/commit-5bf29b7d",
|
|
222
|
+
"title": "[7.x] Add ❤️ emoji",
|
|
223
|
+
},
|
|
224
|
+
]
|
|
225
|
+
`);
|
|
226
|
+
});
|
|
227
|
+
it('returns pull request', () => {
|
|
228
|
+
expect(res).toEqual([
|
|
229
|
+
{
|
|
230
|
+
didUpdate: false,
|
|
231
|
+
pullRequestNumber: 1337,
|
|
232
|
+
pullRequestUrl: 'myHtmlUrl',
|
|
233
|
+
status: 'success',
|
|
234
|
+
targetBranch: '7.x',
|
|
235
|
+
},
|
|
236
|
+
]);
|
|
237
|
+
});
|
|
238
|
+
it('should create new branches in origin (backport-org/integration-test)', async () => {
|
|
239
|
+
const branches = await getBranches({
|
|
240
|
+
accessToken,
|
|
241
|
+
repoOwner: REPO_OWNER,
|
|
242
|
+
repoName: REPO_NAME,
|
|
243
|
+
});
|
|
244
|
+
expect(branches.map((b) => b.name)).toEqual([
|
|
245
|
+
'7.x',
|
|
246
|
+
BRANCH_NAME,
|
|
247
|
+
'master',
|
|
248
|
+
]);
|
|
249
|
+
});
|
|
250
|
+
it('should NOT create branch in the fork (sqren/integration-test)', async () => {
|
|
251
|
+
const branches = await getBranches({
|
|
252
|
+
accessToken,
|
|
253
|
+
repoOwner: AUHTOR,
|
|
254
|
+
repoName: REPO_NAME,
|
|
255
|
+
});
|
|
256
|
+
expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
|
|
257
|
+
});
|
|
258
|
+
it('should cherry pick the correct commit', async () => {
|
|
259
|
+
const branches = await getBranches({
|
|
260
|
+
accessToken,
|
|
261
|
+
repoOwner: REPO_OWNER,
|
|
262
|
+
repoName: REPO_NAME,
|
|
263
|
+
});
|
|
264
|
+
const sha = branches.find((branch) => branch.name === '7.x')?.commit.sha;
|
|
265
|
+
expect(sha).toEqual('b68e4fcaaf4427fe1e902c718b3bb3f07b560fb5');
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
function mockCreatePullRequest(response) {
|
|
270
|
+
const scope = (0, nock_1.default)('https://api.foo.com', { allowUnmocked: true })
|
|
271
|
+
.post('/repos/backport-org/integration-test/pulls')
|
|
272
|
+
.reply(200, response);
|
|
273
|
+
return (0, nockHelpers_1.listenForCallsToNockScope)(scope);
|
|
274
|
+
}
|
|
275
|
+
async function getBranches({ accessToken, repoOwner, repoName, }) {
|
|
276
|
+
// console.log(`fetch branches for ${repoOwner}`);
|
|
277
|
+
const octokit = new rest_1.Octokit({
|
|
278
|
+
auth: accessToken,
|
|
279
|
+
});
|
|
280
|
+
const res = await octokit.repos.listBranches({
|
|
281
|
+
owner: repoOwner,
|
|
282
|
+
repo: repoName,
|
|
283
|
+
});
|
|
284
|
+
return res.data;
|
|
285
|
+
}
|
|
286
|
+
async function deleteBranch({ accessToken, repoOwner, repoName, branchName, }) {
|
|
287
|
+
try {
|
|
288
|
+
const octokit = new rest_1.Octokit({
|
|
289
|
+
auth: accessToken,
|
|
290
|
+
});
|
|
291
|
+
// console.log({ accessToken });
|
|
292
|
+
const opts = {
|
|
293
|
+
owner: repoOwner,
|
|
294
|
+
repo: repoName,
|
|
295
|
+
ref: `heads/${branchName}`,
|
|
296
|
+
};
|
|
297
|
+
const res = await octokit.git.deleteRef(opts);
|
|
298
|
+
// console.log(`Deleted ${repoOwner}:heads/${branchName}`);
|
|
299
|
+
return res.data;
|
|
300
|
+
}
|
|
301
|
+
catch (e) {
|
|
302
|
+
// console.log(
|
|
303
|
+
// `Could not delete ${repoOwner}:heads/${branchName} (${e.message})`
|
|
304
|
+
// );
|
|
305
|
+
if (e.message === 'Reference does not exist') {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
throw e;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
async function resetState(accessToken) {
|
|
312
|
+
await deleteBranch({
|
|
313
|
+
accessToken,
|
|
314
|
+
repoOwner: REPO_OWNER,
|
|
315
|
+
repoName: REPO_NAME,
|
|
316
|
+
branchName: BRANCH_NAME,
|
|
317
|
+
});
|
|
318
|
+
await deleteBranch({
|
|
319
|
+
accessToken,
|
|
320
|
+
repoOwner: AUHTOR,
|
|
321
|
+
repoName: REPO_NAME,
|
|
322
|
+
branchName: BRANCH_NAME,
|
|
323
|
+
});
|
|
324
|
+
await del(E2E_TEST_DATA_PATH);
|
|
325
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const path_1 = require("path");
|
|
4
|
+
const entrypoint_module_1 = require("../entrypoint.module");
|
|
5
|
+
const getDevAccessToken_1 = require("./private/getDevAccessToken");
|
|
6
|
+
jest.unmock('find-up');
|
|
7
|
+
jest.setTimeout(15000);
|
|
8
|
+
describe('Handle unbackported pull requests', () => {
|
|
9
|
+
it('shows missing backports for PR number 8', async () => {
|
|
10
|
+
const accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
11
|
+
const commits = await (0, entrypoint_module_1.getCommits)({
|
|
12
|
+
accessToken: accessToken,
|
|
13
|
+
repoOwner: 'backport-org',
|
|
14
|
+
repoName: 'repo-with-conflicts',
|
|
15
|
+
pullNumber: 8,
|
|
16
|
+
});
|
|
17
|
+
expect(commits[0]).toEqual({
|
|
18
|
+
committedDate: '2021-12-16T00:03:34Z',
|
|
19
|
+
expectedTargetPullRequests: [{ branch: '7.x', state: 'MISSING' }],
|
|
20
|
+
originalMessage: 'Change Barca to Braithwaite (#8)',
|
|
21
|
+
pullNumber: 8,
|
|
22
|
+
pullUrl: 'https://github.com/backport-org/repo-with-conflicts/pull/8',
|
|
23
|
+
sha: '343402a748be2375325b2730fa979bcea5b96ba1',
|
|
24
|
+
sourceBranch: 'main',
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
it('shows that backport failed because PR number 8 was not backported', async () => {
|
|
28
|
+
const accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
29
|
+
const result = await (0, entrypoint_module_1.backportRun)({
|
|
30
|
+
accessToken: accessToken,
|
|
31
|
+
repoOwner: 'backport-org',
|
|
32
|
+
repoName: 'repo-with-conflicts',
|
|
33
|
+
pullNumber: 12,
|
|
34
|
+
targetBranches: ['7.x'],
|
|
35
|
+
dir: (0, path_1.resolve)('./src/test/tmp-mock-environments/handleUnbackportedPullRequests'),
|
|
36
|
+
ci: true,
|
|
37
|
+
publishStatusComment: false,
|
|
38
|
+
});
|
|
39
|
+
expect(
|
|
40
|
+
//@ts-expect-error
|
|
41
|
+
result.results[0].error.meta?.commitsWithoutBackports[0].commit.pullNumber).toBe(8);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -50,7 +50,7 @@ describe('inquirer cli', () => {
|
|
|
50
50
|
devAccessToken,
|
|
51
51
|
]);
|
|
52
52
|
const lineCount = res.split('\n').length;
|
|
53
|
-
expect(lineCount).
|
|
53
|
+
expect(lineCount).toBeGreaterThan(10);
|
|
54
54
|
expect(res.includes('Select commit (Use arrow keys)')).toBe(true);
|
|
55
55
|
});
|
|
56
56
|
it('should return error when access token is invalid', async () => {
|
|
@@ -141,6 +141,8 @@ function runBackportAsync(options, { waitForString, } = {}) {
|
|
|
141
141
|
const proc = (0, child_process_1.spawn)('./node_modules/.bin/ts-node', [
|
|
142
142
|
'--transpile-only',
|
|
143
143
|
'./src/entrypoint.cli.ts',
|
|
144
|
+
'--log-file-path',
|
|
145
|
+
'/dev/null',
|
|
144
146
|
...options,
|
|
145
147
|
]);
|
|
146
148
|
const p = new Promise((resolve, reject) => {
|
|
@@ -78,7 +78,7 @@ describe('integration', () => {
|
|
|
78
78
|
"base": "7.x",
|
|
79
79
|
"body": "# Backport
|
|
80
80
|
|
|
81
|
-
This is an automatic backport to 7.x of:
|
|
81
|
+
This is an automatic backport to \`7.x\` of:
|
|
82
82
|
- Add ❤️ emoji (5bf29b7d)
|
|
83
83
|
|
|
84
84
|
### Questions ?
|
|
@@ -214,7 +214,7 @@ describe('integration', () => {
|
|
|
214
214
|
"base": "7.x",
|
|
215
215
|
"body": "# Backport
|
|
216
216
|
|
|
217
|
-
This is an automatic backport to 7.x of:
|
|
217
|
+
This is an automatic backport to \`7.x\` of:
|
|
218
218
|
- Add ❤️ emoji (5bf29b7d)
|
|
219
219
|
|
|
220
220
|
### Questions ?
|
package/dist/test/nockHelpers.js
CHANGED
|
@@ -18,9 +18,7 @@ function mockGqlRequest({ name, statusCode, body, headers, apiBaseUrl, }) {
|
|
|
18
18
|
}
|
|
19
19
|
exports.mockGqlRequest = mockGqlRequest;
|
|
20
20
|
function getGqlName(query) {
|
|
21
|
-
const obj = (0, graphql_tag_1.default)
|
|
22
|
-
${query}
|
|
23
|
-
`;
|
|
21
|
+
const obj = (0, graphql_tag_1.default)(query);
|
|
24
22
|
// @ts-expect-error
|
|
25
23
|
return obj.definitions[0].name.value;
|
|
26
24
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const entrypoint_module_1 = require("./entrypoint.module");
|
|
4
|
+
async function init() {
|
|
5
|
+
const { accessToken } = await (0, entrypoint_module_1.getLocalGlobalConfig)();
|
|
6
|
+
if (!accessToken) {
|
|
7
|
+
throw new Error('Missing access token');
|
|
8
|
+
}
|
|
9
|
+
const commit = await (0, entrypoint_module_1.getCommits)({
|
|
10
|
+
accessToken: accessToken,
|
|
11
|
+
repoOwner: 'backport-org',
|
|
12
|
+
repoName: 'repo-with-conflicts',
|
|
13
|
+
pullNumber: 8,
|
|
14
|
+
});
|
|
15
|
+
console.log({ commit });
|
|
16
|
+
}
|
|
17
|
+
init();
|