Skip to content

Commit

Permalink
feat(build): update env to match compiler (#95)
Browse files Browse the repository at this point in the history
* feat(build): update env to match compiler

* go fmt

Co-authored-by: David May <[email protected]>
  • Loading branch information
JordanSussman and wass3r committed Aug 12, 2020
1 parent 1d96b18 commit 1657f6b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions library/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Build struct {

// Environment returns a list of environment variables
// provided from the fields of the Build type.
func (b *Build) Environment() map[string]string {
func (b *Build) Environment(workspace string) map[string]string {
envs := map[string]string{
"VELA_BUILD_AUTHOR": ToString(b.GetAuthor()),
"VELA_BUILD_AUTHOR_EMAIL": ToString(b.GetEmail()),
Expand All @@ -73,7 +73,7 @@ func (b *Build) Environment() map[string]string {
"VELA_BUILD_SOURCE": ToString(b.GetSource()),
"VELA_BUILD_STATUS": ToString(b.GetStatus()),
"VELA_BUILD_TITLE": ToString(b.GetTitle()),
"VELA_BUILD_WORKSPACE": ToString("TODO"),
"VELA_BUILD_WORKSPACE": ToString(workspace),

// deprecated environment variables
"BUILD_AUTHOR": ToString(b.GetAuthor()),
Expand All @@ -98,7 +98,7 @@ func (b *Build) Environment() map[string]string {
"BUILD_SOURCE": ToString(b.GetSource()),
"BUILD_STATUS": ToString(b.GetStatus()),
"BUILD_TITLE": ToString(b.GetTitle()),
"BUILD_WORKSPACE": ToString("TODO"),
"BUILD_WORKSPACE": ToString(workspace),
}

// check if the Build event is comment
Expand All @@ -120,6 +120,7 @@ func (b *Build) Environment() map[string]string {
// add the deployment target to the list
envs["VELA_BUILD_TARGET"] = target
envs["VELA_DEPLOYMENT"] = target
envs["BUILD_TARGET"] = target
}

// check if the Build event is pull_request
Expand All @@ -138,7 +139,7 @@ func (b *Build) Environment() map[string]string {
// check if the Build event is tag
if strings.EqualFold(b.GetEvent(), constants.EventTag) {
// capture the tag reference
tag := ToString(strings.TrimPrefix(b.GetRef(), "refs/tags/"))
tag := ToString(strings.SplitN(b.GetRef(), "refs/tags/", 2)[1])

// add the tag reference to the list
envs["BUILD_TAG"] = tag
Expand Down
3 changes: 2 additions & 1 deletion library/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func TestLibrary_Build_Environment(t *testing.T) {
"VELA_BUILD_TITLE": "push received from https://github.com/github/octocat",
"VELA_BUILD_WORKSPACE": "TODO",
"VELA_DEPLOYMENT": "production",
"BUILD_TARGET": "production",
"BUILD_AUTHOR": "OctoKitty",
"BUILD_AUTHOR_EMAIL": "[email protected]",
"BUILD_BASE_REF": "",
Expand Down Expand Up @@ -314,7 +315,7 @@ func TestLibrary_Build_Environment(t *testing.T) {

// run test
for _, test := range tests {
got := test.build.Environment()
got := test.build.Environment("TODO")

if !reflect.DeepEqual(got, test.want) {
t.Errorf("Environment is %v, want %v", got, test.want)
Expand Down

0 comments on commit 1657f6b

Please sign in to comment.