mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-07-13 15:14:22 +00:00
Fix bitbucket file fetching (#3604)
closes https://github.com/woodpecker-ci/woodpecker/issues/3600
This commit is contained in:
parent
c9a3bfb321
commit
b0c9dfd2cf
@ -17,6 +17,7 @@ package bitbucket
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -232,9 +233,15 @@ func (c *config) Repos(ctx context.Context, u *model.User) ([]*model.Repo, error
|
|||||||
func (c *config) File(ctx context.Context, u *model.User, r *model.Repo, p *model.Pipeline, f string) ([]byte, error) {
|
func (c *config) File(ctx context.Context, u *model.User, r *model.Repo, p *model.Pipeline, f string) ([]byte, error) {
|
||||||
config, err := c.newClient(ctx, u).FindSource(r.Owner, r.Name, p.Commit, f)
|
config, err := c.newClient(ctx, u).FindSource(r.Owner, r.Name, p.Commit, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
var rspErr internal.Error
|
||||||
|
if ok := errors.As(err, &rspErr); ok && rspErr.Status == http.StatusNotFound {
|
||||||
|
return nil, &forge_types.ErrConfigNotFound{
|
||||||
|
Configs: []string{f},
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return []byte(*config), err
|
return []byte(*config), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dir fetches a folder from the bitbucket repository
|
// Dir fetches a folder from the bitbucket repository
|
||||||
@ -245,6 +252,12 @@ func (c *config) Dir(ctx context.Context, u *model.User, r *model.Repo, p *model
|
|||||||
for {
|
for {
|
||||||
filesResp, err := client.GetRepoFiles(r.Owner, r.Name, p.Commit, f, page)
|
filesResp, err := client.GetRepoFiles(r.Owner, r.Name, p.Commit, f, page)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
var rspErr internal.Error
|
||||||
|
if ok := errors.As(err, &rspErr); ok && rspErr.Status == http.StatusNotFound {
|
||||||
|
return nil, &forge_types.ErrConfigNotFound{
|
||||||
|
Configs: []string{f},
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, file := range filesResp.Values {
|
for _, file := range filesResp.Values {
|
||||||
|
@ -18,6 +18,7 @@ package bitbucket
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
@ -179,6 +180,7 @@ func Test_bitbucket(t *testing.T) {
|
|||||||
g.It("Should handle not found error", func() {
|
g.It("Should handle not found error", func() {
|
||||||
_, err := c.File(ctx, fakeUser, fakeRepo, fakePipeline, "file_not_found")
|
_, err := c.File(ctx, fakeUser, fakeRepo, fakePipeline, "file_not_found")
|
||||||
g.Assert(err).IsNotNil()
|
g.Assert(err).IsNotNil()
|
||||||
|
g.Assert(errors.Is(err, &types.ErrConfigNotFound{})).IsTrue()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -222,8 +224,9 @@ func Test_bitbucket(t *testing.T) {
|
|||||||
g.Assert(string(files[0].Data)).Equal("dummy payload")
|
g.Assert(string(files[0].Data)).Equal("dummy payload")
|
||||||
})
|
})
|
||||||
g.It("Should handle not found errors", func() {
|
g.It("Should handle not found errors", func() {
|
||||||
_, err := c.Dir(ctx, fakeUser, fakeRepo, fakePipeline, "/dir_not_found")
|
_, err := c.Dir(ctx, fakeUser, fakeRepo, fakePipeline, "dir_not_found/")
|
||||||
g.Assert(err).IsNotNil()
|
g.Assert(err).IsNotNil()
|
||||||
|
g.Assert(errors.Is(err, &types.ErrConfigNotFound{})).IsTrue()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user