Skip to content

Commit

Permalink
refactor(hook): nest API response and use Gorm preload to populate re…
Browse files Browse the repository at this point in the history
…po and build data (#1147)

* init commit

* fix tests, prune duplicate data, prettify

* gci

* use int64 for DB reps of integer fields

---------

Co-authored-by: David May <[email protected]>
  • Loading branch information
ecrupper and wass3rw3rk committed Sep 16, 2024
1 parent f3b5f5c commit ddee444
Show file tree
Hide file tree
Showing 56 changed files with 2,346 additions and 385 deletions.
4 changes: 2 additions & 2 deletions api/admin/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"

"github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
"github.com/go-vela/server/util"
"github.com/go-vela/types/library"
)

// swagger:operation PUT /api/v1/admin/hook admin AdminUpdateHook
Expand Down Expand Up @@ -57,7 +57,7 @@ func UpdateHook(c *gin.Context) {
l.Debug("platform admin: updating hook")

// capture body from API request
input := new(library.Hook)
input := new(types.Hook)

err := c.Bind(input)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions api/hook/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"

"github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/util"
"github.com/go-vela/types/library"
)

// swagger:operation POST /api/v1/hooks/{org}/{repo} webhook CreateHook
Expand Down Expand Up @@ -74,7 +74,7 @@ func CreateHook(c *gin.Context) {
l.Debugf("creating new hook for repo %s", r.GetFullName())

// capture body from API request
input := new(library.Hook)
input := new(types.Hook)

err := c.Bind(input)
if err != nil {
Expand All @@ -96,7 +96,7 @@ func CreateHook(c *gin.Context) {
}

// update fields in webhook object
input.SetRepoID(r.GetID())
input.SetRepo(r)
input.SetNumber(1)

if input.GetCreated() == 0 {
Expand Down
2 changes: 1 addition & 1 deletion api/hook/redeliver.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func RedeliverHook(c *gin.Context) {

l.Debugf("redelivering hook %s", entry)

err := scm.FromContext(c).RedeliverWebhook(c, u, r, h)
err := scm.FromContext(c).RedeliverWebhook(c, u, h)
if err != nil {
retErr := fmt.Errorf("unable to redeliver hook %s: %w", entry, err)

Expand Down
4 changes: 2 additions & 2 deletions api/hook/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"

"github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/hook"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/util"
"github.com/go-vela/types/library"
)

// swagger:operation PUT /api/v1/hooks/{org}/{repo}/{hook} webhook UpdateHook
Expand Down Expand Up @@ -82,7 +82,7 @@ func UpdateHook(c *gin.Context) {
l.Debugf("updating hook %s", entry)

// capture body from API request
input := new(library.Hook)
input := new(types.Hook)

err := c.Bind(input)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions api/repo/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
)

// swagger:operation POST /api/v1/repos repos CreateRepo
Expand Down Expand Up @@ -241,7 +240,7 @@ func CreateRepo(c *gin.Context) {
r.SetHash(dbRepo.GetHash())
}

h := new(library.Hook)
h := new(types.Hook)

// err being nil means we have a record of this repo (dbRepo)
if err == nil {
Expand Down Expand Up @@ -321,7 +320,7 @@ func CreateRepo(c *gin.Context) {
// create init hook in the DB after repo has been added in order to capture its ID
if c.Value("webhookvalidation").(bool) {
// update initialization hook
h.SetRepoID(r.GetID())
h.SetRepo(r)
// create first hook for repo in the database
_, err = database.FromContext(c).CreateHook(ctx, h)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion api/repo/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func RepairRepo(c *gin.Context) {
return
}

hook.SetRepoID(r.GetID())
hook.SetRepo(r)

_, err = database.FromContext(c).CreateHook(ctx, hook)
if err != nil {
Expand Down
Loading

0 comments on commit ddee444

Please sign in to comment.