Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
✨ Script to delete old docs
  • Loading branch information
coyotte508 committed Mar 1, 2023
commit c22258fd1a1ca7ec1f56e02284bf331df44e3e3d
5 changes: 5 additions & 0 deletions scripts/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tabWidth": 2,
"useTabs": true,
"printWidth": 120
}
43 changes: 43 additions & 0 deletions scripts/delete-old-prs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env -S deno run --allow-env --allow-net --allow-run --allow-read
// To format: npx prettier --write .
import { commit, listFiles } from "npm:@huggingface/hub@0.1.2";

const oneMonthAgo = new Date(Date.now() - 30 * 24 * 3600 * 1000);

const allFiles = listFiles({
repo: { type: "dataset", name: "hf-doc-build/doc-build-dev" },
recursive: true,
});

const filesToDelete: string[] = [];

for await (const file of allFiles) {
if (file.type !== "file" || !file.path.endsWith(".zip")) {
continue;
}

const date = file.lastCommit?.author.date;

if (!date) {
continue;
}

if (oneMonthAgo < new Date(date)) {
continue;
}

filesToDelete.push(file.path);
}

if (filesToDelete.length) {
console.log("deleting", filesToDelete.length, "files");
await commit({
repo: { type: "dataset", name: "hf-doc-build/doc-build-dev" },
credentials: { accessToken: Deno.env.get("HF_ACCESS_TOKEN") },
title: "Delete old docs",
operations: filesToDelete.map((file) => ({
operation: "delete",
path: file,
})),
});
}