Skip to content

Commit

Permalink
basic utility funtions added
Browse files Browse the repository at this point in the history
  • Loading branch information
darsan-in committed Aug 3, 2024
1 parent f536843 commit da5f608
Show file tree
Hide file tree
Showing 6 changed files with 4,482 additions and 0 deletions.
19 changes: 19 additions & 0 deletions create_file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Octokit } from "octokit";

const octakit = new Octokit({ auth: process.env.GITHUB_TOKEN });

const {
repos: { createOrUpdateFileContents },
} = octakit.rest;

export default function addFile(owner, repoName, destPath, content, message) {
createOrUpdateFileContents({
repo: repoName,
owner: owner,
path: destPath,
content: content,
message: message,
committer: { name: "DARSAN", email: "[email protected]" },
author: { name: "DARSAN", email: "[email protected]" },
});
}
49 changes: 49 additions & 0 deletions list_repo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Octokit } from "octokit";

const octakit = new Octokit({ auth: process.env.GITHUB_TOKEN });

const {
repos: { listForAuthenticatedUser },
} = octakit.rest;

function _makeGroupByOwner(data) {
const result = {};

data.forEach((repo) => {
const owner = repo.owner.login;

if (result[owner] === null) {
result[owner] = [];
}

result[owner].push(repo.name);
});

return result;
}

export async function listRepoRemote() {
const { data } = await listForAuthenticatedUser({
username: "iamspdarsan",
type: "all",
per_page: 100,
});

return _makeGroupByOwner(data);
}

export function listRepoLocal() {
const { data } = JSON.parse(readFileSync("out.json", { encoding: "utf8" }));

return _makeGroupByOwner(data);
}

export function dumpToLocal() {
listRepoRemote()
.then((content) => {
writeFileSync("out.json", JSON.stringify(content, null, 2), {
encoding: "utf8",
});
})
.catch(console.error);
}
22 changes: 22 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
async function main() {
const groupedData = listRepoLocal();

const ignoreList = [".github", "kinact", "fastimage", "bonse"];

let actionCount = 0;

for (const owner of Object.keys(groupedData)) {
for (const repoName of groupedData[owner]) {
if (!ignoreList.includes(repoName.toLowerCase())) {
try {
await triggerWorkflow(owner, repoName);

actionCount += 1;
} catch (err) {
console.log(err);
}
}
}
}
console.log("Action triggerd on ", actionCount, "repos");
}
Loading

0 comments on commit da5f608

Please sign in to comment.