Skip to content

Conversation

umatare5
Copy link
Contributor

@umatare5 umatare5 commented Aug 9, 2025

WHAT

This PR refactors the badge command to use dedicated subcommands for coverage, ratio, and time instead of handling them with a single switch-case block.

Key changes:

  • Added three dedicated subcommands: badge coverage, badge ratio, and badge time
  • Updated badge command to display help by default when no subcommand is provided.

Before:

❯ go run main.go badge --help
generate badge.

Usage:
  octocov badge [flags]

Flags:
      --config string   config file path
  -h, --help            help for badge
      --out string      output file path

After:

❯ go run main.go badge --help
generate badge.

Usage:
  octocov badge [flags]
  octocov badge [command]

Available Commands:
  coverage    generate coverage badge
  ratio       generate code to test ratio badge
  time        generate test execution time badge

Flags:
  -h, --help   help for badge

Use "octocov badge [command] --help" for more information about a command.

For the subcommands:

go run main.go badge coverage --help
❯ go run main.go badge coverage --help
generate coverage badge

Usage:
  octocov badge coverage [flags]

Flags:
      --config string   config file path
  -h, --help            help for coverage
      --out string      output file path
go run main.go badge ratio --help

❯ go run main.go badge ratio --help
generate code to test ratio badge

Usage:
octocov badge ratio [flags]

Flags:
--config string config file path
-h, --help help for ratio
--out string output file path

go run main.go badge time --help

❯ go run main.go badge time --help
generate test execution time badge

Usage:
octocov badge time [flags]

Flags:
--config string config file path
-h, --help help for time
--out string output file path

Tests

I tested this code with the following .octocov.yml in both GitHub Actions and the local environment.

coverage:
  paths:
    - coverage.out
codeToTestRatio:
  code:
    - '**/*.go'
    - '!**/*_test.go'
  test:
    - '**/*_test.go'
testExecutionTime:
  acceptable: 1 min
  steps:
    - 'Generate Go coverage from testdata'

On Workflow

Please refer to the final workflow in following PR:

All commands and flags are verified in the workflow as follows:

Screenshot 2025-08-09 at 16 49 36

On Local

Case 1: octocov badge coverage
❯ octocov badge coverage | head -n 1
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="133.5" height="20" role="img" aria-label="octocov::badge">

❯ octocov badge coverage --config .octocov.yml | head -n 1
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="133.5" height="20" role="img" aria-label="octocov::badge">

❯ octocov badge coverage --out cover.out && ls cover.out
cover.out
Case 2: octocov badge ratio
❯ octocov badge ratio | head -n 1
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="168.5" height="20" role="img" aria-label="octocov::badge">

❯ octocov badge ratio --config .octocov.yml | head -n 1
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="168.5" height="20" role="img" aria-label="octocov::badge">

❯ octocov badge ratio --out cover.out && ls cover.out
cover.out

Note

octocov badge time doesn't support the local environment if my understanding is correct.

WHY

@umatare5 umatare5 marked this pull request as ready for review August 9, 2025 07:52
@k1LoW k1LoW added enhancement New feature or request minor labels Aug 9, 2025
@k1LoW
Copy link
Owner

k1LoW commented Aug 9, 2025

@umatare5 GREAT WORK!!! Thank you!!!

@k1LoW k1LoW merged commit e46d04e into k1LoW:main Aug 9, 2025
5 checks passed
@github-actions github-actions bot mentioned this pull request Aug 9, 2025
@umatare5
Copy link
Contributor Author

umatare5 commented Aug 9, 2025

Thank you as well!

@umatare5 umatare5 deleted the umatare5/patch-2 branch August 9, 2025 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request minor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants