fix: correct semver compare and cross-year date matching - #20
Merged
Conversation
- auto_version: compare versions via int tuples instead of stripping dots, which mis-ordered multi-digit segments (e.g. 0.2.15 vs 0.3.0). - get_post_index_range: compare PTT list_date (yearless M/DD) by (month, day) only, so a target date carrying a non-current year no longer fails to match. Cross-year ranges remain unsupported (noted). - Add assert-based self-checks for both. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
CI runs flake8/mypy over the whole repo. The module-level sys.modules stubbing before importing api_post triggered E402. Move it into a helper function (function-level import is exempt) and use setattr for the stub attribute to keep mypy's warn_unused_ignores happy. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修掉的 bug
1.
auto_version.py版本比較錯誤原本
int(v.replace('.', ''))把點去掉轉 int 不是正確的 semver 比較,各段位數不同時會誤判:0.3.0→30vs0.2.15→215→ 誤判0.2.15較新1.0.0→100vs0.20.0→200→ 誤判0.20.0較新CI 用
python src/auto_version.py的 stdout 決定要不要 rebuild / 打哪個 tag,遲早選錯版本。改用_version_key()以 int tuple 比較,stdout 行為不變。2.
get_post_index_range跨年日期永遠對不上PTT
list_date是無年份的M/DD,parse_date_str一律補當年;若 target 帶非當年年份(docstring 範例就是1987/09/06),post_date == target_date永遠 False → 一律回報「找不到文章」。改成所有比較只比
(month, day)(兩段 binary search + 兩段 verification 全改)。已知上限(已用
ponytail:註解標明,本次不處理)low = mid + 1的 best-effort 行為未動。測試
新增純
assertself-check,python src/test_auto_version.py與python src/test_api_post.py皆印OK。🤖 Generated with Claude Code