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
This commit is contained in:
6543 2023-12-19 09:13:39 +01:00 committed by GitHub
parent 257a76c5ea
commit 1ca549190b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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{