mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-04 18:21:06 +02:00
Fix bitbucket dir fetching (#3668)
This commit is contained in:
parent
dbd91d3884
commit
fa4b1f76bd
@ -217,14 +217,14 @@ func Test_bitbucket(t *testing.T) {
|
||||
|
||||
g.Describe("When requesting repo directory contents", func() {
|
||||
g.It("Should return the details", func() {
|
||||
files, err := c.Dir(ctx, fakeUser, fakeRepo, fakePipeline, "/dir")
|
||||
files, err := c.Dir(ctx, fakeUser, fakeRepo, fakePipeline, "dir")
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(len(files)).Equal(3)
|
||||
g.Assert(files[0].Name).Equal("README.md")
|
||||
g.Assert(string(files[0].Data)).Equal("dummy payload")
|
||||
})
|
||||
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(errors.Is(err, &types.ErrConfigNotFound{})).IsTrue()
|
||||
})
|
||||
|
@ -114,7 +114,7 @@ func getRepoFile(c *gin.Context) {
|
||||
switch c.Param("file") {
|
||||
case "dir":
|
||||
c.String(http.StatusOK, repoDirPayload)
|
||||
case "dir_not_found/":
|
||||
case "dir_not_found":
|
||||
c.String(http.StatusNotFound, "")
|
||||
case "file_not_found":
|
||||
c.String(http.StatusNotFound, "")
|
||||
|
@ -52,7 +52,7 @@ const (
|
||||
pathOrgPerms = "%s/2.0/workspaces/%s/permissions?%s"
|
||||
pathPullRequests = "%s/2.0/repositories/%s/%s/pullrequests?%s"
|
||||
pathBranchCommits = "%s/2.0/repositories/%s/%s/commits/%s"
|
||||
pathDir = "%s/2.0/repositories/%s/%s/src/%s%s"
|
||||
pathDir = "%s/2.0/repositories/%s/%s/src/%s/%s"
|
||||
pageSize = 100
|
||||
)
|
||||
|
||||
|
@ -262,8 +262,14 @@ func (c *client) File(ctx context.Context, u *model.User, r *model.Repo, p *mode
|
||||
return nil, fmt.Errorf("unable to create bitbucket client: %w", err)
|
||||
}
|
||||
|
||||
b, _, err := bc.Projects.GetTextFileContent(ctx, r.Owner, r.Name, f, p.Commit)
|
||||
b, resp, err := bc.Projects.GetTextFileContent(ctx, r.Owner, r.Name, f, p.Commit)
|
||||
if err != nil {
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
// requested directory might not exist
|
||||
return nil, &forge_types.ErrConfigNotFound{
|
||||
Configs: []string{f},
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return b, nil
|
||||
@ -281,7 +287,10 @@ func (c *client) Dir(ctx context.Context, u *model.User, r *model.Repo, p *model
|
||||
list, resp, err := bc.Projects.ListFiles(ctx, r.Owner, r.Name, path, opts)
|
||||
if err != nil {
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
break // requested directory might not exist
|
||||
// requested directory might not exist
|
||||
return nil, &forge_types.ErrConfigNotFound{
|
||||
Configs: []string{path},
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ func (f *forgeFetcherContext) fetch(c context.Context, config string) ([]*types.
|
||||
|
||||
fileMetas, err := f.getFirstAvailableConfig(ctx, configs)
|
||||
if err == nil {
|
||||
return fileMetas, err
|
||||
return fileMetas, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("user defined config '%s' not found: %w", config, err)
|
||||
@ -102,7 +102,7 @@ func (f *forgeFetcherContext) fetch(c context.Context, config string) ([]*types.
|
||||
// for the order see shared/constants/constants.go
|
||||
fileMetas, err := f.getFirstAvailableConfig(ctx, constant.DefaultConfigOrder[:])
|
||||
if err == nil {
|
||||
return fileMetas, err
|
||||
return fileMetas, nil
|
||||
}
|
||||
|
||||
select {
|
||||
|
Loading…
x
Reference in New Issue
Block a user