Skip to content

[WIP] Update workflow to include clone, fork, and star metrics#113

Draft
Copilot wants to merge 1 commit intomainfrom
copilot/update-repo-clone-stats-workflow
Draft

[WIP] Update workflow to include clone, fork, and star metrics#113
Copilot wants to merge 1 commit intomainfrom
copilot/update-repo-clone-stats-workflow

Conversation

Copy link

Copilot AI commented Feb 28, 2026

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

Original prompt

目标:把现有工作流 .github/workflows/repo-clone-stats.yml 从“仅 clone badge + gist”升级为:每日采样并生成 clone/fork/star 三指标全量历史折线统计图(SVG),保存到仓库 stats/ 目录,并自动更新 README.md 引用该 SVG。

仓库信息:UFund-Me/Qbot
需要修改的源文件:.github/workflows/repo-clone-stats.yml
源文件 URL: https://github.com/UFund-Me/Qbot/blob/main/.github/workflows/repo-clone-stats.yml
参考 CommitOID:cf0c9ee786b0b539803787c26e628172d9480758

功能需求(必须满足):

  1. 全量历史:每次 workflow 运行时,将当天的统计点追加到一个历史数据文件(建议 JSON 或 CSV),从启用之日起长期累积。
  2. 三条折线、一张图:生成单个 stats/metrics.svg(或类似命名),包含 clones / forks / stars 三条折线,带简单图例与坐标(至少能区分三条线)。
  3. 数据来源
    • clones:使用 GitHub Traffic API GET /repos/{owner}/{repo}/traffic/clones 获取(注意该 API 仅返回最近 14 天,因此需要每日采样并存档到仓库数据文件中)。应选择一个一致的度量(例如 daily count 之和、或当天 count/uniques),并在 README 中说明或在图例/标题中标注。
    • forks/stars:使用 GitHub API 获取仓库当前累计 forks_countstargazers_count,每日记录一个点,形成时间序列。
  4. 仓库落盘:允许新增 stats/ 目录,至少包含:
    • stats/metrics.json(或 stats/metrics.csv)历史数据
    • stats/metrics.svg 折线图
  5. 更新 README:在 README.md 中添加/更新一段内容,展示该 SVG(例如 ![Repo stats](stats/metrics.svg)),并确保相对路径有效。
  6. 自动提交:workflow 需要在生成/更新 stats/* 与 README 后,自动 commit 并 push 回 main(或默认分支)。
  7. 安全与权限
    • 尽量避免使用 gist 与 gh secret set 这类会修改 secrets 的行为。
    • 读取 traffic clones 可能需要 PAT(现有 secrets.SECRET_TOKEN 可继续使用),但 push 回仓库使用 GITHUB_TOKEN
    • Workflow 需声明 permissions: contents: write(以及如需要的其他最小权限)。
  8. 兼容性:使用 actions/checkout@v4;避免已弃用的 set-output 语法,改用 $GITHUB_OUTPUT
  9. 可维护性:把生成 SVG 的逻辑放在仓库脚本中(如 scripts/generate_repo_stats.py),workflow 只负责安装依赖/运行脚本。

实现建议(可调整):

  • 新增脚本 scripts/update_repo_stats.py
    • 读取 stats/metrics.json(若不存在则初始化)
    • 拉取 clones(最近 14 天)并取“当天”数据点(按 UTC 日期),保存为 clones 值;如当天数据缺失则可用 0 或跳过(需说明策略)。
    • 拉取仓库信息得到 forks/stars 当前累计值
    • {date, clones, forks, stars} 追加(若当天已存在则覆盖更新)
    • 调用/包含 SVG 生成函数,输出 stats/metrics.svg
  • 新增脚本 scripts/render_svg.py 或集成在同一脚本里:
    • 读取全量历史数据,按日期排序
    • 生成基础折线图 SVG(固定宽高、padding、axis、三条折线不同颜色、图例)。
    • 简化坐标:可对 y 进行归一化或同轴展示;但要可读,优先同轴(值量级不同可做双轴或归一化并标注)。在 PR 中写清取舍。
  • 更新 workflow:
    • cron:将 0 */24 * * * 改为更标准的每日一次,如 0 0 * * *(UTC)。
    • 使用 curl -H "Authorization: Bearer $TOKEN" + Accept 获取 API。
    • 安装 python3(ubuntu-latest 自带),必要时 pip install(尽量零依赖)。
    • git commit 条件:只有在 git status --porcelain 非空时才提交。

验收标准:

  • 合并后,workflow 每日运行会在 stats/metrics.json 追加当天数据并更新 stats/metrics.svg
  • README 能正确展示折线 SVG。
  • 不再依赖 gist 存储与 badge 逻辑;原逻辑可删除或保留但默认不用(建议清理)。

用户要求:

  • 时间范围:全量
  • 图表:一张 SVG 三条线
  • 允许新增 stats/ 并提交

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@triangle959
Copy link

triangle959 commented Feb 28, 2026 via email

@sonarqubecloud
Copy link

@Charmve
Copy link
Member

Charmve commented Feb 28, 2026

@copilot Please proceed to implement the changes and push commits to this PR branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants