1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/pkg/orchestrator/gitHubActions.go
Marc Bormeth 911d4bc770
feat(sonar): make step orchestrator-agnostic (#2874)
* Make sonarExecuteScan orchestrator-agnostic

* Increase coverage + support empty or false env vars

* Use cleared env for unit tests

* Refactor to standalone package

* Fix review findings

* Fix review findings

* Fix unit test

* Add logging

* Refactor

* Add to codeowners 😎

* Apply suggestions from code review

* Remove unreachable code

* no message

* fix typos

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2021-06-09 09:38:52 +02:00

28 lines
726 B
Go

package orchestrator
import "os"
type GitHubActionsConfigProvider struct{}
func (a *GitHubActionsConfigProvider) GetBranchBuildConfig() BranchBuildConfig {
return BranchBuildConfig{Branch: os.Getenv("GITHUB_REF")}
}
func (a *GitHubActionsConfigProvider) GetPullRequestConfig() PullRequestConfig {
return PullRequestConfig{
Branch: os.Getenv("GITHUB_HEAD_REF"),
Base: os.Getenv("GITHUB_BASE_REF"),
Key: os.Getenv("GITHUB_EVENT_PULL_REQUEST_NUMBER"),
}
}
func (a *GitHubActionsConfigProvider) IsPullRequest() bool {
_, exists := os.LookupEnv("GITHUB_HEAD_REF")
return exists
}
func isGitHubActions() bool {
envVars := []string{"GITHUB_ACTION", "GITHUB_ACTIONS"}
return areIndicatingEnvVarsSet(envVars)
}