-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
104 lines (98 loc) · 3.33 KB
/
main.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { Octokit } from "@octokit/rest";
const octokit = new Octokit({
auth: process.env.GH_TOKEN,
});
var repos = [];
octokit.rest.repos
.listForUser({
username: "tinarskii",
sort: "full_name",
per_page: 100,
})
.then(({ data }) => {
data.forEach(async (repo, idx) => {
repos.push({
repo: repo.name,
star: repo.stargazers_count,
forks: repo.forks,
issues: repo.open_issues,
isFork: repo.fork,
pulls: await (
await octokit.rest.pulls.list({ owner: "tinarskii", repo: repo.name })
).data.length,
});
if (repos.length === data.length) {
const readmeContent = await octokit.rest.repos.getReadme({
owner: "tinarskii",
repo: "tinarskii",
});
const content = Buffer.from(
readmeContent.data.content,
"base64"
).toString();
const data = content.split("\n");
const start_line = data.indexOf("<!-- [PROFILE UPDATER]: START -->");
const end_line = data.indexOf("<!-- [PROFILE UPDATER]: END -->");
if (start_line === -1 && end_line === -1) {
console.log("Error: Could not find start/end line syntax");
}
data.splice(
start_line + 1,
end_line - start_line - 1,
`## My Projects\n` +
`${repos
.filter((repo) => !repo.isFork)
.map(
(repo) =>
`- [${repo.repo}](https://github.com/tinarskii/${repo.repo})` +
(!repo.star && !repo.fork && !repo.pulls && !repo.issues
? ""
: " (" +
(repo.star > 0
? ` [${repo.star} stars](https://github.com/tinarskii/${repo.repo}/stargazers)`
: "") +
(" " + repo.pulls > 0
? ` [${repo.pulls} pulls](https://github.com/tinarskii/${repo.repo}/pulls)`
: "") +
(" " + repo.fork > 0
? ` [${repo.fork} forks](https://github.com/tinarskii/${repo.repo}/network/members)`
: "") +
(" " + repo.issues > 0
? ` [${repo.issues} issues](https://github.com/tinarskii/${repo.repo}/issues)`
: "") +
" )")
)
.sort()
.toString()
.split(",")
.join("\n")}` +
`\n\n` +
`## My contribution\n` +
`${repos
.filter((repo) => repo.isFork)
.map(
(repo) =>
`- [${repo.repo}](https://github.com/tinarskii/${repo.repo})`
)
.sort()
.toString()
.split(",")
.join("\n")}`
);
const modify = data.join("\n");
octokit.rest.repos.createOrUpdateFileContents({
owner: "tinarskii",
repo: "tinarskii",
path: "README.md",
branch: "main",
message: "Update README.md",
sha: readmeContent.data.sha,
content: Buffer.from(modify).toString("base64"),
committer: {
name: "Tin's bot",
email: "Toddsbin@users.noreply.github.com",
},
});
}
});
});