-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support merging JSON arrays, objects #148
Conversation
Partly resolves cli/cli#1268 and replaces cli/cli#5652
Partly resolves cli#1268 and replaces cli#5652. Requires cli/go-gh#148 to be merged and optionally released.
@samcoe the idea here is to retain the basic - and intentionally rather minimal - design Nate put into place for JSON arrays and write them to stdout as we read them. This should have no practical impact to existing JSON array responses. Using the same interface - again, to retain the same basic design and not require near the level of refactoring cli/cli#5652 did - we can merge JSON objects using v1.0.0 of mergo, cache the merged object in memory, and write the merged object in the end. Given there can be multiple arrays and arrays will always be nested within at least the root |
@heaths : Thank you for this! ❤️ One thing I want to share is that @samcoe has left GitHub though hopefully will still be a contributor and advocate. 😞 Wanting to make sure we demonstrate our side of the commitment on this topic, I'm bringing this up with @williammartin so we can avoid the same stagnation from last time. |
Good luck to you, @samcoe, in your new venture! Thanks for all the support over the years! |
@heaths : having reviewed these changes a few times, I think I have a mental picture of how these changes fit into
Beyond that, is there anything else to consider regarding these changes and the original PR? |
No. In fact, I would pretty much forget the old PR exists. That was a huge refactor whereas you can see the new one on draft status is tiny. The logic of REST vs GraphQL was already determined, so I built on that. The goal was to keep the same basic flow that is currently in release: streaming for REST array responses (in case anyone took a dependency on that behavior), at least. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening this @heaths, I have left a few comments and some thoughts inline here.
Firstly, I think you've done a really good job at minimising the changes required in the current api
command code so kudos for that.
Secondly, though I don't think it should necessarily be done as part of this work, do you think it's worth exploring an earlier branching of graphql
and rest
in the API command? Things like isFirstPage
and the streaming vs writing on Close
behaviours are screaming that there's too much going on here. Similarly, when I look at the api
command there's so many conditionals predicated on whether we're hitting graphql or not and it seems likely that would only increase. If we branched earlier, much of this PRs code would seem to become much simpler and idiomatic.
Finally, I see you put this in go-gh
, is there a reason for that? Particularly since it seems tailored for our use case in the api
command (e.g. objectMergerPage.Read
not actually reading into the provided byte slice) I'm not sure that it makes sense for this to live as a consumable semvered package.
If you look at the original PR #5652 where I did refactor how a lot of this worked, it's huge. I'm not opposed to a major refactor similar to that, but I spent countless hours maintaining a clean merge since the PR was ignored for so long. I can't afford that again. However, I don't think the idea here is wrong. Only when we need to paginate do we even need to consider merging, which is what these related changes do. Yes, the cli/cli does have a lot of branching on "/graphql" but the behavior for REST vs. GraphQL is very different, so that's not surprising. Paging is different, merging is different, output is different.
The idea I discussed with @andyfeller and Sam was that because this was effectively a thin wrapper around I'll respond to individual comments. |
Just to be super clear, I have no expectations for this to happen:
I'm asking for your opinion as someone who has more familiarity with the code than Andy or me.
I also would not use the word wrong here. As in my comment above, you've done a remarkable job at providing something that explicitly doesn't require wholesale changes in the command layer. It's crafty!
The point I'm failing to make is that the API command branches 7 times (at a cursory count) based on whether this is a graphql request or not. That makes for a lot of state that needs to be carried around mentally when reading the code. Additionally, it forces other abstractions to contort into supporting the shared code path (see If instead, we branched once, early, I'm curious how that tradeoff would play out. Yes, there would be some duplication but I wonder if we're in a case of "duplication is far cheaper than the wrong abstraction". The more code that gets written to support this style, the more we will feel the pressure to continue to invest in it over time. Again, I'm not asking for you to do any work to implement this, or even to validate it, I'm just interested in whether it resonates with you given your experience poking around in here. If you were to say "I don't know and I don't have the time to investigate it" that's totally understandable.
Thanks for the insight. I'm not opposed to keeping it here though I have some reservations about the existing abstraction. Having it here doesn't require that we maintain it beyond keeping it exposed and not breaking it, and if it's useful in its current state so be it. I've responded to individual comments and unresolved those that I would like a response to. |
Also, just to set expectations, I don't think there is anything about this PR that is really blocking. I just want to make sure we all get on the same page about its usage and limitations. Right now I fully expect that the PR will not change significantly, and will get merged in shortly. I certainly don't intend to drag this out especially given the experience we talked about before on #5652. |
I see. Thanks for clarifying. Yes, bifurcating early might actually be better. That's why keeping my original PR clean against your upstream I'm open to doing this work. What is your timeline for the next release, though? I have a couple thoughts depending on that:
If we split the work, an initial release to merge JSON arrays and objects could ship. Refactoring later should have no user impact. That said, I'd also have less incentive to finish 3, but still interested. That said, if one of your team wants to work on that, I wouldn't be offended. 😄 |
Yeh understood. Total nightmare for everyone once that starts happening.
We release every 2 weeks or so, sometimes more frequently. I would anticipate we ship by next Tuesday at the latest. I don't think any large scale refactor would need to make it into the next release though. I think we should proceed with getting this work into
So just for context right now I'm the only full time maintainer on the core CLI. @andyfeller is a machine and jumps back and forth between this and copilot CLI work. We are looking to add more engineers but it's a process. That said, I do think that I would find it valuable to get my hands grubby on this one since the refactor isn't time sensitive. There's a lot I still need to learn about the nuances of this command. I don't think I'd looked at the implementation of |
Closing per discussion above and in cli/cli#8620. |
Partly resolves cli#1268 and replaces cli#5652. Requires cli/go-gh#148 to be merged and optionally released.
Partly resolves cli#1268 and replaces cli#5652. Requires cli/go-gh#148 to be merged and optionally released.
Partly resolves cli#1268 and replaces cli#5652. Requires cli/go-gh#148 to be merged and optionally released.
Partly resolves cli#1268 and replaces cli#5652. Requires cli/go-gh#148 to be merged and optionally released.
Partly resolves cli#1268 and replaces cli#5652. Requires cli/go-gh#148 to be merged and optionally released.
Partly resolves cli/cli#1268 and replaces cli/cli#5652