Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] GitHub code: tar processing #3050

Merged
merged 7 commits into from
Jan 4, 2024
Merged

[WIP] GitHub code: tar processing #3050

merged 7 commits into from
Jan 4, 2024

Conversation

spolu
Copy link
Contributor

@spolu spolu commented Jan 3, 2024

Fixes #3030

Function to:

  • downloads
  • filters
  • preprocess files to build all necessary information for aggregation

The cli will let me check what our repo looks like

@spolu
Copy link
Contributor Author

spolu commented Jan 3, 2024

Left to do is to create directories objects so that it's super easy to use from the activity that will call into it.

@spolu spolu force-pushed the spolu-github_tar_processing branch from 8530ad6 to 0edaa90 Compare January 4, 2024 16:04
@spolu spolu requested a review from flvndvd January 4, 2024 16:06
Copy link
Contributor

@flvndvd flvndvd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, left a couple of comments.

{
owner: login,
repo: repoName,
ref: defaultBranch,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the code one can provide "parseSuccessResponseBody": false to have a stream. See https://github.com/octokit/request.js?tab=readme-ov-file#request.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

// Save the tarball to the temp directory.
await asyncPipeline(tarballStream as Readable, createWriteStream(tarPath));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit pipeline are useful when there is an operation in between read and write. Here a simple pipe could do the trick:

Something like:

const fileStream = createWriteStream(tarPath);
request(<gh_link>).pipe(fileStream);

for await (const file of getFiles(tempDir)) {
console.log(file);
// get file extension
const ext = file.split(".").pop();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
const ext = file.split(".").pop();
const ext = path.extname(file);

EXTENSION_WHITELIST.includes(`.${ext}`) ||
FILENAME_WHITELIST.includes(file);

const isUnderLimite = size < 1024 * 1024;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const isUnderLimite = size < 1024 * 1024;
const isUnderLimit = size < 1024 * 1024;

.toString("hex")
.substring(0, 16)}`;

const fileName = file.split("/").pop() || "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could abstract all of this by using the native path library.

// This function returns file and directories object with parent, internalIds, and sourceUrl
// information. The root of the directory is considered the null parent (and will have to be
// stitched by the activity).
export async function processRepository(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit maybe split this function a bit.

`Files total size: ${files.reduce((acc, f) => acc + f.sizeBytes, 0)}`
);

await cleanUpProcessRepository(tempDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we wrap the code above with a try/catch/finally so we always remove it afterward?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just for testing and the only thing that can really fail is processRepository, but if it fails we don't know the tempDir :/

I'll add a clean-up in a try/catch/finally in processRepository

@spolu spolu merged commit 4c530ba into main Jan 4, 2024
2 checks passed
@spolu spolu deleted the spolu-github_tar_processing branch January 4, 2024 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Caloris] [Github Code] Tar download and processing
2 participants