From 271b68d44e373f2a0cdc0187d51093ca4774bdbf Mon Sep 17 00:00:00 2001 From: ecrupper Date: Thu, 26 Oct 2023 16:04:38 -0500 Subject: [PATCH] fix(router/scm): change HTTP method from GET to PATCH for sync endpoints --- api/scm/sync.go | 14 +++++--------- api/scm/sync_org.go | 14 +++++--------- router/scm.go | 8 ++++---- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/api/scm/sync.go b/api/scm/sync.go index 045c0a1b6..f268c9a92 100644 --- a/api/scm/sync.go +++ b/api/scm/sync.go @@ -17,7 +17,7 @@ import ( "github.com/sirupsen/logrus" ) -// swagger:operation GET /api/v1/scm/repos/{org}/{repo}/sync scm SyncRepo +// swagger:operation PATCH /api/v1/scm/repos/{org}/{repo}/sync scm SyncRepo // // Sync up scm service and database in the context of a specific repo // @@ -125,11 +125,9 @@ func SyncRepo(c *gin.Context) { // update webhook webhookExists, err := scm.FromContext(c).Update(ctx, u, r, lastHook.GetWebhookID()) if err != nil { - // if webhook has been manually deleted from GitHub, // set to inactive in database if !webhookExists { - r.SetActive(false) _, err := database.FromContext(c).UpdateRepo(ctx, r) @@ -144,15 +142,13 @@ func SyncRepo(c *gin.Context) { c.JSON(http.StatusOK, fmt.Sprintf("webhook not found, repo %s deactivated", r.GetFullName())) return + } - } else { - - retErr := fmt.Errorf("unable to update repo webhook for %s: %w", r.GetFullName(), err) + retErr := fmt.Errorf("unable to update repo webhook for %s: %w", r.GetFullName(), err) - util.HandleError(c, http.StatusInternalServerError, retErr) + util.HandleError(c, http.StatusInternalServerError, retErr) - return - } + return } } diff --git a/api/scm/sync_org.go b/api/scm/sync_org.go index c0b2e08fa..bf7607533 100644 --- a/api/scm/sync_org.go +++ b/api/scm/sync_org.go @@ -16,7 +16,7 @@ import ( "github.com/sirupsen/logrus" ) -// swagger:operation GET /api/v1/scm/orgs/{org}/sync scm SyncReposForOrg +// swagger:operation PATCH /api/v1/scm/orgs/{org}/sync scm SyncReposForOrg // // Sync up repos from scm service and database in a specified org // @@ -138,11 +138,9 @@ func SyncReposForOrg(c *gin.Context) { // update webhook webhookExists, err := scm.FromContext(c).Update(ctx, u, repo, lastHook.GetWebhookID()) if err != nil { - // if webhook has been manually deleted from GitHub, // set to inactive in database if !webhookExists { - repo.SetActive(false) _, err := database.FromContext(c).UpdateRepo(ctx, repo) @@ -155,15 +153,13 @@ func SyncReposForOrg(c *gin.Context) { } continue + } - } else { - - retErr := fmt.Errorf("unable to update repo webhook for %s: %w", repo.GetFullName(), err) + retErr := fmt.Errorf("unable to update repo webhook for %s: %w", repo.GetFullName(), err) - util.HandleError(c, http.StatusInternalServerError, retErr) + util.HandleError(c, http.StatusInternalServerError, retErr) - return - } + return } } } diff --git a/router/scm.go b/router/scm.go index a8ce5745b..10c1cea81 100644 --- a/router/scm.go +++ b/router/scm.go @@ -12,8 +12,8 @@ import ( // ScmHandlers is a function that extends the provided base router group // with the API handlers for source code management functionality. // -// GET /api/v1/scm/orgs/:org/sync -// GET /api/v1/scm/repos/:org/:repo/sync . +// PATCH /api/v1/scm/orgs/:org/sync +// PATCH /api/v1/scm/repos/:org/:repo/sync . func ScmHandlers(base *gin.RouterGroup) { // SCM orgs endpoints orgs := base.Group("/scm/orgs") @@ -21,7 +21,7 @@ func ScmHandlers(base *gin.RouterGroup) { // SCM org endpoints org := orgs.Group("/:org", org.Establish()) { - org.GET("/sync", scm.SyncReposForOrg) + org.PATCH("/sync", scm.SyncReposForOrg) } // end of SCM org endpoints } // end of SCM orgs endpoints @@ -31,7 +31,7 @@ func ScmHandlers(base *gin.RouterGroup) { // SCM repo endpoints repo := repos.Group("/:org/:repo", org.Establish(), repo.Establish()) { - repo.GET("/sync", scm.SyncRepo) + repo.PATCH("/sync", scm.SyncRepo) } // end of SCM repo endpoints } // end of SCM repos endpoints }