Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding a delete event #1038

Merged
merged 21 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/build/list_org.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ func ListBuildsForOrg(c *gin.Context) {
// verify the event provided is a valid event type
if event != constants.EventComment && event != constants.EventDeploy &&
event != constants.EventPush && event != constants.EventPull &&
event != constants.EventTag && event != constants.EventSchedule {
event != constants.EventTag && event != constants.EventSchedule &&
event != constants.EventDelete {
retErr := fmt.Errorf("unable to process event %s: invalid event type provided", event)

util.HandleError(c, http.StatusBadRequest, retErr)
Expand Down
3 changes: 2 additions & 1 deletion api/build/list_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ func ListBuildsForRepo(c *gin.Context) {
// verify the event provided is a valid event type
if event != constants.EventComment && event != constants.EventDeploy &&
event != constants.EventPush && event != constants.EventPull &&
event != constants.EventTag && event != constants.EventSchedule {
event != constants.EventTag && event != constants.EventSchedule &&
event != constants.EventDelete {
retErr := fmt.Errorf("unable to process event %s: invalid event type provided", event)

util.HandleError(c, http.StatusBadRequest, retErr)
Expand Down
6 changes: 6 additions & 0 deletions api/repo/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"github.com/go-vela/server/util"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
"github.com/go-vela/types/library/actions"

Check failure on line 18 in api/repo/create.go

View workflow job for this annotation

GitHub Actions / test

github.com/go-vela/[email protected]: replacement directory ../types does not exist

Check failure on line 18 in api/repo/create.go

View workflow job for this annotation

GitHub Actions / test

github.com/go-vela/[email protected]: replacement directory ../types does not exist

Check failure on line 18 in api/repo/create.go

View workflow job for this annotation

GitHub Actions / build

github.com/go-vela/[email protected]: replacement directory ../types does not exist

Check failure on line 18 in api/repo/create.go

View workflow job for this annotation

GitHub Actions / database_sql

github.com/go-vela/[email protected]: replacement directory ../types does not exist

Check failure on line 18 in api/repo/create.go

View workflow job for this annotation

GitHub Actions / build

github.com/go-vela/[email protected]: replacement directory ../types does not exist

Check failure on line 18 in api/repo/create.go

View workflow job for this annotation

GitHub Actions / database_postgres (postgres:16-alpine)

github.com/go-vela/[email protected]: replacement directory ../types does not exist

Check failure on line 18 in api/repo/create.go

View workflow job for this annotation

GitHub Actions / database_postgres (postgres:15-alpine)

github.com/go-vela/[email protected]: replacement directory ../types does not exist
"github.com/google/uuid"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -378,6 +378,12 @@
comment.SetEdited(true)

events.SetComment(comment)
case constants.EventDelete:
deletion := events.GetPush()
deletion.SetDeleteBranch(true)
deletion.SetDeleteTag(true)

events.SetPush(deletion)
}
}

Expand Down
17 changes: 16 additions & 1 deletion api/webhook/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,27 @@ func PostWebhook(c *gin.Context) {
b.SetHeadRef(headref)
}

// if the event is delete,
// call SCM for more data not provided in webhook payload
if strings.EqualFold(b.GetEvent(), constants.EventDelete) {
// send API call to capture the commit sha for the branch
_, commit, err := scm.FromContext(c).GetBranch(ctx, u, r, r.GetBranch())
if err != nil {
retErr := fmt.Errorf("failed to get commit for repo %s on %s branch: %w", r.GetFullName(), r.GetBranch(), err)
util.HandleError(c, http.StatusInternalServerError, retErr)
}

b.SetCommit(commit)
b.SetRef(commit)
}

claire1618 marked this conversation as resolved.
Show resolved Hide resolved
// variable to store changeset files
var files []string

// check if the build event is not issue_comment or pull_request
if !strings.EqualFold(b.GetEvent(), constants.EventComment) &&
!strings.EqualFold(b.GetEvent(), constants.EventPull) {
!strings.EqualFold(b.GetEvent(), constants.EventPull) &&
!strings.EqualFold(b.GetEvent(), constants.EventDelete) {
// send API call to capture list of files changed for the commit
files, err = scm.FromContext(c).Changeset(ctx, u, repo, b.GetCommit())
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions compiler/template/native/testdata/build/conditional/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ steps:
- go get ./...
image: {{ $image }}
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

{{ end }}

Expand All @@ -21,7 +21,7 @@ steps:
- go test ./...
image: {{ $image }}
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

- name: build
commands:
Expand All @@ -31,4 +31,4 @@ steps:
GOOS: linux
image: {{ $image }}
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]
6 changes: 3 additions & 3 deletions compiler/template/native/testdata/build/conditional/want.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ steps:
- go get ./...
image: golang:latest
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

- name: test
commands:
- go test ./...
image: golang:latest
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

- name: build
commands:
Expand All @@ -22,4 +22,4 @@ steps:
GOOS: linux
image: golang:latest
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]
6 changes: 3 additions & 3 deletions compiler/template/native/testdata/step/basic/tmpl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ steps:
image: {{ .image }}
{{ .pull_policy }}
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

- name: test
commands:
- go test ./...
image: {{ .image }}
{{ .pull_policy }}
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

- name: build
commands:
Expand All @@ -27,4 +27,4 @@ steps:
image: {{ .image }}
{{ .pull_policy }}
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]
6 changes: 3 additions & 3 deletions compiler/template/native/testdata/step/basic/want.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ steps:
image: golang:latest
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

- name: sample_test
commands:
- go test ./...
image: golang:latest
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

- name: sample_build
commands:
Expand All @@ -24,4 +24,4 @@ steps:
image: golang:latest
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]
6 changes: 3 additions & 3 deletions compiler/template/native/testdata/step/conditional/tmpl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ steps:
image: {{ .image }}
{{ .pull_policy }}
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

{{ end }}

Expand All @@ -23,7 +23,7 @@ steps:
image: {{ .image }}
{{ .pull_policy }}
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

- name: build
commands:
Expand All @@ -34,4 +34,4 @@ steps:
image: {{ .image }}
{{ .pull_policy }}
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]
6 changes: 3 additions & 3 deletions compiler/template/native/testdata/step/conditional/want.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ steps:
image: golang:latest
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

- name: sample_test
commands:
- go test ./...
image: golang:latest
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

- name: sample_build
commands:
Expand All @@ -24,4 +24,4 @@ steps:
image: golang:latest
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]
6 changes: 3 additions & 3 deletions compiler/template/native/testdata/step/loop_map/tmpl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ steps:
image: golang:latest
{{ $pull }}
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

