Skip to content
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

isolate repo clone #1416

Merged
merged 12 commits into from
Jul 24, 2020
Merged

isolate repo clone #1416

merged 12 commits into from
Jul 24, 2020

Conversation

vilmibm
Copy link
Contributor

@vilmibm vilmibm commented Jul 23, 2020

Depends on #1409
Part of #1405
Part of #1082

This PR isolates gh repo clone.

Unlike the previous isolation PRs, this one reuses existing tests. This did require some massaging,
but was a lot faster and easier then re-writing the test cases from scratch.

I moved some stuff around to share code between non-isolated and isolated commands; we can split
stuff back out of git as needed once everything is isolated.

I did add a new field to cmdutil.Factory: Config(). This seemed like the correct thing but I'm
curious what your thoughts are, Mislav.

@vilmibm vilmibm added this to Backlog 🗒 in The GitHub CLI via automation Jul 23, 2020
@vilmibm vilmibm requested a review from mislav July 23, 2020 21:42
return c.errBuf.String()
}

func runCloneCommand(httpClient *http.Client, cli string) (*cmdOut, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thinking is that each new isolated command will come with a run*Command function that replaces use of runCommand in tests. This worked well here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great approach! I would argue that we could even name it RunCommand scoped to the new package so we don't have to rename any existing RunCommand calls from tests that we copy over 🤘

@vilmibm vilmibm changed the base branch from trunk to migrate-repo-view July 23, 2020 22:15
@vilmibm vilmibm changed the base branch from migrate-repo-view to trunk July 23, 2020 22:16
@vilmibm vilmibm changed the base branch from trunk to migrate-repo-view July 24, 2020 15:07
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Love the approach! It's great that you've figured out how to port old tests.

I feel very good about this PR being merged in the current state and that the following set of repo migrations could be done in followup PRs. ✨

return baseRepo, nil
}

repoResolvingCmdFactory := *cmdFactory
Copy link
Contributor

Choose a reason for hiding this comment

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

Oooh is this a way to create a shallow copy of a struct? Seems really nifty

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep!


repoResolvingCmdFactory := *cmdFactory

repoResolvingCmdFactory.BaseRepo = resolvedBaseRepo
Copy link
Contributor

@mislav mislav Jul 24, 2020

Choose a reason for hiding this comment

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

I wonder if we could/should make the result of BaseRepo cached? Just in case a command calls it more than once (it usually doesn't); right now that would perform full resolution (w/ API call) every time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm fine with this being uncached for a few reasons:

  • the caller will probably most often be saving the result in a variable anyway
  • we don't currently have any commands that need to call this more than once
  • we might move away from "smart" resolution, anyway

@@ -94,6 +96,15 @@ func init() {
ctx := context.New()
return ctx.BaseRepo()
},
Config: func() (config.Config, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The addition of Config here is great. Same for BaseRepo, should we perhaps cache the result after the 1st call? In case a command consults a config multiple times (e.g. looking up different config options), we'd avoid re-parsing the configuration file from disk every time. (Not that it's anywhere near as expensive as an API call)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm more amenable to caching this than BaseRepo but also think it's something we can put off to keep the code simpler as we continue with this migration.

return c.errBuf.String()
}

func runCloneCommand(httpClient *http.Client, cli string) (*cmdOut, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Great approach! I would argue that we could even name it RunCommand scoped to the new package so we don't have to rename any existing RunCommand calls from tests that we copy over 🤘

The GitHub CLI automation moved this from Backlog 🗒 to Needs to be merged 🎉 Jul 24, 2020
@vilmibm vilmibm changed the base branch from migrate-repo-view to trunk July 24, 2020 16:08
@vilmibm vilmibm merged commit 7512034 into cli:trunk Jul 24, 2020
The GitHub CLI automation moved this from Needs to be merged 🎉 to Pending Release 🥚 Jul 24, 2020
@github-actions github-actions bot moved this from Pending Release 🥚 to Done 💤 in The GitHub CLI Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
The GitHub CLI
  
Done 💤
Development

Successfully merging this pull request may close these issues.

None yet

2 participants