forked from bitfocus/companion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodules_last_commit.mjs
102 lines (85 loc) · 2.29 KB
/
modules_last_commit.mjs
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
#!/usr/bin/env zx
import fs from 'fs-extra'
import dotenv from 'dotenv'
dotenv.config()
const GH_TOKEN = process.env.GITHUB_TOKEN
async function doModule(modName) {
const res = await fetch(`https://api.github.com/repos/bitfocus/${modName}/commits?per_page=100`, {
headers: {
Authorization: `Bearer ${GH_TOKEN}`,
},
})
const data = await res.json()
let str = null
for (const commit of data) {
try {
if (
commit.author?.login !== 'Julusian' &&
commit.author?.login !== 'companion-module-bot' &&
commit.author?.login !== 'dependabot[bot]'
) {
const date = new Date(commit.commit.author.date)
console.log(date, date.getFullYear(), date.getMonth(), date.getDate())
// console.log(commit.commit.author.date, date, commit.author.login)
str = `${modName},${commit.author?.login ?? ''},${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()}`
break
}
} catch (e) {
console.error(e, commit)
}
}
if (!str) {
str = `${modName},,`
}
try {
const issues = await fetch(`https://api.github.com/graphql`, {
method: 'POST',
headers: {
Authorization: `Bearer ${GH_TOKEN}`,
'Content-type': 'application/json',
},
body: JSON.stringify({
query: `query {
repository(owner:"bitfocus", name:"${modName}") {
open: issues(states:OPEN) {
totalCount
}
closed: issues(states:CLOSED) {
totalCount
}
total: issues {
totalCount
}
}
}`,
}),
})
const data2 = await issues.json()
console.log(data2)
str += `,${data2.data.repository.total.totalCount},${data2.data.repository.open.totalCount},${data2.data.repository.closed.totalCount}`
} catch (e) {
console.error('issues', e)
}
console.log(str)
res2.push(str)
}
const pkgJsonStr = await fs.readFile('./module-legacy/package.json')
const pkgJson = JSON.parse(pkgJsonStr.toString())
const res2 = []
try {
const mods = await fs.readdir('./bundled-modules')
for (const name of mods) {
if (!name.startsWith('.') && (await fs.stat(path.join('./bundled-modules', name))).isDirectory()) {
await doModule('companion-module-' + name)
}
}
for (const [name, version] of Object.entries(pkgJson.dependencies)) {
if (name.startsWith('companion-module-')) {
await doModule(name)
}
}
} catch (e) {
//
console.error(e)
}
console.log(res2.join('\n'))