Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ To that end, `prr` introduces a new workflow for reviewing PRs:
1. Mark up the review file using your favorite text editor
1. Submit the review at your convenience

When run from within a git repository on a branch associated with a PR, `prr`
can auto-detect the repository and PR number—just run `prr get`, `prr edit`,
or `prr submit` without arguments. This works with fork workflows too.

The tool was born of frustration from using the point-and-click editor text
boxes on PRs. I happen to do a lot of code review and tabbing to and from the
browser to cross reference code from the changes was driving me nuts.
Expand Down
4 changes: 4 additions & 0 deletions book/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ To that end, `prr` introduces a new workflow for reviewing PRs:
1. Mark up the review file using your favorite text editor
1. Submit the review at your convenience

When run from within a git repository on a branch associated with a PR, `prr`
can auto-detect the repository and PR number—just run `prr get`, `prr edit`,
or `prr submit` without arguments. This works with fork workflows too.

The tool was born of frustration from using the point-and-click editor text
boxes on PRs. I happen to do a lot of code review and tabbing to and from the
browser to cross reference code from the changes was driving me nuts.
Expand Down
35 changes: 35 additions & 0 deletions book/src/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ The following local configuration options are supported:
* `[local]`
* [`repository`](#the-repository-field)
* [`workdir`](#the-local-workdir-field)
* [`upstream_remote`](#the-upstream_remote-field)
* [`origin_remote`](#the-origin_remote-field)

### The `repository` field

Expand All @@ -110,6 +112,14 @@ The optional `repository` field takes a string in format of
If specified, you may omit the `${ORG}/${REPO}` from PR string arguments.
For example, you may run `prr get 6` instead of `prr get danobi/prr/6`.

> [!TIP]
> As an alternative to configuring this field, you can omit the PR
> argument entirely when running from a git repository. If you're on a branch
> that has an associated PR, `prr` will auto-detect the owner, repo, and PR
> number from the git remote and current branch name. This works with fork
> workflows too — `prr` uses `upstream` (if present) to identify the repository,
> and `origin` to identify your fork.


Example:

Expand All @@ -118,6 +128,31 @@ Example:
repository = "danobi/prr"
```

### The `upstream_remote` field

The optional `upstream_remote` field overrides the git remote name that `prr`
treats as the upstream repository when auto-detecting PRs. Defaults to
`"upstream"`.

Example:

```toml
[local]
upstream_remote = "main-repo"
```

### The `origin_remote` field

The optional `origin_remote` field overrides the git remote name that `prr`
treats as your fork when auto-detecting PRs. Defaults to `"origin"`.

Example:

```toml
[local]
origin_remote = "my-fork"
```

### The local `workdir` field

The optional `workdir` field takes a string that represents a path.
Expand Down
20 changes: 18 additions & 2 deletions book/src/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,22 @@ $ prr get danobi/prr-test-repo/6
/home/dxu/dev/review/danobi/prr-test-repo/6.prr
```

`prr-get` downloads a pull request onto your filesystem into what we call a
`prr get` downloads a pull request onto your filesystem into what we call a
"review file". On success, the path to the review file is printed to your
terminal.

> [!TIP]
> If you're inside a git clone on a branch that has an associated PR,
> you can omit the PR argument entirely—`prr` will auto-detect the repository
> and PR number from the git remote and current branch:
>
> ```sh
> $ prr get
> ```
>
> This works with fork workflows too: `prr` uses the `upstream` remote (if present)
> to identify the repository, and the `origin` remote to identify your fork.

But to be sure, let's check our status:

```sh
Expand All @@ -32,13 +44,15 @@ Great! We've confirmed the review was downloaded.
### Mark up the review file

Now that the review file is downloaded, let's mark it up. You can open
the review file in your favorite editor or use `prr-edit` to automatically
the review file in your favorite editor or use `prr edit` to automatically
open it in `$EDITOR`.

```
$ prr edit danobi/prr-test-repo/6
```

(Or just `prr edit` if you're on the PR's branch.)

Your editor should show the contents as something like this:

```
Expand Down Expand Up @@ -134,6 +148,8 @@ Do this by running:
$ prr submit danobi/prr-test-repo/6
```

(Or just `prr submit` if you're on the PR's branch.)

On success there will not be any output. But just to be safe, let's confirm
submission status:

Expand Down
12 changes: 6 additions & 6 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ pub(crate) enum Command {
/// Ignore unsubmitted review checks
#[clap(short, long)]
force: bool,
/// Pull request to review (eg. `danobi/prr/24`)
pr: String,
/// Pull request to review (eg. `danobi/prr/24`). Auto-detected if omitted.
pr: Option<String>,
/// Open review file in $EDITOR after download
#[clap(long)]
open: bool,
},
/// Open an existing review in $EDITOR
Edit {
/// Pull request to edit (eg. `danobi/prr/24`)
pr: String,
/// Pull request to edit (eg. `danobi/prr/24`). Auto-detected if omitted.
pr: Option<String>,
},
/// Submit a review
Submit {
/// Pull request to review (eg. `danobi/prr/24`)
pr: String,
/// Pull request to review (eg. `danobi/prr/24`). Auto-detected if omitted.
pr: Option<String>,
#[clap(short, long)]
debug: bool,
},
Expand Down
15 changes: 12 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ async fn main() -> Result<()> {

match args.command {
Command::Get { pr, force, open } => {
let (owner, repo, pr_num) = prr.parse_pr_str(&pr)?;
let (owner, repo, pr_num) = match pr {
Some(pr_str) => prr.parse_pr_str(&pr_str)?,
None => prr.detect_pr().await?,
};
let review = prr.get_pr(&owner, &repo, pr_num, force).await?;
let path = review.path();
println!("{}", path.display());
Expand All @@ -77,12 +80,18 @@ async fn main() -> Result<()> {
}
}
Command::Edit { pr } => {
let (owner, repo, pr_num) = prr.parse_pr_str(&pr)?;
let (owner, repo, pr_num) = match pr {
Some(pr_str) => prr.parse_pr_str(&pr_str)?,
None => prr.detect_pr().await?,
};
let review = prr.get_review(&owner, &repo, pr_num)?;
open_review(&review.path()).context("Failed to open review file")?;
}
Command::Submit { pr, debug } => {
let (owner, repo, pr_num) = prr.parse_pr_str(&pr)?;
let (owner, repo, pr_num) = match pr {
Some(pr_str) => prr.parse_pr_str(&pr_str)?,
None => prr.detect_pr().await?,
};
prr.submit_pr(&owner, &repo, pr_num, debug).await?;
}
Command::Apply { pr } => {
Expand Down
Loading