chore: Refactor base url logic#2951
Conversation
26629bc to
0c1d3f1
Compare
Signed-off-by: Steve Hipwell <steve.hipwell@gmail.com>
0c1d3f1 to
4313b3d
Compare
|
|
||
| if uv4.String() != "https://api.github.com/" && !GHECDataResidencyMatch.MatchString(uv4.String()) { | ||
| hostname := uv4.Hostname() | ||
| if hostname != DotComHost && !GHECDataResidencyHostMatch.MatchString(hostname) { |
There was a problem hiding this comment.
suggestion: this condition keeps repeating in multiple places. Would there be any value in refactoring it to a function?
There was a problem hiding this comment.
I think it's used in 2 places like that and 1 other place negated, so it could be turned into a function. The question is would a function called something like isDotComOrGHEC() (please give me a better name) provide as much clarity as seeing the code above? I was thinking that from a Go perspective this would be premature drying, but after writing my replay I'm leaning more towards the function approach. Especially as I could then add some tests.
There was a problem hiding this comment.
I'd go with the rule of 3 (3 or more implementations to trigger an abstraction) on this one given the logic is not significantly complex and abstraction feels like an over correction.
If you are going to abstract it I'd suggest getting rid of the negation (nots in sequence always tend to make things harder to reason IMO - though I might be alone on that 😉 ). Something like:
func isGitHubHosted(hostname string) bool {
return hostname == DotComHost || GHECDataResidencyHostMatch.MatchString(hostname)
}
then
if !isGitHubHosted(hostname) {
// Add the prefix or segment
}
nickfloyd
left a comment
There was a problem hiding this comment.
Just a comment on the discussion - other than that this is g2g
|
|
||
| if uv4.String() != "https://api.github.com/" && !GHECDataResidencyMatch.MatchString(uv4.String()) { | ||
| hostname := uv4.Hostname() | ||
| if hostname != DotComHost && !GHECDataResidencyHostMatch.MatchString(hostname) { |
There was a problem hiding this comment.
I'd go with the rule of 3 (3 or more implementations to trigger an abstraction) on this one given the logic is not significantly complex and abstraction feels like an over correction.
If you are going to abstract it I'd suggest getting rid of the negation (nots in sequence always tend to make things harder to reason IMO - though I might be alone on that 😉 ). Something like:
func isGitHubHosted(hostname string) bool {
return hostname == DotComHost || GHECDataResidencyHostMatch.MatchString(hostname)
}
then
if !isGitHubHosted(hostname) {
// Add the prefix or segment
}
Resolves #2943
Closes #2944
Before the change?
After the change?
url.URLPull request checklist
Does this introduce a breaking change?
Please see our docs on breaking changes to help!