Skip to content

Refactor config package and add functionality - #44

Merged
samcoe merged 5 commits into
trunkfrom
config-integration
Jun 21, 2022
Merged

samcoe merged 5 commits into
trunkfrom
config-integration

Conversation

@samcoe

@samcoe samcoe commented May 24, 2022 •

Copy link
Copy Markdown
Contributor

This PR introduces a bunch of functionality necessary for gh to utilize go-gh for config handling.

Things changed:

  • Renamed and improved configmap to yamlmap
  • Exported config package with functions for manipulating configuration files. Only business logic that is encapsulated is around reading and writing of configuration files.
  • Exported auth package with functions related to auth tokens and hosts. This functionality is not new, it just used to live in the internal config package.

I added inline comments and questions for design decisions.

Note: This PR is not as long as it seems, lots of code was just shuffled around.

cc cli/cli#5560

@samcoe samcoe self-assigned this May 24, 2022
@samcoe
samcoe force-pushed the config-integration branch 6 times, most recently from 7c2c2f1 to 80af8a5 Compare May 25, 2022 13:34
Comment thread pkg/auth/auth.go
Comment thread pkg/config/config.go
Comment thread pkg/config/config.go
Comment thread pkg/config/config.go
@samcoe
samcoe force-pushed the config-integration branch from 80af8a5 to 9041602 Compare May 25, 2022 14:13
@samcoe
samcoe marked this pull request as ready for review May 25, 2022 14:14
@samcoe
samcoe requested a review from mislav May 25, 2022 14:14

@mislav mislav left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks great! I love the surface simplicity, the separate yamlmap package, and the fact that extension authors are discouraged to interact with the core config directly. I have some polish-level comments

Comment thread pkg/auth/auth.go Outdated
hostsKey = "hosts"
)

func TokenForHost(cfg *config.Config, host string) (string, string) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should these top-level functions take cfg as argument, or instead just access the config.Config instance internally as a singleton?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think I agree, these functions feel like they should know how to access the config themselves, I can't think of a scenario where we would want the user to pass in their own config.Config instance. My only worry is that config.Config becomes an implicit dependency of these functions rather than an explicit one.

Comment thread pkg/auth/auth.go
Comment thread pkg/config/config.go Outdated
Comment thread pkg/config/config.go
Comment thread pkg/config/config.go Outdated
entries *yamlmap.Map
}

func Get(c *Config, keys []string) (string, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Now that config.Config is just a struct and not some interface anymore, what are the tradeoffs of having config.Get/Set/Remove etc. be methods on the top level instead of on the struct itself?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That is a good question. I don't know if I can think of a pro/con for either way. Perhaps having them be methods on the struct is more idiomatic? I don't have strong opinions on either direction.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

After thinking about this more I couldn't come up with a good reason not to make these methods so I made the change.

Comment thread pkg/config/errors.go
Comment thread pkg/config/errors.go Outdated
@samcoe
samcoe requested a review from mislav May 26, 2022 12:47
@samcoe
samcoe force-pushed the config-integration branch from 6e036a7 to ae1157f Compare May 26, 2022 13:28
@samcoe

samcoe commented May 30, 2022

Copy link
Copy Markdown
Contributor Author

@mislav This is ready for re-review when you get a chance 🙇

@mislav mislav left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks great. Thanks for your hard work and for the patience

@samcoe
samcoe merged commit 3c417a3 into trunk Jun 21, 2022
@samcoe
samcoe deleted the config-integration branch June 21, 2022 14:36
@samcoe samcoe mentioned this pull request Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants