diff --git a/api/build/restart.go b/api/build/restart.go index d819c1805..1b8f23c12 100644 --- a/api/build/restart.go +++ b/api/build/restart.go @@ -350,7 +350,7 @@ func RestartBuild(c *gin.Context) { d.SetBuilds(build) - _, err = database.FromContext(c).UpdateDeployment(d) + _, err = database.FromContext(c).UpdateDeployment(ctx, d) if err != nil { logger.Errorf("unable to set update deployment for build %s: %v", entry, err) } diff --git a/api/deployment/get.go b/api/deployment/get.go index b940fd408..72456e79a 100644 --- a/api/deployment/get.go +++ b/api/deployment/get.go @@ -87,7 +87,7 @@ func GetDeployment(c *gin.Context) { } // send API call to database to capture the deployment - d, err := database.FromContext(c).GetDeployment(int64(number)) + d, err := database.FromContext(c).GetDeployment(ctx, int64(number)) if err != nil { // send API call to SCM to capture the deployment d, err = scm.FromContext(c).GetDeployment(ctx, u, r, int64(number)) diff --git a/api/webhook/post.go b/api/webhook/post.go index 4564b97f1..1a321aef2 100644 --- a/api/webhook/post.go +++ b/api/webhook/post.go @@ -697,7 +697,7 @@ func PostWebhook(c *gin.Context) { } else { build := append(d.GetBuilds(), b) d.SetBuilds(build) - _, err := database.FromContext(c).UpdateDeployment(d) + _, err := database.FromContext(c).UpdateDeployment(ctx, d) if err != nil { retErr := fmt.Errorf("%s: failed to update deployment %s/%d: %w", baseErr, repo.GetFullName(), d.GetNumber(), err) util.HandleError(c, http.StatusInternalServerError, retErr) diff --git a/database/deployment/delete.go b/database/deployment/delete.go index 489f91e81..73e2658b9 100644 --- a/database/deployment/delete.go +++ b/database/deployment/delete.go @@ -3,6 +3,7 @@ package deployment import ( + "context" "github.com/go-vela/types/constants" "github.com/go-vela/types/database" "github.com/go-vela/types/library" @@ -10,7 +11,7 @@ import ( ) // DeleteDeployment deletes an existing deployment from the database. -func (e *engine) DeleteDeployment(d *library.Deployment) error { +func (e *engine) DeleteDeployment(ctx context.Context, d *library.Deployment) error { e.logger.WithFields(logrus.Fields{ "deployment": d.GetID(), }).Tracef("deleting deployment %d in the database", d.GetID()) diff --git a/database/deployment/delete_test.go b/database/deployment/delete_test.go index 65eb04673..2fcd4c68f 100644 --- a/database/deployment/delete_test.go +++ b/database/deployment/delete_test.go @@ -66,7 +66,7 @@ func TestDeployment_Engine_DeleteDeployment(t *testing.T) { // run tests for _, test := range tests { t.Run(test.name, func(t *testing.T) { - err = test.database.DeleteDeployment(_deploymentOne) + err = test.database.DeleteDeployment(context.TODO(), _deploymentOne) if test.failure { if err == nil { diff --git a/database/deployment/get.go b/database/deployment/get.go index bdc7cd68b..9d84b958e 100644 --- a/database/deployment/get.go +++ b/database/deployment/get.go @@ -3,6 +3,7 @@ package deployment import ( + "context" "strconv" "github.com/go-vela/types/constants" @@ -11,7 +12,7 @@ import ( ) // GetDeployment gets a deployment by ID from the database. -func (e *engine) GetDeployment(id int64) (*library.Deployment, error) { +func (e *engine) GetDeployment(ctx context.Context, id int64) (*library.Deployment, error) { e.logger.Tracef("getting deployment %d from the database", id) // variable to store query results diff --git a/database/deployment/get_test.go b/database/deployment/get_test.go index 49d4097f5..d962c798a 100644 --- a/database/deployment/get_test.go +++ b/database/deployment/get_test.go @@ -73,7 +73,7 @@ func TestDeployment_Engine_GetDeployment(t *testing.T) { // run tests for _, test := range tests { t.Run(test.name, func(t *testing.T) { - got, err := test.database.GetDeployment(1) + got, err := test.database.GetDeployment(context.TODO(), 1) if test.failure { if err == nil { diff --git a/database/deployment/interface.go b/database/deployment/interface.go index 0429c4d29..837aa2121 100644 --- a/database/deployment/interface.go +++ b/database/deployment/interface.go @@ -33,9 +33,9 @@ type DeploymentInterface interface { // CreateDeployment defines a function that creates a new deployment. CreateDeployment(context.Context, *library.Deployment) (*library.Deployment, error) // DeleteDeployment defines a function that deletes an existing deployment. - DeleteDeployment(*library.Deployment) error + DeleteDeployment(context.Context, *library.Deployment) error // GetDeployment defines a function that gets a deployment by ID. - GetDeployment(int64) (*library.Deployment, error) + GetDeployment(context.Context, int64) (*library.Deployment, error) // GetDeploymentForRepo defines a function that gets a deployment by repo ID and number. GetDeploymentForRepo(context.Context, *library.Repo, int64) (*library.Deployment, error) // ListDeployments defines a function that gets a list of all deployments. @@ -43,5 +43,5 @@ type DeploymentInterface interface { // ListDeploymentsForRepo defines a function that gets a list of deployments by repo ID. ListDeploymentsForRepo(context.Context, *library.Repo, int, int) ([]*library.Deployment, error) // UpdateDeployment defines a function that updates an existing deployment. - UpdateDeployment(*library.Deployment) (*library.Deployment, error) + UpdateDeployment(context.Context, *library.Deployment) (*library.Deployment, error) } diff --git a/database/deployment/update.go b/database/deployment/update.go index e7f0973bb..b163516ff 100644 --- a/database/deployment/update.go +++ b/database/deployment/update.go @@ -3,6 +3,7 @@ package deployment import ( + "context" "github.com/go-vela/types/constants" "github.com/go-vela/types/database" "github.com/go-vela/types/library" @@ -10,7 +11,7 @@ import ( ) // UpdateDeployment updates an existing deployment in the database. -func (e *engine) UpdateDeployment(d *library.Deployment) (*library.Deployment, error) { +func (e *engine) UpdateDeployment(ctx context.Context, d *library.Deployment) (*library.Deployment, error) { e.logger.WithFields(logrus.Fields{ "deployment": d.GetID(), }).Tracef("updating deployment %d in the database", d.GetID()) diff --git a/database/deployment/update_test.go b/database/deployment/update_test.go index 5b3e00f56..ca9b2548e 100644 --- a/database/deployment/update_test.go +++ b/database/deployment/update_test.go @@ -68,7 +68,7 @@ WHERE "id" = $13`). // run tests for _, test := range tests { t.Run(test.name, func(t *testing.T) { - _, err = test.database.UpdateDeployment(_deploymentOne) + _, err = test.database.UpdateDeployment(context.TODO(), _deploymentOne) if test.failure { if err == nil { diff --git a/database/integration_test.go b/database/integration_test.go index 4d3b5104a..ffa3381b3 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -547,13 +547,13 @@ func testDeployments(t *testing.T, db Interface, resources *Resources) { // update the deployments for _, deployment := range resources.Deployments { - _, err = db.UpdateDeployment(deployment) + _, err = db.UpdateDeployment(context.TODO(), deployment) if err != nil { t.Errorf("unable to update deployment %d: %v", deployment.GetID(), err) } // lookup the deployment by ID - got, err := db.GetDeployment(deployment.GetID()) + got, err := db.GetDeployment(context.TODO(), deployment.GetID()) if err != nil { t.Errorf("unable to get deployment %d by ID: %v", deployment.GetID(), err) } @@ -566,7 +566,7 @@ func testDeployments(t *testing.T, db Interface, resources *Resources) { // delete the deployments for _, deployment := range resources.Deployments { - err = db.DeleteDeployment(deployment) + err = db.DeleteDeployment(context.TODO(), deployment) if err != nil { t.Errorf("unable to delete hook %d: %v", deployment.GetID(), err) }