Files
outline/app/utils/mention.ts
T
Tom MoorandClaude Fable 5 a1d0520c9f Add missing JSDoc to exported members in app and server utils (#12940)
* Add missing JSDoc to exported members in app and server utils

Documents all exported functions, classes, enums, and constants in
app/utils and server/utils that were missing JSDoc, per the project
documentation guidelines.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AsEQYA8zN813thxu7GjjzU

* Use @returns tag to match codebase convention

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AsEQYA8zN813thxu7GjjzU

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-08 08:30:11 -04:00

137 lines
3.4 KiB
TypeScript

import type { IntegrationSettings, IntegrationType } from "@shared/types";
import { IntegrationService, MentionType } from "@shared/types";
import type Integration from "~/models/Integration";
const gitlabSystemPaths = new Set([
"explore",
"help",
"admin",
"dashboard",
"users",
"groups",
"projects",
"snippets",
"search",
"-",
]);
/**
* Checks whether a URL can be converted to a mention for the given
* integration.
*
* @param options the URL and integration to check against.
* @returns true if the URL can be mentioned through the integration.
*/
export const isURLMentionable = ({
url,
integration,
}: {
url: URL;
integration: Integration;
}): boolean => {
const { hostname, pathname } = url;
switch (integration.service) {
case IntegrationService.GitHub: {
return hostname === "github.com";
}
case IntegrationService.Linear: {
const pathParts = pathname.split("/");
const settings =
integration.settings as IntegrationSettings<IntegrationType.Embed>;
return (
hostname === "linear.app" &&
settings.linear?.workspace.key === pathParts[1] // ensure installed workspace key matches with the provided url.
);
}
case IntegrationService.GitLab: {
const settings =
integration.settings as IntegrationSettings<IntegrationType.Embed>;
let gitlabHostname: string | undefined;
try {
gitlabHostname = settings.gitlab?.url
? new URL(settings.gitlab.url).hostname
: undefined;
} catch {
// Invalid URL stored in settings
return false;
}
return hostname === "gitlab.com" || hostname === gitlabHostname;
}
default:
return false;
}
};
/**
* Determines the type of mention a URL represents for the given integration,
* such as an issue, pull request, or project.
*
* @param options the URL and integration to evaluate.
* @returns the mention type, or undefined if the URL is not recognized.
*/
export const determineMentionType = ({
url,
integration,
}: {
url: URL;
integration: Integration;
}): MentionType | undefined => {
const { pathname } = url;
const pathParts = pathname.split("/");
switch (integration.service) {
case IntegrationService.GitHub: {
const type = pathParts[3];
return type === "pull"
? MentionType.PullRequest
: type === "issues"
? MentionType.Issue
: type === "projects"
? MentionType.Project
: undefined;
}
case IntegrationService.Linear: {
const type = pathParts[2];
return type === "issue"
? MentionType.Issue
: type === "project"
? MentionType.Project
: undefined;
}
case IntegrationService.GitLab: {
const hasShowParam = url.searchParams.has("show");
if (
/\/-\/merge_requests\/\d+/.test(pathname) ||
(/\/-\/merge_requests\/?$/.test(pathname) && hasShowParam)
) {
return MentionType.PullRequest;
}
if (
/\/-\/(issues|work_items)\/\d+/.test(pathname) ||
(/\/-\/(issues|work_items)\/?$/.test(pathname) && hasShowParam)
) {
return MentionType.Issue;
}
if (!pathname.includes("/-/")) {
const parts = pathname.split("/").filter(Boolean);
if (parts.length >= 2 && !gitlabSystemPaths.has(parts[0])) {
return MentionType.Project;
}
}
return undefined;
}
default:
return;
}
};