Skip to content

Conversation

132ikl
Copy link
Member

@132ikl 132ikl commented Sep 28, 2025

This PR adds the toolkit run pr and toolkit download pr commands to toolkit. This is a more fleshed out version of the snippet shared in #16633, with robust error handling and cross-platform unzip support.
When using toolkit run pr, the script will also check if the most recent binary for that PR has already been downloaded, and if so it will run that instead.

I tried to make the error reporting as good as a built-in command to see how difficult that would be, and with use of the --head: oneof<> trick, it turned out pretty good. With access to the call span, the workflow is very similar to when writing a built-in command. I also used a Spanned-like record, which helped as well.

toolkit run pr 16740
# => Error: nu::shell::error
# =>
# =>   × Command not found
# =>    ╭─[entry #4:1:26]
# =>  1 │ overlay use -pr toolkit; toolkit run pr 16740
# =>    ·                          ───────┬──────
# =>    ·                                 ╰── requires `gh`
# =>    ╰────
# =>   help: Please install the `gh` commandline tool
More error reporting notes In an earlier version of the script, `run pr` called `download pr` directly. I ended up changing the way this worked so that `run pr` could use the workflow_id. Here's a couple snippets I thought were neat from this older version.

 
Passing span via --head:

def download [--head: oneof<>] {
  let span = $head | default (metadata $head).span
  error make {msg: "a", label: {text: here, span: $span}}
}

def run [--head: oneof<>] { 
  let span = (metadata $head).span
  download --head=$span
}

download
# => Error: nu::shell::error
# => 
# =>   × a
# =>    ╭─[entry #6:1:1]
# =>  1 │ download
# =>    · ────┬───
# =>    ·     ╰── here
# =>    ╰────

run
# => Error: nu::shell::error
# => 
# =>   × a
# =>    ╭─[entry #7:1:1]
# =>  1 │ run
# =>    · ─┬─
# =>    ·  ╰── here
# =>    ╰────

Using "spanned" number as CLI parameter and as internal caller parameter

def download [number: oneof<int, record<item: int, span: record>>] {
  let number = match $number {
    {item: $_, span: $_} => $number,
    $val => {item: $number, span: (metadata $number).span}
  }

  error make {msg: "a", label: {text: here, span: $number.span}}
}

def run [number: int] {
  let number = {item: $number, span: (metadata $number).span}
  download $number
}

download 123
# => Error: nu::shell::error
# => 
# =>   × a
# =>    ╭─[entry #9:1:10]
# =>  1 │ download 123
# =>    ·          ─┬─
# =>    ·           ╰── here
# =>    ╰────

run 123
# => Error: nu::shell::error
# => 
# =>   × a
# =>    ╭─[entry #10:1:5]
# =>  1 │ run 123
# =>    ·     ─┬─
# =>    ·      ╰── here
# =>    ╰────

Release notes summary - What our users need to know

The toolkit in the Nushell repository can now download and run PRs by downloading artifacts from CI runs. It can be run like this:

use toolkit
toolkit run pr <number>

@132ikl 132ikl added the notes:other Include the release notes summary in the "Other changes" section label Sep 28, 2025
Copy link
Member

@cptpiepmatz cptpiepmatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command works for me and the code looks good. Error handling seems very nice 👍🏻

@132ikl 132ikl merged commit 2f88a09 into nushell:main Oct 7, 2025
16 checks passed
@github-actions github-actions bot added this to the v0.108.0 milestone Oct 7, 2025
@Bahex Bahex added the notes:ready The "Release notes summary" section of this PR is ready to be included in our release notes. label Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:other Include the release notes summary in the "Other changes" section notes:ready The "Release notes summary" section of this PR is ready to be included in our release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants