fix: add server_url
attribute to github context (#1727)
* fix: add `server_url` attribute to github context The `server_urL` attribute was missing in the `github` context. Previously it was exposed as environment variable only. Closes #1726 * fix: also set `api_url` and `graphql_url` attributes
This commit is contained in:
parent
148a545021
commit
c0130ed030
2 changed files with 27 additions and 22 deletions
pkg
|
@ -36,6 +36,9 @@ type GithubContext struct {
|
||||||
RetentionDays string `json:"retention_days"`
|
RetentionDays string `json:"retention_days"`
|
||||||
RunnerPerflog string `json:"runner_perflog"`
|
RunnerPerflog string `json:"runner_perflog"`
|
||||||
RunnerTrackingID string `json:"runner_tracking_id"`
|
RunnerTrackingID string `json:"runner_tracking_id"`
|
||||||
|
ServerURL string `json:"server_url "`
|
||||||
|
APIURL string `json:"api_url"`
|
||||||
|
GraphQLURL string `json:"graphql_url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func asString(v interface{}) string {
|
func asString(v interface{}) string {
|
||||||
|
|
|
@ -631,6 +631,27 @@ func (rc *RunContext) getGithubContext(ctx context.Context) *model.GithubContext
|
||||||
|
|
||||||
ghc.SetRefTypeAndName()
|
ghc.SetRefTypeAndName()
|
||||||
|
|
||||||
|
// defaults
|
||||||
|
ghc.ServerURL = "https://github.com"
|
||||||
|
ghc.APIURL = "https://api.github.com"
|
||||||
|
ghc.GraphQLURL = "https://api.github.com/graphql"
|
||||||
|
// per GHES
|
||||||
|
if rc.Config.GitHubInstance != "github.com" {
|
||||||
|
ghc.ServerURL = fmt.Sprintf("https://%s", rc.Config.GitHubInstance)
|
||||||
|
ghc.APIURL = fmt.Sprintf("https://%s/api/v3", rc.Config.GitHubInstance)
|
||||||
|
ghc.GraphQLURL = fmt.Sprintf("https://%s/api/graphql", rc.Config.GitHubInstance)
|
||||||
|
}
|
||||||
|
// allow to be overridden by user
|
||||||
|
if rc.Config.Env["GITHUB_SERVER_URL"] != "" {
|
||||||
|
ghc.ServerURL = rc.Config.Env["GITHUB_SERVER_URL"]
|
||||||
|
}
|
||||||
|
if rc.Config.Env["GITHUB_API_URL"] != "" {
|
||||||
|
ghc.ServerURL = rc.Config.Env["GITHUB_API_URL"]
|
||||||
|
}
|
||||||
|
if rc.Config.Env["GITHUB_GRAPHQL_URL"] != "" {
|
||||||
|
ghc.ServerURL = rc.Config.Env["GITHUB_GRAPHQL_URL"]
|
||||||
|
}
|
||||||
|
|
||||||
return ghc
|
return ghc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -704,28 +725,9 @@ func (rc *RunContext) withGithubEnv(ctx context.Context, github *model.GithubCon
|
||||||
env["RUNNER_TRACKING_ID"] = github.RunnerTrackingID
|
env["RUNNER_TRACKING_ID"] = github.RunnerTrackingID
|
||||||
env["GITHUB_BASE_REF"] = github.BaseRef
|
env["GITHUB_BASE_REF"] = github.BaseRef
|
||||||
env["GITHUB_HEAD_REF"] = github.HeadRef
|
env["GITHUB_HEAD_REF"] = github.HeadRef
|
||||||
|
env["GITHUB_SERVER_URL"] = github.ServerURL
|
||||||
defaultServerURL := "https://github.com"
|
env["GITHUB_API_URL"] = github.APIURL
|
||||||
defaultAPIURL := "https://api.github.com"
|
env["GITHUB_GRAPHQL_URL"] = github.GraphQLURL
|
||||||
defaultGraphqlURL := "https://api.github.com/graphql"
|
|
||||||
|
|
||||||
if rc.Config.GitHubInstance != "github.com" {
|
|
||||||
defaultServerURL = fmt.Sprintf("https://%s", rc.Config.GitHubInstance)
|
|
||||||
defaultAPIURL = fmt.Sprintf("https://%s/api/v3", rc.Config.GitHubInstance)
|
|
||||||
defaultGraphqlURL = fmt.Sprintf("https://%s/api/graphql", rc.Config.GitHubInstance)
|
|
||||||
}
|
|
||||||
|
|
||||||
if env["GITHUB_SERVER_URL"] == "" {
|
|
||||||
env["GITHUB_SERVER_URL"] = defaultServerURL
|
|
||||||
}
|
|
||||||
|
|
||||||
if env["GITHUB_API_URL"] == "" {
|
|
||||||
env["GITHUB_API_URL"] = defaultAPIURL
|
|
||||||
}
|
|
||||||
|
|
||||||
if env["GITHUB_GRAPHQL_URL"] == "" {
|
|
||||||
env["GITHUB_GRAPHQL_URL"] = defaultGraphqlURL
|
|
||||||
}
|
|
||||||
|
|
||||||
if rc.Config.ArtifactServerPath != "" {
|
if rc.Config.ArtifactServerPath != "" {
|
||||||
setActionRuntimeVars(rc, env)
|
setActionRuntimeVars(rc, env)
|
||||||
|
|
Loading…
Add table
Reference in a new issue