From 32d29ac03170272fd4af6d9b958c26add4690334 Mon Sep 17 00:00:00 2001 From: Charles7c Date: Mon, 14 Apr 2025 21:14:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B4=A1=E7=8C=AE=E8=80=85?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=EF=BC=8C=E6=94=AF=E6=8C=81=E6=8E=92=E9=99=A4?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E4=BB=93=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../workflows/update-continew-contribs.yaml | 2 +- .gitignore | 5 ++++ src/fetch.ts | 3 +++ src/main.ts | 23 +++++++++++++------ src/types.ts | 1 + 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/.github/workflows/update-continew-contribs.yaml b/.github/workflows/update-continew-contribs.yaml index 522b701..d95cea5 100644 --- a/.github/workflows/update-continew-contribs.yaml +++ b/.github/workflows/update-continew-contribs.yaml @@ -40,7 +40,7 @@ jobs: run: pnpm install - name: Run generation script - run: pnpm tsx src/main.ts -t ${{ secrets.TOKEN }} -o continew-org + run: pnpm tsx src/main.ts -t ${{ secrets.TOKEN }} -o continew-org -e continew-cloud - name: Copy uses: appleboy/scp-action@v0.1.7 diff --git a/.gitignore b/.gitignore index 32434a3..762ce22 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ node_modules .DS_Store lib + +# IDE setting files +.idea +!.idea/icon.png +.vscode \ No newline at end of file diff --git a/src/fetch.ts b/src/fetch.ts index 8d8f8c5..bd6268b 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -137,6 +137,9 @@ export async function fetchContributorsInfo(params: { const allContributorsInfos = new Map() contributorsData.forEach(contributor => { const [userName, avatarURL] = [contributor.login, contributor.avatar_url] + if (!userName || !avatarURL) { + return + } const userInfoByName = allContributorsInfos.get(userName) if (!userInfoByName) { allContributorsInfos.set(userName, { diff --git a/src/main.ts b/src/main.ts index 21f21d4..e447762 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,16 +8,17 @@ import type { CliOptions, RepoInfo, ContributorsInfo } from './types' async function main() { - const { Github_token: defaultToken, Github_owner: defaultOwner } = process.env - const defaultRepoName = await getRepoName() + // const { Github_token: defaultToken, Github_owner: defaultOwner } = process.env + // const defaultRepoName = await getRepoName() const GITHUBReg = /https:\/\/github.com\/([\w\-_]+)\/([\w\-_]+)/ let urlInfo = null program .name('gh-contrib-svg') .arguments('[url]') - .option('-t, --token ', 'Personal GitHub token', defaultToken) - .option('-o, --owner ', 'Repo owner name', defaultOwner) - .option('-r, --repo ', 'GitHub repo path', defaultRepoName) + .option('-t, --token ', 'Personal GitHub token') + .option('-o, --owner ', 'Repo owner name') + .option('-r, --repo ', 'GitHub repo path') + .option('-e, --exclude ', 'Exclude gitHub repo path') .option('-s, --size ', 'Single avatar block size (pixel)', "120") .option('-w, --width ', 'Output image width (pixel)', "1000") .option('-c, --count ', 'Avatar count in one line', "8") @@ -34,7 +35,7 @@ async function main() { }) .parse(process.argv) const options = Object.assign(program.opts(), urlInfo) - const { token, repo, owner, size: avatarBlockSize, width, count: lineCount } = options as CliOptions + const { token, repo, owner, exclude, size: avatarBlockSize, width, count: lineCount } = options as CliOptions if (token && owner) { let repos: RepoInfo[] = [] @@ -55,9 +56,17 @@ async function main() { const startTime = performance.now() const allContributorsInfos = new Map() for (const { owner, repo } of repos) { + if (exclude && repo === exclude) { + continue + } const contributorsInfos = await fetchContributorsInfo({ token, repo, owner }); contributorsInfos.forEach((info, username) => { - allContributorsInfos.set(username, info); + const userInfoByName = allContributorsInfos.get(username) + if (!userInfoByName) { + allContributorsInfos.set(username, info) + } else { + userInfoByName.commitURLs = [...userInfoByName.commitURLs, ...info.commitURLs] + } }); } diff --git a/src/types.ts b/src/types.ts index a38de1c..c3ea3fe 100644 --- a/src/types.ts +++ b/src/types.ts @@ -2,6 +2,7 @@ export interface CliOptions { token: string // Github access token owner: string repo: string + exclude: string size: string width: string count: string