Skip to content

Commit

Permalink
enhance(env): add VELA_PULL_REQUEST_SOURCE and _TARGET to comment type (
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper authored Jan 17, 2024
1 parent 0e2e18b commit f40578e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-title-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: validate
- name: validate title
run: |
echo "${{ github.event.pull_request.title }}" | grep -Eq '^(feat|fix|chore|refactor|enhance|test|docs)\(.*\):.*$' && (echo "Pass"; exit 0) || (echo "Incorrect Format. Please see https://go-vela.github.io/docs/community/contributing_guidelines/#development-workflow"; exit 1)
2 changes: 2 additions & 0 deletions library/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ func (b *Build) Environment(workspace, channel string) map[string]string {
envs["BUILD_PULL_REQUEST_NUMBER"] = number
envs["VELA_BUILD_PULL_REQUEST"] = number
envs["VELA_PULL_REQUEST"] = number
envs["VELA_PULL_REQUEST_SOURCE"] = b.GetHeadRef()
envs["VELA_PULL_REQUEST_TARGET"] = b.GetBaseRef()
}

// check if the Build event is deployment
Expand Down
13 changes: 9 additions & 4 deletions library/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/go-vela/types/raw"
"github.com/google/go-cmp/cmp"
)

func TestLibrary_Build_Duration(t *testing.T) {
Expand Down Expand Up @@ -51,6 +52,8 @@ func TestLibrary_Build_Environment(t *testing.T) {
_comment.SetEvent("comment")
_comment.SetEventAction("created")
_comment.SetRef("refs/pulls/1/head")
_comment.SetHeadRef("dev")
_comment.SetBaseRef("main")

_deploy := testBuild()
_deploy.SetEvent("deployment")
Expand Down Expand Up @@ -146,7 +149,7 @@ func TestLibrary_Build_Environment(t *testing.T) {
"VELA_BUILD_APPROVED_BY": "OctoCat",
"VELA_BUILD_AUTHOR": "OctoKitty",
"VELA_BUILD_AUTHOR_EMAIL": "[email protected]",
"VELA_BUILD_BASE_REF": "",
"VELA_BUILD_BASE_REF": "main",
"VELA_BUILD_BRANCH": "main",
"VELA_BUILD_CHANNEL": "TODO",
"VELA_BUILD_CLONE": "https://github.com/github/octocat.git",
Expand All @@ -171,9 +174,11 @@ func TestLibrary_Build_Environment(t *testing.T) {
"VELA_BUILD_TITLE": "push received from https://github.com/github/octocat",
"VELA_BUILD_WORKSPACE": "TODO",
"VELA_PULL_REQUEST": "1",
"VELA_PULL_REQUEST_SOURCE": "dev",
"VELA_PULL_REQUEST_TARGET": "main",
"BUILD_AUTHOR": "OctoKitty",
"BUILD_AUTHOR_EMAIL": "[email protected]",
"BUILD_BASE_REF": "",
"BUILD_BASE_REF": "main",
"BUILD_BRANCH": "main",
"BUILD_CHANNEL": "TODO",
"BUILD_CLONE": "https://github.com/github/octocat.git",
Expand Down Expand Up @@ -439,8 +444,8 @@ func TestLibrary_Build_Environment(t *testing.T) {
for _, test := range tests {
got := test.build.Environment("TODO", "TODO")

if !reflect.DeepEqual(got, test.want) {
t.Errorf("Environment is %v, want %v", got, test.want)
if diff := cmp.Diff(test.want, got); diff != "" {
t.Errorf("(Environment: -want +got):\n%s", diff)
}
}
}
Expand Down

0 comments on commit f40578e

Please sign in to comment.