Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion apps/api/src/app/api/electric/[...path]/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
agentCommands,
chatSessions,
devicePresence,
githubPullRequests,
githubRepositories,
integrationConnections,
invitations,
members,
Expand Down Expand Up @@ -33,7 +35,9 @@ export type AllowedTable =
| "subscriptions"
| "workspaces"
| "chat_sessions"
| "session_hosts";
| "session_hosts"
| "github_repositories"
| "github_pull_requests";

interface WhereClause {
fragment: string;
Expand Down Expand Up @@ -138,6 +142,20 @@ export async function buildWhereClause(
case "session_hosts":
return build(sessionHosts, sessionHosts.organizationId, organizationId);

case "github_repositories":
return build(
githubRepositories,
githubRepositories.organizationId,
organizationId,
);

case "github_pull_requests":
return build(
githubPullRequests,
githubPullRequests.organizationId,
organizationId,
);

default:
return null;
}
Expand Down
6 changes: 5 additions & 1 deletion apps/api/src/app/api/github/jobs/initial-sync/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function POST(request: Request) {
return Response.json({ error: "Invalid payload" }, { status: 400 });
}

const { installationDbId } = parsed.data;
const { installationDbId, organizationId } = parsed.data;

const [installation] = await db
.select()
Expand Down Expand Up @@ -98,6 +98,7 @@ export async function POST(request: Request) {
.insert(githubRepositories)
.values({
installationId: installationDbId,
organizationId,
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
repoId: String(repo.id),
owner: repo.owner.login,
name: repo.name,
Expand All @@ -108,6 +109,7 @@ export async function POST(request: Request) {
.onConflictDoUpdate({
target: [githubRepositories.repoId],
set: {
organizationId,
owner: repo.owner.login,
name: repo.name,
fullName: repo.full_name,
Expand Down Expand Up @@ -187,6 +189,7 @@ export async function POST(request: Request) {
.insert(githubPullRequests)
.values({
repositoryId: dbRepo.id,
organizationId,
prNumber: pr.number,
nodeId: pr.node_id,
headBranch: pr.head.ref,
Expand All @@ -213,6 +216,7 @@ export async function POST(request: Request) {
githubPullRequests.prNumber,
],
set: {
organizationId: dbRepo.organizationId,
headSha: pr.head.sha,
title: pr.title,
state: pr.state,
Expand Down
4 changes: 4 additions & 0 deletions apps/api/src/app/api/github/sync/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export async function POST(request: Request) {
.insert(githubRepositories)
.values({
installationId: installation.id,
organizationId,
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
repoId: String(repo.id),
owner: repo.owner.login,
name: repo.name,
Expand All @@ -80,6 +81,7 @@ export async function POST(request: Request) {
.onConflictDoUpdate({
target: [githubRepositories.repoId],
set: {
organizationId,
owner: repo.owner.login,
name: repo.name,
fullName: repo.full_name,
Expand Down Expand Up @@ -159,6 +161,7 @@ export async function POST(request: Request) {
.insert(githubPullRequests)
.values({
repositoryId: dbRepo.id,
organizationId,
prNumber: pr.number,
nodeId: pr.node_id,
headBranch: pr.head.ref,
Expand All @@ -185,6 +188,7 @@ export async function POST(request: Request) {
githubPullRequests.prNumber,
],
set: {
organizationId: dbRepo.organizationId,
headSha: pr.head.sha,
title: pr.title,
state: pr.state,
Expand Down
3 changes: 3 additions & 0 deletions apps/api/src/app/api/github/webhook/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ webhooks.on(
.insert(githubRepositories)
.values({
installationId: installation.id,
organizationId: installation.organizationId,
repoId: String(repo.id),
owner: owner ?? "",
name: name ?? repo.name,
Expand Down Expand Up @@ -158,6 +159,7 @@ webhooks.on(
.insert(githubPullRequests)
.values({
repositoryId: repo.id,
organizationId: repo.organizationId,
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
prNumber: pr.number,
nodeId: pr.node_id,
headBranch: pr.head.ref,
Expand All @@ -179,6 +181,7 @@ webhooks.on(
.onConflictDoUpdate({
target: [githubPullRequests.repositoryId, githubPullRequests.prNumber],
set: {
organizationId: repo.organizationId,
headBranch: pr.head.ref,
headSha: pr.head.sha,
baseBranch: pr.base.ref,
Expand Down
Loading