Skip to content

Conversation

@yuanyuanxin
Copy link
Contributor

@yuanyuanxin yuanyuanxin commented Feb 4, 2026

Summary

修复固件 CHANGELOG 抓取逻辑,现在能正确从 wh110-firmware 仓库获取固件的 CHANGELOG。

变更内容

  • 配置文件新增 source_repo 字段:当输入的 repo 名与实际仓库名不同时使用
  • firmware 配置:source_repo: "wh110-firmware"changelog_path: "CHANGELOG.md"
  • 脚本更新:优先使用 source_repo 作为抓取 CHANGELOG 的目标仓库

测试结果

📥 正在获取 firmware v1.2.1 的 CHANGELOG(from wh110-firmware)...
✅ firmware v1.2.1: 已提取 CHANGELOG

Test plan

  • 本地测试 firmware CHANGELOG 抓取成功
  • 在 GitHub Actions 运行 dry run 验证

🤖 Generated with Claude Code

Summary by CodeRabbit

发布说明

  • 功能改进

    • 支持从指定的源仓库获取组件更新日志,并为固件组件添加了更新日志路径配置。
    • 新增按发布时间自动检测最新版本的流程(可通过发布日期驱动),自动将匹配的组件加入待处理列表。
  • 修复与增强

    • 改进日志与错误提示,包含来源仓库信息并对跳过原因给出明确说明。

- Add source_repo field to config for repos where input name differs from actual repo
- firmware now fetches CHANGELOG from wh110-firmware repo
- Update fetch script to use source_repo when fetching

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 4, 2026

Walkthrough

此 PR 为获取发布说明的脚本引入自动检测与源仓库识别:新增从 source_repo 获取最新 tag 的逻辑(含日期比较)、RELEASE_DATE 环境变量支持,并将 firmware 配置指向独立源仓库与明确的 CHANGELOG 路径。

Changes

Cohort / File(s) Summary
CHANGELOG 获取脚本
scripts/fetch-changelogs.py
新增 get_latest_tag_info(repo, token),加入 auto_detect 流程:从 source_repo 自动检测最新 tag 并按 RELEASE_DATE/日期匹配决定是否加入待抓取列表;统一使用 source_repo 拉取 changelog 并增强日志与错误说明。
发布说明配置
scripts/release-notes-config.json
firmware 项中新增 source_repo: "wh110-firmware"changelog_path: "CHANGELOG.md"auto_detect: true,将 changelog 来源显式指向独立仓库并启用自动检测。
CI 工作流
.github/workflows/collect-changelogs.yml
在“Fetch changelogs”步骤中传入 RELEASE_DATE 环境变量,使脚本可依据外部传入的发布日期执行基于日期的自动检测逻辑。

Sequence Diagram(s)

sequenceDiagram
    participant GHWF as GitHub Workflow
    participant Script as fetch-changelogs.py
    participant GitHubAPI as GitHub API
    participant Config as release-notes-config.json

    GHWF->>Script: 启动脚本 (RELEASE_DATE env)
    Script->>Config: 读取组件配置 (含 source_repo, auto_detect)
    Script->>GitHubAPI: get_latest_tag_info(source_repo, token)
    GitHubAPI-->>Script: 返回 tag 与 commit date
    Script->>Script: 比较 tag date 与 RELEASE_DATE / 最近两天
    alt 匹配
        Script->>Script: 将 repo+version 注入待抓取列表
    else 不匹配或异常
        Script-->>GHWF: 记录跳过原因(日志)
    end
    Script->>GitHubAPI: 拉取 source_repo 的 CHANGELOG.md
    GitHubAPI-->>Script: 返回 changelog 内容
    Script-->>GHWF: 输出并汇总抓取结果
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • chenjunnn
  • ThirteenLLB

Poem

🐇 小兔报喜:源仓整齐指新家,
自动寻标记,按日筛优雅,
CHANGELOG 从源头来报道,
日志明晰,跳过有解释,
发布更稳,兔儿咧嘴笑 🥕


Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore
❌ Failed checks (2 errors, 1 warning)
Check name Status Explanation Resolution
Pr Description ❌ Error PR描述满足Test Plan要求但缺少Feishu工作项ID引用,分支名为'fix/'形式不被豁免 请在PR描述中添加Feishu项目工作项ID的引用,格式为'm-'或'f-'
Branch Name ❌ Error 源分支名称 fix/firmware-changelog-fetch 不符合要求的模式 fix/f-<number>/<description>,缺少必需的编号前缀部分。 请将源分支重命名为 fix/f-<issue-number>/firmware-changelog-fetch 格式,其中 <issue-number> 为对应的问题编号。
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题'fix: enable firmware CHANGELOG fetching'遵循 Conventional Commits 格式,具体明确地描述了主要变更:修复固件CHANGELOG抓取功能。
Changelog ✅ Passed PR在CHANGELOG.md中添加了详细的用户面向改动记录,包括fetch-changelogs.py脚本和release-notes-config.json配置文件等功能,已按Keep a Changelog规范正确更新。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/firmware-changelog-fetch

Comment @coderabbitai help to get the list of available commands and usage tips.

