Skip to content

Commit

Permalink
fix(router/scm): change HTTP method from GET to PATCH for sync endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper committed Oct 26, 2023
1 parent 4eec5e9 commit 271b68d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
14 changes: 5 additions & 9 deletions api/scm/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
}

Expand Down
14 changes: 5 additions & 9 deletions api/scm/sync_org.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions router/scm.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ 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")
{
// 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

Expand All @@ -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
}

0 comments on commit 271b68d

Please sign in to comment.