diff --git a/server/forge/bitbucket/bitbucket_test.go b/server/forge/bitbucket/bitbucket_test.go index dd384296402..c9f878bd76f 100644 --- a/server/forge/bitbucket/bitbucket_test.go +++ b/server/forge/bitbucket/bitbucket_test.go @@ -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() }) diff --git a/server/forge/bitbucket/fixtures/handler.go b/server/forge/bitbucket/fixtures/handler.go index ab2104f7b69..146dcfef854 100644 --- a/server/forge/bitbucket/fixtures/handler.go +++ b/server/forge/bitbucket/fixtures/handler.go @@ -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, "") diff --git a/server/forge/bitbucket/internal/client.go b/server/forge/bitbucket/internal/client.go index 16e4380bc15..9bae76ae8c9 100644 --- a/server/forge/bitbucket/internal/client.go +++ b/server/forge/bitbucket/internal/client.go @@ -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 ) diff --git a/server/forge/bitbucketdatacenter/bitbucketdatacenter.go b/server/forge/bitbucketdatacenter/bitbucketdatacenter.go index b881a701db9..58b0c6d3726 100644 --- a/server/forge/bitbucketdatacenter/bitbucketdatacenter.go +++ b/server/forge/bitbucketdatacenter/bitbucketdatacenter.go @@ -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 } diff --git a/server/services/config/forge.go b/server/services/config/forge.go index 7413e783d41..9de4bfb3fc2 100644 --- a/server/services/config/forge.go +++ b/server/services/config/forge.go @@ -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 {