当前位置: 首页 > news >正文

Repository Contribution Count Action:开源贡献者的专属统计神器

作为一名开源贡献者,你是否曾为如何展示自己在各大项目中的贡献而烦恼?手动统计 PR 和 Commits 数量不仅费时费力,而且难以保持实时更新。今天给大家介绍一款 GitHub Action 工具 —— Repository Contribution Count Action,它可以自动统计你在指定仓库中的贡献数量,并生成美观的图标徽章,让你的开源成就一目了然。

在这里插入图片描述

什么是 Repository Contribution Count Action?

Repository Contribution Count Action 是一个专门用于统计用户在 GitHub 仓库中 PR 或 Commits 数量并生成图标展示的 GitHub Action。它能够帮助开发者自动化展示自己在开源社区的贡献,适用于个人 Profile 页面、项目文档、技术博客等多种场景。

核心功能特性

📊 多维度贡献统计

  • 支持 PR 和 Commits 两种贡献类型的统计
  • 自动解析多种 GitHub 链接格式
  • 支持批量输入多个仓库链接

🎨 美观的可视化展示

  • 基于 shields.io 生成专业级徽章
  • 智能颜色分级(根据贡献数量自动选择颜色)
  • 支持 5 种徽章样式(flat、flat-square、plastic、for-the-badge、social)

🔄 灵活的排序与输出

  • 支持按贡献数量排序(从高到低)
  • 提供 Markdown、HTML、JSON 三种输出格式
  • 自动生成统计摘要信息

适用人群

这款工具特别适合以下人群:

  1. 开源贡献者:想要展示自己在各大开源项目中的贡献
  2. 技术博主:在个人简介中展示技术实力
  3. 求职者:在简历或个人主页中突出开源经历
  4. 团队负责人:统计团队成员的开源贡献情况
  5. 开源项目维护者:展示项目贡献者排行榜

使用方法

1. 基础配置

在你的 GitHub 仓库中创建一个工作流文件 .github/workflows/contribution-stats.yml

name: Update Contribution Statson:schedule:- cron: '0 16 * * *' # 每日北京时间晚上12点更新 (UTC+8,所以是UTC 16:00)workflow_dispatch: # 支持手动触发jobs:update-stats:runs-on: ubuntu-lateststeps:- name: Checkout Profile Repouses: actions/checkout@v4with:repository: your-username/your-usernametoken: ${{ secrets.GITHUB_TOKEN }}- name: Generate Contribution Statisticsid: statsuses: lxKylin/repo-contribution-count-action@v1.1.0with:pr-links: |https://github.com/vitejs/docs-cn/commits?author=your-usernamehttps://github.com/vitest-dev/docs-cn/commits?author=your-usernamehttps://github.com/your-org/your-project/pulls?q=is%3Apr+author%3Ayour-usernamegithub-token: ${{ secrets.GITHUB_TOKEN }}badge-style: 'flat'output-format: 'markdown'sort-by-count: 'true'- name: Update Profile READMErun: |echo "开始更新 README.md..."# 检查当前目录内容echo "当前目录内容:"ls -la# 检查 README.md 是否存在标记echo "检查 README.md 中的标记..."grep -n "PR_STATS" README.md || echo "未找到标记"# 创建临时文件包含新的内容cat > temp_stats.md << 'EOF'<!-- PR_STATS_START -->### 我的开源贡献(由 [repo-contribution-count-action](https://github.com/lxKylin/repo-contribution-count-action) 生成)${{ steps.stats.outputs.badges }}> ${{ steps.stats.outputs.summary }}<!-- PR_STATS_END -->EOFecho "临时文件内容:"cat temp_stats.md# 使用 awk 替换 README.md 中指定部分的内容awk 'BEGIN { in_section = 0; found_start = 0 }/<!-- PR_STATS_START -->/ {if (!found_start) {found_start = 1in_section = 1while ((getline line < "temp_stats.md") > 0) {print line}close("temp_stats.md")next}}/<!-- PR_STATS_END -->/ {if (in_section) {in_section = 0next}}!in_section { print }' README.md > README_new.md# 检查文件是否生成成功if [ -f README_new.md ]; thenecho "README_new.md 生成成功"echo "文件大小对比:"wc -l README.md README_new.mdmv README_new.md README.mdecho "README.md 更新完成"elseecho "ERROR: README_new.md 生成失败"exit 1fi# 清理临时文件rm -f temp_stats.md# 显示更新后的文件内容(前20行)echo "更新后的 README.md 前20行:"head -20 README.md- name: Commit and Pushrun: |echo "检查文件更改..."git status# 检查是否有更改if git diff --quiet README.md; thenecho "README.md 没有变化,跳过提交"elseecho "README.md 有更改,准备提交..."git config --local user.email "action@github.com"git config --local user.name "GitHub Action"git add README.mdgit commit -m "refactor: 更新 PR 统计数据 $(date '+%Y-%m-%d %H:%M:%S')"git pushecho "提交完成!"fi

