From d69d11a1736076f4cae33da7eaa7ba603625c0fc Mon Sep 17 00:00:00 2001 From: Stefan Walluhn Date: Fri, 28 Mar 2025 19:01:36 +0100 Subject: [PATCH 1/4] allow per label task overrides --- src/trello.js | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/trello.js b/src/trello.js index 5732538..84f0119 100644 --- a/src/trello.js +++ b/src/trello.js @@ -15,10 +15,8 @@ const stripStoryPointsAndTaskToken = function (name) { .replace(/\s*#\w+\s*$/, ""); // task token, e.g. #orga_5417 }; -const extractTrackingData = async function (t) { - const card = await t.card("name", "labels", "idShort", "shortLink"); - - const projectLabels = card.labels +const extractProjectFromLabels = function (labels) { + const projectLabels = labels .map((label) => label.name.match(/(?<=#)[a-z0-9]+$/)?.[0]) .filter((prefix) => prefix !== undefined); if (projectLabels.length === 0) { @@ -27,11 +25,33 @@ const extractTrackingData = async function (t) { if (projectLabels.length > 1) { throw new Error("Card has multiple project labels."); } - const project = projectLabels[0]; + return projectLabels[0]; +}; + +const extractTaskFromLabels = function (labels) { + const tasks = labels + .map((label) => label.name.match(/(?<=!)\w+$/)?.[0]) + .filter((prefix) => prefix !== undefined); + if (tasks.length === 0) { + return null; + } + if (tasks.length > 1) { + throw new Error("Card has multiple tasks labels."); + } + return tasks[0]; +}; + +const extractTrackingData = async function (t) { + const card = await t.card("name", "labels", "idShort", "shortLink"); + + const project = extractProjectFromLabels(card.labels); + const task = + extractTaskFromLabels(card.labels) ?? + `${project}_${card.idShort}_${card.shortLink}`; return { project, - task: `${project}_${card.idShort}_${card.shortLink}`, + task, description: stripStoryPointsAndTaskToken(card.name), }; }; From 6aedf36cd9b6fd91cff6ff8108456ca9ba72d561 Mon Sep 17 00:00:00 2001 From: Stefan Walluhn Date: Fri, 28 Mar 2025 19:37:47 +0100 Subject: [PATCH 2/4] only show tracking to allow copy & paste --- src/trektor.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/trektor.js b/src/trektor.js index 8a60c97..b6ec31b 100644 --- a/src/trektor.js +++ b/src/trektor.js @@ -27,7 +27,6 @@ TrelloPowerUp.initialize({ { title: "Trekking", text: `#${tracking.task}`, - callback: trelloCallbacks.track, }, ], ); From ffdf7e0886394a24ee5dc7b0f973ed1faad8d692 Mon Sep 17 00:00:00 2001 From: Stefan Walluhn Date: Fri, 28 Mar 2025 19:38:01 +0100 Subject: [PATCH 3/4] refactoring --- src/extract.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/trello.js | 48 +----------------------------------------------- 2 files changed, 45 insertions(+), 47 deletions(-) create mode 100644 src/extract.js diff --git a/src/extract.js b/src/extract.js new file mode 100644 index 0000000..f4602ba --- /dev/null +++ b/src/extract.js @@ -0,0 +1,44 @@ +const stripStoryPointsAndTaskToken = function (name) { + return name + .replace(/^(\s*\(\d+\))?\s*/, "") // story points, e.g. (3) + .replace(/\s*#\w+\s*$/, ""); // task token, e.g. #orga_5417 +}; + +const extractProjectFromLabels = function (labels) { + const projectLabels = labels + .map((label) => label.name.match(/(?<=#)[a-z0-9]+$/)?.[0]) + .filter((prefix) => prefix !== undefined); + if (projectLabels.length === 0) { + throw new Error("Card has no valid project labels."); + } + if (projectLabels.length > 1) { + throw new Error("Card has multiple project labels."); + } + return projectLabels[0]; +}; + +const extractTaskFromLabels = function (labels) { + const tasks = labels + .map((label) => label.name.match(/(?<=!)\w+$/)?.[0]) + .filter((prefix) => prefix !== undefined); + if (tasks.length === 0) { + return null; + } + if (tasks.length > 1) { + throw new Error("Card has multiple tasks labels."); + } + return tasks[0]; +}; + +export const extractTrackingData = async function (t) { + const card = await t.card("name", "labels", "idShort", "shortLink"); + const project = extractProjectFromLabels(card.labels); + + return { + project, + task: + extractTaskFromLabels(card.labels) ?? + `${project}_${card.idShort}_${card.shortLink}`, + description: stripStoryPointsAndTaskToken(card.name), + }; +}; diff --git a/src/trello.js b/src/trello.js index 84f0119..b7a5878 100644 --- a/src/trello.js +++ b/src/trello.js @@ -1,4 +1,5 @@ import { TogglGateway, TogglService } from "./toggl.js"; +import { extractTrackingData } from "./extract.js"; const withErrorMessage = async function (t, fnc) { try { @@ -9,53 +10,6 @@ const withErrorMessage = async function (t, fnc) { } }; -const stripStoryPointsAndTaskToken = function (name) { - return name - .replace(/^(\s*\(\d+\))?\s*/, "") // story points, e.g. (3) - .replace(/\s*#\w+\s*$/, ""); // task token, e.g. #orga_5417 -}; - -const extractProjectFromLabels = function (labels) { - const projectLabels = labels - .map((label) => label.name.match(/(?<=#)[a-z0-9]+$/)?.[0]) - .filter((prefix) => prefix !== undefined); - if (projectLabels.length === 0) { - throw new Error("Card has no valid project labels."); - } - if (projectLabels.length > 1) { - throw new Error("Card has multiple project labels."); - } - return projectLabels[0]; -}; - -const extractTaskFromLabels = function (labels) { - const tasks = labels - .map((label) => label.name.match(/(?<=!)\w+$/)?.[0]) - .filter((prefix) => prefix !== undefined); - if (tasks.length === 0) { - return null; - } - if (tasks.length > 1) { - throw new Error("Card has multiple tasks labels."); - } - return tasks[0]; -}; - -const extractTrackingData = async function (t) { - const card = await t.card("name", "labels", "idShort", "shortLink"); - - const project = extractProjectFromLabels(card.labels); - const task = - extractTaskFromLabels(card.labels) ?? - `${project}_${card.idShort}_${card.shortLink}`; - - return { - project, - task, - description: stripStoryPointsAndTaskToken(card.name), - }; -}; - const setTrackingData = async function (t, tracking) { await t.set("card", "shared", "tracking", tracking); }; From 4bf235855936db461737d488a0a913355aac2629 Mon Sep 17 00:00:00 2001 From: Stefan Walluhn Date: Fri, 4 Apr 2025 12:38:09 +0200 Subject: [PATCH 4/4] re-add callback on detail badges, since they are in use by devs --- src/trektor.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/trektor.js b/src/trektor.js index b6ec31b..8a60c97 100644 --- a/src/trektor.js +++ b/src/trektor.js @@ -27,6 +27,7 @@ TrelloPowerUp.initialize({ { title: "Trekking", text: `#${tracking.task}`, + callback: trelloCallbacks.track, }, ], );