mirror of
https://github.com/actions-runner-controller/actions-runner-controller.git
synced 2026-09-30 00:52:04 +02:00
Remove dead GitHubConfig surface left by scaleset migration (#4676)
This commit is contained in:
@@ -3,30 +3,17 @@ package actions
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var ErrInvalidGitHubConfigURL = fmt.Errorf("invalid config URL, should point to an enterprise, org, or repository")
|
||||
|
||||
type GitHubScope int
|
||||
|
||||
const (
|
||||
GitHubScopeUnknown GitHubScope = iota
|
||||
GitHubScopeEnterprise
|
||||
GitHubScopeOrganization
|
||||
GitHubScopeRepository
|
||||
)
|
||||
|
||||
type GitHubConfig struct {
|
||||
ConfigURL *url.URL
|
||||
Scope GitHubScope
|
||||
|
||||
Enterprise string
|
||||
Organization string
|
||||
Repository string
|
||||
|
||||
IsHosted bool
|
||||
}
|
||||
|
||||
func ParseGitHubConfigFromURL(in string) (*GitHubConfig, error) {
|
||||
@@ -35,11 +22,8 @@ func ParseGitHubConfigFromURL(in string) (*GitHubConfig, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
isHosted := isHostedGitHubURL(u)
|
||||
|
||||
configURL := &GitHubConfig{
|
||||
ConfigURL: u,
|
||||
IsHosted: isHosted,
|
||||
}
|
||||
|
||||
invalidURLError := fmt.Errorf("%q: %w", u.String(), ErrInvalidGitHubConfigURL)
|
||||
@@ -52,17 +36,14 @@ func ParseGitHubConfigFromURL(in string) (*GitHubConfig, error) {
|
||||
return nil, invalidURLError
|
||||
}
|
||||
|
||||
configURL.Scope = GitHubScopeOrganization
|
||||
configURL.Organization = pathParts[0]
|
||||
|
||||
case 2: // Repository or enterprise
|
||||
if strings.ToLower(pathParts[0]) == "enterprises" {
|
||||
configURL.Scope = GitHubScopeEnterprise
|
||||
configURL.Enterprise = pathParts[1]
|
||||
break
|
||||
}
|
||||
|
||||
configURL.Scope = GitHubScopeRepository
|
||||
configURL.Organization = pathParts[0]
|
||||
configURL.Repository = pathParts[1]
|
||||
default:
|
||||
@@ -71,39 +52,3 @@ func ParseGitHubConfigFromURL(in string) (*GitHubConfig, error) {
|
||||
|
||||
return configURL, nil
|
||||
}
|
||||
|
||||
func (c *GitHubConfig) GitHubAPIURL(path string) *url.URL {
|
||||
result := &url.URL{
|
||||
Scheme: c.ConfigURL.Scheme,
|
||||
Host: c.ConfigURL.Host, // default for Enterprise mode
|
||||
Path: "/api/v3", // default for Enterprise mode
|
||||
}
|
||||
|
||||
isHosted := isHostedGitHubURL(c.ConfigURL)
|
||||
|
||||
if isHosted {
|
||||
result.Host = fmt.Sprintf("api.%s", c.ConfigURL.Host)
|
||||
result.Path = ""
|
||||
|
||||
if c.ConfigURL.Host == "www.github.com" {
|
||||
// re-routing www.github.com to api.github.com
|
||||
result.Host = "api.github.com"
|
||||
}
|
||||
}
|
||||
|
||||
result.Path += path
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func isHostedGitHubURL(u *url.URL) bool {
|
||||
_, forceGhes := os.LookupEnv("GITHUB_ACTIONS_FORCE_GHES")
|
||||
if forceGhes {
|
||||
return false
|
||||
}
|
||||
|
||||
return u.Host == "github.com" ||
|
||||
u.Host == "www.github.com" ||
|
||||
u.Host == "github.localhost" ||
|
||||
strings.HasSuffix(u.Host, ".ghe.com")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user