-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
83 lines (70 loc) · 1.93 KB
/
index.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const { Octokit } = require("@octokit/rest");
const { createTokenAuth } = require("@octokit/auth-token");
const json2md = require("json2md");
const fs = require("fs");
const { config } = require("dotenv");
// let tokenAuth = new Octokit.C Credential("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");
config();
function getOrThrow(key) {
const value = process.env[key];
if (!value) {
throw new Error(`Missing env var ${key}`);
}
return value;
}
(async () => {
const auth = createTokenAuth(getOrThrow("TOKEN"));
const { token } = await auth();
const octoCat = new Octokit({
auth: token,
});
const repos = await octoCat.repos.listForOrg({
headers: {
authorization: `bearer ${token}`,
},
org: "xp-network",
per_page: 100,
type: "private",
sort: "pushed",
});
const markdown = [];
for (const repo of repos.data) {
markdown.push([{ h1: repo.name }]);
const branches = await octoCat.repos.listBranches({
owner: "xp-network",
repo: repo.name,
per_page: 100,
});
console.log(branches.data.map((branch) => branch.name));
for (const branch of branches.data) {
const commits = await octoCat.repos.listCommits({
owner: "xp-network",
repo: repo.name,
per_page: 50,
sha: branch.name,
});
const commitMessages = commits.data.map(
(commit) =>
`[${commit.sha.substring(0, 3)}..${commit.sha.slice(
commit.sha.length - 3
)}] ${commit.commit.message.split("\n")[0]} | By - ${
commit.commit.author.name
} | On - ${commit.commit.committer.date ?? "N/A"}`
);
const md = [
{
h2: branch.name,
},
{ ol: commitMessages },
];
markdown.push(md);
console.log();
}
}
fs.writeFile("ACTIVITY.md", json2md(markdown), (e) => {
if (e) {
console.log(e);
}
});
console.log("Updated the readme.");
})();