Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@wilso199
Copy link
Contributor

@wilso199 wilso199 commented Oct 1, 2020

Fixes #1942

I added the ability for a hostname flag to be passed in for the gh api command and updated the tests accordingly.

To validate the hostname I used a function (hostnameValidator) that was present in pkg/cmd/auth/login.

I wasn't sure of the best location to place this function so for now I copied it to the api file. If you could suggest a location, I will happily abstract the duplicated function out of both files and write some test cases to validate its behavior.

Update -- I moved the hostnameValidator function to utils/utils.go and added tests. If we would rather it live somewhere else I'm happy to move it. Not sure if there is a use case for a validators.go or package to hold validation functions for inputs/flags across the project.

return filled, nil
}

func hostnameValidator(v interface{}) error {
Copy link

@cksriprajittichai cksriprajittichai Oct 1, 2020

Choose a reason for hiding this comment

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

Hey @wilso199, I was looking at the issue and saw your PR, so checking it out. Nice work!

What's the point of hostnameValidator taking an interface{} instead of a string? Won't the hostname always be a string?

If we decide to stick with taking an interface{}, we should do a safe type assertion to avoid a panic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cksriprajittichai I completely agree with your suggestion. Once I get some input on the best place to put this function for it to be shared, I'll be sure to implement your change! I can't see a use case where this would take something other than a string.

Copy link

@abdullahceylan abdullahceylan Oct 1, 2020

Choose a reason for hiding this comment

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

Hey @wilso199
Maybe utils folder would be a good place for this function. Then can be used wherever it needed.

@mislav mislav force-pushed the 1942-api-hostname-flag branch from 3d19208 to fbff1fc Compare October 21, 2020 16:45
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.

Thank you!

We plan to phase out the utils package, so I've moved the helper to internal/ghinstance

@mislav mislav merged commit 2afc462 into cli:trunk Oct 21, 2020

fmt.Fprintf(opts.IO.ErrOut, "%s Logged in as %s\n", utils.GreenCheck(), utils.Bold(username))

return nil
Copy link

Choose a reason for hiding this comment

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

README-EDITS

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.

Accept --hostname in gh api

5 participants