backport 8.6.2 → 8.8.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.private.test.js +78 -52
- package/dist/lib/{cherrypickAndCreateTargetPullRequest.d.ts → cherrypickAndCreateTargetPullRequest/cherrypickAndCreateTargetPullRequest.d.ts} +2 -2
- package/dist/lib/cherrypickAndCreateTargetPullRequest/cherrypickAndCreateTargetPullRequest.js +98 -0
- package/dist/lib/{cherrypickAndCreateTargetPullRequest.test.d.ts → cherrypickAndCreateTargetPullRequest/cherrypickAndCreateTargetPullRequest.test.d.ts} +0 -0
- package/dist/lib/{cherrypickAndCreateTargetPullRequest.test.js → cherrypickAndCreateTargetPullRequest/cherrypickAndCreateTargetPullRequest.test.js} +12 -10
- package/dist/lib/cherrypickAndCreateTargetPullRequest/getBackportBranchName.d.ts +2 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest/getBackportBranchName.js +22 -0
- package/dist/lib/{getCommitsWithoutBackports.d.ts → cherrypickAndCreateTargetPullRequest/getCommitsWithoutBackports.d.ts} +2 -2
- package/dist/lib/{getCommitsWithoutBackports.js → cherrypickAndCreateTargetPullRequest/getCommitsWithoutBackports.js} +6 -6
- package/dist/lib/{getCommitsWithoutBackports.test.d.ts → cherrypickAndCreateTargetPullRequest/getCommitsWithoutBackports.test.d.ts} +0 -0
- package/dist/lib/{getCommitsWithoutBackports.test.js → cherrypickAndCreateTargetPullRequest/getCommitsWithoutBackports.test.js} +24 -17
- package/dist/lib/cherrypickAndCreateTargetPullRequest/getMergeCommit.d.ts +3 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest/getMergeCommit.js +17 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest/getTargetPRLabels.d.ts +7 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest/getTargetPRLabels.js +33 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest/getTargetPRLabels.test.d.ts +1 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest/getTargetPRLabels.test.js +166 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest/waitForCherrypick.d.ts +3 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest/waitForCherrypick.js +154 -0
- package/dist/lib/getSourceBranchFromCommits.d.ts +2 -0
- package/dist/lib/getSourceBranchFromCommits.js +10 -0
- package/dist/lib/getTargetBranches.js +2 -3
- package/dist/lib/getTargetBranches.test.js +6 -4
- package/dist/lib/git.test.js +1 -1
- package/dist/lib/github/v3/addAssigneesToPullRequest.d.ts +11 -2
- package/dist/lib/github/v3/addAssigneesToPullRequest.js +9 -1
- package/dist/lib/github/v3/addAssigneesToPullRequest.test.js +5 -2
- package/dist/lib/github/v3/addLabelsToPullRequest.d.ts +10 -2
- package/dist/lib/github/v3/addLabelsToPullRequest.js +5 -1
- package/dist/lib/github/v3/addReviewersToPullRequest.d.ts +1 -1
- package/dist/lib/github/v3/addReviewersToPullRequest.js +5 -1
- package/dist/lib/github/v3/createPullRequest.js +9 -2
- package/dist/lib/github/v3/createPullRequest.test.js +61 -56
- package/dist/lib/github/v3/createStatusComment.test.js +4 -2
- package/dist/lib/github/v4/enablePullRequestAutoMerge.js +4 -0
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +10 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +5 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +10 -4
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +7 -5
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +8 -2
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +6 -5
- package/dist/lib/prompt.test.js +14 -6
- package/dist/lib/prompts.js +2 -2
- package/dist/lib/sourceCommit/getPullRequestStates.d.ts +3 -2
- package/dist/lib/sourceCommit/getPullRequestStates.js +13 -20
- package/dist/lib/sourceCommit/getPullRequestStates.test.js +69 -28
- package/dist/lib/sourceCommit/parseSourceCommit.d.ts +2 -1
- package/dist/lib/sourceCommit/parseSourceCommit.js +15 -7
- package/dist/lib/sourceCommit/parseSourceCommit.test.js +15 -4
- package/dist/runSequentially.js +5 -5
- package/dist/test/e2e/cli/different-merge-strategies.private.test.js +6 -2
- package/dist/test/e2e/cli/gracefully-handles-corrupt-repo.private.test.js +5 -1
- package/dist/test/e2e/cli/repo-with-changing-branchLabelMapping.private.test.js +2 -2
- package/dist/test/e2e/cli/repo-with-programatically-added-commits.mutation.test.js +1 -1
- package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +6 -2
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +4 -4
- package/dist/test/handleUnbackportedPullRequests.private.test.js +3 -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 +11 -11
- package/yarn.lock +95 -139
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +0 -255
|
@@ -54,7 +54,7 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
54
54
|
sha: '2e63475c483f7844b0f2833bc57fdee32095bacb',
|
|
55
55
|
message: 'Add 👻',
|
|
56
56
|
},
|
|
57
|
-
|
|
57
|
+
targetPullRequestStates: [],
|
|
58
58
|
sourceBranch: 'source-branch-from-options',
|
|
59
59
|
},
|
|
60
60
|
{
|
|
@@ -67,6 +67,7 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
67
67
|
message: 'Add witch (#85)',
|
|
68
68
|
},
|
|
69
69
|
sourcePullRequest: {
|
|
70
|
+
labels: ['my-label-b'],
|
|
70
71
|
number: 85,
|
|
71
72
|
url: 'https://github.com/elastic/kibana/pull/85',
|
|
72
73
|
mergeCommit: {
|
|
@@ -74,7 +75,7 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
74
75
|
message: 'Add witch (#85)',
|
|
75
76
|
},
|
|
76
77
|
},
|
|
77
|
-
|
|
78
|
+
targetPullRequestStates: [],
|
|
78
79
|
sourceBranch: 'master',
|
|
79
80
|
},
|
|
80
81
|
{
|
|
@@ -87,6 +88,7 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
87
88
|
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
88
89
|
},
|
|
89
90
|
sourcePullRequest: {
|
|
91
|
+
labels: ['v6.3.0'],
|
|
90
92
|
number: 80,
|
|
91
93
|
url: 'https://github.com/elastic/kibana/pull/80',
|
|
92
94
|
mergeCommit: {
|
|
@@ -94,7 +96,7 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
94
96
|
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
95
97
|
},
|
|
96
98
|
},
|
|
97
|
-
|
|
99
|
+
targetPullRequestStates: [
|
|
98
100
|
{
|
|
99
101
|
branch: '6.3',
|
|
100
102
|
state: 'MERGED',
|
|
@@ -117,7 +119,7 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
117
119
|
sha: '3827bbbaf39914eda4f02f6940189844375fd097',
|
|
118
120
|
message: 'Add backport config',
|
|
119
121
|
},
|
|
120
|
-
|
|
122
|
+
targetPullRequestStates: [],
|
|
121
123
|
sourceBranch: 'source-branch-from-options',
|
|
122
124
|
},
|
|
123
125
|
{
|
|
@@ -129,7 +131,7 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
129
131
|
sha: '5ea0da550ac191029459289d67f99ad7d310812b',
|
|
130
132
|
message: 'Initial commit',
|
|
131
133
|
},
|
|
132
|
-
|
|
134
|
+
targetPullRequestStates: [],
|
|
133
135
|
sourceBranch: 'source-branch-from-options',
|
|
134
136
|
},
|
|
135
137
|
];
|
|
@@ -54,6 +54,7 @@ describe('fetchPullRequestsBySearchQuery', () => {
|
|
|
54
54
|
sha: 'eebf165c82a4b718d95c11b3877e365b1949ff28',
|
|
55
55
|
},
|
|
56
56
|
sourcePullRequest: {
|
|
57
|
+
labels: ['v7.8.0'],
|
|
57
58
|
number: 9,
|
|
58
59
|
url: 'https://github.com/backport-org/backport-e2e/pull/9',
|
|
59
60
|
mergeCommit: {
|
|
@@ -62,10 +63,11 @@ describe('fetchPullRequestsBySearchQuery', () => {
|
|
|
62
63
|
},
|
|
63
64
|
},
|
|
64
65
|
sourceBranch: 'master',
|
|
65
|
-
|
|
66
|
+
targetPullRequestStates: [
|
|
66
67
|
{
|
|
67
68
|
branch: '7.8',
|
|
68
69
|
label: 'v7.8.0',
|
|
70
|
+
labelRegex: '^v(\\d+).(\\d+).\\d+$',
|
|
69
71
|
isSourceBranch: false,
|
|
70
72
|
state: 'OPEN',
|
|
71
73
|
number: 10,
|
|
@@ -87,6 +89,7 @@ describe('fetchPullRequestsBySearchQuery', () => {
|
|
|
87
89
|
sha: 'ee8c492334cef1ca077a56addb79a26f79821d2f',
|
|
88
90
|
},
|
|
89
91
|
sourcePullRequest: {
|
|
92
|
+
labels: ['v7.8.0', 'v7.9.0', 'v8.0.0'],
|
|
90
93
|
number: 5,
|
|
91
94
|
url: 'https://github.com/backport-org/backport-e2e/pull/5',
|
|
92
95
|
mergeCommit: {
|
|
@@ -95,11 +98,12 @@ describe('fetchPullRequestsBySearchQuery', () => {
|
|
|
95
98
|
},
|
|
96
99
|
},
|
|
97
100
|
sourceBranch: 'master',
|
|
98
|
-
|
|
101
|
+
targetPullRequestStates: [
|
|
99
102
|
{
|
|
100
103
|
branch: '7.8',
|
|
101
104
|
isSourceBranch: false,
|
|
102
105
|
label: 'v7.8.0',
|
|
106
|
+
labelRegex: '^v(\\d+).(\\d+).\\d+$',
|
|
103
107
|
mergeCommit: {
|
|
104
108
|
message: 'Add 🍏 emoji (#5) (#7)',
|
|
105
109
|
sha: '46cd6f9999effdf894a36dbc7db90e890f4be840',
|
|
@@ -112,6 +116,7 @@ describe('fetchPullRequestsBySearchQuery', () => {
|
|
|
112
116
|
branch: '7.x',
|
|
113
117
|
isSourceBranch: false,
|
|
114
118
|
label: 'v7.9.0',
|
|
119
|
+
labelRegex: '^v7.9.0$',
|
|
115
120
|
mergeCommit: {
|
|
116
121
|
message: 'Add 🍏 emoji (#5) (#6)',
|
|
117
122
|
sha: '4bcd876d4ceaa73cf437bfc89b74d1a4e704c0a6',
|
|
@@ -124,6 +129,7 @@ describe('fetchPullRequestsBySearchQuery', () => {
|
|
|
124
129
|
branch: 'master',
|
|
125
130
|
isSourceBranch: true,
|
|
126
131
|
label: 'v8.0.0',
|
|
132
|
+
labelRegex: '^v8.0.0$',
|
|
127
133
|
mergeCommit: {
|
|
128
134
|
message: 'Add 🍏 emoji (#5)',
|
|
129
135
|
sha: 'ee8c492334cef1ca077a56addb79a26f79821d2f',
|
|
@@ -46,13 +46,13 @@ async function getOptionsFromGithub(options) {
|
|
|
46
46
|
exports.getOptionsFromGithub = getOptionsFromGithub;
|
|
47
47
|
async function getRemoteConfigFileOptions(res, cwd, skipRemoteConfig) {
|
|
48
48
|
if (skipRemoteConfig) {
|
|
49
|
-
logger_1.logger.info('
|
|
49
|
+
logger_1.logger.info('Remote config: Skipping. `--skip-remote-config` specified via config file or cli');
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
const remoteConfig = res.repository.defaultBranchRef.target.remoteConfigHistory.edges?.[0]
|
|
53
53
|
?.remoteConfig;
|
|
54
54
|
if (!remoteConfig) {
|
|
55
|
-
logger_1.logger.info("
|
|
55
|
+
logger_1.logger.info("Remote config: Skipping. Remote config doesn't exist");
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
58
|
if (cwd) {
|
|
@@ -62,18 +62,19 @@ async function getRemoteConfigFileOptions(res, cwd, skipRemoteConfig) {
|
|
|
62
62
|
(0, git_1.getLocalConfigFileCommitDate)({ cwd }),
|
|
63
63
|
]);
|
|
64
64
|
if (isLocalConfigUntracked) {
|
|
65
|
-
logger_1.logger.info('
|
|
65
|
+
logger_1.logger.info('Remote config: Skipping. Local config is new');
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
68
|
if (isLocalConfigModified) {
|
|
69
|
-
logger_1.logger.info('
|
|
69
|
+
logger_1.logger.info('Remote config: Skipping. Local config is modified');
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
72
|
if (localCommitDate &&
|
|
73
73
|
localCommitDate > Date.parse(remoteConfig.committedDate)) {
|
|
74
|
-
logger_1.logger.info(`
|
|
74
|
+
logger_1.logger.info(`Remote config: Skipping. Local config is newer: ${new Date(localCommitDate).toISOString()} > ${remoteConfig.committedDate}`);
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
+
logger_1.logger.info('Remote config: Parsing.');
|
|
78
79
|
return (0, remoteConfig_1.parseRemoteConfig)(remoteConfig);
|
|
79
80
|
}
|
package/dist/lib/prompt.test.js
CHANGED
|
@@ -7,7 +7,7 @@ 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 `targetPullRequestStates`', () => {
|
|
11
11
|
const commits = [
|
|
12
12
|
{
|
|
13
13
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
@@ -20,6 +20,7 @@ describe('prompt', () => {
|
|
|
20
20
|
message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
|
|
21
21
|
},
|
|
22
22
|
sourcePullRequest: {
|
|
23
|
+
labels: [],
|
|
23
24
|
number: 119700,
|
|
24
25
|
url: 'foo',
|
|
25
26
|
mergeCommit: {
|
|
@@ -27,8 +28,9 @@ describe('prompt', () => {
|
|
|
27
28
|
message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
|
|
28
29
|
},
|
|
29
30
|
},
|
|
30
|
-
|
|
31
|
+
targetPullRequestStates: [
|
|
31
32
|
{
|
|
33
|
+
labelRegex: 'foo tbd',
|
|
32
34
|
number: 120178,
|
|
33
35
|
branch: '8.0',
|
|
34
36
|
label: '',
|
|
@@ -36,6 +38,7 @@ describe('prompt', () => {
|
|
|
36
38
|
state: 'MERGED',
|
|
37
39
|
},
|
|
38
40
|
{
|
|
41
|
+
labelRegex: 'foo tbd',
|
|
39
42
|
number: 120179,
|
|
40
43
|
branch: '7.16',
|
|
41
44
|
state: 'MERGED',
|
|
@@ -43,6 +46,7 @@ describe('prompt', () => {
|
|
|
43
46
|
isSourceBranch: false,
|
|
44
47
|
},
|
|
45
48
|
{
|
|
49
|
+
labelRegex: 'foo tbd',
|
|
46
50
|
number: 120179,
|
|
47
51
|
branch: '7.15',
|
|
48
52
|
state: 'NOT_CREATED',
|
|
@@ -73,6 +77,7 @@ describe('prompt', () => {
|
|
|
73
77
|
message: '[APM] Prefer service.name for logs correlation (#120694)',
|
|
74
78
|
},
|
|
75
79
|
sourcePullRequest: {
|
|
80
|
+
labels: [],
|
|
76
81
|
number: 120694,
|
|
77
82
|
url: 'foo',
|
|
78
83
|
mergeCommit: {
|
|
@@ -80,7 +85,7 @@ describe('prompt', () => {
|
|
|
80
85
|
message: '[APM] Prefer service.name for logs correlation (#120694)',
|
|
81
86
|
},
|
|
82
87
|
},
|
|
83
|
-
|
|
88
|
+
targetPullRequestStates: [],
|
|
84
89
|
},
|
|
85
90
|
{
|
|
86
91
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
@@ -93,6 +98,7 @@ describe('prompt', () => {
|
|
|
93
98
|
message: '[APM] Disable telemetry in agent config endpoint (#120106)',
|
|
94
99
|
},
|
|
95
100
|
sourcePullRequest: {
|
|
101
|
+
labels: [],
|
|
96
102
|
number: 120106,
|
|
97
103
|
url: 'foo',
|
|
98
104
|
mergeCommit: {
|
|
@@ -100,7 +106,7 @@ describe('prompt', () => {
|
|
|
100
106
|
message: '[APM] Disable telemetry in agent config endpoint (#120106)',
|
|
101
107
|
},
|
|
102
108
|
},
|
|
103
|
-
|
|
109
|
+
targetPullRequestStates: [],
|
|
104
110
|
},
|
|
105
111
|
{
|
|
106
112
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
@@ -113,6 +119,7 @@ describe('prompt', () => {
|
|
|
113
119
|
message: '[APM] Remove index_pattern.json and add custom field formatters (#119915)',
|
|
114
120
|
},
|
|
115
121
|
sourcePullRequest: {
|
|
122
|
+
labels: [],
|
|
116
123
|
number: 119915,
|
|
117
124
|
url: 'foo',
|
|
118
125
|
mergeCommit: {
|
|
@@ -120,7 +127,7 @@ describe('prompt', () => {
|
|
|
120
127
|
message: '[APM] Remove index_pattern.json and add custom field formatters (#119915)',
|
|
121
128
|
},
|
|
122
129
|
},
|
|
123
|
-
|
|
130
|
+
targetPullRequestStates: [],
|
|
124
131
|
},
|
|
125
132
|
{
|
|
126
133
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
@@ -133,6 +140,7 @@ describe('prompt', () => {
|
|
|
133
140
|
message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
|
|
134
141
|
},
|
|
135
142
|
sourcePullRequest: {
|
|
143
|
+
labels: [],
|
|
136
144
|
number: 119700,
|
|
137
145
|
url: 'foo',
|
|
138
146
|
mergeCommit: {
|
|
@@ -140,7 +148,7 @@ describe('prompt', () => {
|
|
|
140
148
|
message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
|
|
141
149
|
},
|
|
142
150
|
},
|
|
143
|
-
|
|
151
|
+
targetPullRequestStates: [],
|
|
144
152
|
},
|
|
145
153
|
];
|
|
146
154
|
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,7 @@ 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.targetPullRequestStates
|
|
48
48
|
.filter(({ isSourceBranch }) => !isSourceBranch)
|
|
49
49
|
.map((pr) => {
|
|
50
50
|
const prLink = getPrLink(pr.number, pr.url);
|
|
@@ -56,7 +56,7 @@ function getDetailedPullStatus(c) {
|
|
|
56
56
|
return `${list}\n`;
|
|
57
57
|
}
|
|
58
58
|
function getSimplePullStatus(c) {
|
|
59
|
-
return c.
|
|
59
|
+
return c.targetPullRequestStates
|
|
60
60
|
.filter(({ isSourceBranch }) => !isSourceBranch)
|
|
61
61
|
.map(({ state, branch }) => {
|
|
62
62
|
if (state === 'MERGED') {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../../options/options';
|
|
2
|
-
import { SourceCommitWithTargetPullRequest } from './parseSourceCommit';
|
|
2
|
+
import { SourcePullRequestNode, SourceCommitWithTargetPullRequest } from './parseSourceCommit';
|
|
3
3
|
export declare type PullRequestState = 'OPEN' | 'CLOSED' | 'MERGED' | 'NOT_CREATED';
|
|
4
4
|
declare type CreatedPullRequest = {
|
|
5
5
|
url: string;
|
|
@@ -12,6 +12,7 @@ declare type CreatedPullRequest = {
|
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
14
|
declare type TargetBranchWithLabel = {
|
|
15
|
+
labelRegex: string;
|
|
15
16
|
branch: string;
|
|
16
17
|
label: string;
|
|
17
18
|
isSourceBranch: boolean;
|
|
@@ -19,7 +20,7 @@ declare type TargetBranchWithLabel = {
|
|
|
19
20
|
export declare type TargetPullRequest = (CreatedPullRequest & Partial<TargetBranchWithLabel>) | ((TargetBranchWithLabel & Partial<CreatedPullRequest>) & {
|
|
20
21
|
state: PullRequestState;
|
|
21
22
|
});
|
|
22
|
-
export declare function
|
|
23
|
+
export declare function getSourcePullRequest(sourceCommit: SourceCommitWithTargetPullRequest): SourcePullRequestNode | undefined;
|
|
23
24
|
export declare function getPullRequestStates({ sourceCommit, branchLabelMapping, }: {
|
|
24
25
|
sourceCommit: SourceCommitWithTargetPullRequest;
|
|
25
26
|
branchLabelMapping: ValidConfigOptions['branchLabelMapping'];
|
|
@@ -1,21 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPullRequestStates = exports.
|
|
3
|
+
exports.getPullRequestStates = exports.getSourcePullRequest = 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
|
-
const remoteConfig_1 = require("../remoteConfig");
|
|
8
7
|
function getSourcePullRequest(sourceCommit) {
|
|
9
8
|
return sourceCommit.associatedPullRequests.edges?.[0]?.node;
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
const sourcePullRequest = getSourcePullRequest(sourceCommit);
|
|
13
|
-
const remoteConfig = sourcePullRequest?.mergeCommit.remoteConfigHistory.edges?.[0]?.remoteConfig;
|
|
14
|
-
if (remoteConfig) {
|
|
15
|
-
return (0, remoteConfig_1.parseRemoteConfig)(remoteConfig)?.branchLabelMapping;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.getSourceCommitBranchLabelMapping = getSourceCommitBranchLabelMapping;
|
|
10
|
+
exports.getSourcePullRequest = getSourcePullRequest;
|
|
19
11
|
function mergeByKey(obj1, obj2, key) {
|
|
20
12
|
const merged = (0, lodash_1.merge)((0, lodash_1.keyBy)(obj1, key), (0, lodash_1.keyBy)(obj2, key));
|
|
21
13
|
const a = (0, lodash_1.values)(merged);
|
|
@@ -110,10 +102,11 @@ function getTargetBranchesFromLabels(sourcePullRequest, branchLabelMapping) {
|
|
|
110
102
|
const targetBranchesFromLabels = sourcePullRequest.labels.nodes
|
|
111
103
|
.map((label) => label.name)
|
|
112
104
|
.map((label) => {
|
|
113
|
-
const
|
|
114
|
-
if (
|
|
115
|
-
const
|
|
116
|
-
|
|
105
|
+
const res = getTargetBranchFromLabel({ branchLabelMapping, label });
|
|
106
|
+
if (res) {
|
|
107
|
+
const { labelRegex, targetBranch } = res;
|
|
108
|
+
const isSourceBranch = targetBranch === sourcePullRequest.baseRefName;
|
|
109
|
+
return { branch: targetBranch, label, labelRegex, isSourceBranch };
|
|
117
110
|
}
|
|
118
111
|
})
|
|
119
112
|
.filter(filterEmpty_1.filterNil);
|
|
@@ -121,17 +114,17 @@ function getTargetBranchesFromLabels(sourcePullRequest, branchLabelMapping) {
|
|
|
121
114
|
}
|
|
122
115
|
function getTargetBranchFromLabel({ branchLabelMapping, label, }) {
|
|
123
116
|
// only get first match
|
|
124
|
-
const result = Object.entries(branchLabelMapping).find(([
|
|
125
|
-
const regex = new RegExp(
|
|
117
|
+
const result = Object.entries(branchLabelMapping).find(([labelRegex]) => {
|
|
118
|
+
const regex = new RegExp(labelRegex);
|
|
126
119
|
const isMatch = label.match(regex) !== null;
|
|
127
120
|
return isMatch;
|
|
128
121
|
});
|
|
129
122
|
if (result) {
|
|
130
|
-
const [
|
|
131
|
-
const regex = new RegExp(
|
|
132
|
-
const targetBranch = label.replace(regex,
|
|
123
|
+
const [labelRegex, targetBranchReplaceValue] = result;
|
|
124
|
+
const regex = new RegExp(labelRegex);
|
|
125
|
+
const targetBranch = label.replace(regex, targetBranchReplaceValue);
|
|
133
126
|
if (targetBranch) {
|
|
134
|
-
return targetBranch;
|
|
127
|
+
return { targetBranch, labelRegex };
|
|
135
128
|
}
|
|
136
129
|
}
|
|
137
130
|
}
|