From 1ca549190b4ae443d3d24abc53f74ca0cc6c4fc3 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 19 Dec 2023 09:13:39 +0100 Subject: [PATCH] Gitea driver: ignore GetOrg error if we get a valid user. (#2967) `[POST] /api/repos?forge_remote_id=12345` ```json {"level":"error","error":"GetOrgByName","time":"2023-12-19T01:03:36Z","caller":"/woodpecker/src/github.com/woodpecker-ci/woodpecker/server/api/repo.go:143","message":"Could not fetch organization from forge."} ``` because `https://codeberg.org/api/v1/orgs/6543` returns an error. `https://codeberg.org/api/v1/users/6543` do not. close #2714 --- server/forge/gitea/gitea.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/server/forge/gitea/gitea.go b/server/forge/gitea/gitea.go index 13ba41693..501de1572 100644 --- a/server/forge/gitea/gitea.go +++ b/server/forge/gitea/gitea.go @@ -21,6 +21,7 @@ package gitea import ( "context" "crypto/tls" + "errors" "fmt" "net" "net/http" @@ -548,11 +549,8 @@ func (c *Gitea) Org(ctx context.Context, u *model.User, owner string) (*model.Or return nil, err } - org, _, err := client.GetOrg(owner) - if err != nil { - return nil, err - } - if org != nil { + org, _, orgErr := client.GetOrg(owner) + if orgErr == nil && org != nil { return &model.Org{ Name: org.UserName, Private: gitea.VisibleType(org.Visibility) != gitea.VisibleTypePublic, @@ -561,6 +559,9 @@ func (c *Gitea) Org(ctx context.Context, u *model.User, owner string) (*model.Or user, _, err := client.GetUserInfo(owner) if err != nil { + if orgErr != nil { + err = errors.Join(orgErr, err) + } return nil, err } return &model.Org{