{{ range $key, $value := .images }}

Expand All @@ -22,7 +22,7 @@ steps:
image: {{ $value }}
{{ $pull }}
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

{{ end }}

Expand All @@ -35,4 +35,4 @@ steps:
image: golang:latest
{{ $pull }}
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]
6 changes: 3 additions & 3 deletions compiler/template/native/testdata/step/loop_map/want.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ steps:
image: golang:latest
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

- name: sample_test_latest
commands:
- go test ./...
image: golang:latest
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]
claire1618 marked this conversation as resolved.
Show resolved Hide resolved

- name: sample_build
commands:
Expand All @@ -24,4 +24,4 @@ steps:
image: golang:latest
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]
6 changes: 3 additions & 3 deletions compiler/template/native/testdata/step/loop_slice/tmpl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ steps:
image: golang:latest
{{ $pull }}
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

{{ range $value := .images }}

Expand All @@ -22,7 +22,7 @@ steps:
image: {{ $value }}
{{ $pull }}
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

{{ end }}

Expand All @@ -35,4 +35,4 @@ steps:
image: golang:latest
{{ $pull }}
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]
10 changes: 5 additions & 5 deletions compiler/template/native/testdata/step/loop_slice/want.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@ steps:
image: golang:latest
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

- name: sample_test_golang:latest
commands:
- go test ./...
image: golang:latest
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

- name: sample_test_golang:1.12
commands:
- go test ./...
image: golang:1.12
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

- name: sample_test_golang:1.13
commands:
- go test ./...
image: golang:1.13
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

- name: sample_build
commands:
Expand All @@ -40,4 +40,4 @@ steps:
image: golang:latest
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]
2 changes: 1 addition & 1 deletion compiler/template/native/testdata/step/multiline/step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ steps:
image: golang:latest
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]


4 changes: 2 additions & 2 deletions compiler/template/native/testdata/step/multiline/tmpl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ steps:
image: golang:latest
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

{{ .test }}

Expand All @@ -21,4 +21,4 @@ steps:
image: golang:latest
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]
6 changes: 3 additions & 3 deletions compiler/template/native/testdata/step/multiline/want.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ steps:
image: golang:latest
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

- name: sample_test
commands:
- go test ./...
image: golang:latest
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]

- name: sample_build
commands:
Expand All @@ -24,4 +24,4 @@ steps:
image: golang:latest
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ steps:
image: alpine
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ steps:
image: alpine
pull: true
ruleset:
event: [ push, pull_request ]
event: [ push, pull_request, delete ]
Loading
Loading