Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/extract.js
Original file line number Diff line number Diff line change
@@ -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),
};
};
1 change: 0 additions & 1 deletion src/trektor.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ TrelloPowerUp.initialize({
{
title: "Trekking",
text: `#${tracking.task}`,
callback: trelloCallbacks.track,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

das hatte ich immer als feature empfunden, dass ich da auch auf den anderen button drücken kann.

hat das gründe? mir isses aber auch egal, nur aus interesse?

},
],
);
Expand Down
28 changes: 1 addition & 27 deletions src/trello.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TogglGateway, TogglService } from "./toggl.js";
import { extractTrackingData } from "./extract.js";

const withErrorMessage = async function (t, fnc) {
try {
Expand All @@ -9,33 +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 extractTrackingData = async function (t) {
const card = await t.card("name", "labels", "idShort", "shortLink");

const projectLabels = card.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.");
}
const project = projectLabels[0];

return {
project,
task: `${project}_${card.idShort}_${card.shortLink}`,
description: stripStoryPointsAndTaskToken(card.name),
};
};

const setTrackingData = async function (t, tracking) {
await t.set("card", "shared", "tracking", tracking);
};
Expand Down