Skip to content

Commit

Permalink
first pass: upserting and deleting folders
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas committed Dec 10, 2024
1 parent 3bf642b commit d931d7b
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions connectors/src/connectors/github/temporal/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {
renderDocumentTitleAndContent,
renderMarkdownSection,
upsertToDatasource,
deleteFolderNode,
upsertFolderNode,
} from "@connectors/lib/data_sources";
import { ExternalOAuthTokenError } from "@connectors/lib/error";
import {
Expand Down Expand Up @@ -668,6 +670,12 @@ export async function githubRepoGarbageCollectActivity(
repoId: repoId.toString(),
},
});

await deleteFolderNode({
dataSourceConfig,
folderId: repoId,
loggerArgs: logger.bindings(),
});
}

async function deleteIssue(
Expand Down Expand Up @@ -846,6 +854,19 @@ async function garbageCollectCodeSync(
},
},
});

// Also delete data source folders
const fq = new PQueue({ concurrency: 8 });
directoriesToDelete.forEach((d) =>
fq.add(async () => {
Context.current().heartbeat();
await deleteFolderNode({
dataSourceConfig,
folderId: d.internalId,
loggerArgs: logger.bindings(),
});
})
);
}
}

Expand Down Expand Up @@ -910,6 +931,12 @@ export async function githubCodeSyncActivity({
},
});

await deleteFolderNode({
dataSourceConfig,
folderId: repoId.toString(),
loggerArgs: logger.bindings(),
});

return;
}

Expand Down Expand Up @@ -941,6 +968,14 @@ export async function githubCodeSyncActivity({
githubCodeRepository.lastSeenAt = codeSyncStartedAt;
await githubCodeRepository.save();

// Add as dataSource folder
await upsertFolderNode({
dataSourceConfig,
folderId: githubCodeRepository.repoId,
title: githubCodeRepository.repoName,
parents: [githubCodeRepository.repoId],
});

logger.info(
{
repoId,
Expand Down Expand Up @@ -991,6 +1026,12 @@ export async function githubCodeSyncActivity({
},
});

await deleteFolderNode({
dataSourceConfig,
folderId: repoId.toString(),
loggerArgs: logger.bindings(),
});

return;
}

Expand Down Expand Up @@ -1167,6 +1208,13 @@ export async function githubCodeSyncActivity({
});
}

await upsertFolderNode({
dataSourceConfig,
folderId: d.internalId,
parents: [d.internalId, ...d.parents, repoId.toString()],
title: d.dirName,
});

// If the parents have updated then the internalId gets updated as well so we should never
// have an udpate to parentInternalId. We check that this is always the case. If the
// directory is moved (the parents change) then it will trigger the creation of a new
Expand Down

0 comments on commit d931d7b

Please sign in to comment.