generated from darsan-in/Template-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_file.js
45 lines (35 loc) · 1.25 KB
/
create_file.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const { listRepoRemote } = require("./list_repo");
const { readFileSync } = require("fs");
const { getSha } = require("./get_last_commit_sha");
async function addFile(owner, repoName, destPath, content, message, sha) {
const { Octokit } = await import("@octokit/rest");
const octakit = new Octokit({ auth: process.env.GITHUB_TOKEN });
const {
repos: { createOrUpdateFileContents },
} = octakit.rest;
createOrUpdateFileContents({
repo: repoName,
owner: owner,
path: destPath,
content: content,
message: message,
committer: { name: "DARSAN", email: "[email protected]" },
author: { name: "DARSAN", email: "[email protected]" },
sha: sha,
});
}
async function main() {
const groupedRepolists = await listRepoRemote();
const wftContent = readFileSync("wft.yaml", {
encoding: "base64",
});
const destPath = ".github/workflows/consistent-desc.yaml";
const commitMsg = "End-User meta workflow updated";
Object.keys(groupedRepolists).forEach((username) => {
groupedRepolists[username].forEach(async (repoName) => {
const sha = await getSha(username, repoName, destPath);
addFile(username, repoName, destPath, wftContent, commitMsg, sha);
});
});
}
main();