feat: support self-hosted instances and GitHub Enterprise#6
feat: support self-hosted instances and GitHub Enterprise#6NicolasRitouet merged 4 commits intomainfrom
Conversation
Add KEYWAY_GITHUB_URL and KEYWAY_GITHUB_API_URL env vars for GHE. Skip update checks and update commands for self-hosted instances. Derive badge and docs URLs from config instead of hardcoding. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughAdds environment-driven URL configuration (GitHub API/base, docs, dashboard) and applies it across the codebase; introduces guards to skip update checks and disable update commands when a custom/self-hosted API URL is configured. Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as CLI (version/check)
participant Config as Config (env funcs)
participant GitHub as GitHub Releases API
participant Net as Network/HTTP
CLI->>Config: GetGitHubAPIURL() / IsCustomAPIURL()
alt custom/self-hosted detected
CLI-->>CLI: Skip update check / return no update command
else default GitHub API
CLI->>Net: HTTP GET releases (using URL from Config)
Net->>GitHub: request
GitHub-->>Net: latest release JSON
Net-->>CLI: response
CLI->>CLI: parse version & show update notice
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Covers GetGitHubURL, GetGitHubAPIURL, GetGitHubBaseURL, GetDocsURL, IsCustomAPIURL, and self-hosted guards in CheckForUpdate, FetchLatestVersion, and GetUpdateCommand. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
aadc030 to
bce66e7
Compare
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
bce66e7 to
7443ca3
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@internal/config/config.go`:
- Around line 107-111: IsCustomAPIURL incorrectly treats values with trailing
slashes as custom; update the function IsCustomAPIURL to normalize both the
environment value (KEYWAY_API_URL) and DefaultAPIURL before comparing (e.g.,
TrimSpace, remove trailing slashes and optionally lower-case) so
"https://api.example.com/" equals "https://api.example.com"; then compare the
normalized strings and return true only when non-empty and different from the
normalized default.
| // IsCustomAPIURL returns true if using a non-default API URL (self-hosted) | ||
| func IsCustomAPIURL() bool { | ||
| apiURL := os.Getenv("KEYWAY_API_URL") | ||
| return apiURL != "" && apiURL != DefaultAPIURL | ||
| } |
There was a problem hiding this comment.
Normalize API URLs before comparison to avoid false “custom” detection.
If KEYWAY_API_URL is set to the default with a trailing slash, Line 110 will incorrectly treat it as custom and disable update checks. Normalize both sides before comparing.
🛠️ Proposed fix
func IsCustomAPIURL() bool {
- apiURL := os.Getenv("KEYWAY_API_URL")
- return apiURL != "" && apiURL != DefaultAPIURL
+ apiURL := strings.TrimSuffix(GetAPIURL(), "/")
+ defaultURL := strings.TrimSuffix(DefaultAPIURL, "/")
+ return apiURL != defaultURL
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // IsCustomAPIURL returns true if using a non-default API URL (self-hosted) | |
| func IsCustomAPIURL() bool { | |
| apiURL := os.Getenv("KEYWAY_API_URL") | |
| return apiURL != "" && apiURL != DefaultAPIURL | |
| } | |
| // IsCustomAPIURL returns true if using a non-default API URL (self-hosted) | |
| func IsCustomAPIURL() bool { | |
| apiURL := strings.TrimSuffix(os.Getenv("KEYWAY_API_URL"), "/") | |
| defaultURL := strings.TrimSuffix(DefaultAPIURL, "/") | |
| return apiURL != "" && apiURL != defaultURL | |
| } |
🤖 Prompt for AI Agents
In `@internal/config/config.go` around lines 107 - 111, IsCustomAPIURL incorrectly
treats values with trailing slashes as custom; update the function
IsCustomAPIURL to normalize both the environment value (KEYWAY_API_URL) and
DefaultAPIURL before comparing (e.g., TrimSpace, remove trailing slashes and
optionally lower-case) so "https://api.example.com/" equals
"https://api.example.com"; then compare the normalized strings and return true
only when non-empty and different from the normalized default.
Summary
KEYWAY_GITHUB_URLenv var for GitHub Enterprise web URLKEYWAY_GITHUB_API_URLenv var for GitHub Enterprise API URL (auto-derives/api/v3from base URL)GetDashboardURL()config instead of hardcodingTest plan
KEYWAY_API_URL=https://api.example.com keyway versionshows no update noticeKEYWAY_GITHUB_URL=https://github.example.comsets GitHub OAuth URLs correctlygo test ./internal/...passes🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Improvements
Tests