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 13 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 @@ -378,6 +378,12 @@ func defaultAllowedEvents(sliceDefaults []string, maskDefaults int64) *library.E
comment.SetEdited(true)

events.SetComment(comment)
case constants.EventDelete:
del := new(actions.Delete)
del.SetBranch(true)
del.SetTag(true)

events.SetDelete(del)
}
}

Expand Down
16 changes: 15 additions & 1 deletion api/webhook/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@

defer func() {
// send API call to update the webhook
_, err = database.FromContext(c).UpdateHook(ctx, h)

Check failure on line 182 in api/webhook/post.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] api/webhook/post.go#L182

Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
Raw output
api/webhook/post.go:182:32: Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
		_, err = database.FromContext(c).UpdateHook(ctx, h)
		                             ^
if err != nil {
logrus.Errorf("unable to update webhook %s/%d: %v", r.GetFullName(), h.GetNumber(), err)
}
Expand Down Expand Up @@ -367,12 +367,26 @@
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)
}

// 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 Expand Up @@ -833,7 +847,7 @@
case "archived", "unarchived", constants.ActionEdited:
logrus.Debugf("repository action %s for %s", h.GetEventAction(), r.GetFullName())
// send call to get repository from database
dbRepo, err := database.FromContext(c).GetRepoForOrg(ctx, r.GetOrg(), r.GetName())

Check failure on line 850 in api/webhook/post.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] api/webhook/post.go#L850

Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
Raw output
api/webhook/post.go:850:38: Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
		dbRepo, err := database.FromContext(c).GetRepoForOrg(ctx, r.GetOrg(), r.GetName())
		                                   ^
if err != nil {
retErr := fmt.Errorf("%s: failed to get repo %s: %w", baseErr, r.GetFullName(), err)

Expand All @@ -844,7 +858,7 @@
}

// send API call to capture the last hook for the repo
lastHook, err := database.FromContext(c).LastHookForRepo(ctx, dbRepo)

Check failure on line 861 in api/webhook/post.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] api/webhook/post.go#L861

Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
Raw output
api/webhook/post.go:861:40: Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
		lastHook, err := database.FromContext(c).LastHookForRepo(ctx, dbRepo)
		                                     ^
if err != nil {
retErr := fmt.Errorf("unable to get last hook for repo %s: %w", r.GetFullName(), err)

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