Skip to content

Commit 53807c9

Browse files
authored
Merge pull request #16 from aboutsource/feature/8103-dauertasks
Feature/8103 dauertasks
2 parents 5c7febb + 4bf2358 commit 53807c9

File tree

2 files changed

+45
-27
lines changed

2 files changed

+45
-27
lines changed

src/extract.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const stripStoryPointsAndTaskToken = function (name) {
2+
return name
3+
.replace(/^(\s*\(\d+\))?\s*/, "") // story points, e.g. (3)
4+
.replace(/\s*#\w+\s*$/, ""); // task token, e.g. #orga_5417
5+
};
6+
7+
const extractProjectFromLabels = function (labels) {
8+
const projectLabels = labels
9+
.map((label) => label.name.match(/(?<=#)[a-z0-9]+$/)?.[0])
10+
.filter((prefix) => prefix !== undefined);
11+
if (projectLabels.length === 0) {
12+
throw new Error("Card has no valid project labels.");
13+
}
14+
if (projectLabels.length > 1) {
15+
throw new Error("Card has multiple project labels.");
16+
}
17+
return projectLabels[0];
18+
};
19+
20+
const extractTaskFromLabels = function (labels) {
21+
const tasks = labels
22+
.map((label) => label.name.match(/(?<=!)\w+$/)?.[0])
23+
.filter((prefix) => prefix !== undefined);
24+
if (tasks.length === 0) {
25+
return null;
26+
}
27+
if (tasks.length > 1) {
28+
throw new Error("Card has multiple tasks labels.");
29+
}
30+
return tasks[0];
31+
};
32+
33+
export const extractTrackingData = async function (t) {
34+
const card = await t.card("name", "labels", "idShort", "shortLink");
35+
const project = extractProjectFromLabels(card.labels);
36+
37+
return {
38+
project,
39+
task:
40+
extractTaskFromLabels(card.labels) ??
41+
`${project}_${card.idShort}_${card.shortLink}`,
42+
description: stripStoryPointsAndTaskToken(card.name),
43+
};
44+
};

src/trello.js

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { TogglGateway, TogglService } from "./toggl.js";
2+
import { extractTrackingData } from "./extract.js";
23

34
const withErrorMessage = async function (t, fnc) {
45
try {
@@ -9,33 +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 extractTrackingData = async function (t) {
19-
const card = await t.card("name", "labels", "idShort", "shortLink");
20-
21-
const projectLabels = card.labels
22-
.map((label) => label.name.match(/(?<=#)[a-z0-9]+$/)?.[0])
23-
.filter((prefix) => prefix !== undefined);
24-
if (projectLabels.length === 0) {
25-
throw new Error("Card has no valid project labels.");
26-
}
27-
if (projectLabels.length > 1) {
28-
throw new Error("Card has multiple project labels.");
29-
}
30-
const project = projectLabels[0];
31-
32-
return {
33-
project,
34-
task: `${project}_${card.idShort}_${card.shortLink}`,
35-
description: stripStoryPointsAndTaskToken(card.name),
36-
};
37-
};
38-
3913
const setTrackingData = async function (t, tracking) {
4014
await t.set("card", "shared", "tracking", tracking);
4115
};

0 commit comments

Comments
 (0)