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
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
116 changes: 116 additions & 0 deletions connectors/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions connectors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@types/uuid": "^9.0.2",
"axios": "^1.5.1",
"body-parser": "^1.20.2",
"blake3": "^2.1.7",
"dd-trace": "^3.16.0",
"eventsource-parser": "^1.0.0",
"express": "^4.18.2",
Expand All @@ -54,13 +55,15 @@
"redis": "^4.6.10",
"sequelize": "^6.31.0",
"talisman": "^1.1.4",
"tar": "^6.2.0",
"uuid": "^9.0.0"
},
"devDependencies": {
"@types/eslint": "^8.21.3",
"@types/fast-levenshtein": "^0.0.2",
"@types/node": "^18.15.5",
"@types/p-queue": "^3.2.1",
"@types/tar": "^6.1.10",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
"eslint": "^8.36.0",
Expand Down
65 changes: 65 additions & 0 deletions connectors/src/admin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import {
STOP_CONNECTOR_BY_TYPE,
SYNC_CONNECTOR_BY_TYPE,
} from "@connectors/connectors";
import {
cleanUpProcessRepository,
processRepository,
} from "@connectors/connectors/github/lib/github_api";
import {
getAuthObject,
getDocumentId,
Expand Down Expand Up @@ -99,6 +103,64 @@ const connectors = async (command: string, args: parseArgs.ParsedArgs) => {
}
};

const github = async (command: string, args: parseArgs.ParsedArgs) => {
switch (command) {
case "test-repo": {
if (!args.wId) {
throw new Error("Missing --wId argument");
}
if (!args.dataSourceName) {
throw new Error("Missing --dataSourceName argument");
}
if (!args.owner) {
throw new Error("Missing --owner argument");
}
if (!args.repo) {
throw new Error("Missing --repo argument");
}

const connector = await Connector.findOne({
where: {
type: "github",
workspaceId: args.wId,
dataSourceName: args.dataSourceName,
},
});

if (!connector) {
throw new Error(
`Could not find connector for workspace ${args.wId}, data source ${args.dataSourceName}`
);
}

const installationId = connector.connectionId;

const { tempDir, files, directories } = await processRepository(
installationId,
args.owner,
args.repo,
"999"
);

files.forEach((f) => {
console.log(f);
});
directories.forEach((d) => {
console.log(d);
});

console.log(
`Found ${files.length} files in ${directories.length} directories`
);
console.log(
`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

}
}
};

const notion = async (command: string, args: parseArgs.ParsedArgs) => {
switch (command) {
case "restart-all": {
Expand Down Expand Up @@ -568,6 +630,9 @@ const main = async () => {
case "notion":
await notion(command, argv);
return;
case "github":
await github(command, argv);
return;
case "google":
await google(command, argv);
return;
Expand Down
Loading