Skip to content

Commit

Permalink
ignore some errors on repairAllRepos (#2792)
Browse files Browse the repository at this point in the history
close  #2791

Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
  • Loading branch information
6543 and qwerty287 authored Dec 13, 2023
1 parent c6ce23e commit 4974d4c
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions server/api/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,10 @@ func DeleteRepo(c *gin.Context) {
// @Param repo_id path int true "the repository id"
func RepairRepo(c *gin.Context) {
repo := session.Repo(c)
repairRepo(c, repo, true)

repairRepo(c, repo, true, false)
if c.Writer.Written() {
return
}
c.Status(http.StatusNoContent)
}

Expand Down Expand Up @@ -544,7 +546,7 @@ func RepairAllRepos(c *gin.Context) {
}

for _, r := range repos {
repairRepo(c, r, false)
repairRepo(c, r, false, true)
if c.Writer.Written() {
return
}
Expand All @@ -553,13 +555,20 @@ func RepairAllRepos(c *gin.Context) {
c.Status(http.StatusNoContent)
}

func repairRepo(c *gin.Context, repo *model.Repo, withPerms bool) {
func repairRepo(c *gin.Context, repo *model.Repo, withPerms, skipOnErr bool) {
forge := server.Config.Services.Forge
_store := store.FromContext(c)

user, err := _store.GetUser(repo.UserID)
if err != nil {
handleDbError(c, err)
if errors.Is(err, types.RecordNotExist) {
if !skipOnErr {
c.AbortWithStatus(http.StatusNotFound)
}
log.Error().Err(err).Msgf("could not get user on repo repair")
} else {
_ = c.AbortWithError(http.StatusInternalServerError, err)
}
return
}

Expand All @@ -582,7 +591,9 @@ func repairRepo(c *gin.Context, repo *model.Repo, withPerms bool) {
from, err := forge.Repo(c, user, repo.ForgeRemoteID, repo.Owner, repo.Name)
if err != nil {
log.Error().Err(err).Msgf("get repo '%s/%s' from forge", repo.Owner, repo.Name)
c.AbortWithStatus(http.StatusInternalServerError)
if !skipOnErr {
c.AbortWithStatus(http.StatusInternalServerError)
}
return
}

Expand Down

0 comments on commit 4974d4c

Please sign in to comment.