2021-06-09 09:38:52 +02:00
|
|
|
package orchestrator
|
|
|
|
|
2021-06-25 10:50:56 +02:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
)
|
2021-06-09 09:38:52 +02:00
|
|
|
|
|
|
|
type GitHubActionsConfigProvider struct{}
|
|
|
|
|
2021-06-25 10:50:56 +02:00
|
|
|
func (g *GitHubActionsConfigProvider) GetBranch() string {
|
|
|
|
return strings.TrimPrefix(os.Getenv("GITHUB_REF"), "refs/heads/")
|
2021-06-09 09:38:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-25 10:50:56 +02:00
|
|
|
func (g *GitHubActionsConfigProvider) GetBuildUrl() string {
|
|
|
|
return g.GetRepoUrl() + "/actions/runs/" + os.Getenv("GITHUB_RUN_ID")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GitHubActionsConfigProvider) GetCommit() string {
|
|
|
|
return os.Getenv("GITHUB_SHA")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GitHubActionsConfigProvider) GetRepoUrl() string {
|
|
|
|
return os.Getenv("GITHUB_SERVER_URL") + os.Getenv("GITHUB_REPOSITORY")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GitHubActionsConfigProvider) GetPullRequestConfig() PullRequestConfig {
|
2021-06-09 09:38:52 +02:00
|
|
|
return PullRequestConfig{
|
|
|
|
Branch: os.Getenv("GITHUB_HEAD_REF"),
|
|
|
|
Base: os.Getenv("GITHUB_BASE_REF"),
|
|
|
|
Key: os.Getenv("GITHUB_EVENT_PULL_REQUEST_NUMBER"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-25 10:50:56 +02:00
|
|
|
func (g *GitHubActionsConfigProvider) IsPullRequest() bool {
|
2021-06-09 09:38:52 +02:00
|
|
|
_, exists := os.LookupEnv("GITHUB_HEAD_REF")
|
|
|
|
return exists
|
|
|
|
}
|
|
|
|
|
|
|
|
func isGitHubActions() bool {
|
|
|
|
envVars := []string{"GITHUB_ACTION", "GITHUB_ACTIONS"}
|
|
|
|
return areIndicatingEnvVarsSet(envVars)
|
|
|
|
}
|