Conversation
|
@probablycorey I love that you're working on this 👏 I feel like the current level of boilerplate is just getting out of hand.
Knowing our specific use-cases, I feel like this interface is too simple. For example, as you said, it always results in an API request, but for some cases we don't necessarily need an API request, e.g. if we parse a PR number from a URL, we can just open that URL directly in On the other hand, some use-cases require more GraphQL fields to be fetched than others. For instance, Finally, I think any helper function that parses PRs from URLs should also return the reference to the I don't know what a correct solution should be, but it seems to me that we have different needs in each of the |
|
Oooh I just had an epiphany about requesting variable level of GraphQL information per different invocation. How about we initialize a model in the caller and pass that to the query function to tell it what level of information we want? prArg := args[0]
pr := api.PullRequestLight{}
err := pullRequestFromArgument(prArg, &pr)
if err != nil {
return err
}
// now we can use all `pr.*` fields as defined by PullRequestLight
// alternatively, `pr view` might request a model with more fields
pr := api.PullRequestHeavy{} // this has many extra fields
err := pullRequestFromArgument(prArg, &pr)
// ...
// `pr.*` now has many extra fields we can peruseThis is assuming that the new queries would be backed by the |
One thing I don't get is why we need to get the baseRepo from a PR from a url, but not from a PR that is opened from a fork? Why don't we change the baseRepo in both instances since the baseRepo will be different in both instances? |
There are several ways to look up PRs, and we've been repeating that code in a few places. It's now getting more complicated so I wanted to clean that up a bit by having a consistent func that will return a PR in these formats.
This seems simple, but I ran into enough problems that I want to verify the interface before I go any further. I'm proposing this...
func getPr(cmd *cobra.Command, prString string) (*api.PullRequest, error)pros
A consistent interface for looking up a PR based on an arg
cons
It will almost always do a graphql lookup on the PR because many methods rely on some PR metadata. This will make our tests a little more complicated because we need to stub that out. It will also make
pr viewa little bit slower because it now makes an api call.problems
I can't get
TestPRCheckout_urlArg_differentBaseto run correctly. The code used to change the base branch if a url was passed to checkout but not if a number or branch was. But that seems inconsistent now. I'm having trouble coming up with a situation where you'd need to change the base branch when a url was passed.