From c66bd5e80918c2044ed53d4e00f13edd7c1e9cd8 Mon Sep 17 00:00:00 2001 From: Antoine Stevan <44101798+amtoine@users.noreply.github.com> Date: Sat, 18 Mar 2023 13:58:21 +0100 Subject: [PATCH] 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 > - :green_circle: `cargo fmt --all` > - :red_circle: `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` > - :yellow_circle: `cargo test --workspace` > > and a :black_circle: (`:black_circle:`) 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 :yum: # 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 :relieved: :wave: # 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 ``` --- toolkit.nu | 69 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/toolkit.nu b/toolkit.nu index 6247a8369f..7122d6a4c1 100644 --- a/toolkit.nu +++ b/toolkit.nu @@ -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 # # # Example @@ -61,6 +105,9 @@ export def test [ # > 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... # ```nushell # >_ toolkit check pr @@ -125,17 +172,27 @@ export def test [ 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)) ] { - print "running `toolkit fmt`" + print $"running ('toolkit fmt' | pretty-print-command)" try { fmt --check } catch { 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`" - clippy + print $"running ('toolkit clippy' | pretty-print-command)" + try { + clippy + } catch { + return (report --fail-clippy) + } - print "running `toolkit test`" - if $fast { test --fast } else { test } + print $"running ('toolkit test' | pretty-print-command)" + try { + if $fast { test --fast } else { test } + } catch { + return (report --fail-test) + } + + report --no-fail }