修复贡献者查询,支持排除指定仓库

This commit is contained in:
2025-04-14 21:14:54 +08:00
parent 017bc570a7
commit 32d29ac031
5 changed files with 26 additions and 8 deletions

View File

@@ -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

5
.gitignore vendored
View File

@@ -1,3 +1,8 @@
node_modules
.DS_Store
lib
# IDE setting files
.idea
!.idea/icon.png
.vscode

View File

@@ -137,6 +137,9 @@ export async function fetchContributorsInfo(params: {
const allContributorsInfos = new Map<string, ContributorsInfo>()
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, {

View File

@@ -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 <token>', 'Personal GitHub token', defaultToken)
.option('-o, --owner <owner>', 'Repo owner name', defaultOwner)
.option('-r, --repo <repo>', 'GitHub repo path', defaultRepoName)
.option('-t, --token <token>', 'Personal GitHub token')
.option('-o, --owner <owner>', 'Repo owner name')
.option('-r, --repo <repo>', 'GitHub repo path')
.option('-e, --exclude <exclude>', 'Exclude gitHub repo path')
.option('-s, --size <size>', 'Single avatar block size (pixel)', "120")
.option('-w, --width <width>', 'Output image width (pixel)', "1000")
.option('-c, --count <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<string, ContributorsInfo>()
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]
}
});
}

View File

@@ -2,6 +2,7 @@ export interface CliOptions {
token: string // Github access token
owner: string
repo: string
exclude: string
size: string
width: string
count: string