1- import type { Commit } from '../../entrypoint.api' ;
2- import { getTargetPRLabels } from './get-target-prlabels ' ;
1+ import type { Commit } from '../../../ entrypoint.api' ;
2+ import { getConfiguredTargetPRLabels } from './get-configured- target-pr-labels ' ;
33
44const commits : Commit [ ] = [
55 {
@@ -25,7 +25,6 @@ const commits: Commit[] = [
2525 } ,
2626 sourceBranch : 'master' ,
2727 targetPullRequestStates : [
28- // PR to 7.11 branch was created automatically using the label `backport-to-7.11`
2928 {
3029 url : 'https://github.com/elastic/kibana/pull/88289' ,
3130 number : 88289 ,
@@ -39,8 +38,6 @@ const commits: Commit[] = [
3938 message : 'Fix major bug (#88188) (#88289)' ,
4039 } ,
4140 } ,
42-
43- // PR to 7.x branch was created manually (not via labels) and does not contain branchLabelMappingKey
4441 {
4542 url : 'https://github.com/elastic/kibana/pull/88288' ,
4643 number : 88288 ,
@@ -55,10 +52,10 @@ const commits: Commit[] = [
5552 } ,
5653] ;
5754
58- describe ( 'getTargetPRLabels ' , ( ) => {
55+ describe ( 'getConfiguredTargetPRLabels ' , ( ) => {
5956 describe ( 'replaces template values' , ( ) => {
6057 it ( 'replaces {{targetBranch}}' , ( ) => {
61- const labels = getTargetPRLabels ( {
58+ const labels = getConfiguredTargetPRLabels ( {
6259 interactive : false ,
6360 commits,
6461 targetPRLabels : [ 'backported-to-{{targetBranch}}' ] ,
@@ -68,7 +65,7 @@ describe('getTargetPRLabels', () => {
6865 } ) ;
6966
7067 it ( 'replaces {{sourceBranch}}' , ( ) => {
71- const labels = getTargetPRLabels ( {
68+ const labels = getConfiguredTargetPRLabels ( {
7269 interactive : false ,
7370 commits,
7471 targetPRLabels : [ 'backported-from-{{sourceBranch}}' ] ,
@@ -78,101 +75,71 @@ describe('getTargetPRLabels', () => {
7875 } ) ;
7976 } ) ;
8077
81- describe ( 'when label is static' , ( ) => {
82- describe ( 'and when interactive=false ', ( ) => {
83- it ( 'adds static label for 7.11' , ( ) => {
84- const labels = getTargetPRLabels ( {
78+ describe ( 'static labels ' , ( ) => {
79+ it ( 'keeps static labels regardless of interactivity ', ( ) => {
80+ expect (
81+ getConfiguredTargetPRLabels ( {
8582 interactive : false ,
8683 commits,
8784 targetPRLabels : [ 'some-static-label' ] ,
8885 targetBranch : '7.11' ,
89- } ) ;
90- expect ( labels ) . toEqual ( [ 'some-static-label' ] ) ;
91- } ) ;
92-
93- it ( 'adds static label for 7.x' , ( ) => {
94- const labels = getTargetPRLabels ( {
95- interactive : false ,
96- commits,
97- targetPRLabels : [ 'some-static-label' ] ,
98- targetBranch : '7.x' ,
99- } ) ;
100- expect ( labels ) . toEqual ( [ 'some-static-label' ] ) ;
101- } ) ;
102- } ) ;
86+ } ) ,
87+ ) . toEqual ( [ 'some-static-label' ] ) ;
10388
104- describe ( 'and when interactive=true' , ( ) => {
105- it ( 'adds static label for 7.x' , ( ) => {
106- const labels = getTargetPRLabels ( {
89+ expect (
90+ getConfiguredTargetPRLabels ( {
10791 interactive : true ,
10892 commits,
109- targetPRLabels : [ 'backport' ] ,
110- targetBranch : '7.x' ,
111- } ) ;
112- expect ( labels ) . toEqual ( [ 'backport' ] ) ;
113- } ) ;
93+ targetPRLabels : [ 'some-static-label' ] ,
94+ targetBranch : '7.11' ,
95+ } ) ,
96+ ) . toEqual ( [ 'some-static-label' ] ) ;
11497 } ) ;
11598 } ) ;
11699
117- describe ( 'when label is dynamic' , ( ) => {
118- describe ( 'and when interactive=false ', ( ) => {
119- it ( 'adds dynamic label for 7.11' , ( ) => {
120- const labels = getTargetPRLabels ( {
100+ describe ( 'dynamic labels ' , ( ) => {
101+ it ( 'applies dynamic label when branch mapping is available ', ( ) => {
102+ expect (
103+ getConfiguredTargetPRLabels ( {
121104 interactive : false ,
122105 commits,
123106 targetPRLabels : [ 'backport-$1' ] ,
124107 targetBranch : '7.11' ,
125- } ) ;
126- expect ( labels ) . toEqual ( [ 'backport-7.11' ] ) ;
127- } ) ;
108+ } ) ,
109+ ) . toEqual ( [ 'backport-7.11' ] ) ;
128110 } ) ;
129111
130- describe ( 'when interactive=true' , ( ) => {
131- it ( 'adds dynamic label for 7.11' , ( ) => {
132- const labels = getTargetPRLabels ( {
133- interactive : false ,
134- commits,
135- targetPRLabels : [ 'backport-$1' ] ,
136- targetBranch : '7.11' ,
137- } ) ;
138- expect ( labels ) . toEqual ( [ 'backport-7.11' ] ) ;
139- } ) ;
140-
141- it ( 'does not add dynamic label for 7.x' , ( ) => {
142- const labels = getTargetPRLabels ( {
112+ it ( 'drops dynamic label when interactive and mapping is missing' , ( ) => {
113+ expect (
114+ getConfiguredTargetPRLabels ( {
143115 interactive : true ,
144116 commits,
145117 targetPRLabels : [ 'backport-$1' ] ,
146118 targetBranch : '7.x' ,
147- } ) ;
148- expect ( labels ) . toEqual ( [ ] ) ;
149- } ) ;
119+ } ) ,
120+ ) . toEqual ( [ ] ) ;
150121 } ) ;
151122 } ) ;
152123
153124 describe ( 'multiple dynamic labels' , ( ) => {
154- describe ( 'interactive=false ', ( ) => {
155- it ( 'adds dynamic and static labels for 7.11' , ( ) => {
156- const labels = getTargetPRLabels ( {
125+ it ( 'keeps resolved labels and drops unresolved ones based on interactivity ', ( ) => {
126+ expect (
127+ getConfiguredTargetPRLabels ( {
157128 interactive : false ,
158129 commits,
159130 targetPRLabels : [ 'backport-$1' , '$1' , 'my-static-label' ] ,
160131 targetBranch : '7.11' ,
161- } ) ;
162- expect ( labels ) . toEqual ( [ 'backport-7.11' , '7.11' , 'my-static-label' ] ) ;
163- } ) ;
164- } ) ;
132+ } ) ,
133+ ) . toEqual ( [ 'backport-7.11' , '7.11' , 'my-static-label' ] ) ;
165134
166- describe ( 'interactive=true' , ( ) => {
167- it ( 'only add the static labels for 7.x' , ( ) => {
168- const labels = getTargetPRLabels ( {
135+ expect (
136+ getConfiguredTargetPRLabels ( {
169137 interactive : true ,
170138 commits,
171139 targetPRLabels : [ 'backport-$1' , '$1' , 'my-static-label' ] ,
172140 targetBranch : '7.x' ,
173- } ) ;
174- expect ( labels ) . toEqual ( [ 'my-static-label' ] ) ;
175- } ) ;
141+ } ) ,
142+ ) . toEqual ( [ 'my-static-label' ] ) ;
176143 } ) ;
177144 } ) ;
178145} ) ;
0 commit comments