backport 8.4.4 → 8.5.2
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/dist/backportRun.js +1 -5
- package/dist/entrypoint.module.d.ts +2 -2
- package/dist/entrypoint.module.js +9 -8
- package/dist/entrypoint.module.private.test.js +86 -32
- package/dist/lib/BackportError.d.ts +3 -0
- package/dist/lib/BackportError.js +2 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +4 -3
- package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +30 -4
- package/dist/lib/getCommits.js +14 -9
- package/dist/lib/getCommitsWithoutBackports.js +3 -3
- package/dist/lib/getCommitsWithoutBackports.test.js +38 -15
- package/dist/lib/getTargetBranches.d.ts +1 -1
- package/dist/lib/getTargetBranches.js +6 -10
- package/dist/lib/getTargetBranches.test.js +9 -9
- package/dist/lib/git.d.ts +2 -2
- package/dist/lib/git.js +9 -2
- package/dist/lib/git.test.js +3 -1
- package/dist/lib/github/v3/createPullRequest.test.js +39 -13
- package/dist/lib/github/v3/createStatusComment.js +5 -2
- package/dist/lib/github/v3/createStatusComment.test.js +7 -3
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +20 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +32 -10
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +9 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +49 -14
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +15 -5
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +41 -11
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -1
- package/dist/lib/github/v4/validateTargetBranch.d.ts +15 -0
- package/dist/lib/github/v4/{validateTargetBranches.js → validateTargetBranch.js} +13 -17
- package/dist/lib/github/v4/{validateTargetBranches.private.test.d.ts → validateTargetBranch.private.test.d.ts} +0 -0
- package/dist/lib/github/v4/validateTargetBranch.private.test.js +23 -0
- package/dist/lib/prompt.test.js +37 -9
- package/dist/lib/prompts.js +5 -2
- package/dist/lib/setupRepo.js +3 -3
- package/dist/lib/sourceCommit/getPullRequestStates.d.ts +27 -0
- package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.js → getPullRequestStates.js} +62 -27
- package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.test.d.ts → getPullRequestStates.test.d.ts} +0 -0
- package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.test.js → getPullRequestStates.test.js} +283 -87
- package/dist/lib/sourceCommit/parseSourceCommit.d.ts +4 -2
- package/dist/lib/sourceCommit/parseSourceCommit.js +20 -5
- package/dist/lib/sourceCommit/parseSourceCommit.test.js +78 -25
- package/dist/options/ConfigOptions.d.ts +1 -1
- package/dist/options/config/config.d.ts +1 -1
- package/dist/options/config/readConfigFile.d.ts +1 -1
- package/dist/options/options.d.ts +1 -1
- package/dist/runSequentially.js +9 -3
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +2 -2
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +2 -2
- package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +10 -8
- package/dist/test/e2e/cli/repo-with-changing-branchLabelMapping.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/repo-with-changing-branchLabelMapping.private.test.js +95 -0
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +11 -4
- package/dist/test/handleUnbackportedPullRequests.private.test.js +10 -1
- package/dist/test/nockHelpers.js +1 -0
- package/dist/utils/filterUnmergedCommits.js +1 -1
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +13 -13
- package/yarn.lock +512 -425
- package/dist/lib/github/v4/validateTargetBranches.d.ts +0 -9
- package/dist/lib/github/v4/validateTargetBranches.private.test.js +0 -51
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
package/dist/lib/setupRepo.js
CHANGED
|
@@ -9,11 +9,11 @@ const ora_1 = require("./ora");
|
|
|
9
9
|
async function setupRepo(options) {
|
|
10
10
|
const repoPath = (0, env_1.getRepoPath)(options);
|
|
11
11
|
const isAlreadyCloned = await getIsRepoCloned(options);
|
|
12
|
-
if (options.cwd.includes(repoPath)) {
|
|
13
|
-
throw new BackportError_1.BackportError(`Refusing to clone repo into "${repoPath}" when current working directory is "${options.cwd}". Please change backport directory via \`--dir\` option or run backport from another location`);
|
|
14
|
-
}
|
|
15
12
|
// clone repo if folder does not already exists
|
|
16
13
|
if (!isAlreadyCloned) {
|
|
14
|
+
if (options.cwd.includes(repoPath)) {
|
|
15
|
+
throw new BackportError_1.BackportError(`Refusing to clone repo into "${repoPath}" when current working directory is "${options.cwd}". Please change backport directory via \`--dir\` option or run backport from another location`);
|
|
16
|
+
}
|
|
17
17
|
const spinner = (0, ora_1.ora)(options.interactive).start();
|
|
18
18
|
try {
|
|
19
19
|
const localRepoPath = await (0, git_1.getLocalSourceRepoPath)(options);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ValidConfigOptions } from '../../options/options';
|
|
2
|
+
import { SourceCommitWithTargetPullRequest } from './parseSourceCommit';
|
|
3
|
+
export declare type PullRequestState = 'OPEN' | 'CLOSED' | 'MERGED' | 'NOT_CREATED';
|
|
4
|
+
declare type CreatedPullRequest = {
|
|
5
|
+
url: string;
|
|
6
|
+
number: number;
|
|
7
|
+
branch: string;
|
|
8
|
+
state: PullRequestState;
|
|
9
|
+
mergeCommit?: {
|
|
10
|
+
sha: string;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
declare type TargetBranchWithLabel = {
|
|
15
|
+
branch: string;
|
|
16
|
+
label: string;
|
|
17
|
+
isSourceBranch: boolean;
|
|
18
|
+
};
|
|
19
|
+
export declare type TargetPullRequest = (CreatedPullRequest & Partial<TargetBranchWithLabel>) | ((TargetBranchWithLabel & Partial<CreatedPullRequest>) & {
|
|
20
|
+
state: PullRequestState;
|
|
21
|
+
});
|
|
22
|
+
export declare function getSourceCommitBranchLabelMapping(sourceCommit: SourceCommitWithTargetPullRequest): ValidConfigOptions['branchLabelMapping'];
|
|
23
|
+
export declare function getPullRequestStates({ sourceCommit, branchLabelMapping, }: {
|
|
24
|
+
sourceCommit: SourceCommitWithTargetPullRequest;
|
|
25
|
+
branchLabelMapping: ValidConfigOptions['branchLabelMapping'];
|
|
26
|
+
}): TargetPullRequest[];
|
|
27
|
+
export {};
|
|
@@ -1,30 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getPullRequestStates = exports.getSourceCommitBranchLabelMapping = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
5
|
const filterEmpty_1 = require("../../utils/filterEmpty");
|
|
6
6
|
const commitFormatters_1 = require("../github/commitFormatters");
|
|
7
7
|
const remoteConfig_1 = require("../remoteConfig");
|
|
8
|
-
function
|
|
9
|
-
|
|
8
|
+
function getSourcePullRequest(sourceCommit) {
|
|
9
|
+
return sourceCommit.associatedPullRequests.edges?.[0]?.node;
|
|
10
|
+
}
|
|
11
|
+
function getSourceCommitBranchLabelMapping(sourceCommit) {
|
|
12
|
+
const sourcePullRequest = getSourcePullRequest(sourceCommit);
|
|
10
13
|
const remoteConfig = sourcePullRequest?.mergeCommit.remoteConfigHistory.edges?.[0]?.remoteConfig;
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
if (remoteConfig) {
|
|
15
|
+
return (0, remoteConfig_1.parseRemoteConfig)(remoteConfig)?.branchLabelMapping;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.getSourceCommitBranchLabelMapping = getSourceCommitBranchLabelMapping;
|
|
19
|
+
function mergeByKey(obj1, obj2, key) {
|
|
20
|
+
const merged = (0, lodash_1.merge)((0, lodash_1.keyBy)(obj1, key), (0, lodash_1.keyBy)(obj2, key));
|
|
21
|
+
const a = (0, lodash_1.values)(merged);
|
|
22
|
+
return a;
|
|
23
|
+
}
|
|
24
|
+
function getPullRequestStates({ sourceCommit, branchLabelMapping, }) {
|
|
25
|
+
const sourcePullRequest = getSourcePullRequest(sourceCommit);
|
|
13
26
|
// if there is no source pull request the commit was pushed directly to the source branch
|
|
14
27
|
// in that case there will be no labels, and thus not possible to deduce the expected target branches
|
|
15
28
|
if (!sourcePullRequest) {
|
|
16
29
|
return [];
|
|
17
30
|
}
|
|
18
|
-
const
|
|
19
|
-
// if there's no `branchLabelMapping`, it's not possible to
|
|
31
|
+
const createdTargetPullRequests = getCreatedTargetPullRequests(sourceCommit);
|
|
32
|
+
// if there's no `branchLabelMapping`, it's not possible to determine the missing target branches
|
|
20
33
|
if (!branchLabelMapping) {
|
|
21
|
-
return
|
|
34
|
+
return createdTargetPullRequests;
|
|
22
35
|
}
|
|
23
|
-
const
|
|
24
|
-
return
|
|
36
|
+
const targetBranchesFromLabels = getTargetBranchesFromLabels(sourcePullRequest, branchLabelMapping);
|
|
37
|
+
return mergeByKey(targetBranchesFromLabels, createdTargetPullRequests, 'branch').map((res) => {
|
|
38
|
+
if (res.state) {
|
|
39
|
+
return { ...res, state: res.state };
|
|
40
|
+
}
|
|
41
|
+
// MERGED (source branch)
|
|
42
|
+
if (res.isSourceBranch) {
|
|
43
|
+
return {
|
|
44
|
+
...res,
|
|
45
|
+
state: 'MERGED',
|
|
46
|
+
url: sourcePullRequest.url,
|
|
47
|
+
number: sourcePullRequest.number,
|
|
48
|
+
mergeCommit: {
|
|
49
|
+
message: sourcePullRequest.mergeCommit.message,
|
|
50
|
+
sha: sourcePullRequest.mergeCommit.sha,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// NOT_CREATED
|
|
55
|
+
return { ...res, state: 'NOT_CREATED' };
|
|
56
|
+
});
|
|
25
57
|
}
|
|
26
|
-
exports.
|
|
27
|
-
function
|
|
58
|
+
exports.getPullRequestStates = getPullRequestStates;
|
|
59
|
+
function getCreatedTargetPullRequests(sourceCommit) {
|
|
60
|
+
const sourcePullRequest = getSourcePullRequest(sourceCommit);
|
|
61
|
+
if (!sourcePullRequest) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
28
64
|
const sourceCommitMessage = (0, commitFormatters_1.getFirstLine)(sourceCommit.message);
|
|
29
65
|
return sourcePullRequest.timelineItems.edges
|
|
30
66
|
.filter(filterEmpty_1.filterNil)
|
|
@@ -65,26 +101,25 @@ function getExistingTargetPullRequests(sourceCommit, sourcePullRequest) {
|
|
|
65
101
|
};
|
|
66
102
|
});
|
|
67
103
|
}
|
|
68
|
-
function getMissingTargetPullRequests(sourcePullRequest, existingTargetPullRequests, branchLabelMapping) {
|
|
69
|
-
const labels = sourcePullRequest.labels.nodes.map((label) => label.name);
|
|
70
|
-
const targetBranchesFromLabels = labels
|
|
71
|
-
.map((label) => getTargetBranchForLabel({ branchLabelMapping, label }))
|
|
72
|
-
.filter(filterEmpty_1.filterNil)
|
|
73
|
-
.filter((targetBranch) => targetBranch !== sourcePullRequest.baseRefName);
|
|
74
|
-
const expectedTargetBranches = existingTargetPullRequests.map((pr) => pr.branch);
|
|
75
|
-
const expected = (0, lodash_1.uniq)(targetBranchesFromLabels);
|
|
76
|
-
return expected
|
|
77
|
-
.filter((targetBranch) => !expectedTargetBranches.includes(targetBranch))
|
|
78
|
-
.map((branch) => {
|
|
79
|
-
return { branch, state: 'NOT_CREATED' };
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
104
|
// narrow TimelineEdge to TimelinePullRequestEdge
|
|
83
105
|
function filterPullRequests(item) {
|
|
84
106
|
const { targetPullRequest } = item.node;
|
|
85
107
|
return targetPullRequest.__typename === 'PullRequest';
|
|
86
108
|
}
|
|
87
|
-
function
|
|
109
|
+
function getTargetBranchesFromLabels(sourcePullRequest, branchLabelMapping) {
|
|
110
|
+
const targetBranchesFromLabels = sourcePullRequest.labels.nodes
|
|
111
|
+
.map((label) => label.name)
|
|
112
|
+
.map((label) => {
|
|
113
|
+
const branch = getTargetBranchFromLabel({ branchLabelMapping, label });
|
|
114
|
+
if (branch) {
|
|
115
|
+
const isSourceBranch = branch === sourcePullRequest.baseRefName;
|
|
116
|
+
return { branch, label, isSourceBranch };
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
.filter(filterEmpty_1.filterNil);
|
|
120
|
+
return (0, lodash_1.uniqBy)(targetBranchesFromLabels, ({ branch }) => branch);
|
|
121
|
+
}
|
|
122
|
+
function getTargetBranchFromLabel({ branchLabelMapping, label, }) {
|
|
88
123
|
// only get first match
|
|
89
124
|
const result = Object.entries(branchLabelMapping).find(([labelPattern]) => {
|
|
90
125
|
const regex = new RegExp(labelPattern);
|
|
File without changes
|