11import * as core from "@actions/core" ;
22import levenshtein from 'js-levenshtein' ;
33
4- export interface IParameter {
4+ export interface IParameter extends IDefaultArea {
55 area : string ;
66 keywords : string [ ] ;
7+ }
8+
9+ export interface IDefaultArea {
710 labels : string [ ] ;
811 assignees : string [ ] ;
912}
@@ -12,6 +15,7 @@ export class Issue {
1215 private titleIssueWords ?: string [ ] ;
1316 private bodyIssueWords ?: string [ ] ;
1417 public parameters : IParameter [ ] ;
18+ public defaultArea : IDefaultArea ;
1519 private similarity : number ;
1620 private bodyValue : number ;
1721
@@ -32,6 +36,7 @@ export class Issue {
3236 this . bodyIssueWords = body . split ( / | \( | \) | \. / ) ;
3337 }
3438 this . parameters = JSON . parse ( core . getInput ( "parameters" , { required : true } ) ) ;
39+ this . defaultArea = JSON . parse ( core . getInput ( "default-area" , { required : true } ) ) ;
3540 this . similarity = + core . getInput ( "similarity" , { required : false } ) ;
3641 this . bodyValue = + core . getInput ( "body-value" , { required : false } ) ;
3742 }
@@ -63,28 +68,7 @@ export class Issue {
6368
6469 console . log ( "Area scores: " , ...potentialAreas ) ;
6570
66- let winningArea = '' ;
67- let winners : Map < string , number > = new Map ( ) ;
68- for ( let area of potentialAreas . entries ( ) ) {
69- if ( winners . size === 0 ) {
70- winners . set ( area [ 0 ] , area [ 1 ] ) ;
71- } else if ( area [ 1 ] > winners . values ( ) . next ( ) . value ) {
72- winners = new Map ( ) ;
73- winners . set ( area [ 0 ] , area [ 1 ] ) ;
74- } else if ( area [ 1 ] === winners . values ( ) . next ( ) . value ) {
75- winners . set ( area [ 0 ] , area [ 1 ] ) ;
76- }
77- }
78- // tiebreaker goes to the area with more *exact* keyword matches
79- if ( winners . size > 1 && this . similarity !== 0 ) {
80- this . similarity = 0 ;
81- winningArea = this . determineArea ( ) ;
82- } else if ( winners . size > 0 ) {
83- winningArea = winners . keys ( ) . next ( ) . value ;
84- }
85-
86- winningArea = winners . keys ( ) . next ( ) . value ;
87-
71+ const winningArea = this . decideWinner ( potentialAreas ) ;
8872 console . log ( "Winning area: " + winningArea ) ;
8973
9074 return winningArea ;
@@ -120,6 +104,29 @@ export class Issue {
120104 return potentialAreas ;
121105 }
122106
107+ private decideWinner ( potentialAreas : Map < string , number > ) : string {
108+ let winningArea = '' ;
109+ let winners : Map < string , number > = new Map ( ) ;
110+ for ( let area of potentialAreas . entries ( ) ) {
111+ if ( winners . size === 0 ) {
112+ winners . set ( area [ 0 ] , area [ 1 ] ) ;
113+ } else if ( area [ 1 ] > winners . values ( ) . next ( ) . value ) {
114+ winners = new Map ( ) ;
115+ winners . set ( area [ 0 ] , area [ 1 ] ) ;
116+ } else if ( area [ 1 ] === winners . values ( ) . next ( ) . value ) {
117+ winners . set ( area [ 0 ] , area [ 1 ] ) ;
118+ }
119+ }
120+ // tiebreaker goes to the area with more *exact* keyword matches
121+ if ( winners . size > 1 && this . similarity !== 0 ) {
122+ this . similarity = 0 ;
123+ winningArea = this . determineArea ( ) ;
124+ } else if ( winners . size > 0 ) {
125+ winningArea = winners . keys ( ) . next ( ) . value ;
126+ }
127+ return winningArea ;
128+ }
129+
123130 private isSimilar ( str1 : string , str2 : string ) : number {
124131 return ( ( ( str1 . length + str2 . length ) / 2 ) * this . similarity ) ;
125132 }
0 commit comments