2. 在 README 中展示

在你的 README.md 文件中添加标记:

<!-- PR_STATS_START --><!-- PR_STATS_END -->

可参照示例来使用

配置参数详解

参数名是否必需默认值说明
pr-links-PR 或 Commits 链接列表,用换行符分隔
github-token-GitHub token,用于访问 GitHub API
badge-styleflat图标样式
output-formatmarkdown输出格式
sort-by-counttrue是否按贡献数量排序
include-merge-commitstrue是否包含 Merge commits

输出结果示例

Action 执行后会生成三个输出:

  1. badges: 格式化的徽章代码
  2. summary: 统计摘要,如"总计在 3 个仓库中创建了 25 个 PRs"
  3. repo-counts: JSON 格式的详细数据

徽章展示效果

Markdown形式
![Total PRs](https://img-home.csdnimg.cn/images/20230724024159.png?origin_url=https%3A%2F%2Fimg.shields.io%2Fbadge%2FTotal%2520PRs-25%2520in%25203%2520repos-brightgreen%3Fstyle%3Dflat&pos_id=img-SkNRt1mV-1760146670769))[![microsoft/vscode PRs](https://img-home.csdnimg.cn/images/20230724024159.png?origin_url=https%3A%2F%2Fimg.shields.io%2Fbadge%2Fmicrosoft%252Fvscode-15%2520PRs-brightgreen%3Fstyle%3Dflat&pos_id=img-WVMDkoY5-1760146671139))](https://github.com/microsoft/vscode)[![facebook/react PRs](https://img-home.csdnimg.cn/images/20230724024159.png?origin_url=https%3A%2F%2Fimg.shields.io%2Fbadge%2Ffacebook%252Freact-8%2520PRs-green%3Fstyle%3Dflat&pos_id=img-bF3tHo5y-1760146671549))](https://github.com/facebook/react)[![vercel/next.js PRs](https://img-home.csdnimg.cn/images/20230724024159.png?origin_url=https%3A%2F%2Fimg.shields.io%2Fbadge%2Fvercel%252Fnext.js-2%2520PRs-green%3Fstyle%3Dflat&pos_id=img-o3XmH6WJ-1760146672048))](https://github.com/vercel/next.js)[![vitejs/docs-cn PRs](https://img-home.csdnimg.cn/images/20230724024159.png?origin_url=https%3A%2F%2Fimg.shields.io%2Fstatic%2Fv1%3Flabel%3Dvitejs%252Fdocs-cn%26message%3D31%2BPRs%26color%3Dorange%26style%3Dflat&pos_id=img-0025lrjG-1760146672472))](https://github.com/vitejs/docs-cn)[![vitest-dev/docs-cn PRs](https://img-home.csdnimg.cn/images/20230724024159.png?origin_url=https%3A%2F%2Fimg.shields.io%2Fstatic%2Fv1%3Flabel%3Dvitest-dev%252Fdocs-cn%26message%3D54%2BPRs%26color%3Dred%26style%3Dflat&pos_id=img-qqzqMisK-1760146672880))](https://github.com/vitest-dev/docs-cn)

在这里插入图片描述

HTML形式
<imgsrc="https://img-home.csdnimg.cn/images/20230724024159.png?origin_url=https%3A%2F%2Fimg.shields.io%2Fbadge%2FTotal%2520PRs-25%2520in%25203%2520repos-brightgreen%3Fstyle%3Dflat&pos_id=img-SkNRt1mV-1760146670769)"alt="Total PRs"
/>
<a href="https://github.com/microsoft/vscode"><imgsrc="https://img-home.csdnimg.cn/images/20230724024159.png?origin_url=https%3A%2F%2Fimg.shields.io%2Fbadge%2Fmicrosoft%252Fvscode-15%2520PRs-brightgreen%3Fstyle%3Dflat&pos_id=img-WVMDkoY5-1760146671139)"alt="microsoft/vscode PRs"/>
</a>
<a href="https://github.com/facebook/react"><imgsrc="https://img-home.csdnimg.cn/images/20230724024159.png?origin_url=https%3A%2F%2Fimg.shields.io%2Fbadge%2Ffacebook%252Freact-8%2520PRs-green%3Fstyle%3Dflat&pos_id=img-bF3tHo5y-1760146671549)"alt="facebook/react PRs"/>
</a>
<a href="https://github.com/vercel/next.js"><imgsrc="https://img-home.csdnimg.cn/images/20230724024159.png?origin_url=https%3A%2F%2Fimg.shields.io%2Fbadge%2Fvercel%252Fnext.js-2%2520PRs-green%3Fstyle%3Dflat&pos_id=img-o3XmH6WJ-1760146672048)"alt="vercel/next.js PRs"/>
</a>
<a href="https://github.com/vitejs/docs-cn"><imgsrc="https://img-home.csdnimg.cn/images/20230724024159.png?origin_url=https%3A%2F%2Fimg.shields.io%2Fstatic%2Fv1%3Flabel%3Dvitejs%252Fdocs-cn%26message%3D31%2BPRs%26color%3Dorange%26style%3Dflat&pos_id=img-0025lrjG-1760146672472)"alt="vitejs/docs-cn PRs"/>
</a>
<a href="https://github.com/vitest-dev/docs-cn"><imgsrc="https://img-home.csdnimg.cn/images/20230724024159.png?origin_url=https%3A%2F%2Fimg.shields.io%2Fstatic%2Fv1%3Flabel%3Dvitest-dev%252Fdocs-cn%26message%3D54%2BPRs%26color%3Dred%26style%3Dflat&pos_id=img-qqzqMisK-1760146672880)"alt="vitest-dev/docs-cn PRs"/>
</a>

在这里插入图片描述

高级用法

自定义样式

支持多种徽章样式,适用于不同场景:

# 扁平方形样式
badge-style: 'flat-square'# 大型徽章样式(适合重要展示)
badge-style: 'for-the-badge'# 社交媒体样式
badge-style: 'social'

多格式输出

根据不同使用场景选择合适的输出格式:

# Markdown 格式(适合 README 文件)
output-format: 'markdown'# HTML 格式(适合网页展示)
output-format: 'html'# JSON 格式(适合程序处理)
output-format: 'json'

最佳实践建议

🔒 安全性

  • 使用 GitHub 提供的 GITHUB_TOKEN 而非个人访问令牌
  • 对于私有仓库,确保 token 具有足够权限

⚡ 性能优化

  • 合理设置更新频率,避免过于频繁的 API 调用
  • 对于大量仓库的统计,考虑分批处理

🎨 展示效果

  • 根据展示环境选择合适的徽章样式
  • 利用排序功能突出重要贡献

技术实现亮点

智能链接解析

Action 采用了强大的正则表达式引擎,能够解析多种 GitHub 链接格式:

// 支持的链接类型
// 1. Commits 链接
https://github.com/vitejs/docs-cn/commits?author=lxKylin// 2. PR 搜索链接
https://github.com/vitejs/docs-cn/pulls?q=is%3Apr+author%3AlxKylin

高效的 API 调用

为了避免 GitHub API 限制,Action 实现了分页查询和智能延迟机制。

灵活的徽章生成

基于 shields.io 服务的徽章生成器支持动态颜色映射和多样式支持。

结语

Repository Contribution Count Action 不仅是一个简单的统计工具,更是开源贡献者展示成就、团队管理者追踪进度、项目维护者了解社区的得力助手。通过自动化的方式,它让开源贡献的价值得到更好的体现和认可。如果对你有帮助,欢迎点个🌟!

这是一个开源项目,欢迎社区贡献:

  • 功能建议和改进意见
  • 代码优化和bug修复
  • 文档完善和示例补充
  • 新功能开发

项目地址:Repository Contribution Count Action

立即开始使用:查看 详细文档 和 使用示例

http://www.dtcms.com/a/470285.html

相关文章:

  • B4414 [GESP202509 三级] 日历制作
  • 手机网站分页设计广州网站推广排名
  • 基于 EtherCAT 转 MODBUS RS485 的轧辊轴承智能温控系统应用
  • oa报表网站开发工作室设计
  • vue3中图片裁切组件封装
  • 从 0 到 1 搭建 Python 语言 Web UI自动化测试学习系列 15--二次开发--封装公共方法 3
  • 做新媒体文的网站网站开发 ppt
  • 东莞市建设局网站电子商务网站建设教程 pdf
  • numpy第三方库学习(更新中)
  • 【开题答辩全过程】以 报考意向分析系统为例,包含答辩的问题和答案
  • Spring AI
  • ssm速通1(2/2)
  • Android GPS定位与行车轨迹追踪完整实战
  • [持续更新] HPC高性能计算CUDA/C++面试知识点
  • 【有源码】基于Hadoop生态的大数据共享单车数据分析与可视化平台-基于Python与大数据的共享单车多维度数据分析可视化系统
  • 上海做网站推荐做景观要用的植物网站
  • 珠海 网站建设和推广万网网站空间
  • Jasperreport 导出word 多个element重叠部分导致不显示(不支持)
  • GRU(门控循环单元) 笔记
  • 莱州网站建设哪家好做网站要会哪些知识
  • ubuntu离线安装 xl2tpd
  • 如何在百度上做网站最好用的免费建站
  • 关联网站有那些wordpress超级排版器插件
  • 熊猫比分 APP:开启体育赛事观赛新“姿势”
  • 第二章:模块的编译与运行-9 Platform Dependency
  • java多模块概念
  • 小企业网站维护什么东西互联网培训
  • 找人做网站做的很烂网站自助建设推广
  • uhttpd HTTPS 在嵌入式与 OpenWrt 上的实战部署与排查
  • 合肥网站建设正规公司抖音如何推广引流