Skip to content

Commit df3961b

Browse files
authored
Merge pull request #874 from jsonwebtoken/libraries-data-automatic-update
Libraries data automatic update
2 parents 72cf3f6 + 21f0498 commit df3961b

File tree

3 files changed

+230
-0
lines changed

3 files changed

+230
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Update libraries stars count (test)
2+
on:
3+
push:
4+
branches: [stars-ci-test]
5+
workflow_dispatch:
6+
7+
8+
jobs:
9+
update-stars:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
steps:
14+
- name: Checkout repo
15+
uses: actions/checkout@v4
16+
with:
17+
persist-credentials: false
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: 20
22+
- name: Install dependencies
23+
run: npm install node-fetch@2
24+
- name: Update stars in libraries-next.json
25+
run: node scripts/updateStars.js
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
- name: Commit and push changes
29+
run: |
30+
git config --global user.name 'javier-okta'
31+
git config --global user.email '[email protected]'
32+
git add .
33+
git commit -m "chore: update stars count [skip ci]" || echo "No changes to commit"
34+
git push
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

scripts/example-repos.json

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
{
2+
"dot-net": {
3+
"id": "dot-net",
4+
"name": ".NET",
5+
"uniqueClass": "net",
6+
"image": "/img/1.svg",
7+
"bgColor": "rgb(42, 168, 229)",
8+
"libs": [
9+
{
10+
"minimumVersion": null,
11+
"support": {
12+
"sign": true,
13+
"verify": true,
14+
"iss": true,
15+
"sub": true,
16+
"aud": true,
17+
"exp": true,
18+
"nbf": true,
19+
"iat": true,
20+
"jti": true,
21+
"hs256": true,
22+
"hs384": true,
23+
"hs512": true,
24+
"rs256": true,
25+
"rs384": true,
26+
"rs512": true,
27+
"es256": true,
28+
"es384": true,
29+
"es512": true,
30+
"ps256": true,
31+
"ps384": true,
32+
"ps512": true
33+
},
34+
"authorUrl": "https://www.microsoft.com",
35+
"authorName": "Microsoft",
36+
"gitHubRepoPath": "AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet",
37+
"repoUrl": "https://github.com/MSOpenTech/azure-activedirectory-identitymodel-extensions-for-dotnet",
38+
"installCommandMarkdown": [
39+
"Install-Package",
40+
"[System.IdentityModel.Tokens.Jwt](https://www.nuget.org/packages/System.IdentityModel.Tokens.Jwt/)"
41+
],
42+
"stars": 1115
43+
},
44+
{
45+
"minimumVersion": null,
46+
"support": {
47+
"sign": true,
48+
"verify": true,
49+
"iss": true,
50+
"sub": true,
51+
"aud": true,
52+
"exp": true,
53+
"nbf": true,
54+
"iat": true,
55+
"jti": false,
56+
"hs256": true,
57+
"hs384": true,
58+
"hs512": true,
59+
"rs256": true,
60+
"rs384": true,
61+
"rs512": true,
62+
"es256": true,
63+
"es384": true,
64+
"es512": true,
65+
"ps256": false,
66+
"ps384": false,
67+
"ps512": false
68+
},
69+
"authorUrl": "https://github.com/jwt-dotnet/jwt",
70+
"authorName": "Alexander Batishchev",
71+
"gitHubRepoPath": "jwt-dotnet/jwt",
72+
"repoUrl": "https://github.com/jwt-dotnet/jwt",
73+
"installCommandMarkdown": [
74+
"Install-Package",
75+
"[JWT.NET](https://www.nuget.org/packages/JWT)"
76+
],
77+
"stars": 2109
78+
}
79+
]
80+
},
81+
"swift": {
82+
"id": "swift",
83+
"name": "Swift",
84+
"uniqueClass": "swift",
85+
"image": "/img/15.svg",
86+
"bgColor": "rgb(234, 45, 46)",
87+
"libs": [
88+
{
89+
"minimumVersion": null,
90+
"support": {
91+
"sign": true,
92+
"verify": true,
93+
"iss": true,
94+
"sub": false,
95+
"aud": true,
96+
"exp": true,
97+
"nbf": true,
98+
"iat": true,
99+
"jti": false,
100+
"hs256": true,
101+
"hs384": true,
102+
"hs512": true,
103+
"rs256": false,
104+
"rs384": false,
105+
"rs512": false,
106+
"es256": false,
107+
"es384": false,
108+
"es512": false,
109+
"ps256": false,
110+
"ps384": false,
111+
"ps512": false
112+
},
113+
"authorUrl": "https://github.com/kylef",
114+
"authorName": "Kyle Fuller",
115+
"gitHubRepoPath": "kylef/JSONWebToken.swift",
116+
"repoUrl": "https://github.com/kylef/JSONWebToken.swift",
117+
"installCommandMarkdown": [
118+
"pod 'JSONWebToken'"
119+
],
120+
"stars": 751
121+
},
122+
{
123+
"minimumVersion": null,
124+
"support": {
125+
"sign": true,
126+
"verify": true,
127+
"iss": true,
128+
"sub": true,
129+
"aud": true,
130+
"exp": true,
131+
"nbf": true,
132+
"iat": true,
133+
"jti": true,
134+
"hs256": true,
135+
"hs384": true,
136+
"hs512": true,
137+
"rs256": true,
138+
"rs384": true,
139+
"rs512": true,
140+
"es256": true,
141+
"es384": true,
142+
"es512": true,
143+
"ps256": false,
144+
"ps384": false,
145+
"ps512": false
146+
},
147+
"authorUrl": "https://github.com/vapor",
148+
"authorName": "Vapor",
149+
"gitHubRepoPath": "vapor/jwt-kit",
150+
"repoUrl": "https://github.com/vapor/jwt-kit",
151+
"installCommandMarkdown": [
152+
".package(url: \"https://github.com/vapor/jwt-kit.git\", from: \"4.0.0\")"
153+
],
154+
"stars": 250
155+
}
156+
]
157+
}
158+
}

scripts/updateStars.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import fs from "fs"
2+
import path from "path"
3+
4+
const filePath = path.join(process.cwd(), "/scripts/example-repos.json")
5+
const reposGroup = JSON.parse(fs.readFileSync(filePath, "utf-8"))
6+
7+
async function getStars(repoUrl) {
8+
const match = repoUrl.match(/github\.com\/([^/]+)\/([^/]+)(?:\/|$)/)
9+
if(!match) throw new Error(`Invalid github repo URL: ${repoUrl}`)
10+
const [, owner, repo] = match
11+
const res = await fetch(`https://api.github.com/repos/${owner}/${repo}`, {
12+
headers: {
13+
Accept: "application/vnd.github+json"
14+
}
15+
})
16+
if(!res.ok) throw new Error(`${repoUrl} -> ${res.status} ${res.statusText}`)
17+
const data = await res.json()
18+
return data.stargazers_count ?? null
19+
}
20+
21+
(async () => {
22+
const objectEntries = Object.values(reposGroup)
23+
for(const group of objectEntries) {
24+
for(const lib of group.libs) {
25+
try {
26+
const stars = await getStars(lib.repoUrl)
27+
lib.stars = stars
28+
console.log(`✅ ${lib.repoUrl} -> ${stars}`)
29+
} catch(e) {
30+
lib.stars = null
31+
console.error(`❌ ${lib.repoUrl}: ${e.message}`)
32+
}
33+
}
34+
}
35+
fs.writeFileSync(filePath, JSON.stringify(reposGroup, null, 2) + "\n")
36+
})()

0 commit comments

Comments
 (0)