⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
refactor(api): trim gitlab plugin comments
zaralX1bf20d55174f
diff --git a/apps/api/src/gitlab-integration/controllers/import-gitlab-issues.ts b/apps/api/src/gitlab-integration/controllers/import-gitlab-issues.tsindex 89b39e5d6..a04341dd6 100644--- a/apps/api/src/gitlab-integration/controllers/import-gitlab-issues.ts+++ b/apps/api/src/gitlab-integration/controllers/import-gitlab-issues.ts@@ -105,8 +105,7 @@ export async function importGitlabIssues(}for (const issue of allIssues) {- // Confidential issues stay out of the workspace, the same as they do when- // one arrives through the webhook.+ // Confidential issues are skipped, same as in the webhook.if (issue.confidential) {skipped++;continue;@@ -207,9 +206,6 @@ async function importSingleIssue(return "updated";}- // The project's own counter is the allocator every other task creation path- // uses, so deriving a number from max(number) here would hand the next- // webhook a number that is already taken.const createdTask = await db.transaction(async (tx) => {const number = await claimTaskNumber(projectId, tx);@@ -328,8 +324,7 @@ async function importNotesForTask(if (notes.length === 0) break;for (const note of notes) {- // GitLab records label, milestone and state changes as system notes, and- // an internal note is visible there only to project members.+ // Skip system notes (label/state changes) and internal notes.if (note.system || note.internal) {continue;}@@ -345,8 +340,7 @@ async function importNotesForTask(externalUserName: username || "Unknown",externalUserAvatar: note.author?.avatar_url ?? null,externalSource: "gitlab",- // The notes API returns no URL for a note, and the anchor on the- // issue page is how GitLab itself links to one.+ // The notes API has no URL, so link to the anchor on the issue page.externalUrl: `${issue.web_url}#note_${note.id}`,eventData: {externalCommentId: note.id,diff --git a/apps/api/src/gitlab-integration/controllers/verify-gitlab-access.ts b/apps/api/src/gitlab-integration/controllers/verify-gitlab-access.tsindex 26e521283..f162f52da 100644--- a/apps/api/src/gitlab-integration/controllers/verify-gitlab-access.ts+++ b/apps/api/src/gitlab-integration/controllers/verify-gitlab-access.ts@@ -8,8 +8,7 @@ import {verifyGitlabToken,} from "../../plugins/gitlab/utils/gitlab-api";-// Managing issue labels needs Developer. Reporter can open an issue but cannot-// create the priority and status labels Kaneo relies on.+// Developer is the lowest role that can create the priority/status labels.const REQUIRED_ACCESS_LEVEL = 30;function highestAccessLevel(project: GitlabProject): number {@@ -52,8 +51,7 @@ async function verifyGitlabAccess({try {await verifyGitlabToken(normalized, accessToken, tokenType);} catch (error) {- // A 404 from /user means the URL does not serve the GitLab API, not that- // a project is missing.+ // 404 from /user: the URL is not a GitLab instance.if (error instanceof GitlabApiError && error.status === 404) {return failure("The URL does not point to a GitLab instance.",@@ -71,9 +69,7 @@ async function verifyGitlabAccess({const project = await client.getProject(projectPath);- // A group or instance token carries no per-project access level, so a- // missing level is not proof of missing rights -- the project answering at- // all already means the token can read it.+ // Group and instance tokens have no project access level.const accessLevel = highestAccessLevel(project);const hasRequiredPermissions =accessLevel === 0 || accessLevel >= REQUIRED_ACCESS_LEVEL;diff --git a/apps/api/src/gitlab-integration/response.ts b/apps/api/src/gitlab-integration/response.tsindex 05c4579e5..2f8b047a0 100644--- a/apps/api/src/gitlab-integration/response.ts+++ b/apps/api/src/gitlab-integration/response.ts@@ -1,7 +1,6 @@import { responseTimestamp, z } from "../openapi";-// Credentials are only ever returned masked; the webhook secret goes only to-// callers holding workspace:manage_settings.+// Tokens are masked; the webhook secret needs manage_settings.export const gitlabIntegrationSchema = z.object({id: z.string(),diff --git a/apps/api/src/plugins/gitlab/config.ts b/apps/api/src/plugins/gitlab/config.tsindex bf46bfb3f..926c3dd73 100644--- a/apps/api/src/plugins/gitlab/config.ts+++ b/apps/api/src/plugins/gitlab/config.ts@@ -6,11 +6,7 @@ export { branchPatterns };export const gitlabConfigSchema = v.object({baseUrl: v.pipe(v.string(), v.url()),accessToken: v.pipe(v.string(), v.trim(), v.nonEmpty()),- // GitLab accepts personal, project and group tokens in PRIVATE-TOKEN, and- // OAuth2 tokens in Authorization: Bearer. The user picks which they pasted.tokenType: v.optional(v.picklist(["private", "bearer"])),- // Nested groups make a single path the only workable identifier, so unlike- // the Gitea config there is no owner/name split.projectPath: v.pipe(v.string(), v.trim(), v.nonEmpty()),webhookSecret: v.optional(v.string()),branchPattern: v.optional(v.string()),@@ -69,8 +65,7 @@ export function normalizeGitlabBaseUrl(url: string): string {throw new Error("GitLab base URL must use http or https");}- // A query or fragment would swallow the appended /api/v4/... path and let a- // caller aim the request at an arbitrary path on the target host.+ // A query or fragment would break the /api/v4 path appended later.if (parsed.search || parsed.hash || parsed.username || parsed.password) {throw new Error("GitLab base URL must not contain a query, fragment, or credentials",@@ -80,9 +75,7 @@ export function normalizeGitlabBaseUrl(url: string): string {return `${parsed.origin}${parsed.pathname.replace(/\/+$/, "")}`;}-// Paths arrive from a form and from webhook payloads, and both reach the API-// as a single encoded path segment, so a leading slash or a stray ".." must not-// survive into the request.+// Reject a leading slash or ".." before the path goes into the URL.export function normalizeProjectPath(path: string): string {const segments = path.trim()diff --git a/apps/api/src/plugins/gitlab/events/task-comment-created.ts b/apps/api/src/plugins/gitlab/events/task-comment-created.tsindex 3d52cdab7..44132406f 100644--- a/apps/api/src/plugins/gitlab/events/task-comment-created.ts+++ b/apps/api/src/plugins/gitlab/events/task-comment-created.ts@@ -55,8 +55,6 @@ export async function handleTaskCommentCreated(event.comment,);- // The note webhook reports this note as authored by the token's own user, so- // recording its id is what stops it coming back as a duplicate comment.const metadata = parseLinkSyncMetadata(existingLink.metadata, {externalLinkId: existingLink.id,field: "syncedNoteIds",diff --git a/apps/api/src/plugins/gitlab/events/task-description-changed.ts b/apps/api/src/plugins/gitlab/events/task-description-changed.tsindex b7b49b267..b267d8d8e 100644--- a/apps/api/src/plugins/gitlab/events/task-description-changed.ts+++ b/apps/api/src/plugins/gitlab/events/task-description-changed.ts@@ -53,8 +53,6 @@ export async function handleTaskDescriptionChanged(return;}- // The issue body carries a task footer, and that whole string is what comes- // back through the webhook, so it is the value the echo check compares.const issueDescription = formatIssueBody(newDescription, event.taskId);await createGitlabClient(config).updateIssue(config.projectPath, issueIid, {diff --git a/apps/api/src/plugins/gitlab/utils/gitlab-api.ts b/apps/api/src/plugins/gitlab/utils/gitlab-api.tsindex 52c6c7d0f..cf33e9282 100644--- a/apps/api/src/plugins/gitlab/utils/gitlab-api.ts+++ b/apps/api/src/plugins/gitlab/utils/gitlab-api.ts@@ -130,8 +130,7 @@ export async function gitlabFetch<T>(const res = await fetch(url, {...init,signal: controller.signal,- // Following redirects would let a public host bounce the request to an- // internal address after the destination check has already passed.+ // A redirect could lead past the destination check to an internal host.redirect: "manual",headers: {...authHeaders(token, tokenType),diff --git a/apps/api/src/plugins/gitlab/utils/issue-description.ts b/apps/api/src/plugins/gitlab/utils/issue-description.tsindex 65f125814..060298a85 100644--- a/apps/api/src/plugins/gitlab/utils/issue-description.ts+++ b/apps/api/src/plugins/gitlab/utils/issue-description.ts@@ -1,6 +1,4 @@-// formatIssueBody appends a `Task: <id>` footer to every description Kaneo-// writes to GitLab. Reading that body back into the task unchanged would keep-// the footer there, and the next edit in Kaneo would append a second one.+// Strip the `Task:` footer Kaneo appends, or every sync adds another one.const FOOTER = /(?:\r?\n)*-{3}\r?\n<sub>Task: [^<\r\n]+<\/sub>\s*$/;const FOOTER_ONLY = /^\s*<sub>Task: [^<\r\n]+<\/sub>\s*$/;diff --git a/apps/api/src/plugins/gitlab/utils/labels.ts b/apps/api/src/plugins/gitlab/utils/labels.tsindex 7f232bdf9..c8b18cf77 100644--- a/apps/api/src/plugins/gitlab/utils/labels.ts+++ b/apps/api/src/plugins/gitlab/utils/labels.ts@@ -18,9 +18,7 @@ function getLabelColor(labelName: string): string {return labelColors[labelName] || "6B7280";}-// GitLab creates a missing project label on its own when an issue is labelled,-// but picks the colour itself. Creating them up front is what keeps the-// priority and status labels recognisable.+// Created up front so GitLab does not pick its own colours for them.export async function ensureLabelsExistGitlab(config: GitlabConfig,labels: string[],@@ -52,10 +50,7 @@ export async function ensureLabelsExistGitlab(}}-/**- * Adds and removes issue labels in one request, so an issue never briefly- * carries two `status:` labels for a racing read to pick up.- */+/** Adds and removes labels in one request, so two status labels never coexist. */export async function updateIssueLabelsGitlab(config: GitlabConfig,issueIid: number,diff --git a/apps/api/src/plugins/gitlab/utils/link-sync.ts b/apps/api/src/plugins/gitlab/utils/link-sync.tsindex 743336b09..59b65786d 100644--- a/apps/api/src/plugins/gitlab/utils/link-sync.ts+++ b/apps/api/src/plugins/gitlab/utils/link-sync.ts@@ -12,19 +12,10 @@ export type LinkMetadata = {[key: string]: unknown;};-/**- * How long an identical value still counts as the other side's echo. Generous- * enough for a slow webhook delivery, short enough that setting a title back to- * an older value tomorrow is treated as the real edit it is.- */+/** How long an identical value still counts as an echo. */export const TEXT_ECHO_WINDOW_MS = 60_000;-/**- * A value one side writes comes straight back from the other as a webhook or an- * event. The value itself is what identifies the echo -- suppressing anything- * that merely arrives soon after a write would drop a real edit made right on- * top of it -- and the window bounds how long that identity holds.- */+/** An echo is the value the other side last wrote, within the window. */export function isEchoOf(state: LinkSyncState | undefined,source: string,diff --git a/apps/api/src/plugins/gitlab/utils/payload.ts b/apps/api/src/plugins/gitlab/utils/payload.tsindex 02fbb9872..818d531a2 100644--- a/apps/api/src/plugins/gitlab/utils/payload.ts+++ b/apps/api/src/plugins/gitlab/utils/payload.ts@@ -1,8 +1,4 @@-/**- * Shapes shared by every GitLab webhook payload. Unlike the REST API, which- * returns issue labels as plain names, webhooks send label objects keyed by- * `title`.- */+/** Webhooks send labels as objects keyed by `title`, unlike the REST API. */export type GitlabWebhookProject = {name: string;web_url: string;diff --git a/apps/api/src/plugins/gitlab/utils/sync-label-to-gitlab.ts b/apps/api/src/plugins/gitlab/utils/sync-label-to-gitlab.tsindex 55d685e1f..8d072c4a6 100644--- a/apps/api/src/plugins/gitlab/utils/sync-label-to-gitlab.ts+++ b/apps/api/src/plugins/gitlab/utils/sync-label-to-gitlab.ts@@ -52,9 +52,7 @@ async function getGitlabIssueContext(taskId: string) {},});- // Label changes reach here straight from the label controllers rather than- // through the plugin registry, so the registry's active-integration filter- // does not apply and a disabled integration has to be skipped here.+ // Called from label controllers, bypassing the registry's isActive filter.const externalLink = externalLinks.find((link) =>link.resourceType === "issue" &&diff --git a/apps/api/src/plugins/gitlab/utils/synced-notes.ts b/apps/api/src/plugins/gitlab/utils/synced-notes.tsindex ba472ef79..ccf455fdd 100644--- a/apps/api/src/plugins/gitlab/utils/synced-notes.ts+++ b/apps/api/src/plugins/gitlab/utils/synced-notes.ts@@ -1,8 +1,4 @@-// Ids of the notes Kaneo posted to GitLab itself. The note webhook reports them-// as authored by the token's user, so there is nothing in the payload that marks-// them as ours -- the recorded id is what keeps them from coming back as a-// duplicate comment. Only the most recent ids matter, since an older note will-// have been delivered long ago.+// Kaneo's own notes come back authored by the token user; match them by id.const MAX_TRACKED_NOTE_IDS = 50;export function syncedNoteIds(metadata: string | null | undefined): number[] {diff --git a/apps/api/src/plugins/gitlab/utils/verify-token.ts b/apps/api/src/plugins/gitlab/utils/verify-token.tsindex b31b9bfd2..f4383deac 100644--- a/apps/api/src/plugins/gitlab/utils/verify-token.ts+++ b/apps/api/src/plugins/gitlab/utils/verify-token.ts@@ -1,10 +1,6 @@import { timingSafeEqual } from "node:crypto";-// GitLab echoes the hook's secret token back in a plain header rather than-// signing the body the way Gitea does, so delivery is authenticated by-// comparing that token. GitLab 19.0 added a Standard Webhooks signing token in-// `webhook-signature`, but that secret is generated by GitLab and pasted into-// Kaneo, which is the opposite direction from the secret set up here.+// GitLab sends the secret back in X-Gitlab-Token instead of signing the body.export function verifyWebhookToken(secret: string,tokenHeader: string | undefined,diff --git a/apps/api/src/plugins/gitlab/utils/webhook-project.ts b/apps/api/src/plugins/gitlab/utils/webhook-project.tsindex 32deed778..686cb8670 100644--- a/apps/api/src/plugins/gitlab/utils/webhook-project.ts+++ b/apps/api/src/plugins/gitlab/utils/webhook-project.ts@@ -1,8 +1,6 @@import { normalizeGitlabBaseUrl } from "../config";-// A webhook payload carries the project's web URL and its full path, so the-// instance root is the URL with that path removed. This also covers instances-// served under a path prefix, where the root is not just the origin.+// Instance root is web_url minus the project path, keeping any path prefix.export function baseUrlFromProjectWebUrl(webUrl: string,pathWithNamespace: string,diff --git a/apps/api/src/plugins/gitlab/webhook-handler.ts b/apps/api/src/plugins/gitlab/webhook-handler.tsindex 9bd91b6bd..5cebfd351 100644--- a/apps/api/src/plugins/gitlab/webhook-handler.ts+++ b/apps/api/src/plugins/gitlab/webhook-handler.ts@@ -116,8 +116,6 @@ export async function handleGitlabWebhookRequest(return { success: false, error: "Invalid JSON payload" };}- // GitLab names the event in the body as well as in X-Gitlab-Event, and the- // body is what the token above authenticates.const objectKind =typeof payload.object_kind === "string" ? payload.object_kind : undefined;diff --git a/apps/api/src/plugins/gitlab/webhooks/issue-closed.ts b/apps/api/src/plugins/gitlab/webhooks/issue-closed.tsindex a7cd510cd..5dff1a8e5 100644--- a/apps/api/src/plugins/gitlab/webhooks/issue-closed.ts+++ b/apps/api/src/plugins/gitlab/webhooks/issue-closed.ts@@ -85,8 +85,7 @@ export async function handleGitlabIssueClosed(}}- // A close arriving right after Kaneo closed the issue is our own echo, but- // only when the state Kaneo last wrote is the state being reported.+ // Only an echo if it reports the state Kaneo last wrote.const lastOutbound = existingMetadata.lastOutboundStateSyncAt;if (typeof lastOutbound === "number" &&diff --git a/apps/api/src/plugins/gitlab/webhooks/issue-opened.ts b/apps/api/src/plugins/gitlab/webhooks/issue-opened.tsindex ef5ac9418..421fd7dbb 100644--- a/apps/api/src/plugins/gitlab/webhooks/issue-opened.ts+++ b/apps/api/src/plugins/gitlab/webhooks/issue-opened.ts@@ -48,8 +48,7 @@ export async function handleGitlabIssueOpened(const issue = payload.object_attributes;const { project } = payload;- // A confidential issue is limited to project members in GitLab; turning it- // into a task would publish its title and description to the whole workspace.+ // Confidential issues are visible only to project members in GitLab.if (issue.confidential) {return;}@@ -200,9 +199,6 @@ export async function handleGitlabIssueOpened(`[${taskIdentifier}](${taskUrl})`,);- // This note returns through the note webhook authored by the token's- // own user, so without its id recorded it lands in the task activity as- // a comment Kaneo wrote to itself.await updateExternalLink(issueLink.id, {metadata: {...linkMetadata,diff --git a/apps/api/src/plugins/gitlab/webhooks/issue-updated.ts b/apps/api/src/plugins/gitlab/webhooks/issue-updated.tsindex ad634b283..6b165eb00 100644--- a/apps/api/src/plugins/gitlab/webhooks/issue-updated.ts+++ b/apps/api/src/plugins/gitlab/webhooks/issue-updated.ts@@ -26,9 +26,7 @@ import { labelColor, labelTitles } from "../utils/payload";import { isSystemLabelName } from "../utils/system-labels";import { baseUrlFromProjectWebUrl } from "../utils/webhook-project";-// GitLab reports an edit, a label change and a status label change as one-// "update" action with a `changes` object, so what Gitea splits across-// issue_edited and issue_labeled arrives here together.+// Edits and label changes arrive together as one "update" action.type IssueUpdatedPayload = {object_attributes: {iid: number;@@ -189,8 +187,7 @@ export async function handleGitlabIssueUpdated(}if (changes?.description) {- // Kaneo recorded the full body it wrote, footer included, so the echo- // is recognised against the raw body; the task keeps it without one.+ // Kaneo recorded the body with its footer, so compare the raw body.const issueBody = issue.description ?? "";if (!isEchoOf(metadata.lastSync?.description, "kaneo", issueBody)) {const description = taskDescriptionFromIssue(issue.description);diff --git a/apps/api/src/plugins/gitlab/webhooks/merge-request-opened.ts b/apps/api/src/plugins/gitlab/webhooks/merge-request-opened.tsindex d6e36a58a..417de6019 100644--- a/apps/api/src/plugins/gitlab/webhooks/merge-request-opened.ts+++ b/apps/api/src/plugins/gitlab/webhooks/merge-request-opened.ts@@ -16,8 +16,6 @@ import type { GitlabWebhookProject, GitlabWebhookUser } from "../utils/payload";import { resolveTargetStatus } from "../utils/resolve-column";import { baseUrlFromProjectWebUrl } from "../utils/webhook-project";-// A merge request is stored as a `pull_request` external link: the resource-// type is the shared vocabulary the task UI already renders, not a forge term.type MergeRequestOpenedPayload = {user?: GitlabWebhookUser | null;object_attributes: {@@ -128,8 +126,7 @@ export async function handleGitlabMergeRequestOpened(return;}- // A reopen arrives with the link already recorded, and the task still needs- // to move back out of whatever state closing it left behind.+ // On reopen the link already exists, but the task still has to move.const targetStatus = await resolveTargetStatus(integration.projectId,"pr_opened",diff --git a/apps/api/src/plugins/gitlab/webhooks/note-created.ts b/apps/api/src/plugins/gitlab/webhooks/note-created.tsindex 557188769..67308e5ea 100644--- a/apps/api/src/plugins/gitlab/webhooks/note-created.ts+++ b/apps/api/src/plugins/gitlab/webhooks/note-created.ts@@ -31,15 +31,12 @@ export async function handleGitlabNoteCreated(return;}- // GitLab posts a system note for label, milestone and status changes. Those- // are not comments and would read as one in the task activity.+ // System notes are label/state changes, not comments.if (note.system) {return;}- // An internal note, or any note on a confidential issue, is visible in GitLab- // only to project members with Reporter access. Copying it into the task- // activity would show it to everyone in the Kaneo workspace.+ // Internal and confidential notes are for project members only.if (note.internal || payload.event_type === "confidential_note") {return;}@@ -70,8 +67,6 @@ export async function handleGitlabNoteCreated(continue;}- // A note Kaneo posted itself comes back authored by the token's own user,- // so the author is no help; the id Kaneo recorded when posting is.if (syncedNoteIds(externalLink.metadata).includes(note.id)) {continue;}diff --git a/apps/api/src/plugins/gitlab/webhooks/push.ts b/apps/api/src/plugins/gitlab/webhooks/push.tsindex 58c54f1b0..2111233e7 100644--- a/apps/api/src/plugins/gitlab/webhooks/push.ts+++ b/apps/api/src/plugins/gitlab/webhooks/push.ts@@ -31,8 +31,7 @@ const PROTECTED_BRANCHES = ["production",];-// A branch name may contain slashes, and those are path separators in GitLab's-// tree URL rather than characters to escape.+// Slashes in a branch name are path separators in the tree URL.function treePath(branchName: string): string {return branchName.split("/").map(encodeURIComponent).join("/");}diff --git a/apps/web/src/components/activity/comment-card.tsx b/apps/web/src/components/activity/comment-card.tsxindex 9e7cb6342..3956268db 100644--- a/apps/web/src/components/activity/comment-card.tsx+++ b/apps/web/src/components/activity/comment-card.tsx@@ -25,8 +25,6 @@ import { formatDateTime, formatRelativeTime } from "@/lib/format";import { getInitials } from "@/lib/get-initials";import { toast } from "@/lib/toast";-// A comment can arrive from any of the linked forges, so the icon and the name-// follow the source rather than always reading GitHub.const forges = {github: { name: "GitHub", Icon: GithubIcon },gitea: { name: "Gitea", Icon: FolderGit },@@ -75,8 +73,7 @@ export default function CommentCard({const canEdit = currentUser?.id === user?.id;const forge = forgeOf(externalSource);- // Only GitHub has a profile URL that can be derived from a username alone; a- // Gitea or GitLab profile lives on whichever instance the comment came from.+ // Gitea and GitLab profile URLs depend on the instance.const githubProfileUrl =forge?.name === "GitHub" && user?.name? `https://github.com/${user.name}`diff --git a/apps/web/src/components/project/gitlab-project-browser-modal.tsx b/apps/web/src/components/project/gitlab-project-browser-modal.tsxindex 9f2d1a92a..e97338e04 100644--- a/apps/web/src/components/project/gitlab-project-browser-modal.tsx+++ b/apps/web/src/components/project/gitlab-project-browser-modal.tsx@@ -49,9 +49,7 @@ export function GitlabProjectBrowserModal({queryFn: () =>listGitlabProjects({ projectId, baseUrl, accessToken, tokenType }),enabled: canFetch,- // The token is part of the request but deliberately not part of the key, so- // the result is dropped when the modal closes rather than being replayed for- // whatever token is in the form the next time it opens.+ // Token is not in the key; gcTime: 0 drops the result when the modal closes.gcTime: 0,});diff --git a/tests/api/plugins/gitlab/webhooks/issue-opened.test.ts b/tests/api/plugins/gitlab/webhooks/issue-opened.test.tsindex 194d19839..abdb8fa98 100644--- a/tests/api/plugins/gitlab/webhooks/issue-opened.test.ts+++ b/tests/api/plugins/gitlab/webhooks/issue-opened.test.ts@@ -94,8 +94,6 @@ const integration = {}),};-// A webhook payload names a label in `title`, unlike the REST API, which returns-// issue labels as plain strings.function issueOpenedPayload(labels: Array<{ title: string }>) {return {user: { username: "octocat" },