bb36cb9e01
* refactor: move integrations to top-level settings with install-wide configs Jira and Linear configurations are now install-wide singletons rather than per-workspace duplicates, and the GitHub/Jira/Linear settings pages live under /settings/integrations instead of being nested inside each workspace. Issue and PR watchers stay per-workspace via a workspace switcher inside each integration page. Backend ships one-shot migrations that promote the most-recently-updated row and copy its secret onto the new global key. * fix: address review feedback on integrations refactor Fix migration crash on installs whose jira_configs predate the auth-health columns by selecting only guaranteed-present legacy columns and falling back to defaults for the rest. Cover the empty-legacy-table and pre-health-columns upgrade paths with new store tests. On the frontend, refactor useIntegrationEnabled to take string parameters instead of an inline options object so getSnapshot stays referentially stable across renders, and stop dispatching a misleading no-op sync event when localStorage.setItem fails in private mode. * fix: hydrate workspace list on integration settings pages The integration pages wrapped their content in a fresh StateProvider, which created a nested store scope with an empty initial state and shadowed the settings layout's hydrated workspace list. WorkspaceScopedSection then saw zero workspaces and rendered the "Create a workspace to configure this integration" empty state even when the user had workspaces. Drop the redundant StateProvider from the jira and linear pages so they share the layout's store. The github page switches to StateHydrator so it can still seed the GitHub OAuth status without resetting the rest of the store. * refactor(integrations): flatten watcher tables, pick workspace in create dialog Hiding watchers behind a workspace switcher made the list invisible at a glance — a user with multiple workspaces had to flip between each one to see what was configured. Replace the switcher with a flat table that lists every watch across every workspace, with a Workspace column for context, and move workspace selection into the create dialog so the user picks once when the watcher is born. Backend: jira list-issue-watches and github list-review-watches / list-issue-watches accept the workspace_id query param as optional; when omitted, the corresponding store ListAll* method returns rows across every workspace. Per-row mutations still require workspace_id as the IDOR guard. Frontend: useReviewWatches / useIssueWatches / useJiraIssueWatches gain a three-state contract — string for one workspace, undefined for all workspaces, null to skip fetching. Watch tables grow an optional showWorkspace column. Watch dialogs accept an optional workspaceId prop; when absent, the dialog renders a workspace dropdown for the create flow (disabled when editing existing rows so refs aren't orphaned). Github review-watch-dialog crossed the 600-line lint cap so the prompt editor moved to review-watch-prompt-field.tsx. * fix(integrations): make watcher step dropdown reactive across workspace switches Switching to a workspace whose workflows had to be fetched left the workflow step dropdown stuck — the user could pick a workflow but the step Select either showed the previous workflow's steps or appeared inert. The cause was the per-dialog useWorkflowSteps hook deferring its empty-state reset via Promise.resolve().then(() => setSteps([])) to dodge a setState-in-effect lint rule, which let stale steps survive into the next render and gave Radix nothing to anchor the popover to during the in-flight fetch. Hoist the hook into a shared useWorkflowSteps that resets via React's official setState-during-render pattern, exposes a loading flag, and returns a stepPlaceholder helper so the Select can render "Loading steps…" or "No steps in this workflow" instead of an empty popover. The Step Select is now also disabled while loading or when there are no steps, making the state of the dropdown unambiguous. * fix: address PR review feedback on integrations refactor Backend: - linear migration: add column-presence guard mirroring the Jira fix so installs that upgraded from the original Linear schema (without org_slug / last_checked_at / last_ok / last_error) don't crash startup with "no such column"; add TestStore_MigrateLegacyPerWorkspaceTable_PreHealthColumns - jira/handlers.go: drop the now-unused errMsgWorkspaceIDRequired constant that was failing golangci-lint - jira/mock_controller_test.go (new): cover setAuthHealth happy-path and invalid-JSON-rejection so the singleton-shaped payload is locked in Frontend: - useIntegrationAvailable: gate the auth-health probe on loaded && enabled so disabled integrations don't poll /config every 90s - use-workflow-steps: initialize loading to !!workflowId so edit-mode opens show "Loading steps…" instead of "No steps in this workflow" before the first fetch lands - use-workflow-steps.test.ts (new): cover the empty/non-empty workflowId, workflow switch, fetch error, and stepPlaceholder branches - use-linear-enabled.test: tighten the legacy-key migration assertion to pin the migrated value rather than just verifying key cleanup --------- Co-authored-by: Kandev Agent <agent@kandev.dev>
354 lines
11 KiB
TypeScript
354 lines
11 KiB
TypeScript
import { fetchJson, type ApiRequestOptions } from "../client";
|
|
import type {
|
|
GitHubStatusResponse,
|
|
GitHubOrg,
|
|
GitHubRepoInfo,
|
|
GitHubPR,
|
|
TaskPRsResponse,
|
|
TaskPR,
|
|
PRFeedback,
|
|
PRWatchesResponse,
|
|
ReviewWatch,
|
|
ReviewWatchesResponse,
|
|
CreateReviewWatchRequest,
|
|
UpdateReviewWatchRequest,
|
|
TriggerReviewResponse,
|
|
PRStatsResponse,
|
|
IssueWatch,
|
|
IssueWatchesResponse,
|
|
CreateIssueWatchRequest,
|
|
UpdateIssueWatchRequest,
|
|
TriggerIssueResponse,
|
|
SearchPRsResponse,
|
|
SearchIssuesResponse,
|
|
GitHubPRStatus,
|
|
GitHubActionPresets,
|
|
UpdateGitHubActionPresetsRequest,
|
|
} from "@/lib/types/github";
|
|
|
|
// Status
|
|
export async function fetchGitHubStatus(options?: ApiRequestOptions) {
|
|
return fetchJson<GitHubStatusResponse>("/api/v1/github/status", options);
|
|
}
|
|
|
|
// Token configuration
|
|
export async function configureGitHubToken(token: string) {
|
|
return fetchJson<{ configured: boolean }>("/api/v1/github/token", {
|
|
init: {
|
|
method: "POST",
|
|
body: JSON.stringify({ token }),
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function clearGitHubToken() {
|
|
return fetchJson<{ cleared: boolean }>("/api/v1/github/token", {
|
|
init: { method: "DELETE" },
|
|
});
|
|
}
|
|
|
|
// Task PR associations
|
|
export async function listTaskPRs(taskIds: string[], options?: ApiRequestOptions) {
|
|
const query = new URLSearchParams();
|
|
query.set("task_ids", taskIds.join(","));
|
|
return fetchJson<TaskPRsResponse>(`/api/v1/github/task-prs?${query.toString()}`, options);
|
|
}
|
|
|
|
export async function listWorkspaceTaskPRs(workspaceId: string, options?: ApiRequestOptions) {
|
|
return fetchJson<TaskPRsResponse>(
|
|
`/api/v1/github/task-prs?workspace_id=${encodeURIComponent(workspaceId)}`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
export async function getTaskPR(taskId: string, options?: ApiRequestOptions) {
|
|
return fetchJson<TaskPR>(`/api/v1/github/task-prs/${taskId}`, options);
|
|
}
|
|
|
|
// PR feedback (live from GitHub)
|
|
export async function getPRFeedback(
|
|
owner: string,
|
|
repo: string,
|
|
number: number,
|
|
options?: ApiRequestOptions,
|
|
) {
|
|
return fetchJson<PRFeedback>(`/api/v1/github/prs/${owner}/${repo}/${number}`, options);
|
|
}
|
|
|
|
// Lightweight PR status (review + checks + mergeable), skips comments.
|
|
export async function getPRStatus(
|
|
owner: string,
|
|
repo: string,
|
|
number: number,
|
|
options?: ApiRequestOptions,
|
|
) {
|
|
return fetchJson<GitHubPRStatus>(`/api/v1/github/prs/${owner}/${repo}/${number}/status`, options);
|
|
}
|
|
|
|
export type PRStatusRef = { owner: string; repo: string; number: number };
|
|
|
|
// Batch variant of getPRStatus: one round-trip for a whole list page. The
|
|
// backend fans out concurrently and caches per-PR, so repeat calls for the
|
|
// same page are cheap. Keys in the returned map are "<owner>/<repo>#<number>".
|
|
export async function getPRStatusesBatch(refs: PRStatusRef[], options?: ApiRequestOptions) {
|
|
return fetchJson<{ statuses: Record<string, GitHubPRStatus> }>(`/api/v1/github/prs/statuses`, {
|
|
...options,
|
|
init: {
|
|
method: "POST",
|
|
body: JSON.stringify({ refs }),
|
|
...(options?.init ?? {}),
|
|
},
|
|
});
|
|
}
|
|
|
|
// Submit PR review
|
|
export async function submitPRReview(
|
|
owner: string,
|
|
repo: string,
|
|
number: number,
|
|
event: "APPROVE" | "COMMENT" | "REQUEST_CHANGES",
|
|
body?: string,
|
|
) {
|
|
return fetchJson<{ submitted: boolean }>(
|
|
`/api/v1/github/prs/${owner}/${repo}/${number}/reviews`,
|
|
{
|
|
init: {
|
|
method: "POST",
|
|
body: JSON.stringify({ event, body: body ?? "" }),
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
// PR watches
|
|
export async function listPRWatches(options?: ApiRequestOptions) {
|
|
return fetchJson<PRWatchesResponse>("/api/v1/github/watches/pr", options);
|
|
}
|
|
|
|
export async function deletePRWatch(id: string, options?: ApiRequestOptions) {
|
|
return fetchJson<{ success: boolean }>(`/api/v1/github/watches/pr/${id}`, {
|
|
...options,
|
|
init: { method: "DELETE", ...(options?.init ?? {}) },
|
|
});
|
|
}
|
|
|
|
// Review watches
|
|
// Omit workspaceId to fetch every watch across all workspaces.
|
|
export async function listReviewWatches(workspaceId?: string, options?: ApiRequestOptions) {
|
|
const path = workspaceId
|
|
? `/api/v1/github/watches/review?workspace_id=${encodeURIComponent(workspaceId)}`
|
|
: `/api/v1/github/watches/review`;
|
|
return fetchJson<ReviewWatchesResponse>(path, options);
|
|
}
|
|
|
|
export async function createReviewWatch(
|
|
payload: CreateReviewWatchRequest,
|
|
options?: ApiRequestOptions,
|
|
) {
|
|
return fetchJson<ReviewWatch>("/api/v1/github/watches/review", {
|
|
...options,
|
|
init: { method: "POST", body: JSON.stringify(payload), ...(options?.init ?? {}) },
|
|
});
|
|
}
|
|
|
|
export async function updateReviewWatch(
|
|
id: string,
|
|
payload: UpdateReviewWatchRequest,
|
|
options?: ApiRequestOptions,
|
|
) {
|
|
return fetchJson<ReviewWatch>(`/api/v1/github/watches/review/${id}`, {
|
|
...options,
|
|
init: { method: "PUT", body: JSON.stringify(payload), ...(options?.init ?? {}) },
|
|
});
|
|
}
|
|
|
|
export async function deleteReviewWatch(id: string, options?: ApiRequestOptions) {
|
|
return fetchJson<{ success: boolean }>(`/api/v1/github/watches/review/${id}`, {
|
|
...options,
|
|
init: { method: "DELETE", ...(options?.init ?? {}) },
|
|
});
|
|
}
|
|
|
|
export async function triggerReviewWatch(id: string, options?: ApiRequestOptions) {
|
|
return fetchJson<TriggerReviewResponse>(`/api/v1/github/watches/review/${id}/trigger`, {
|
|
...options,
|
|
init: { method: "POST", ...(options?.init ?? {}) },
|
|
});
|
|
}
|
|
|
|
export async function triggerAllReviewWatches(workspaceId: string, options?: ApiRequestOptions) {
|
|
const query = new URLSearchParams({ workspace_id: workspaceId });
|
|
return fetchJson<TriggerReviewResponse>(
|
|
`/api/v1/github/watches/review/trigger-all?${query.toString()}`,
|
|
{
|
|
...options,
|
|
init: { method: "POST", ...(options?.init ?? {}) },
|
|
},
|
|
);
|
|
}
|
|
|
|
// Orgs & repo search
|
|
export async function listUserOrgs(options?: ApiRequestOptions) {
|
|
return fetchJson<{ orgs: GitHubOrg[] }>("/api/v1/github/orgs", options);
|
|
}
|
|
|
|
export async function searchOrgRepos(org: string, query?: string, options?: ApiRequestOptions) {
|
|
const params = new URLSearchParams({ org });
|
|
if (query) params.set("q", query);
|
|
return fetchJson<{ repos: GitHubRepoInfo[] }>(
|
|
`/api/v1/github/repos/search?${params.toString()}`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
// PR info (lightweight)
|
|
export async function fetchPRInfo(
|
|
owner: string,
|
|
repo: string,
|
|
number: number,
|
|
options?: ApiRequestOptions,
|
|
) {
|
|
return fetchJson<GitHubPR>(
|
|
`/api/v1/github/prs/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/${number}/info`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
// Remote repo branches
|
|
export async function fetchRepoBranches(owner: string, repo: string, options?: ApiRequestOptions) {
|
|
return fetchJson<{ branches: { name: string }[] }>(
|
|
`/api/v1/github/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/branches`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
// Stats
|
|
export async function fetchGitHubStats(
|
|
params?: { workspace_id?: string; start_date?: string; end_date?: string },
|
|
options?: ApiRequestOptions,
|
|
) {
|
|
const query = new URLSearchParams();
|
|
if (params?.workspace_id) query.set("workspace_id", params.workspace_id);
|
|
if (params?.start_date) query.set("start_date", params.start_date);
|
|
if (params?.end_date) query.set("end_date", params.end_date);
|
|
const suffix = query.toString();
|
|
return fetchJson<PRStatsResponse>(`/api/v1/github/stats${suffix ? `?${suffix}` : ""}`, options);
|
|
}
|
|
|
|
// Issue watches
|
|
// Omit workspaceId to fetch every watch across all workspaces.
|
|
export async function listIssueWatches(workspaceId?: string, options?: ApiRequestOptions) {
|
|
const path = workspaceId
|
|
? `/api/v1/github/watches/issue?workspace_id=${encodeURIComponent(workspaceId)}`
|
|
: `/api/v1/github/watches/issue`;
|
|
return fetchJson<IssueWatchesResponse>(path, options);
|
|
}
|
|
|
|
export async function createIssueWatch(
|
|
payload: CreateIssueWatchRequest,
|
|
options?: ApiRequestOptions,
|
|
) {
|
|
return fetchJson<IssueWatch>("/api/v1/github/watches/issue", {
|
|
...options,
|
|
init: { method: "POST", body: JSON.stringify(payload), ...(options?.init ?? {}) },
|
|
});
|
|
}
|
|
|
|
export async function updateIssueWatch(
|
|
id: string,
|
|
payload: UpdateIssueWatchRequest,
|
|
options?: ApiRequestOptions,
|
|
) {
|
|
return fetchJson<IssueWatch>(`/api/v1/github/watches/issue/${id}`, {
|
|
...options,
|
|
init: { method: "PUT", body: JSON.stringify(payload), ...(options?.init ?? {}) },
|
|
});
|
|
}
|
|
|
|
export async function deleteIssueWatch(id: string, options?: ApiRequestOptions) {
|
|
return fetchJson<{ deleted: boolean }>(`/api/v1/github/watches/issue/${id}`, {
|
|
...options,
|
|
init: { method: "DELETE", ...(options?.init ?? {}) },
|
|
});
|
|
}
|
|
|
|
export async function triggerIssueWatch(id: string, options?: ApiRequestOptions) {
|
|
return fetchJson<TriggerIssueResponse>(`/api/v1/github/watches/issue/${id}/trigger`, {
|
|
...options,
|
|
init: { method: "POST", ...(options?.init ?? {}) },
|
|
});
|
|
}
|
|
|
|
export async function triggerAllIssueWatches(workspaceId: string, options?: ApiRequestOptions) {
|
|
const query = new URLSearchParams({ workspace_id: workspaceId });
|
|
return fetchJson<TriggerIssueResponse>(
|
|
`/api/v1/github/watches/issue/trigger-all?${query.toString()}`,
|
|
{
|
|
...options,
|
|
init: { method: "POST", ...(options?.init ?? {}) },
|
|
},
|
|
);
|
|
}
|
|
|
|
// User PR / issue search (for the /github page).
|
|
// Pass `query` to use a verbatim GitHub search string, or `filter` to append to
|
|
// the default (type:pr state:open / type:issue state:open).
|
|
type SearchParams = {
|
|
query?: string;
|
|
filter?: string;
|
|
page?: number;
|
|
perPage?: number;
|
|
};
|
|
|
|
function buildSearchQuery(params: SearchParams) {
|
|
const search = new URLSearchParams();
|
|
if (params.query) search.set("query", params.query);
|
|
if (params.filter) search.set("filter", params.filter);
|
|
if (params.page && params.page > 1) search.set("page", String(params.page));
|
|
if (params.perPage) search.set("per_page", String(params.perPage));
|
|
return search.toString();
|
|
}
|
|
|
|
export async function searchUserPRs(params: SearchParams, options?: ApiRequestOptions) {
|
|
const suffix = buildSearchQuery(params);
|
|
return fetchJson<SearchPRsResponse>(
|
|
`/api/v1/github/user/prs${suffix ? `?${suffix}` : ""}`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
export async function searchUserIssues(params: SearchParams, options?: ApiRequestOptions) {
|
|
const suffix = buildSearchQuery(params);
|
|
return fetchJson<SearchIssuesResponse>(
|
|
`/api/v1/github/user/issues${suffix ? `?${suffix}` : ""}`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
// Action presets (quick-launch prompts on the /github page).
|
|
export async function fetchGitHubActionPresets(workspaceId: string, options?: ApiRequestOptions) {
|
|
const query = new URLSearchParams({ workspace_id: workspaceId });
|
|
return fetchJson<GitHubActionPresets>(
|
|
`/api/v1/github/action-presets?${query.toString()}`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
export async function updateGitHubActionPresets(
|
|
payload: UpdateGitHubActionPresetsRequest,
|
|
options?: ApiRequestOptions,
|
|
) {
|
|
return fetchJson<GitHubActionPresets>("/api/v1/github/action-presets", {
|
|
...options,
|
|
init: { ...(options?.init ?? {}), method: "PUT", body: JSON.stringify(payload) },
|
|
});
|
|
}
|
|
|
|
export async function resetGitHubActionPresets(workspaceId: string, options?: ApiRequestOptions) {
|
|
const query = new URLSearchParams({ workspace_id: workspaceId });
|
|
return fetchJson<GitHubActionPresets>(`/api/v1/github/action-presets/reset?${query.toString()}`, {
|
|
...options,
|
|
init: { ...(options?.init ?? {}), method: "POST" },
|
|
});
|
|
}
|