From 1274de2b2dea8ae4fe263bbf262a88d6edcc2646 Mon Sep 17 00:00:00 2001 From: Harri Avellan Date: Thu, 18 Jul 2024 14:30:45 +0300 Subject: [PATCH] Handle empty repositories in gitea when listing PRs (#3925) --- server/forge/gitea/gitea.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/forge/gitea/gitea.go b/server/forge/gitea/gitea.go index a489e66a8..546984cf1 100644 --- a/server/forge/gitea/gitea.go +++ b/server/forge/gitea/gitea.go @@ -472,12 +472,17 @@ func (c *Gitea) PullRequests(ctx context.Context, u *model.User, r *model.Repo, return nil, err } - pullRequests, _, err := client.ListRepoPullRequests(r.Owner, r.Name, gitea.ListPullRequestsOptions{ + pullRequests, resp, err := client.ListRepoPullRequests(r.Owner, r.Name, gitea.ListPullRequestsOptions{ ListOptions: gitea.ListOptions{Page: p.Page, PageSize: p.PerPage}, State: gitea.StateOpen, }) if err != nil { - return nil, err + // Repositories without commits return empty list with status code 404 + if pullRequests != nil && resp != nil && resp.StatusCode == http.StatusNotFound { + err = nil + } else { + return nil, err + } } result := make([]*model.PullRequest, len(pullRequests))