11'use strict' ; 
22
3- // (XXX) Do we need the protocol? 
4- const  CI_RE  =  / h t t p s : \/ \/ c i \. n o d e j s \. o r g ( \S + ) / mg; 
3+ const  CI_URL_RE  =  / \/ \/ c i \. n o d e j s \. o r g ( \S + ) / mg; 
54const  CI_DOMAIN  =  'ci.nodejs.org' ; 
65
76// constants 
87const  CITGM  =  'CITGM' ; 
9- const  FULL  =  'FULL' ; 
8+ const  PR  =  'PR' ; 
9+ const  COMMIT  =  'COMMIT' ; 
1010const  BENCHMARK  =  'BENCHMARK' ; 
1111const  LIBUV  =  'LIBUV' ; 
1212const  NOINTL  =  'NOINTL' ; 
1313const  V8  =  'V8' ; 
1414const  LINTER  =  'LINTER' ; 
15- const  LITE  =  'LITE' ; 
15+ const  LITE_PR  =  'LITE_PR' ; 
16+ const  LITE_COMMIT  =  'LITE_COMMIT' ; 
1617
1718const  CI_TYPES  =  new  Map ( [ 
18-   [ CITGM ,  {  name : 'CITGM' ,  re : / c i t g m / } ] , 
19-   [ FULL , 
20-     {  name : 'Full' , 
21-       re : / n o d e - t e s t - p u l l - r e q u e s t \/ | n o d e - t e s t - c o m m i t \/ / } ] , 
22-   [ BENCHMARK ,  {  name : 'Benchmark' ,  re : / b e n c h m a r k / } ] , 
23-   [ LIBUV ,  {  name : 'libuv' ,  re : / l i b u v / } ] , 
24-   [ NOINTL ,  {  name : 'No Intl' ,  re : / n o i n t l / } ] , 
25-   [ V8 ,  {  name : 'V8' ,  re : / n o d e - t e s t - c o m m i t - v 8 / } ] , 
26-   [ LINTER ,  {  name : 'Linter' ,  re : / n o d e - t e s t - l i n t e r / } ] , 
27-   [ LITE ,  {  name : 'Lite' ,  re : / n o d e - t e s t - .+ - l i t e / } ] 
19+   [ CITGM ,  {  name : 'CITGM' ,  jobName : 'citgm-smoker'  } ] , 
20+   [ PR ,  {  name : 'Full PR' ,  jobName : 'node-test-pull-request'  } ] , 
21+   [ COMMIT ,  {  name : 'Full Commit' ,  jobName : 'node-test-commit'  } ] , 
22+   [ BENCHMARK ,  { 
23+     name : 'Benchmark' , 
24+     jobName : 'benchmark-node-micro-benchmarks' 
25+   } ] , 
26+   [ LIBUV ,  {  name : 'libuv' ,  jobName : 'libuv-test-commit'  } ] , 
27+   [ NOINTL ,  {  name : 'No Intl' ,  jobName : 'node-test-commit-nointl'  } ] , 
28+   [ V8 ,  {  name : 'V8' ,  jobName : 'node-test-commit-v8-linux'  } ] , 
29+   [ LINTER ,  {  name : 'Linter' ,  jobName : 'node-test-linter'  } ] , 
30+   [ LITE_PR ,  { 
31+     name : 'Lite PR' , 
32+     jobName : 'node-test-pull-request-lite' 
33+   } ] , 
34+   [ LITE_COMMIT ,  { 
35+     name : 'Lite Commit' , 
36+     jobName : 'node-test-commit-lite' 
37+   } ] 
2838] ) ; 
2939
30- class  CIParser  { 
40+ function  parseJobFromURL ( url )  { 
41+   if  ( typeof  url  !==  'string' )  { 
42+     return  undefined ; 
43+   } 
44+ 
45+   for  ( let  [  type ,  info  ]  of  CI_TYPES )  { 
46+     const  re  =  new  RegExp ( `${ CI_DOMAIN } ${ info . jobName }  ) ; 
47+     const  match  =  url . match ( re ) ; 
48+     if  ( match )  { 
49+       return  { 
50+         link : url , 
51+         jobid : parseInt ( match [ 1 ] ) , 
52+         type : type 
53+       } ; 
54+     } 
55+   } 
56+ 
57+   return  undefined ; 
58+ } 
59+ 
60+ /** 
61+  * Parse links of CI Jobs posted in a GitHub thread 
62+  */ 
63+ class  JobParser  { 
3164  /** 
3265   * @param  {{bodyText: string, publishedAt: string}[] } thread 
3366   */ 
@@ -44,11 +77,15 @@ class CIParser {
4477    for  ( const  c  of  thread )  { 
4578      const  text  =  c . bodyText ; 
4679      if  ( ! text . includes ( CI_DOMAIN ) )  continue ; 
47-       const  cis  =  this . parseText ( text ) ; 
48-       for  ( const  ci  of  cis )  { 
49-         const  entry  =  result . get ( ci . type ) ; 
80+       const  jobs  =  this . parseText ( text ) ; 
81+       for  ( const  job  of  jobs )  { 
82+         const  entry  =  result . get ( job . type ) ; 
5083        if  ( ! entry  ||  entry . date  <  c . publishedAt )  { 
51-           result . set ( ci . type ,  { link : ci . link ,  date : c . publishedAt } ) ; 
84+           result . set ( job . type ,  { 
85+             link : job . link , 
86+             date : c . publishedAt , 
87+             jobid : job . jobid 
88+           } ) ; 
5289        } 
5390      } 
5491    } 
@@ -57,30 +94,31 @@ class CIParser {
5794
5895  /** 
5996   * @param  {string } text 
97+    * @returns  {{link: string, jobid: number, type: string} } 
6098   */ 
6199  parseText ( text )  { 
62-     const  m  =  text . match ( CI_RE ) ; 
63-     if  ( ! m )  { 
100+     const  links  =  text . match ( CI_URL_RE ) ; 
101+     if  ( ! links )  { 
64102      return  [ ] ; 
65103    } 
66104
67105    const  result  =  [ ] ; 
68-     for  ( const  link  of  m )  { 
69-       for  ( const  [ type ,  info ]  of  CI_TYPES )  { 
70-         if  ( info . re . test ( link ) )  { 
71-           result . push ( {  type,  link } ) ; 
72-           break ; 
73-         } 
106+     for  ( const  link  of  links )  { 
107+       const  parsed  =  parseJobFromURL ( `https:${ link }  ) ; 
108+       if  ( parsed )  { 
109+         result . push ( parsed ) ; 
74110      } 
75111    } 
76112
77113    return  result ; 
78114  } 
79115} 
80116
81- CIParser . TYPES  =  CI_TYPES ; 
82- CIParser . constants  =  { 
83-   CITGM ,  FULL ,  BENCHMARK ,  LIBUV ,  V8 ,  NOINTL ,  LINTER ,  LITE 
117+ module . exports  =  { 
118+   JobParser, 
119+   CI_TYPES , 
120+   constants : { 
121+     CITGM ,  PR ,  COMMIT ,  BENCHMARK ,  LIBUV ,  V8 ,  NOINTL , 
122+     LINTER ,  LITE_PR ,  LITE_COMMIT 
123+   } 
84124} ; 
85- 
86- module . exports  =  CIParser ; 
0 commit comments