Skip to content

Conversation

@mislav
Copy link
Contributor

@mislav mislav commented Apr 30, 2021

This completely rewrites the PR lookup mechanism so that the caller must specify the GraphQL fields to query for each PR. Additionally, this fixes a few export problems with pr view --json.

Features:

  • Each pr command now gets assigned a concept of a PR "Finder". This makes it easier to stub the PR in tests without having to stub the underlying HTTP calls or git invocations.

  • pr view --web is much faster since it only fetches the "url" field.

  • pr diff 123 now skips a whole API call where a whole PR was unnecessarily preloaded just to access its diff in a subsequent call.

  • PullRequestGraphQL query builder is now used to construct PR queries.

  • A bunch of individual commands are now freed from having to know about concepts such as BaseRepo, Branch, Config, or Remotes since they were mostly necessary just for the PR lookup.

Speedups:

command speedup (ms)
checkout 135
checks 257
close 181
comment 239
create 121
diff 386
edit 129
merge 108
ready 181
reopen 108
review 170
view 241

Downsides

  • The changeset is huge ☹️ I am sorry
  • Our legacy runCommand-style tests are really resistant to transitioning to dependency injection via interfaces, so I've had to make a stopgap hack called RunCommandFinder to be able to inject mock finders into commands

TODO:

Fixes #3539, fixes #3497, fixes #2849, fixes #3346, fixes #3561

This completely rewrites the PR lookup mechanism so that the caller
must specify the GraphQL fields to query for each PR. Additionally, this
fixes some export problems with `pr view --json`.

Features:

- Each pr command now gets assigned a concept of a Finder. This makes it
  easier to stub the PR in tests without having to stub the underlying
  HTTP calls or git invocations.

- `pr view --web` is much faster since it only fetches the "url" field.

- `pr diff 123` now skips a whole API call where a whole PR was
  unnecessarily preloaded just to access its diff in a subsequent call.

- PullRequestGraphQL query builder is now used to construct queries.

- A bunch of individual commands are now freed of having to know about
  concepts such as BaseRepo, Branch, Config, or Remotes.
@mislav mislav marked this pull request as draft April 30, 2021 18:45
@mislav mislav marked this pull request as ready for review May 10, 2021 16:21
return &resp.Repository.PullRequest, nil
}

func findForBranch(httpClient *http.Client, repo ghrepo.Interface, baseBranch, headBranch string, stateFilters, fields []string) (*api.PullRequest, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as findByNumber.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants