diff --git a/.github/workflows/pr-title-validate.yml b/.github/workflows/pr-title-validate.yml index f62dacf0..aa3588f6 100644 --- a/.github/workflows/pr-title-validate.yml +++ b/.github/workflows/pr-title-validate.yml @@ -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) \ No newline at end of file diff --git a/library/build.go b/library/build.go index 5b919dfb..3c872933 100644 --- a/library/build.go +++ b/library/build.go @@ -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 diff --git a/library/build_test.go b/library/build_test.go index bd0b265c..5c82c7a3 100644 --- a/library/build_test.go +++ b/library/build_test.go @@ -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) { @@ -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") @@ -146,7 +149,7 @@ func TestLibrary_Build_Environment(t *testing.T) { "VELA_BUILD_APPROVED_BY": "OctoCat", "VELA_BUILD_AUTHOR": "OctoKitty", "VELA_BUILD_AUTHOR_EMAIL": "OctoKitty@github.com", - "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", @@ -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": "OctoKitty@github.com", - "BUILD_BASE_REF": "", + "BUILD_BASE_REF": "main", "BUILD_BRANCH": "main", "BUILD_CHANNEL": "TODO", "BUILD_CLONE": "https://github.com/github/octocat.git", @@ -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) } } }