- Add auto_detect flag in config for components without auto-release
- Script automatically checks if latest tag matches release date
- If match found, component is added to fetch list automatically
- Pass RELEASE_DATE env to fetch script in workflow
- Fix missing return in fetch_changelog_from_tag function

Now users don't need to manually specify firmware=x.x.x - it will be
auto-detected if the firmware repo has a matching tag.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@scripts/fetch-changelogs.py`:
- Around line 74-116: The function get_latest_tag_info contains leftover
decoding logic after its final return (including references to an undefined
symbol data and base64 decoding), which is unreachable and triggers Ruff F821;
remove the entire block starting from "content = data.get(...)" through the
final return so that get_latest_tag_info ends after "return version, date_str",
leaving no references to undefined variables or dead code.
- Line 214: Print call uses an f-string with no placeholders (the print(f"  ⚠️ 
未找到 tag,跳过", file=sys.stderr) occurrence) which triggers Ruff F541; change that
print to use a normal string literal (remove the f-prefix) so the message is
printed to stderr without an f-string.

Comment on lines +74 to +116
def get_latest_tag_info(repo, token):
"""
获取仓库最新 tag 的版本号和日期

Args:
repo: 仓库名
token: GitHub token

Returns:
(version, date_str) 元组,version 不含 v 前缀,date_str 为 YYYY-MM-DD 格式
如果没有 tag 则返回 (None, None)
"""
# 获取最新 tag
endpoint = f"/repos/{ORG}/{repo}/tags?per_page=1"
tags = github_api(endpoint, token)
if not tags:
return None, None

tag_name = tags[0]["name"]
version = tag_name.lstrip("v")

# 获取 tag 对应的 commit 日期
sha = tags[0]["commit"]["sha"]
commit_endpoint = f"/repos/{ORG}/{repo}/git/commits/{sha}"
commit_data = github_api(commit_endpoint, token)
if not commit_data:
return version, None

# 解析日期 (格式: 2026-02-02T01:46:19Z)
date_str = commit_data.get("committer", {}).get("date", "")[:10]
return version, date_str

content = data.get("content", "")
encoding = data.get("encoding", "")
if encoding == "base64":
try:
return base64.b64decode(content).decode("utf-8")
except UnicodeDecodeError:
print(f"⚠️ {repo}: CHANGELOG 非 UTF-8,已跳过", file=sys.stderr)
return None

print(f"⚠️ {repo}: 未知编码格式 {encoding}", file=sys.stderr)
return None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

删除 get_latest_tag_info 中残留的重复解码逻辑
该函数在 return 之后还有一段解码逻辑,且引用未定义的 data,会触发 Ruff F821 并可能导致 CI 失败。建议删除这段残留代码,避免误导后续维护。

建议修改
@@
     date_str = commit_data.get("committer", {}).get("date", "")[:10]
     return version, date_str
-
-    content = data.get("content", "")
-    encoding = data.get("encoding", "")
-    if encoding == "base64":
-        try:
-            return base64.b64decode(content).decode("utf-8")
-        except UnicodeDecodeError:
-            print(f"⚠️  {repo}: CHANGELOG 非 UTF-8,已跳过", file=sys.stderr)
-            return None
-
-    print(f"⚠️  {repo}: 未知编码格式 {encoding}", file=sys.stderr)
-    return None
🧰 Tools
🪛 Ruff (0.14.14)

[warning] 83-83: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF002)


[warning] 83-83: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF002)


[error] 106-106: Undefined name data

(F821)


[error] 107-107: Undefined name data

(F821)


[warning] 112-112: String contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF001)

🤖 Prompt for AI Agents
In `@scripts/fetch-changelogs.py` around lines 74 - 116, The function
get_latest_tag_info contains leftover decoding logic after its final return
(including references to an undefined symbol data and base64 decoding), which is
unreachable and triggers Ruff F821; remove the entire block starting from
"content = data.get(...)" through the final return so that get_latest_tag_info
ends after "return version, date_str", leaving no references to undefined
variables or dead code.


version, tag_date = get_latest_tag_info(source_repo, token)
if version is None:
print(f" ⚠️ 未找到 tag,跳过", file=sys.stderr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

移除无占位符的 f-string
此处 f-string 不含占位符,Ruff F541 会报错。直接使用普通字符串即可。

建议修改
-            print(f"  ⚠️  未找到 tag,跳过", file=sys.stderr)
+            print("  ⚠️  未找到 tag,跳过", file=sys.stderr)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
print(f" ⚠️ 未找到 tag,跳过", file=sys.stderr)
print(" ⚠️ 未找到 tag,跳过", file=sys.stderr)
🧰 Tools
🪛 Ruff (0.14.14)

[error] 214-214: f-string without any placeholders

Remove extraneous f prefix

(F541)


[warning] 214-214: String contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF001)

🤖 Prompt for AI Agents
In `@scripts/fetch-changelogs.py` at line 214, Print call uses an f-string with no
placeholders (the print(f"  ⚠️  未找到 tag,跳过", file=sys.stderr) occurrence) which
triggers Ruff F541; change that print to use a normal string literal (remove the
f-prefix) so the message is printed to stderr without an f-string.

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.

1 participant