Skip to content

feat: 优化 PDF 命名规则并修正自动关闭逻辑 (#91)#531

Merged
hect0x7 merged 1 commit intomasterfrom
fix-pdf-sort-v2
Apr 16, 2026
Merged

feat: 优化 PDF 命名规则并修正自动关闭逻辑 (#91)#531
hect0x7 merged 1 commit intomasterfrom
fix-pdf-sort-v2

Conversation

@hect0x7
Copy link
Copy Markdown
Owner

@hect0x7 hect0x7 commented Apr 16, 2026

此次 PR 旨在解决用户反馈的 PDF 文件名难以辨认以及自动关闭逻辑误伤开发 PR 的问题。

主要改动:

  1. 优化 PDF 文件命名默认规则
    • 本子维度:默认使用 [JM{Aid}] {Atitle},包含项目前缀、ID 和本子标题。
    • 章节维度:默认使用 [JM{Aid}] 第{Pindex}章-JM{Pid}-{Ptitle},提供详细的层级信息。
  2. 增强 Actions 灵活性
    • download_dispatch.yml 中新增 PDF_NAME_RULE 选项,支持用户根据需求自定义命名规则。
  3. 修复 close_specific_pr.yml 误伤逻辑
    • 增加了对 PR 标题的检查。如果标题包含 feat:fix:,则会自动跳过关闭逻辑,允许有意义的特性或修复 PR 正常开启。

关联 Issue: #91

Summary by CodeRabbit

  • New Features

    • PDF naming is now customizable via a manual dispatch input; provided rule is applied when generating PDFs.
  • Chores

    • Auto-close workflow now skips closing PRs whose titles use Conventional Commits-style feat/fix prefixes (case-insensitive).

@github-actions
Copy link
Copy Markdown

To prevent beginners from mistakenly submitting PRs,
if your PR only modifies the usage/workflow_download.py file,
it will be automatically closed.
If you really want to submit a PR, please reopen it yourself.
Make sure you know what you are doing!

@github-actions github-actions bot closed this Apr 16, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e3711284-7026-4614-86ff-0d714d9fa5a6

📥 Commits

Reviewing files that changed from the base of the PR and between 597b384 and c882941.

📒 Files selected for processing (3)
  • .github/workflows/close_specific_pr.yml
  • .github/workflows/download_dispatch.yml
  • usage/workflow_download.py
✅ Files skipped from review due to trivial changes (1)
  • usage/workflow_download.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/close_specific_pr.yml

📝 Walkthrough

Walkthrough

Adds a new PDF_NAME_RULE workflow_dispatch input propagated to the crawler job and consumed by the Python script to set Img2pdfPlugin filename rules (with fallbacks). Separately, the PR-close workflow now skips closing when PR title matches Conventional Commits feat or fix (case-insensitive).

Changes

Cohort / File(s) Summary
Workflow dispatch & env
\.github/workflows/download_dispatch.yml
Adds workflow_dispatch input PDF_NAME_RULE and exposes it as env.PDF_NAME_RULE in the crawler job.
PR-close behavior
\.github/workflows/close_specific_pr.yml
Adds case-insensitive grep of PR title for Conventional Commits feat/fix (optional scope/!); if matched, logs and exits early to skip commenting/closing.
PDF filename rule usage
usage/workflow_download.py
Reads PDF_NAME_RULE from environment (trimmed); if empty, falls back to template rules per context and passes result as filename_rule to Img2pdfPlugin.

Sequence Diagram(s)

sequenceDiagram
  participant User as User (workflow_dispatch)
  participant GH as GitHub Actions (download_dispatch)
  participant Job as crawler job (env)
  participant Py as usage/workflow_download.py
  participant Plugin as Img2pdfPlugin

  User->>GH: trigger download_dispatch with PDF_NAME_RULE
  GH->>Job: start crawler job (env.PDF_NAME_RULE set)
  Job->>Py: run script (reads env.PDF_NAME_RULE)
  Py->>Py: compute pdf_name_rule (trim or fallback templates)
  Py->>Plugin: initialize with filename_rule=pdf_name_rule
  Plugin-->>Py: generate PDF(s)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • Dev #489 — Changes how Img2pdfPlugin.filename_rule is set via a PDF_NAME_RULE workflow input; touches the same workflow and Python logic.

Poem

A rabbit hops with a naming rule so fine,
It trims and falls back to templates by design.
From dispatch to plugin the names now flow,
Hooray for PDFs that know where to go! 🐰✉️

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title uses Conventional Commits format and accurately describes the main changes: optimizing PDF naming rules and fixing auto-close logic in GitHub Actions workflows.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-pdf-sort-v2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@hect0x7 hect0x7 reopened this Apr 16, 2026
Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
.github/workflows/download_dispatch.yml (1)

43-47: 建议补充规则格式示例,降低误填概率

Line [45] 目前只列了字段名,建议直接给可复制的模板示例(含 {})以减少无效规则输入。

✏️ Suggested wording
-        description: 'PDF文件命名规则。支持字段如 Aid, Atitle, Pindex, Pid, Ptitle'
+        description: 'PDF文件命名规则(示例:[JM{Aid}] {Atitle} 或 [JM{Aid}] 第{Pindex}章-JM{Pid}-{Ptitle})。支持字段 Aid, Atitle, Pindex, Pid, Ptitle'
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/download_dispatch.yml around lines 43 - 47, Update the
PDF_NAME_RULE parameter description to include a concrete, copy-pasteable
template example using braces (e.g. include a template like
{Aid}-{Atitle}-{Pindex} in the description) so users can see exact placeholder
syntax; modify the description string for PDF_NAME_RULE to show one or two
example templates and note supported fields (Aid, Atitle, Pindex, Pid, Ptitle)
and that braces are required around field names.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/close_specific_pr.yml:
- Around line 31-33: The grep pattern that checks PR_TITLE (the line using echo
"$PR_TITLE" | grep -Ei "feat:|fix:") is too narrow and misses Conventional
Commit variants like scoped or breaking-change forms; update the grep invocation
to use a regex that matches (^|[[:space:]])(feat|fix)(\([^)]+\))?(!)?: so
PR_TITLE recognizes feat/scope, fix/scope, and ! breaking-change tokens and thus
correctly skips auto-closing for those PRs.

In `@usage/workflow_download.py`:
- Around line 88-91: The code treats pdf_name_rule as configured when it
contains only whitespace; update the check around env('PDF_NAME_RULE', None) and
pdf_name_rule so you normalize/strip the value first (e.g., read pdf_name_rule =
env('PDF_NAME_RULE', None), then if pdf_name_rule is not None: pdf_name_rule =
pdf_name_rule.strip() and only consider it set if non-empty), and fall back to
the default rule based on call_when when the stripped value is empty; refer to
the pdf_name_rule variable, the env(...) call, and call_when to locate and
implement the change.

---

Nitpick comments:
In @.github/workflows/download_dispatch.yml:
- Around line 43-47: Update the PDF_NAME_RULE parameter description to include a
concrete, copy-pasteable template example using braces (e.g. include a template
like {Aid}-{Atitle}-{Pindex} in the description) so users can see exact
placeholder syntax; modify the description string for PDF_NAME_RULE to show one
or two example templates and note supported fields (Aid, Atitle, Pindex, Pid,
Ptitle) and that braces are required around field names.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9df8617c-b0cf-4586-ad4d-ea9b573a2b12

📥 Commits

Reviewing files that changed from the base of the PR and between 145af2a and 597b384.

📒 Files selected for processing (3)
  • .github/workflows/close_specific_pr.yml
  • .github/workflows/download_dispatch.yml
  • usage/workflow_download.py

Comment thread .github/workflows/close_specific_pr.yml Outdated
Comment thread usage/workflow_download.py
原来使用简单的 `Aid` 或 `Pid` 进行命名,用户反馈导出的 PDF 名字全是数字看不出是什么。现在:

1. 默认情况下,本子维度的 PDF 命名为 `Atitle`,章节维度的 PDF 命名为 `Atitle_Ptitle`。

2. 新增可选的环境变量和 Action 面板输入参数 `PDF_NAME_RULE`,允许用户自定义生成规则。
@hect0x7 hect0x7 merged commit ef950ac into master Apr 16, 2026
2 checks passed
@hect0x7 hect0x7 deleted the fix-pdf-sort-v2 branch April 16, 2026 15:28
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