Skip to content

chore: Refactor base url logic#2951

Merged
stevehipwell merged 1 commit intointegrations:mainfrom
stevehipwell:refactor-base-url-logic
Nov 26, 2025
Merged

chore: Refactor base url logic#2951
stevehipwell merged 1 commit intointegrations:mainfrom
stevehipwell:refactor-base-url-logic

Conversation

@stevehipwell
Copy link
Copy Markdown
Collaborator

Resolves #2943
Closes #2944


Before the change?

  • The base URL is often handled as a string with manual concatenations
  • Base URL validation isn't well defined
  • Base URL format is rigid and doesn't actually work for GHEC

After the change?

  • The base URL is handled as a strongly typed url.URL
  • The base URL is validated with a single function
  • GHEC should work correctly

Pull request checklist

  • Schema migrations have been created if needed (example)
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

Signed-off-by: Steve Hipwell <steve.hipwell@gmail.com>
@stevehipwell stevehipwell force-pushed the refactor-base-url-logic branch from 0c1d3f1 to 4313b3d Compare November 26, 2025 13:47

if uv4.String() != "https://api.github.com/" && !GHECDataResidencyMatch.MatchString(uv4.String()) {
hostname := uv4.Hostname()
if hostname != DotComHost && !GHECDataResidencyHostMatch.MatchString(hostname) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

suggestion: this condition keeps repeating in multiple places. Would there be any value in refactoring it to a function?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
}

Copy link
Copy Markdown
Member

@nickfloyd nickfloyd left a comment

Choose a reason for hiding this comment

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

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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
}

@stevehipwell stevehipwell merged commit e2d8f47 into integrations:main Nov 26, 2025
8 checks passed
@stevehipwell stevehipwell deleted the refactor-base-url-logic branch November 26, 2025 17:11
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.

[BUG]: Data residency does not use correct api url

3 participants