@@ -10,8 +10,7 @@ import {BaseMatchConfig, MatchConfig} from './api/get-label-configs';
10
10
import { checkAllChangedFiles , checkAnyChangedFiles } from './changedFiles' ;
11
11
12
12
import { checkAnyBranch , checkAllBranch } from './branch' ;
13
-
14
- type ClientType = ReturnType < typeof github . getOctokit > ;
13
+ import { ClientType } from './api' ;
15
14
16
15
// GitHub Issues cannot have more than 100 labels
17
16
const GITHUB_MAX_LABELS = 100 ;
@@ -39,13 +38,16 @@ async function labeler() {
39
38
client ,
40
39
configPath
41
40
) ;
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 ) ) ;
44
46
45
47
for ( const [ label , configs ] of labelConfigs . entries ( ) ) {
46
48
core . debug ( `processing ${ label } ` ) ;
47
49
if ( checkMatchConfigs ( pullRequest . changedFiles , configs , dot ) ) {
48
- allLabels . add ( label ) ;
50
+ allLabels . set ( label , configs [ 0 ] ?. color || '' ) ;
49
51
} else if ( syncLabels ) {
50
52
allLabels . delete ( label ) ;
51
53
}
@@ -54,13 +56,16 @@ async function labeler() {
54
56
const labelsToAdd = [ ...allLabels ] . slice ( 0 , GITHUB_MAX_LABELS ) ;
55
57
const excessLabels = [ ...allLabels ] . slice ( GITHUB_MAX_LABELS ) ;
56
58
57
- let newLabels : string [ ] = [ ] ;
59
+ let newLabels : [ string , string ] [ ] = [ ] ;
58
60
59
61
try {
60
62
if ( ! isEqual ( labelsToAdd , preexistingLabels ) ) {
61
63
await api . setLabels ( client , pullRequest . number , labelsToAdd ) ;
62
64
newLabels = labelsToAdd . filter (
63
- label => ! preexistingLabels . includes ( label )
65
+ ( [ label ] ) =>
66
+ ! preexistingLabels . some (
67
+ existingsLabel => existingsLabel [ 0 ] === label
68
+ )
64
69
) ;
65
70
}
66
71
} catch ( error : any ) {
@@ -83,14 +88,14 @@ async function labeler() {
83
88
return ;
84
89
}
85
90
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 ( ',' ) ) ;
88
93
89
94
if ( excessLabels . length ) {
90
95
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 ( ', ' ) } `,
94
99
{ title : 'Label limit for a PR exceeded' }
95
100
) ;
96
101
}
0 commit comments