@@ -10,8 +10,7 @@ import {BaseMatchConfig, MatchConfig} from './api/get-label-configs';
1010import { checkAllChangedFiles , checkAnyChangedFiles } from './changedFiles' ;
1111
1212import { checkAnyBranch , checkAllBranch } from './branch' ;
13-
14- type ClientType = ReturnType < typeof github . getOctokit > ;
13+ import { ClientType } from './api' ;
1514
1615// GitHub Issues cannot have more than 100 labels
1716const GITHUB_MAX_LABELS = 100 ;
@@ -39,13 +38,16 @@ async function labeler() {
3938 client ,
4039 configPath
4140 ) ;
42- const preexistingLabels = pullRequest . data . labels . map ( l => l . name ) ;
43- const allLabels : Set < string > = new Set < string > ( preexistingLabels ) ;
41+ const preexistingLabels : [ string , string ] [ ] = pullRequest . data . labels . map (
42+ ( l : { name : string ; color : string } ) => [ l . name , l . color ]
43+ ) ;
44+ const allLabels = new Map < string , string > ( ) ;
45+ preexistingLabels . forEach ( ( [ label , color ] ) => allLabels . set ( label , color ) ) ;
4446
4547 for ( const [ label , configs ] of labelConfigs . entries ( ) ) {
4648 core . debug ( `processing ${ label } ` ) ;
4749 if ( checkMatchConfigs ( pullRequest . changedFiles , configs , dot ) ) {
48- allLabels . add ( label ) ;
50+ allLabels . set ( label , configs [ 0 ] ?. color || '' ) ;
4951 } else if ( syncLabels ) {
5052 allLabels . delete ( label ) ;
5153 }
@@ -54,13 +56,16 @@ async function labeler() {
5456 const labelsToAdd = [ ...allLabels ] . slice ( 0 , GITHUB_MAX_LABELS ) ;
5557 const excessLabels = [ ...allLabels ] . slice ( GITHUB_MAX_LABELS ) ;
5658
57- let newLabels : string [ ] = [ ] ;
59+ let newLabels : [ string , string ] [ ] = [ ] ;
5860
5961 try {
6062 if ( ! isEqual ( labelsToAdd , preexistingLabels ) ) {
6163 await api . setLabels ( client , pullRequest . number , labelsToAdd ) ;
6264 newLabels = labelsToAdd . filter (
63- label => ! preexistingLabels . includes ( label )
65+ ( [ label ] ) =>
66+ ! preexistingLabels . some (
67+ existingsLabel => existingsLabel [ 0 ] === label
68+ )
6469 ) ;
6570 }
6671 } catch ( error : any ) {
@@ -83,14 +88,14 @@ async function labeler() {
8388 return ;
8489 }
8590
86- core . setOutput ( 'new-labels' , newLabels . join ( ',' ) ) ;
87- core . setOutput ( 'all-labels' , labelsToAdd . join ( ',' ) ) ;
91+ core . setOutput ( 'new-labels' , newLabels . map ( ( [ label ] ) => label ) . join ( ',' ) ) ;
92+ core . setOutput ( 'all-labels' , labelsToAdd . map ( ( [ label ] ) => label ) . join ( ',' ) ) ;
8893
8994 if ( excessLabels . length ) {
9095 core . warning (
91- `Maximum of ${ GITHUB_MAX_LABELS } labels allowed. Excess labels: ${ excessLabels . join (
92- ', '
93- ) } `,
96+ `Maximum of ${ GITHUB_MAX_LABELS } labels allowed. Excess labels: ${ excessLabels
97+ . map ( ( [ label ] ) => [ label ] )
98+ . join ( ', ' ) } `,
9499 { title : 'Label limit for a PR exceeded' }
95100 ) ;
96101 }
0 commit comments