Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore some errors on repairAllRepos #2792

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Changes from all commits
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
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 @@
// @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
}

Check warning on line 418 in server/api/repo.go

View check run for this annotation

Codecov / codecov/patch

server/api/repo.go#L415-L418

Added lines #L415 - L418 were not covered by tests
c.Status(http.StatusNoContent)
}

Expand Down Expand Up @@ -544,7 +546,7 @@
}

for _, r := range repos {
repairRepo(c, r, false)
repairRepo(c, r, false, true)

Check warning on line 549 in server/api/repo.go

View check run for this annotation

Codecov / codecov/patch

server/api/repo.go#L549

Added line #L549 was not covered by tests
if c.Writer.Written() {
return
}
Expand All @@ -553,13 +555,20 @@
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) {

Check warning on line 558 in server/api/repo.go

View check run for this annotation

Codecov / codecov/patch

server/api/repo.go#L558

Added line #L558 was not covered by tests
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)
}

Check warning on line 571 in server/api/repo.go

View check run for this annotation

Codecov / codecov/patch

server/api/repo.go#L564-L571

Added lines #L564 - L571 were not covered by tests
return
qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
}

Expand All @@ -582,7 +591,9 @@
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)
}

Check warning on line 596 in server/api/repo.go

View check run for this annotation

Codecov / codecov/patch

server/api/repo.go#L594-L596

Added lines #L594 - L596 were not covered by tests
return
}

Expand Down