FEATURE: add a pretty output to toolkit check pr (#8416)

when i write a PR, i run the tests and i like to have a pretty output to
make extra clear which one of the tests did run, which one did not, etc,
etc...

this always end up a variation of the template
> - `cargo fmt --all -- --check` to check standard code formatting
(`cargo fmt --all` applies these changes)
> - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
> - `cargo test --workspace` to check that all tests pass

but with emojis and without the descriptions

> - 🟢 `cargo fmt --all`
> - 🔴 `cargo clippy --workspace -- -D warnings -D
clippy::unwrap_used -A clippy::needless_collect`
> - 🟡 `cargo test --workspace`
>
> and a  (``) when i did not have the time
or the resources to run the check stage

in this PR, i came up with a way to do that automatically with the
`toolkit` introduced in #8152 😋

# Description
this PR
- adds `toolkit::pretty-print-command` to print the command names being
run with backticks and some colors
- adds `toolkit::report` to return a "report" of the PR check stages =>
see `help toolkit check pr`
- adds the `--pretty` option to `toolkit check pr` to return a
list-with-emojis version of the check report, i.e. a *GitHub*-friendly
list to drop in place in the "Tests + Formatting" section
- adds a clear mention to `toolkit check pr --pretty` in the PR template
to make it easily visible to anyone

hope you'll like it, that's not a huge deal but that's my attempt to
encourage developers to show that they run the tests, what stages did
pass and which one did not 😌 👋

# User-Facing Changes
the developer can now use `toolkit check pr --pretty` to have a
ready-to-use output for *GitHub*

# Tests + Formatting
```
$nothing
```

# After Submitting
```
$nothing
```
This commit is contained in:
Antoine Stevan 2023-03-18 13:58:21 +01:00 committed by GitHub
parent 3f224db990
commit c66bd5e809
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,6 +35,50 @@ export def test [
} }
} }
# print the pipe input inside backticks, dimmed and italic, as a pretty command
def pretty-print-command [] {
$"`(ansi default_dimmed)(ansi default_italic)($in)(ansi reset)`"
}
# return a report about the check stage
#
# - fmt comes first
# - then clippy
# - and finally the tests
#
# without any option, `report` will return an empty report.
# otherwise, the truth values will be incremental, following
# the order above.
def report [
--fail-fmt: bool
--fail-clippy: bool
--fail-test: bool
--no-fail: bool
] {
[fmt clippy test] | wrap stage
| merge (
if $no_fail { [true true true] }
else if $fail_fmt { [false $nothing $nothing] }
else if $fail_clippy { [true false $nothing] }
else if $fail_test { [true true false] }
else { [$nothing $nothing $nothing] }
| wrap success
)
| upsert emoji {|it|
if ($it.success == $nothing) {
":black_circle:"
} else if $it.success {
":green_circle:"
} else {
":red_circle:"
}
}
| each {|it|
$"- ($it.emoji) `toolkit ($it.stage)`"
}
| to text
}
# run all the necessary checks and tests to submit a perfect PR # run all the necessary checks and tests to submit a perfect PR
# #
# # Example # # Example
@ -61,6 +105,9 @@ export def test [
# > for val in vals { # > for val in vals {
# > ``` # > ```
# #
# > **Note**
# > at every stage, the `toolkit check pr` will return a report of the few stages being run.
#
# - we run the toolkit once and it fails... # - we run the toolkit once and it fails...
# ```nushell # ```nushell
# >_ toolkit check pr # >_ toolkit check pr
@ -125,17 +172,27 @@ export def test [
export def "check pr" [ export def "check pr" [
--fast: bool # use the "nextext" `cargo` subcommand to speed up the tests (see [`cargo-nextest`](https://nexte.st/) and [`nextest-rs/nextest`](https://github.com/nextest-rs/nextest)) --fast: bool # use the "nextext" `cargo` subcommand to speed up the tests (see [`cargo-nextest`](https://nexte.st/) and [`nextest-rs/nextest`](https://github.com/nextest-rs/nextest))
] { ] {
print "running `toolkit fmt`" print $"running ('toolkit fmt' | pretty-print-command)"
try { try {
fmt --check fmt --check
} catch { } catch {
print $"\nplease run (ansi default_dimmed)(ansi default_italic)toolkit fmt(ansi reset) to fix the formatting" print $"\nplease run (ansi default_dimmed)(ansi default_italic)toolkit fmt(ansi reset) to fix the formatting"
return return (report --fail-fmt)
} }
print "running `toolkit clippy`" print $"running ('toolkit clippy' | pretty-print-command)"
clippy try {
clippy
} catch {
return (report --fail-clippy)
}
print "running `toolkit test`" print $"running ('toolkit test' | pretty-print-command)"
if $fast { test --fast } else { test } try {
if $fast { test --fast } else { test }
} catch {
return (report --fail-test)
}
report --no-fail
} }