generated from fallion/go-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package integrations | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
// FindCompareBranch tries to find the merge request compare branch based on environment variables used by different CIs. | ||
func FindCompareBranch() string { | ||
githubRef := os.Getenv("GITHUB_BASE_REF") | ||
if githubRef != "" { | ||
return fmt.Sprintf("origin/%v", githubRef) | ||
} | ||
|
||
gitlabRef := os.Getenv("CI_MERGE_REQUEST_TARGET_BRANCH_NAME") | ||
if gitlabRef != "" { | ||
return fmt.Sprintf("origin/%v", gitlabRef) | ||
} | ||
|
||
// Drone specific variable https://docker-runner.docs.drone.io/configuration/environment/variables/drone-target-branch/ | ||
droneRef := os.Getenv("DRONE_TARGET_BRANCH") | ||
if droneRef != "" { | ||
return fmt.Sprintf("origin/%v", droneRef) | ||
} | ||
|
||
return "origin/master" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package integrations | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFindCompareBranch(t *testing.T) { | ||
// Github action specific environment variable | ||
os.Setenv("GITHUB_BASE_REF", "github-develop") | ||
|
||
actionCompareBranch := FindCompareBranch() | ||
|
||
assert.Equal(t, "origin/github-develop", actionCompareBranch) | ||
|
||
os.Setenv("GITHUB_BASE_REF", "") | ||
|
||
// Gitlab specific environment variable | ||
os.Setenv("CI_MERGE_REQUEST_TARGET_BRANCH_NAME", "gitlab-develop") | ||
|
||
gitlabCompareBranch := FindCompareBranch() | ||
|
||
assert.Equal(t, "origin/gitlab-develop", gitlabCompareBranch) | ||
|
||
os.Setenv("CI_MERGE_REQUEST_TARGET_BRANCH_NAME", "") | ||
|
||
// Drone specific environment variable | ||
os.Setenv("DRONE_TARGET_BRANCH", "drone-develop") | ||
|
||
droneCompareBranch := FindCompareBranch() | ||
|
||
assert.Equal(t, "origin/drone-develop", droneCompareBranch) | ||
|
||
os.Setenv("DRONE_TARGET_BRANCH", "") | ||
|
||
// Should default to master if no conditions are satisfied | ||
defaultMaster := FindCompareBranch() | ||
|
||
assert.Equal(t, "origin/master", defaultMaster) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module github.com/outillage/integrations | ||
|
||
go 1.13 | ||
|
||
require github.com/stretchr/testify v1.4.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= | ||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |