Skip to content

Commit

Permalink
fix an off-by-one error in the directory parents
Browse files Browse the repository at this point in the history
  • Loading branch information
aubin-tchoi committed Dec 21, 2024
1 parent aad8017 commit dad9331
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions connectors/src/connectors/github/lib/github_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,13 +850,13 @@ export async function processRepository({
const fileName = basename(file);

const parents = [];
for (let i = 0; i < path.length; i++) {
const pathInternalId = getCodeDirInternalId(
repoId,
path.slice(0, i + 1).join("/")
);
// we order parents bottom to top, so we take paths in the opposite order
for (let i = path.length - 1; i >= 0; i--) {
parents.push({
internalId: pathInternalId,
internalId: getCodeDirInternalId(
repoId,
path.slice(0, i + 1).join("/")
),
dirName: path[i] as string,
dirPath: path.slice(0, i),
});
Expand All @@ -867,10 +867,7 @@ export async function processRepository({
`${path.join("/")}/${fileName}`
);

const parentInternalId =
parents.length === 0
? null
: (parents[parents.length - 1]?.internalId as string);
const parentInternalId = parents[0]?.internalId ?? null;

// Files
files.push({
Expand All @@ -883,8 +880,7 @@ export async function processRepository({
sizeBytes: size,
documentId,
parentInternalId,
/// we reverse the parents here since the convention is bottom to top
parents: [documentId, ...parents.map((p) => p.internalId).reverse()],
parents: [documentId, ...parents.map((p) => p.internalId)],
localFilePath: file,
});

Expand All @@ -894,7 +890,7 @@ export async function processRepository({
if (p && !seenDirs[p.internalId]) {
seenDirs[p.internalId] = true;

const dirParent = parents[i - 1];
const dirParent = parents[i + 1];
const dirParentInternalId = dirParent ? dirParent.internalId : null;

directories.push({
Expand All @@ -906,7 +902,7 @@ export async function processRepository({
)}`,
internalId: p.internalId,
parentInternalId: dirParentInternalId,
parents: parents.slice(0, i).map((p) => p.internalId),
parents: parents.slice(i).map((p) => p.internalId),
});
}
}
Expand Down

0 comments on commit dad9331

Please sign in to comment.