import { repoDb, stmt } from "./scoped-db";
import { captureServerEvent } from "./analytics";
import { registerLocator } from "./scoped-db/locators";
import { scopedId } from "./scoped-db/ids";
import { repoActivityStatement } from "./issue-scope";
import { emitNotification, emitWebhook } from "./events/emit";
import { forbidden } from "./errors";
import { issueUrl, setIssueState } from "./issues";
import type { IssueRow } from "./issues";
import type { RepoAccess } from "./repos";
import type { RepoRow, Viewer } from "~/lib/types";
export function canMaintainRepo(access: RepoAccess): boolean {
return access.permission === "write" || access.permission === "admin";
}
/** Notifies the thread's participants, watchers and @mentions about activity on an issue or pull request. */
export async function notifyIssueThread(
repo: RepoRow,
issue: IssueRow,
actor: Viewer,
reason: "comment" | "state_change",
text: string | null,
): Promise<void> {
await emitNotification({
repoId: repo.id,
issueId: issue.id,
actorId: actor.id,
reason,
title: `${repo.owner_name}/${repo.name}#${issue.number}: ${issue.title}`,
url: issueUrl(repo, issue),
mentionText: text,
directRecipients: [],
});
}
/**
* Adds a comment to an issue or pull request conversation, from the web or an emailed reply. The caller
* has already checked read access and that the repository is not archived; locked threads need write.
*/