Skip to content

Commit

Permalink
fix: merging main into branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Claire.Nicholas authored and Claire.Nicholas committed Jan 19, 2024
2 parents 0c9af1b + 8a6ef2d commit 7cd1abc
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 113 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/pr-title-validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# name of the action
name: validate PR title

# trigger on pull_request events of the opened & edited type.
on:
pull_request:
types: [ opened, synchronize, edited, reopened ]

# pipeline to execute
jobs:
validate:
runs-on: ubuntu-latest

steps:
- name: validate title
run: |
echo "${{ github.event.pull_request.title }}" | grep -Eq '^(feat|fix|chore|refactor|enhance|test|docs)(\(.*\)|):\s.+$' && (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": "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",
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": "OctoKitty@github.com",
"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
17 changes: 15 additions & 2 deletions library/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ func NewEventsFromMask(mask int64) *Events {
return e
}

// EventAllowed determines whether or not an event is allowed based on the repository settings.
// Allowed determines whether or not an event + action is allowed based on whether
// its event:action is set to true in the Events struct.
func (e *Events) Allowed(event, action string) bool {
allowed := false

// if there is an action, create `event:action` comparator string
if len(action) > 0 {
event = event + ":" + action
}
Expand All @@ -54,6 +56,8 @@ func (e *Events) Allowed(event, action string) bool {
allowed = e.GetPullRequest().GetSynchronize()
case constants.EventPull + ":" + constants.ActionEdited:
allowed = e.GetPullRequest().GetEdited()
case constants.EventPull + ":" + constants.ActionReopened:
allowed = e.GetPullRequest().GetReopened()
case constants.EventTag:
allowed = e.GetPush().GetTag()
case constants.EventComment + ":" + constants.ActionCreated:
Expand Down Expand Up @@ -94,6 +98,10 @@ func (e *Events) List() []string {
eventSlice = append(eventSlice, constants.EventPull+":"+constants.ActionEdited)
}

if e.GetPullRequest().GetReopened() {
eventSlice = append(eventSlice, constants.EventPull+":"+constants.ActionReopened)
}

if e.GetPush().GetTag() {
eventSlice = append(eventSlice, constants.EventTag)
}
Expand Down Expand Up @@ -127,7 +135,12 @@ func (e *Events) List() []string {

// ToDatabase is an Events method that converts a nested Events struct into an integer event mask.
func (e *Events) ToDatabase() int64 {
return 0 | e.GetPush().ToMask() | e.GetPullRequest().ToMask() | e.GetComment().ToMask() | e.GetDeployment().ToMask()
return 0 |
e.GetPush().ToMask() |
e.GetPullRequest().ToMask() |
e.GetComment().ToMask() |
e.GetDeployment().ToMask() |
e.GetSchedule().ToMask()
}

// GetPush returns the Push field from the provided Events. If the object is nil,
Expand Down
Loading

0 comments on commit 7cd1abc

Please sign in to comment.