Files
Tom MoorandClaude Opus 5 f49b047648 feat: Convert @ prefixed Markdown links to mentions on server writes (#13403)
* checkpoint

* feat: Convert @ prefixed links to mentions on server Markdown writes

A Markdown link preceded by "@" now becomes a mention when brought in
through the documents API, MCP, or an import, so an exported mention
survives a round trip instead of degrading to a plain link.

The editor rule creates a generic mention carrying the href, and the
type of resource it points at is resolved by the plugin that recognizes
the URL through a new MentionProvider hook. Mentions of external
resources also serialize to their real URL rather than a mention:// URI,
so the reference resolves outside of Outline.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix: Escape values interpolated into rendered mention HTML

markdown-it leaves markup in a link label intact when html is disabled,
so the label and attributes are escaped before being written into the
tag.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 17:42:28 -04:00

104 lines
2.6 KiB
TypeScript

import queryString from "query-string";
import env from "@shared/env";
import { MentionType } from "@shared/types";
import { integrationSettingsPath } from "@shared/utils/routeHelpers";
export const GitHubOAuthNonceCookie = "githubOAuthNonce";
export type OAuthState = {
teamId: string;
nonce: string;
};
export class GitHubUtils {
public static clientId = env.GITHUB_CLIENT_ID;
static get url() {
return integrationSettingsPath("github");
}
/**
* @param error
* @returns URL to be redirected to upon authorization error from GitHub
*/
public static errorUrl(error: string) {
return `${this.url}?error=${error}`;
}
/**
* @returns Callback URL configured for GitHub, to which users will be redirected upon authorization
*/
public static callbackUrl(
{ baseUrl, params }: { baseUrl: string; params?: string } = {
baseUrl: env.URL,
params: undefined,
}
) {
return params
? `${baseUrl}/api/github.callback?${params}`
: `${baseUrl}/api/github.callback`;
}
static authUrl(state: OAuthState): string {
const baseUrl = `https://github.com/apps/${env.GITHUB_APP_NAME}/installations/new`;
const params = {
client_id: this.clientId,
redirect_uri: this.callbackUrl(),
state: JSON.stringify(state),
};
return `${baseUrl}?${queryString.stringify(params)}`;
}
static parseState(state: string): OAuthState | undefined {
try {
return JSON.parse(state);
} catch {
return undefined;
}
}
static installRequestUrl(): string {
return `${this.url}?install_request=true`;
}
/**
* Determines the type of mention a GitHub URL represents.
*
* @param url the URL to evaluate.
* @returns the mention type, or undefined if this is not a GitHub URL for a
* resource that can be mentioned.
*/
public static mentionType(url: URL): MentionType | undefined {
if (url.hostname !== "github.com") {
return undefined;
}
const type = url.pathname.split("/")[3];
return type === "pull"
? MentionType.PullRequest
: type === "issues"
? MentionType.Issue
: type === "projects"
? MentionType.Project
: undefined;
}
public static getColorForStatus(status: string, isDraftPR: boolean = false) {
switch (status) {
case "open":
return isDraftPR ? "#848d97" : "#238636";
case "done":
return "#a371f7";
case "closed":
return "#f85149";
case "completed":
case "merged":
return "#8250df";
case "canceled":
default:
return "#848d97";
}
}
}