-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
81 changed files
with
6,766 additions
and
14,225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/.svelte-kit | ||
/build | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,43 @@ | ||
module.exports = { | ||
// @ts-check | ||
|
||
/** @type {import('eslint').Linter.Config} */ | ||
const config = { | ||
root: true, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:@typescript-eslint/stylistic', | ||
'plugin:svelte/recommended', | ||
'prettier' | ||
], | ||
plugins: ['@typescript-eslint', 'svelte'], | ||
parser: '@typescript-eslint/parser', | ||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'], | ||
plugins: ['svelte3', '@typescript-eslint'], | ||
ignorePatterns: ['*.cjs'], | ||
overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }], | ||
settings: { | ||
'svelte3/typescript': () => require('typescript') | ||
}, | ||
parserOptions: { | ||
project: true, | ||
sourceType: 'module', | ||
ecmaVersion: 2019 | ||
ecmaVersion: 2022, | ||
extraFileExtensions: ['.svelte'] | ||
}, | ||
env: { | ||
browser: true, | ||
es2017: true, | ||
es2022: true, | ||
node: true | ||
}, | ||
overrides: [ | ||
{ | ||
files: ['*.svelte'], | ||
parser: 'svelte-eslint-parser', | ||
parserOptions: { | ||
parser: '@typescript-eslint/parser' | ||
} | ||
} | ||
], | ||
rules: { | ||
'@typescript-eslint/array-type': 'off', | ||
'@typescript-eslint/consistent-type-definitions': 'off', | ||
'svelte/no-at-html-tags': 'off', | ||
'svelte/valid-compile': 'off' | ||
} | ||
}; | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: Update stars | ||
description: Update Github stars count | ||
inputs: | ||
token: | ||
description: GitHub token for GraphQL calls | ||
required: false | ||
runs: | ||
using: node20 | ||
main: 'main.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
import core from '@actions/core'; | ||
import { readFileSync, writeFileSync } from 'node:fs'; | ||
import { fetch } from 'undici'; | ||
|
||
const ghGraphQlUrl = 'https://api.github.com/graphql'; | ||
const gitlabGraphQlUrl = 'https://gitlab.com/api/graphql'; | ||
const githubNameRegexp = new RegExp( | ||
'https://github.com/([a-zA-Z0-9][a-zA-Z0-9-]{0,38}/[a-zA-Z0-9._-]{1,100})' | ||
); | ||
const gitlabNameRegExp = new RegExp('https://gitlab.com/([\\w-]+/[\\w-]+)'); | ||
|
||
async function doGraphQlQuery(url, query, headers = {}) { | ||
try { | ||
let fetchResponse = await fetch(url, { | ||
body: JSON.stringify({ query }), | ||
method: 'POST', | ||
headers: { | ||
'content-type': 'application/json', | ||
...headers | ||
} | ||
}); | ||
let data = await fetchResponse.json(); | ||
return Object.values(data.data || {}); | ||
} catch (e) { | ||
console.error(e.message); | ||
} | ||
return []; | ||
} | ||
|
||
function gatherUrls() { | ||
let components = JSON.parse(readFileSync('src/routes/components/components.json')); | ||
let tools = JSON.parse(readFileSync('src/routes/tools/tools.json')); | ||
let templates = JSON.parse(readFileSync('src/routes/templates/templates.json')); | ||
|
||
return [ | ||
...components.map((component) => component.repository), | ||
...tools.map((tool) => tool.repository), | ||
...templates.map((template) => template.repository) | ||
]; | ||
} | ||
|
||
// Github | ||
|
||
/** | ||
* Get all GitHub repositories | ||
* @returns {Array<{owner: string, repo: string}>} | ||
*/ | ||
function getAllGHRepos() { | ||
return gatherUrls() | ||
.filter((url) => url !== false && githubNameRegexp.test(url)) | ||
.map((gitHubUrl) => gitHubUrl.match(githubNameRegexp)[1].toLowerCase()) | ||
.map((validName) => ({ owner: validName.split('/')[0], repo: validName.split('/')[1] })); | ||
} | ||
|
||
function ghRepoGraphQl({ owner, repo }) { | ||
let identifier = owner + '_' + repo + '_' + Math.random() + ''; | ||
identifier = identifier.replace(/[^a-zA-Z0-9_]/g, '_'); | ||
identifier = identifier.replace(/^[0-9]/g, '_'); | ||
return `${identifier}: repository(name: "${repo}", owner: "${owner}"){nameWithOwner stargazerCount}`; | ||
} | ||
|
||
/** | ||
* Divide an array into multiple smaller array | ||
* @param {Array} input | ||
* @param {number} size | ||
* @return {Array<Array>} | ||
*/ | ||
function chunk(input, size) { | ||
size = size < 1 ? 10 : size; | ||
const pages = Math.ceil(input.length / size); | ||
const final = []; | ||
for (let index = 0; index < pages; index++) { | ||
final.push(input.slice(index * size, (index + 1) * size)); | ||
} | ||
return final; | ||
} | ||
|
||
/** | ||
* Get the number of stars for all GitHub repositories. | ||
* The result is a Map where the key the repo name and the value is the number of stars. | ||
* @returns {Promise<Record<string, number>>} | ||
*/ | ||
async function getGHStars() { | ||
const repoData = getAllGHRepos(); | ||
core.info('Found ' + repoData.length + ' repositories'); | ||
const pagedRepoData = chunk(repoData, 100); | ||
const pageCount = pagedRepoData.length; | ||
core.debug('Divide the repositories into ' + pageCount + ' pages (of 100 repositories)'); | ||
let lines = []; | ||
for (let index = 0; index < pageCount; index++) { | ||
const page = pagedRepoData[index]; | ||
core.debug('Running GraphQL for page ' + (index + 1) + '/' + pageCount); | ||
let body = | ||
'query{' + '\n' + page.map((repoInfo) => ghRepoGraphQl(repoInfo)).join('\n') + '\n' + '}'; | ||
lines = [ | ||
...lines, | ||
...(await doGraphQlQuery(ghGraphQlUrl, body, { | ||
authorization: | ||
'Bearer ' + | ||
core.getInput('token', { | ||
// required: true, | ||
trimWhitespace: true | ||
}) | ||
})) | ||
]; | ||
} | ||
return Object.fromEntries( | ||
lines | ||
.filter((line) => line?.nameWithOwner) | ||
.map((line) => [line.nameWithOwner.toLowerCase(), line.stargazerCount]) | ||
.sort() | ||
); | ||
} | ||
|
||
// Gitlab | ||
|
||
/** | ||
* Get all GitLab repositories path (relative to GitLab root) | ||
* @returns {Array<string>} | ||
*/ | ||
function getAllGitlabRepos() { | ||
return gatherUrls() | ||
.filter((url) => url !== false && gitlabNameRegExp.test(url)) | ||
.map((url) => url.match(gitlabNameRegExp)[1]); | ||
} | ||
|
||
function gitlabRepoGraphQl(name) { | ||
let identifier = name + '_' + Math.random() + ''; | ||
identifier = identifier.replace(/[^a-zA-Z0-9_]+/g, '_'); | ||
identifier = identifier.replace(/^[0-9]/g, '_'); | ||
return `${identifier}: project(fullPath: "${name}"){starCount fullPath}`; | ||
} | ||
|
||
/** | ||
* Get the number of stars for all Gitlab repositories. | ||
* The result is a Map where the key the repo name and the value is the number of stars. | ||
* @returns {Promise<Record<string, number>>} | ||
*/ | ||
async function getGitlabStars() { | ||
const repoData = getAllGitlabRepos(); | ||
core.info('Found ' + repoData.length + ' repositories'); | ||
const pagedRepoData = chunk(repoData, 100); | ||
const pageCount = pagedRepoData.length; | ||
core.debug('Divide the repositories into ' + pageCount + ' pages (of 100 repositories)'); | ||
let lines = []; | ||
for (let index = 0; index < pageCount; index++) { | ||
const page = pagedRepoData[index]; | ||
core.debug('Running GraphQL for page ' + (index + 1) + '/' + pageCount); | ||
const body = | ||
'query{' + '\n' + page.map((repoInfo) => gitlabRepoGraphQl(repoInfo)).join('\n') + '\n' + '}'; | ||
lines = [...lines, ...(await doGraphQlQuery(gitlabGraphQlUrl, body))]; | ||
} | ||
return Object.fromEntries( | ||
lines | ||
.filter((line) => line?.fullPath) | ||
.map((line) => [line.fullPath.toLowerCase(), line.starCount]) | ||
.sort() | ||
); | ||
} | ||
|
||
async function main() { | ||
core.startGroup('GitHub'); | ||
const github = await getGHStars(); | ||
core.endGroup(); | ||
|
||
core.startGroup('GitLab'); | ||
const gitlab = await getGitlabStars(); | ||
core.endGroup(); | ||
|
||
core.info( | ||
`\tGithub: ${Object.keys(github).length} repositories (${Object.values(github).reduce( | ||
(count, item) => count + item, | ||
0 | ||
)} stars)` | ||
); | ||
core.info( | ||
`\tGitlab: ${Object.keys(gitlab).length} repositories (${Object.values(gitlab).reduce( | ||
(count, item) => count + item, | ||
0 | ||
)} stars)` | ||
); | ||
writeFileSync('src/lib/stars.json', JSON.stringify({ github, gitlab })); | ||
} | ||
|
||
try { | ||
core.info('Start'); | ||
main().then(() => core.info('Done')); | ||
} catch (error) { | ||
core.setFailed(error); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Update stars count | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 * * 0' # At 00:00 on Sunday. | ||
workflow_dispatch: | ||
|
||
jobs: | ||
update: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: pnpm/action-setup@v2 | ||
with: | ||
version: 8 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: .nvmrc | ||
cache: 'pnpm' | ||
- name: Install dependencies | ||
run: pnpm install | ||
- name: Run script | ||
uses: ./.github/actions/update-stars | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Run format | ||
run: pnpm run format | ||
- name: Create Pull Request | ||
uses: peter-evans/create-pull-request@v5 | ||
with: | ||
commit-message: "(AUTO) Update stars" | ||
title: "🤖 Update stars" | ||
body: Update all stars count from Github and Gitlab | ||
branch: ci-update-stars | ||
add-paths: src/lib/stars.json | ||
delete-branch: true | ||
token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
20 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.