11import { TogglGateway , TogglService } from "./toggl.js" ;
2+ import { extractTrackingData } from "./extract.js" ;
23
34const withErrorMessage = async function ( t , fnc ) {
45 try {
@@ -9,53 +10,6 @@ const withErrorMessage = async function (t, fnc) {
910 }
1011} ;
1112
12- const stripStoryPointsAndTaskToken = function ( name ) {
13- return name
14- . replace ( / ^ ( \s * \( \d + \) ) ? \s * / , "" ) // story points, e.g. (3)
15- . replace ( / \s * # \w + \s * $ / , "" ) ; // task token, e.g. #orga_5417
16- } ;
17-
18- const extractProjectFromLabels = function ( labels ) {
19- const projectLabels = labels
20- . map ( ( label ) => label . name . match ( / (?< = # ) [ a - z 0 - 9 ] + $ / ) ?. [ 0 ] )
21- . filter ( ( prefix ) => prefix !== undefined ) ;
22- if ( projectLabels . length === 0 ) {
23- throw new Error ( "Card has no valid project labels." ) ;
24- }
25- if ( projectLabels . length > 1 ) {
26- throw new Error ( "Card has multiple project labels." ) ;
27- }
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 } ` ;
51-
52- return {
53- project,
54- task,
55- description : stripStoryPointsAndTaskToken ( card . name ) ,
56- } ;
57- } ;
58-
5913const setTrackingData = async function ( t , tracking ) {
6014 await t . set ( "card" , "shared" , "tracking" , tracking ) ;
6115} ;
0 commit comments