@@ -15,10 +15,8 @@ const stripStoryPointsAndTaskToken = function (name) {
1515 . replace ( / \s * # \w + \s * $ / , "" ) ; // task token, e.g. #orga_5417
1616} ;
1717
18- const extractTrackingData = async function ( t ) {
19- const card = await t . card ( "name" , "labels" , "idShort" , "shortLink" ) ;
20-
21- const projectLabels = card . labels
18+ const extractProjectFromLabels = function ( labels ) {
19+ const projectLabels = labels
2220 . map ( ( label ) => label . name . match ( / (?< = # ) [ a - z 0 - 9 ] + $ / ) ?. [ 0 ] )
2321 . filter ( ( prefix ) => prefix !== undefined ) ;
2422 if ( projectLabels . length === 0 ) {
@@ -27,11 +25,33 @@ const extractTrackingData = async function (t) {
2725 if ( projectLabels . length > 1 ) {
2826 throw new Error ( "Card has multiple project labels." ) ;
2927 }
30- const project = projectLabels [ 0 ] ;
28+ return projectLabels [ 0 ] ;
29+ } ;
30+
31+ const extractTaskFromLabels = function ( labels ) {
32+ const tasks = labels
33+ . map ( ( label ) => label . name . match ( / (?< = ! ) \w + $ / ) ?. [ 0 ] )
34+ . filter ( ( prefix ) => prefix !== undefined ) ;
35+ if ( tasks . length === 0 ) {
36+ return null ;
37+ }
38+ if ( tasks . length > 1 ) {
39+ throw new Error ( "Card has multiple tasks labels." ) ;
40+ }
41+ return tasks [ 0 ] ;
42+ } ;
43+
44+ const extractTrackingData = async function ( t ) {
45+ const card = await t . card ( "name" , "labels" , "idShort" , "shortLink" ) ;
46+
47+ const project = extractProjectFromLabels ( card . labels ) ;
48+ const task =
49+ extractTaskFromLabels ( card . labels ) ??
50+ `${ project } _${ card . idShort } _${ card . shortLink } ` ;
3151
3252 return {
3353 project,
34- task : ` ${ project } _ ${ card . idShort } _ ${ card . shortLink } ` ,
54+ task,
3555 description : stripStoryPointsAndTaskToken ( card . name ) ,
3656 } ;
3757} ;
0 commit comments