diff --git a/.github/workflows/update-libraries.yaml b/.github/workflows/update-libraries.yaml new file mode 100644 index 00000000..fa72e192 --- /dev/null +++ b/.github/workflows/update-libraries.yaml @@ -0,0 +1,36 @@ +name: Update libraries stars count (test) +on: + push: + branches: [stars-ci-test] + workflow_dispatch: + + +jobs: + update-stars: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + persist-credentials: true + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + - name: Install dependencies + run: npm install node-fetch@2 + - name: Update stars in libraries-next.json + run: node scripts/updateStars.js + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Commit and push changes + run: | + git config --global user.name 'javiert-okta' + git config --global user.email 'javiersebastian.tinocomachado@okta.com' + git add . + git commit -m "chore: update stars count [skip ci]" || echo "No changes to commit" + git push + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index f6f42523..76c36e9f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,6 +30,7 @@ "negotiator": "^1.0.0", "neverthrow": "^8.1.1", "next": "^14.2.25", + "node-fetch": "^2.7.0", "node-forge": "^1.3.1", "octokit": "^4.0.2", "prismjs": "^1.29.0", @@ -11377,6 +11378,26 @@ "tslib": "^2.0.3" } }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "license": "MIT", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, "node_modules/node-forge": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", @@ -13476,6 +13497,12 @@ "node": ">=8.0" } }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "license": "MIT" + }, "node_modules/trim-lines": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/trim-lines/-/trim-lines-3.0.1.tgz", @@ -14601,6 +14628,22 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "license": "BSD-2-Clause" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "license": "MIT", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index 3ba940b8..a62dbe55 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "negotiator": "^1.0.0", "neverthrow": "^8.1.1", "next": "^14.2.25", + "node-fetch": "^2.7.0", "node-forge": "^1.3.1", "octokit": "^4.0.2", "prismjs": "^1.29.0", diff --git a/scripts/example-repos.json b/scripts/example-repos.json new file mode 100644 index 00000000..1396e8ad --- /dev/null +++ b/scripts/example-repos.json @@ -0,0 +1,158 @@ +{ + "dot-net": { + "id": "dot-net", + "name": ".NET", + "uniqueClass": "net", + "image": "/img/1.svg", + "bgColor": "rgb(42, 168, 229)", + "libs": [ + { + "minimumVersion": null, + "support": { + "sign": true, + "verify": true, + "iss": true, + "sub": true, + "aud": true, + "exp": true, + "nbf": true, + "iat": true, + "jti": true, + "hs256": true, + "hs384": true, + "hs512": true, + "rs256": true, + "rs384": true, + "rs512": true, + "es256": true, + "es384": true, + "es512": true, + "ps256": true, + "ps384": true, + "ps512": true + }, + "authorUrl": "https://www.microsoft.com", + "authorName": "Microsoft", + "gitHubRepoPath": "AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet", + "repoUrl": "https://github.com/MSOpenTech/azure-activedirectory-identitymodel-extensions-for-dotnet", + "installCommandMarkdown": [ + "Install-Package", + "[System.IdentityModel.Tokens.Jwt](https://www.nuget.org/packages/System.IdentityModel.Tokens.Jwt/)" + ], + "stars": 1115 + }, + { + "minimumVersion": null, + "support": { + "sign": true, + "verify": true, + "iss": true, + "sub": true, + "aud": true, + "exp": true, + "nbf": true, + "iat": true, + "jti": false, + "hs256": true, + "hs384": true, + "hs512": true, + "rs256": true, + "rs384": true, + "rs512": true, + "es256": true, + "es384": true, + "es512": true, + "ps256": false, + "ps384": false, + "ps512": false + }, + "authorUrl": "https://github.com/jwt-dotnet/jwt", + "authorName": "Alexander Batishchev", + "gitHubRepoPath": "jwt-dotnet/jwt", + "repoUrl": "https://github.com/jwt-dotnet/jwt", + "installCommandMarkdown": [ + "Install-Package", + "[JWT.NET](https://www.nuget.org/packages/JWT)" + ], + "stars": 2175 + } + ] + }, + "swift": { + "id": "swift", + "name": "Swift", + "uniqueClass": "swift", + "image": "/img/15.svg", + "bgColor": "rgb(234, 45, 46)", + "libs": [ + { + "minimumVersion": null, + "support": { + "sign": true, + "verify": true, + "iss": true, + "sub": false, + "aud": true, + "exp": true, + "nbf": true, + "iat": true, + "jti": false, + "hs256": true, + "hs384": true, + "hs512": true, + "rs256": false, + "rs384": false, + "rs512": false, + "es256": false, + "es384": false, + "es512": false, + "ps256": false, + "ps384": false, + "ps512": false + }, + "authorUrl": "https://github.com/kylef", + "authorName": "Kyle Fuller", + "gitHubRepoPath": "kylef/JSONWebToken.swift", + "repoUrl": "https://github.com/kylef/JSONWebToken.swift", + "installCommandMarkdown": [ + "pod 'JSONWebToken'" + ], + "stars": 758 + }, + { + "minimumVersion": null, + "support": { + "sign": true, + "verify": true, + "iss": true, + "sub": true, + "aud": true, + "exp": true, + "nbf": true, + "iat": true, + "jti": true, + "hs256": true, + "hs384": true, + "hs512": true, + "rs256": true, + "rs384": true, + "rs512": true, + "es256": true, + "es384": true, + "es512": true, + "ps256": false, + "ps384": false, + "ps512": false + }, + "authorUrl": "https://github.com/vapor", + "authorName": "Vapor", + "gitHubRepoPath": "vapor/jwt-kit", + "repoUrl": "https://github.com/vapor/jwt-kit", + "installCommandMarkdown": [ + ".package(url: \"https://github.com/vapor/jwt-kit.git\", from: \"4.0.0\")" + ], + "stars": 252 + } + ] + } +} diff --git a/scripts/updateStars.js b/scripts/updateStars.js new file mode 100644 index 00000000..3b456edc --- /dev/null +++ b/scripts/updateStars.js @@ -0,0 +1,36 @@ +import fs from "fs" +import path from "path" + +const filePath = path.join(process.cwd(), "/scripts/example-repos.json") +const reposGroup = JSON.parse(fs.readFileSync(filePath, "utf-8")) + +async function getStars(repoUrl) { + const match = repoUrl.match(/github\.com\/([^/]+)\/([^/]+)(?:\/|$)/) + if(!match) throw new Error(`Invalid github repo URL: ${repoUrl}`) + const [, owner, repo] = match + const res = await fetch(`https://api.github.com/repos/${owner}/${repo}`, { + headers: { + Accept: "application/vnd.github+json" + } + }) + if(!res.ok) throw new Error(`${repoUrl} -> ${res.status} ${res.statusText}`) + const data = await res.json() + return data.stargazers_count ?? null +} + +(async () => { + const objectEntries = Object.values(reposGroup) + for(const group of objectEntries) { + for(const lib of group.libs) { + try { + const stars = await getStars(lib.repoUrl) + lib.stars = stars + console.log(`✅ ${lib.repoUrl} -> ${stars}`) + } catch(e) { + lib.stars = null + console.error(`❌ ${lib.repoUrl}: ${e.message}`) + } + } + } + fs.writeFileSync(filePath, JSON.stringify(reposGroup, null, 2) + "\n") +})() \ No newline at end of file