Skip to content

Commit

Permalink
Bitbucket list files fix (#154)
Browse files Browse the repository at this point in the history
* if input page args has url, then it should be used to fetch list of files
  • Loading branch information
mohitg0795 authored Feb 22, 2022
1 parent 2f3e807 commit d3dd72e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions scm/driver/bitbucket/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func (s *contentService) Delete(ctx context.Context, repo, path string, params *

func (s *contentService) List(ctx context.Context, repo, path, ref string, opts scm.ListOptions) ([]*scm.ContentInfo, *scm.Response, error) {
endpoint := fmt.Sprintf("/2.0/repositories/%s/src/%s/%s?%s", repo, ref, path, encodeListOptions(opts))
if opts.URL != "" {
endpoint = opts.URL
}

out := new(contents)
res, err := s.client.do(ctx, "GET", endpoint, nil, out)
copyPagination(out.pagination, res)
Expand Down
26 changes: 26 additions & 0 deletions scm/driver/bitbucket/content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,29 @@ func TestContentList(t *testing.T) {
t.Log(diff)
}
}

func TestContentListWithUrlInput(t *testing.T) {
defer gock.Off()

mockNextPageUri := "https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/master/packages/activity?pageLen=3&page=RPfL"

gock.New(mockNextPageUri).
Reply(200).
Type("application/json").
File("testdata/content_list.json")

client, _ := New("https://api.bitbucket.org")
got, _, err := client.Contents.List(context.Background(), "atlassian/atlaskit", "packages/activity", "master", scm.ListOptions{URL: mockNextPageUri})
if err != nil {
t.Error(err)
}

want := []*scm.ContentInfo{}
raw, _ := ioutil.ReadFile("testdata/content_list.json.golden")
json.Unmarshal(raw, &want)

if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("Unexpected Results")
t.Log(diff)
}
}

0 comments on commit d3dd72e

Please sign in to comment.