backport 8.4.4 → 8.5.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/dist/entrypoint.module.d.ts +1 -1
- package/dist/entrypoint.module.js +8 -7
- package/dist/entrypoint.module.private.test.js +79 -29
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +1 -1
- package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +12 -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 -5
- package/dist/lib/git.d.ts +2 -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/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/test/e2e/cli/entrypoint.cli.private.test.js +2 -2
- 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/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/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
|
@@ -47,17 +47,21 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
47
47
|
const expectedCommits = [
|
|
48
48
|
{
|
|
49
49
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
50
|
+
suggestedTargetBranches: [],
|
|
50
51
|
sourceCommit: {
|
|
52
|
+
branchLabelMapping: undefined,
|
|
51
53
|
committedDate: '2021-12-24T00:00:00Z',
|
|
52
54
|
sha: '2e63475c483f7844b0f2833bc57fdee32095bacb',
|
|
53
55
|
message: 'Add 👻',
|
|
54
56
|
},
|
|
55
|
-
|
|
57
|
+
pullRequestStates: [],
|
|
56
58
|
sourceBranch: 'source-branch-from-options',
|
|
57
59
|
},
|
|
58
60
|
{
|
|
59
61
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
62
|
+
suggestedTargetBranches: [],
|
|
60
63
|
sourceCommit: {
|
|
64
|
+
branchLabelMapping: undefined,
|
|
61
65
|
committedDate: '2021-12-23T00:00:00Z',
|
|
62
66
|
sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
|
|
63
67
|
message: 'Add witch (#85)',
|
|
@@ -70,12 +74,14 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
70
74
|
message: 'Add witch (#85)',
|
|
71
75
|
},
|
|
72
76
|
},
|
|
73
|
-
|
|
77
|
+
pullRequestStates: [],
|
|
74
78
|
sourceBranch: 'master',
|
|
75
79
|
},
|
|
76
80
|
{
|
|
77
81
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
82
|
+
suggestedTargetBranches: [],
|
|
78
83
|
sourceCommit: {
|
|
84
|
+
branchLabelMapping: undefined,
|
|
79
85
|
committedDate: '2021-12-22T00:00:00Z',
|
|
80
86
|
sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
|
|
81
87
|
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
@@ -88,7 +94,7 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
88
94
|
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
89
95
|
},
|
|
90
96
|
},
|
|
91
|
-
|
|
97
|
+
pullRequestStates: [
|
|
92
98
|
{
|
|
93
99
|
branch: '6.3',
|
|
94
100
|
state: 'MERGED',
|
|
@@ -104,22 +110,26 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
104
110
|
},
|
|
105
111
|
{
|
|
106
112
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
113
|
+
suggestedTargetBranches: [],
|
|
107
114
|
sourceCommit: {
|
|
115
|
+
branchLabelMapping: undefined,
|
|
108
116
|
committedDate: '2021-12-21T00:00:00Z',
|
|
109
117
|
sha: '3827bbbaf39914eda4f02f6940189844375fd097',
|
|
110
118
|
message: 'Add backport config',
|
|
111
119
|
},
|
|
112
|
-
|
|
120
|
+
pullRequestStates: [],
|
|
113
121
|
sourceBranch: 'source-branch-from-options',
|
|
114
122
|
},
|
|
115
123
|
{
|
|
116
124
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
125
|
+
suggestedTargetBranches: [],
|
|
117
126
|
sourceCommit: {
|
|
127
|
+
branchLabelMapping: undefined,
|
|
118
128
|
committedDate: '2021-12-20T00:00:00Z',
|
|
119
129
|
sha: '5ea0da550ac191029459289d67f99ad7d310812b',
|
|
120
130
|
message: 'Initial commit',
|
|
121
131
|
},
|
|
122
|
-
|
|
132
|
+
pullRequestStates: [],
|
|
123
133
|
sourceBranch: 'source-branch-from-options',
|
|
124
134
|
},
|
|
125
135
|
];
|
|
@@ -42,7 +42,13 @@ describe('fetchPullRequestsBySearchQuery', () => {
|
|
|
42
42
|
const expectedCommits = [
|
|
43
43
|
{
|
|
44
44
|
author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
|
|
45
|
+
suggestedTargetBranches: [],
|
|
45
46
|
sourceCommit: {
|
|
47
|
+
branchLabelMapping: {
|
|
48
|
+
'^v(\\d+).(\\d+).\\d+$': '$1.$2',
|
|
49
|
+
'^v7.9.0$': '7.x',
|
|
50
|
+
'^v8.0.0$': 'master',
|
|
51
|
+
},
|
|
46
52
|
committedDate: '2020-08-16T21:44:28Z',
|
|
47
53
|
message: 'Add sheep emoji (#9)',
|
|
48
54
|
sha: 'eebf165c82a4b718d95c11b3877e365b1949ff28',
|
|
@@ -56,9 +62,11 @@ describe('fetchPullRequestsBySearchQuery', () => {
|
|
|
56
62
|
},
|
|
57
63
|
},
|
|
58
64
|
sourceBranch: 'master',
|
|
59
|
-
|
|
65
|
+
pullRequestStates: [
|
|
60
66
|
{
|
|
61
67
|
branch: '7.8',
|
|
68
|
+
label: 'v7.8.0',
|
|
69
|
+
isSourceBranch: false,
|
|
62
70
|
state: 'OPEN',
|
|
63
71
|
number: 10,
|
|
64
72
|
url: 'https://github.com/backport-org/backport-e2e/pull/10',
|
|
@@ -67,7 +75,13 @@ describe('fetchPullRequestsBySearchQuery', () => {
|
|
|
67
75
|
},
|
|
68
76
|
{
|
|
69
77
|
author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
|
|
78
|
+
suggestedTargetBranches: [],
|
|
70
79
|
sourceCommit: {
|
|
80
|
+
branchLabelMapping: {
|
|
81
|
+
'^v(\\d+).(\\d+).\\d+$': '$1.$2',
|
|
82
|
+
'^v7.9.0$': '7.x',
|
|
83
|
+
'^v8.0.0$': 'master',
|
|
84
|
+
},
|
|
71
85
|
committedDate: '2020-08-15T12:40:19Z',
|
|
72
86
|
message: 'Add 🍏 emoji (#5)',
|
|
73
87
|
sha: 'ee8c492334cef1ca077a56addb79a26f79821d2f',
|
|
@@ -81,26 +95,42 @@ describe('fetchPullRequestsBySearchQuery', () => {
|
|
|
81
95
|
},
|
|
82
96
|
},
|
|
83
97
|
sourceBranch: 'master',
|
|
84
|
-
|
|
98
|
+
pullRequestStates: [
|
|
85
99
|
{
|
|
86
|
-
branch: '7.
|
|
100
|
+
branch: '7.8',
|
|
101
|
+
isSourceBranch: false,
|
|
102
|
+
label: 'v7.8.0',
|
|
103
|
+
mergeCommit: {
|
|
104
|
+
message: 'Add 🍏 emoji (#5) (#7)',
|
|
105
|
+
sha: '46cd6f9999effdf894a36dbc7db90e890f4be840',
|
|
106
|
+
},
|
|
107
|
+
number: 7,
|
|
87
108
|
state: 'MERGED',
|
|
88
|
-
|
|
89
|
-
|
|
109
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/7',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
branch: '7.x',
|
|
113
|
+
isSourceBranch: false,
|
|
114
|
+
label: 'v7.9.0',
|
|
90
115
|
mergeCommit: {
|
|
91
116
|
message: 'Add 🍏 emoji (#5) (#6)',
|
|
92
117
|
sha: '4bcd876d4ceaa73cf437bfc89b74d1a4e704c0a6',
|
|
93
118
|
},
|
|
119
|
+
number: 6,
|
|
120
|
+
state: 'MERGED',
|
|
121
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/6',
|
|
94
122
|
},
|
|
95
123
|
{
|
|
96
|
-
branch: '
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
url: 'https://github.com/backport-org/backport-e2e/pull/7',
|
|
124
|
+
branch: 'master',
|
|
125
|
+
isSourceBranch: true,
|
|
126
|
+
label: 'v8.0.0',
|
|
100
127
|
mergeCommit: {
|
|
101
|
-
message: 'Add 🍏 emoji (#5)
|
|
102
|
-
sha: '
|
|
128
|
+
message: 'Add 🍏 emoji (#5)',
|
|
129
|
+
sha: 'ee8c492334cef1ca077a56addb79a26f79821d2f',
|
|
103
130
|
},
|
|
131
|
+
number: 5,
|
|
132
|
+
state: 'MERGED',
|
|
133
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/5',
|
|
104
134
|
},
|
|
105
135
|
],
|
|
106
136
|
},
|
|
@@ -48,7 +48,7 @@ export declare function getOptionsFromGithub(options: {
|
|
|
48
48
|
publishStatusCommentOnAbort?: boolean | undefined;
|
|
49
49
|
publishStatusCommentOnFailure?: boolean | undefined;
|
|
50
50
|
publishStatusCommentOnSuccess?: boolean | undefined;
|
|
51
|
-
pullNumber?: number | undefined;
|
|
51
|
+
pullNumber?: number | number[] | undefined;
|
|
52
52
|
repoForkOwner?: string | undefined;
|
|
53
53
|
repoName?: string | undefined;
|
|
54
54
|
repoOwner?: string | undefined;
|
package/dist/lib/prompt.test.js
CHANGED
|
@@ -7,12 +7,14 @@ const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
|
7
7
|
const prompts_1 = require("./prompts");
|
|
8
8
|
describe('prompt', () => {
|
|
9
9
|
describe('getChoicesForCommitPrompt', () => {
|
|
10
|
-
it('should display status badges via `
|
|
10
|
+
it('should display status badges via `pullRequestStates`', () => {
|
|
11
11
|
const commits = [
|
|
12
12
|
{
|
|
13
13
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
14
14
|
sourceBranch: 'master',
|
|
15
|
+
suggestedTargetBranches: [],
|
|
15
16
|
sourceCommit: {
|
|
17
|
+
branchLabelMapping: {},
|
|
16
18
|
committedDate: '1',
|
|
17
19
|
sha: 'ae9d51b7fe3ee6f30d0d196c782e0dcabb7ac5ff',
|
|
18
20
|
message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
|
|
@@ -25,10 +27,28 @@ describe('prompt', () => {
|
|
|
25
27
|
message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
|
|
26
28
|
},
|
|
27
29
|
},
|
|
28
|
-
|
|
29
|
-
{
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
pullRequestStates: [
|
|
31
|
+
{
|
|
32
|
+
number: 120178,
|
|
33
|
+
branch: '8.0',
|
|
34
|
+
label: '',
|
|
35
|
+
isSourceBranch: false,
|
|
36
|
+
state: 'MERGED',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
number: 120179,
|
|
40
|
+
branch: '7.16',
|
|
41
|
+
state: 'MERGED',
|
|
42
|
+
label: '',
|
|
43
|
+
isSourceBranch: false,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
number: 120179,
|
|
47
|
+
branch: '7.15',
|
|
48
|
+
state: 'NOT_CREATED',
|
|
49
|
+
label: '',
|
|
50
|
+
isSourceBranch: false,
|
|
51
|
+
},
|
|
32
52
|
],
|
|
33
53
|
},
|
|
34
54
|
];
|
|
@@ -45,7 +65,9 @@ describe('prompt', () => {
|
|
|
45
65
|
{
|
|
46
66
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
47
67
|
sourceBranch: 'master',
|
|
68
|
+
suggestedTargetBranches: [],
|
|
48
69
|
sourceCommit: {
|
|
70
|
+
branchLabelMapping: {},
|
|
49
71
|
committedDate: '',
|
|
50
72
|
sha: 'b1b491959dab47aeb83c88ee2accb2db46d23793',
|
|
51
73
|
message: '[APM] Prefer service.name for logs correlation (#120694)',
|
|
@@ -58,12 +80,14 @@ describe('prompt', () => {
|
|
|
58
80
|
message: '[APM] Prefer service.name for logs correlation (#120694)',
|
|
59
81
|
},
|
|
60
82
|
},
|
|
61
|
-
|
|
83
|
+
pullRequestStates: [],
|
|
62
84
|
},
|
|
63
85
|
{
|
|
64
86
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
65
87
|
sourceBranch: 'master',
|
|
88
|
+
suggestedTargetBranches: [],
|
|
66
89
|
sourceCommit: {
|
|
90
|
+
branchLabelMapping: {},
|
|
67
91
|
committedDate: '',
|
|
68
92
|
sha: 'b1bb4a93959f19a653b9cfb207a5c6acb6559482',
|
|
69
93
|
message: '[APM] Disable telemetry in agent config endpoint (#120106)',
|
|
@@ -76,12 +100,14 @@ describe('prompt', () => {
|
|
|
76
100
|
message: '[APM] Disable telemetry in agent config endpoint (#120106)',
|
|
77
101
|
},
|
|
78
102
|
},
|
|
79
|
-
|
|
103
|
+
pullRequestStates: [],
|
|
80
104
|
},
|
|
81
105
|
{
|
|
82
106
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
83
107
|
sourceBranch: 'master',
|
|
108
|
+
suggestedTargetBranches: [],
|
|
84
109
|
sourceCommit: {
|
|
110
|
+
branchLabelMapping: {},
|
|
85
111
|
committedDate: '',
|
|
86
112
|
sha: '434f6e6a88faf24dc1ea41f9f726db78e46355a7',
|
|
87
113
|
message: '[APM] Remove index_pattern.json and add custom field formatters (#119915)',
|
|
@@ -94,12 +120,14 @@ describe('prompt', () => {
|
|
|
94
120
|
message: '[APM] Remove index_pattern.json and add custom field formatters (#119915)',
|
|
95
121
|
},
|
|
96
122
|
},
|
|
97
|
-
|
|
123
|
+
pullRequestStates: [],
|
|
98
124
|
},
|
|
99
125
|
{
|
|
100
126
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
101
127
|
sourceBranch: 'master',
|
|
128
|
+
suggestedTargetBranches: [],
|
|
102
129
|
sourceCommit: {
|
|
130
|
+
branchLabelMapping: {},
|
|
103
131
|
committedDate: '',
|
|
104
132
|
sha: 'ae9d51b7fe3ee6f30d0d196c782e0dcabb7ac5ff',
|
|
105
133
|
message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
|
|
@@ -112,7 +140,7 @@ describe('prompt', () => {
|
|
|
112
140
|
message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
|
|
113
141
|
},
|
|
114
142
|
},
|
|
115
|
-
|
|
143
|
+
pullRequestStates: [],
|
|
116
144
|
},
|
|
117
145
|
];
|
|
118
146
|
const choices = (0, prompts_1.getChoicesForCommitPrompt)(commits, false).map(({ name, short }) => ({ name: (0, strip_ansi_1.default)(name), short }));
|
package/dist/lib/prompts.js
CHANGED
|
@@ -44,7 +44,9 @@ function getPrLink(number, url) {
|
|
|
44
44
|
return url ? `(${(0, terminal_link_1.default)(`#${number}`, url)})` : '';
|
|
45
45
|
}
|
|
46
46
|
function getDetailedPullStatus(c) {
|
|
47
|
-
const items = c.
|
|
47
|
+
const items = c.pullRequestStates
|
|
48
|
+
.filter(({ isSourceBranch }) => !isSourceBranch)
|
|
49
|
+
.map((pr) => {
|
|
48
50
|
const prLink = getPrLink(pr.number, pr.url);
|
|
49
51
|
return ` └ ${getPrStateIcon(pr.state)} ${pr.branch} ${prLink} ${getPrStateText(pr.state)}`;
|
|
50
52
|
});
|
|
@@ -54,7 +56,8 @@ function getDetailedPullStatus(c) {
|
|
|
54
56
|
return `${list}\n`;
|
|
55
57
|
}
|
|
56
58
|
function getSimplePullStatus(c) {
|
|
57
|
-
return c.
|
|
59
|
+
return c.pullRequestStates
|
|
60
|
+
.filter(({ isSourceBranch }) => !isSourceBranch)
|
|
58
61
|
.map(({ state, branch }) => {
|
|
59
62
|
if (state === 'MERGED') {
|
|
60
63
|
return chalk_1.default.green(branch);
|
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
|