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/azureDevOps.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

32 lines
813 B
Go

package orchestrator
import (
"os"
"strings"
)
type AzureDevOpsConfigProvider struct{}
func (a *AzureDevOpsConfigProvider) GetPullRequestConfig() PullRequestConfig {
return PullRequestConfig{
Branch: os.Getenv("SYSTEM_PULLREQUEST_SOURCEBRANCH"),
Base: os.Getenv("SYSTEM_PULLREQUEST_TARGETBRANCH"),
Key: os.Getenv("SYSTEM_PULLREQUEST_PULLREQUESTID"),
}
}
func (a *AzureDevOpsConfigProvider) GetBranchBuildConfig() BranchBuildConfig {
tmp := os.Getenv("BUILD_SOURCEBRANCH")
trimmed := strings.TrimPrefix(tmp, "refs/heads/")
return BranchBuildConfig{Branch: trimmed}
}
func (a *AzureDevOpsConfigProvider) IsPullRequest() bool {
return os.Getenv("BUILD_REASON") == "PullRequest"
}
func isAzure() bool {
envVars := []string{"AZURE_HTTP_USER_AGENT"}
return areIndicatingEnvVarsSet(envVars)
}