Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: changes from merge conflict
  • Loading branch information
jbrockopp committed Mar 4, 2023
commit 2b7e70a182ab41a720a2d24a01280279e397049a
2 changes: 1 addition & 1 deletion api/repo/chown.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func ChownRepo(c *gin.Context) {
// update repo owner
r.SetUserID(u.GetID())

// send API call to updated the repo
// send API call to update the repo
err := database.FromContext(c).UpdateRepo(r)
if err != nil {
retErr := fmt.Errorf("unable to change owner of repo %s to %s: %w", r.GetFullName(), u.GetName(), err)
Expand Down
5 changes: 3 additions & 2 deletions api/repo/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func CreateRepo(c *gin.Context) {
// get repo information from the source
r, err := scm.FromContext(c).GetRepo(u, input)
if err != nil {
retErr := fmt.Errorf("unable to read repo %s from source: %w", input.GetFullName(), err)
retErr := fmt.Errorf("unable to retrieve repo info for %s from source: %w", r.GetFullName(), err)

util.HandleError(c, http.StatusBadRequest, retErr)

Expand Down Expand Up @@ -238,8 +238,9 @@ func CreateRepo(c *gin.Context) {
r.SetHash(dbRepo.GetHash())
}

// send API call to create the webhook
// check if we should create the webhook
if c.Value("webhookvalidation").(bool) {
// send API call to create the webhook
_, err = scm.FromContext(c).Enable(u, r.GetOrg(), r.GetName(), r.GetHash())
if err != nil {
retErr := fmt.Errorf("unable to create webhook for %s: %w", r.GetFullName(), err)
Expand Down
25 changes: 18 additions & 7 deletions api/repo/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,36 @@ func DeleteRepo(c *gin.Context) {
if err != nil {
retErr := fmt.Errorf("unable to delete webhook for %s: %w", r.GetFullName(), err)

// set the status code based off the
code := http.StatusInternalServerError
if err.Error() == "Repo not found" {
code = http.StatusNotFound
util.HandleError(c, http.StatusNotFound, retErr)

return
}

util.HandleError(c, code, retErr)
util.HandleError(c, http.StatusInternalServerError, retErr)

return
}

err = database.FromContext(c).DeleteRepo(r)
// Mark the repo as inactive
r.SetActive(false)

err = database.FromContext(c).UpdateRepo(r)
if err != nil {
retErr := fmt.Errorf("unable to delete repo %s: %w", r.GetFullName(), err)
retErr := fmt.Errorf("unable to set repo %s to inactive: %w", r.GetFullName(), err)

util.HandleError(c, http.StatusInternalServerError, retErr)

return
}

c.JSON(http.StatusOK, fmt.Sprintf("repo %s deleted", r.GetFullName()))
// Comment out actual delete until delete mechanism is fleshed out
// err = database.FromContext(c).DeleteRepo(r.ID)
// if err != nil {
// retErr := fmt.Errorf("Error while deleting repo %s: %w", r.FullName, err)
// util.HandleError(c, http.StatusInternalServerError, retErr)
// return
// }

c.JSON(http.StatusOK, fmt.Sprintf("repo %s set to inactive", r.GetFullName()))
}
2 changes: 1 addition & 1 deletion api/repo/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func ListRepos(c *gin.Context) {
// https://pkg.go.dev/github.com/sirupsen/logrus?tab=doc#Entry.WithFields
logrus.WithFields(logrus.Fields{
"user": u.GetName(),
}).Infof("reading repos for user %s", u.GetName())
}).Infof("listing repos for user %s", u.GetName())

// capture page query parameter if present
page, err := strconv.Atoi(c.DefaultQuery("page", "1"))
Expand Down
24 changes: 18 additions & 6 deletions api/repo/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,26 @@ func RepairRepo(c *gin.Context) {
return
}

// send API call to create the webhook
_, err = scm.FromContext(c).Enable(u, r.GetOrg(), r.GetName(), r.GetHash())
if err != nil {
retErr := fmt.Errorf("unable to create webhook for %s: %w", r.GetFullName(), err)
// check if we should create the webhook
if c.Value("webhookvalidation").(bool) {
// send API call to create the webhook
_, err = scm.FromContext(c).Enable(u, r.GetOrg(), r.GetName(), r.GetHash())
if err != nil {
retErr := fmt.Errorf("unable to create webhook for %s: %w", r.GetFullName(), err)

util.HandleError(c, http.StatusInternalServerError, retErr)
switch err.Error() {
case "repo already enabled":
util.HandleError(c, http.StatusConflict, retErr)
return
case "repo not found":
util.HandleError(c, http.StatusNotFound, retErr)
return
}

return
util.HandleError(c, http.StatusInternalServerError, retErr)

return
}
}

// if the repo was previously inactive, mark it as active
Expand Down