Skip to content

refactor: move main.py's code into an action package - #355

Merged
shenxianpeng merged 1 commit into
mainfrom
refactor/split-main
Nov 23, 2026
Merged

shenxianpeng merged 1 commit into
mainfrom
refactor/split-main

Conversation

@shenxianpeng

@shenxianpeng shenxianpeng commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Second of two steps that split the action's code by area (the first was #354, tests only). This PR moves main.py's code into an action/ package. Nothing changes in what the action does.

Before vs after

Before After
main.py: 3,037 lines, all the code main.py: 69 lines, main() and the two helpers it calls; action.yml still runs it
action/: 8 modules, the largest 1,212 lines
Module Lines What it holds
action/escape.py 46 escaping text for the step log and workflow commands (_log_safe, _annotation_escape)
action/inputs.py 114 the inputs, read from the environment action.yml sets; their validation
action/model.py 135 ScopeResult, Commit, the run's overall status and exit code
action/context.py 360 the event, the pull request and its commits (git or API)
action/base_config.py 225 config-source: base
action/cli.py 610 running commit-check and turning its JSON into scopes
action/render.py 1,212 the step log and the Markdown report (incl. the output specification comment)
action/publish.py 353 job summary, result output, PR comment, AI label

Dependencies only point down the list: nothing imports a module below it, so there are no import cycles. The report and the step log stay in one module because the step log uses about 20 of the report's helpers.

Nothing in the code changed

  • All 186 top-level functions, classes and constants are moved as is. A name used from another module is now written module.name. With that prefix removed, every definition parses to the same AST as before.
  • module.name rather than from module import name: each name is looked up in the one module that defines it, so a test that patches it patches it everywhere.
  • The action's output (step log, job summary, result output, exit code) is byte for byte the same as main's in 6 local runs: message + branch, dry run, an invalid boolean input, author + files, message-ai-attribution, and an invalid config-source.
  • action.yml, the release flow and the v2 tag are untouched. python main.py puts the action's own directory on sys.path, so action/ imports from there. The caller's checkout is not on the path, so nothing in it can shadow the package.

Tests

  • They change only where they reach the code: main.X becomes module.X, and patch("main.X") becomes patch("action.module.X"). patch("main.subprocess.run") becomes patch("subprocess.run"), which patches the same object.
  • TestReconfigureIo and TestLogErrorAndExit move to tests/main_test.py, next to the code they test.
  • The same 412 tests pass. CI coverage now measures main and action, and both are at 100%.

main.py held all 3,037 lines of the action. Its code now lives in
action/, one module per part of the work, and main.py keeps only
main() and the two helpers it calls:

- escape: escaping text for the step log and workflow commands
- inputs: the inputs, read from the environment action.yml sets
- model: ScopeResult and the run's overall status
- context: the event, the pull request and its commits
- base_config: config-source: base
- cli: running commit-check and turning its JSON into scopes
- render: the step log and the Markdown report
- publish: job summary, result output, PR comment, AI label

Nothing changed in what the action does. Every function, class and
constant is moved as is; a name used from another module is now
written as module.name, so a test patches it in one place. action.yml
still runs main.py, and the action's output is byte for byte the same.

The tests change only where they reach the code: main.X becomes
module.X and patch("main.X") becomes patch("action.module.X").
Coverage now measures main.py and action/, and stays at 100%.
@shenxianpeng
shenxianpeng requested a review from a team as a code owner November 23, 2026 20:17
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 8 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 94d56f39-661f-4d04-8099-95a724e29fdb
Commits

Reviewing files that changed from the base of the PR and between 1b6a524 and bfb0057.

Files selected for processing: 22

  • .github/workflows/ci.yml
  • action/__init__.py
  • action/base_config.py
  • action/cli.py
  • action/context.py
  • action/escape.py
  • action/inputs.py
  • action/model.py
  • action/publish.py
  • action/render.py
  • main.py
  • tests/base_config_test.py
  • tests/cli_test.py
  • tests/context_test.py
  • tests/helpers.py
  • tests/inputs_test.py
  • tests/integration_test.py
  • tests/log_test.py
  • tests/main_test.py
  • tests/model_test.py
  • tests/publish_test.py
  • tests/report_test.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@shenxianpeng shenxianpeng self-assigned this Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

✔ Commit Check passed

✔ Pull request: 2 passed
✔ Commits: passed
✔ Author: 2 passed
✔ Branch: passed

All 6 checks
Pull request
  ✔ title        refactor: move main.py's code into an action package
  ✔ description  no AI attribution
Commits
  ✔ bfb0057      refactor: move main.py's code into an action package
Author
  ✔ name         Xianpeng Shen
  ✔ email        3353385+shenxianpeng@users.noreply.github.com
Branch
  ✔ branch       refactor/split-main

Checked by Commit Check 2.24.1 · Rules · Check before you push

@github-actions github-actions Bot added the ai-assisted Written with the help of an AI tool label Nov 23, 2026
@shenxianpeng shenxianpeng removed the ai-assisted Written with the help of an AI tool label Nov 23, 2026 — with Claude
@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (1b6a524) to head (bfb0057).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #355   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         9    +8     
  Lines         1257      1281   +24     
=========================================
+ Hits          1257      1281   +24     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shenxianpeng shenxianpeng added the maintenance Maintenance update label Nov 23, 2026
@shenxianpeng
shenxianpeng merged commit ca4bb6d into main Nov 23, 2026
22 of 25 checks passed
@shenxianpeng
shenxianpeng deleted the refactor/split-main branch November 23, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Maintenance update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant