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

refactor(hook): nest API response and use Gorm preload to populate repo and build data #1147

Merged
merged 12 commits into from
Sep 16, 2024
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
Loading