@@ -12,7 +12,7 @@ async function assignPrCreator(octokit: any, pullRequest: any): Promise<void> {
12
12
console . log ( 'Creator successfully assigned' ) ;
13
13
}
14
14
15
- async function fillCurrentMilestone ( octokit : any , pullRequest : any ) : Promise < void > {
15
+ async function fillCurrentMilestone ( octokit : any , pullRequest : any , teamName : string ) : Promise < void > {
16
16
// Assign PR to right sprint milestone
17
17
const { data : milestones } = await octokit . request ( 'GET /repos/{owner}/{repo}/milestones' , {
18
18
owner : github . context . repo . owner ,
@@ -25,13 +25,27 @@ async function fillCurrentMilestone(octokit: any, pullRequest: any): Promise<voi
25
25
}
26
26
27
27
const now = new Date ( ) ;
28
+ // All open milestones
28
29
// @ts -ignore
29
- const openMilestone = milestones . find ( ( milestone ) => {
30
+ const openMilestones = milestones . filter ( ( milestone ) => {
30
31
return milestone . state === 'open'
31
32
&& milestone . due_on && new Date ( milestone . due_on ) >= now ;
32
33
} ) ;
33
34
34
- if ( ! openMilestone ) {
35
+ // Find milestone for the team, if team name was provided
36
+ let foundMilestone ;
37
+ if ( teamName ) {
38
+ const teamNameRegExp = new RegExp ( teamName , 'i' ) ;
39
+ // @ts -ignore
40
+ foundMilestone = openMilestones . find ( ( { description, title } ) => {
41
+ return title . match ( teamNameRegExp )
42
+ || description . match ( teamNameRegExp ) ;
43
+ } ) ;
44
+ } else if ( openMilestones . length ) {
45
+ ( [ foundMilestone ] = openMilestones ) ;
46
+ }
47
+
48
+ if ( ! foundMilestone ) {
35
49
core . setFailed ( 'Cannot find current sprint milestone!' ) ;
36
50
return ;
37
51
}
@@ -40,15 +54,16 @@ async function fillCurrentMilestone(octokit: any, pullRequest: any): Promise<voi
40
54
owner : github . context . repo . owner ,
41
55
repo : github . context . repo . repo ,
42
56
issue_number : pullRequest . number ,
43
- milestone : openMilestone . number ,
57
+ milestone : foundMilestone . number ,
44
58
} ) ;
45
- console . log ( `Milestone successfully filled with ${ openMilestone . title } ` ) ;
59
+ console . log ( `Milestone successfully filled with ${ foundMilestone . title } ` ) ;
46
60
}
47
61
48
62
async function run ( ) : Promise < void > {
49
63
try {
50
64
const repoToken = core . getInput ( 'repo-token' ) ;
51
65
const teamMembers = core . getInput ( 'team-members' ) ;
66
+ const teamName = core . getInput ( 'team-members' ) ;
52
67
const octokit = github . getOctokit ( repoToken ) ;
53
68
54
69
const teamMemberList = teamMembers ? teamMembers . split ( ',' ) . map ( ( member : string ) => member . trim ( ) ) : [ ] ;
@@ -67,7 +82,7 @@ async function run(): Promise<void> {
67
82
// Assign PR to creator of PR
68
83
if ( ! isCreatorAssign ) await assignPrCreator ( octokit , pullRequest ) ;
69
84
// Fill milestone if there is any yet.
70
- if ( ! pullRequest . milestone ) await fillCurrentMilestone ( octokit , pullRequest ) ;
85
+ if ( ! pullRequest . milestone ) await fillCurrentMilestone ( octokit , pullRequest , teamName ) ;
71
86
} catch ( error ) {
72
87
core . setFailed ( error . message ) ;
73
88
}
0 commit comments