Skip to content

Commit 731e51d

Browse files
committed
Merge remote-tracking branch 'origin'
2 parents 08514fd + 174c666 commit 731e51d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2057
-35
lines changed

scm/const.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,52 @@ func (r Role) String() (s string) {
163163
return "unknown"
164164
}
165165
}
166+
167+
// ContentKind defines the kind of a content in a directory.
168+
type ContentKind int
169+
170+
// ContentKind values.
171+
const (
172+
ContentKindUnsupported ContentKind = iota
173+
ContentKindFile
174+
ContentKindDirectory
175+
ContentKindSymlink
176+
ContentKindGitlink
177+
)
178+
179+
// String returns the string representation of ContentKind.
180+
func (k ContentKind) String() string {
181+
switch k {
182+
case ContentKindFile:
183+
return "file"
184+
case ContentKindDirectory:
185+
return "directory"
186+
case ContentKindSymlink:
187+
return "symlink"
188+
case ContentKindGitlink:
189+
return "gitlink"
190+
default:
191+
return "unsupported"
192+
}
193+
}
194+
195+
// UnmarshalJSON unmarshales the JSON-encoded ContentKind.
196+
func (k *ContentKind) UnmarshalJSON(data []byte) error {
197+
var s string
198+
if err := json.Unmarshal(data, &s); err != nil {
199+
return err
200+
}
201+
switch s {
202+
case ContentKindFile.String():
203+
*k = ContentKindFile
204+
case ContentKindDirectory.String():
205+
*k = ContentKindDirectory
206+
case ContentKindSymlink.String():
207+
*k = ContentKindSymlink
208+
case ContentKindGitlink.String():
209+
*k = ContentKindGitlink
210+
default:
211+
*k = ContentKindUnsupported
212+
}
213+
return nil
214+
}

scm/content.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ type (
2222
Data []byte
2323
}
2424

25+
// ContentInfo stores the kind of any content in a repository.
26+
ContentInfo struct {
27+
Path string
28+
Kind ContentKind
29+
}
30+
2531
// ContentService provides access to repositroy content.
2632
ContentService interface {
2733
// Find returns the repository file content by path.
@@ -35,5 +41,10 @@ type (
3541

3642
// Delete deletes a reository file.
3743
Delete(ctx context.Context, repo, path, ref string) (*Response, error)
44+
45+
// List returns a list of contents in a repository directory by path. It is
46+
// up to the driver to list the directory recursively or non-recursively,
47+
// but a robust driver should return a non-recursive list if possible.
48+
List(ctx context.Context, repo, path, ref string, opts ListOptions) ([]*ContentInfo, *Response, error)
3849
}
3950
)

scm/driver/bitbucket/content.go

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ type contentService struct {
1818

1919
func (s *contentService) Find(ctx context.Context, repo, path, ref string) (*scm.Content, *scm.Response, error) {
2020
endpoint := fmt.Sprintf("/2.0/repositories/%s/src/%s/%s", repo, ref, path)
21-
buf := new(bytes.Buffer)
22-
res, err := s.client.do(ctx, "GET", endpoint, nil, buf)
21+
out := new(bytes.Buffer)
22+
res, err := s.client.do(ctx, "GET", endpoint, nil, out)
2323
return &scm.Content{
2424
Path: path,
25-
Data: buf.Bytes(),
25+
Data: out.Bytes(),
2626
}, res, err
2727
}
2828

@@ -37,3 +37,53 @@ func (s *contentService) Update(ctx context.Context, repo, path string, params *
3737
func (s *contentService) Delete(ctx context.Context, repo, path, ref string) (*scm.Response, error) {
3838
return nil, scm.ErrNotSupported
3939
}
40+
41+
func (s *contentService) List(ctx context.Context, repo, path, ref string, opts scm.ListOptions) ([]*scm.ContentInfo, *scm.Response, error) {
42+
endpoint := fmt.Sprintf("/2.0/repositories/%s/src/%s/%s?%s", repo, ref, path, encodeListOptions(opts))
43+
out := new(contents)
44+
res, err := s.client.do(ctx, "GET", endpoint, nil, out)
45+
copyPagination(out.pagination, res)
46+
return convertContentInfoList(out), res, err
47+
}
48+
49+
type contents struct {
50+
pagination
51+
Values []*content `json:"values"`
52+
}
53+
54+
type content struct {
55+
Path string `json:"path"`
56+
Type string `json:"type"`
57+
Attributes []string `json:"attributes"`
58+
}
59+
60+
func convertContentInfoList(from *contents) []*scm.ContentInfo {
61+
to := []*scm.ContentInfo{}
62+
for _, v := range from.Values {
63+
to = append(to, convertContentInfo(v))
64+
}
65+
return to
66+
}
67+
68+
func convertContentInfo(from *content) *scm.ContentInfo {
69+
to := &scm.ContentInfo{Path: from.Path}
70+
switch from.Type {
71+
case "commit_file":
72+
to.Kind = func() scm.ContentKind {
73+
for _, attr := range from.Attributes {
74+
switch attr {
75+
case "link":
76+
return scm.ContentKindSymlink
77+
case "subrepository":
78+
return scm.ContentKindGitlink
79+
}
80+
}
81+
return scm.ContentKindFile
82+
}()
83+
case "commit_directory":
84+
to.Kind = scm.ContentKindDirectory
85+
default:
86+
to.Kind = scm.ContentKindUnsupported
87+
}
88+
return to
89+
}

scm/driver/bitbucket/content_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,28 @@ func TestContentDelete(t *testing.T) {
6464
t.Errorf("Expect Not Supported error")
6565
}
6666
}
67+
68+
func TestContentList(t *testing.T) {
69+
defer gock.Off()
70+
71+
gock.New("https://api.bitbucket.org").
72+
Get("/2.0/repositories/atlassian/atlaskit/src/master/packages/activity").
73+
Reply(200).
74+
Type("application/json").
75+
File("testdata/content_list.json")
76+
77+
client, _ := New("https://api.bitbucket.org")
78+
got, _, err := client.Contents.List(context.Background(), "atlassian/atlaskit", "packages/activity", "master", scm.ListOptions{})
79+
if err != nil {
80+
t.Error(err)
81+
}
82+
83+
want := []*scm.ContentInfo{}
84+
raw, _ := ioutil.ReadFile("testdata/content_list.json.golden")
85+
json.Unmarshal(raw, &want)
86+
87+
if diff := cmp.Diff(got, want); diff != "" {
88+
t.Errorf("Unexpected Results")
89+
t.Log(diff)
90+
}
91+
}

scm/driver/bitbucket/git.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ func (s *gitService) ListChanges(ctx context.Context, repo, ref string, opts scm
6969
return convertDiffstats(out), res, err
7070
}
7171

72+
func (s *gitService) CompareChanges(ctx context.Context, repo, source, target string, opts scm.ListOptions) ([]*scm.Change, *scm.Response, error) {
73+
path := fmt.Sprintf("2.0/repositories/%s/diffstat/%s..%s?%s", repo, source, target, encodeListOptions(opts))
74+
out := new(diffstats)
75+
res, err := s.client.do(ctx, "GET", path, nil, &out)
76+
copyPagination(out.pagination, res)
77+
return convertDiffstats(out), res, err
78+
}
79+
7280
type branch struct {
7381
Type string `json:"type"`
7482
Name string `json:"name"`

scm/driver/bitbucket/git_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,29 @@ func TestGitListChanges(t *testing.T) {
204204
t.Log(diff)
205205
}
206206
}
207+
func TestGitCompareChanges(t *testing.T) {
208+
defer gock.Off()
209+
210+
gock.New("https://api.bitbucket.org").
211+
Get("/2.0/repositories/atlassian/atlaskit/diffstat/dec26e0fe887167743c2b7e36531dedfeb6cd478..425863f9dbe56d70c8dcdbf2e4e0805e85591fcc").
212+
MatchParam("page", "1").
213+
MatchParam("pagelen", "30").
214+
Reply(200).
215+
Type("application/json").
216+
File("testdata/diffstat.json")
217+
218+
client, _ := New("https://api.bitbucket.org")
219+
got, _, err := client.Git.CompareChanges(context.Background(), "atlassian/atlaskit", "dec26e0fe887167743c2b7e36531dedfeb6cd478", "425863f9dbe56d70c8dcdbf2e4e0805e85591fcc", scm.ListOptions{Page: 1, Size: 30})
220+
if err != nil {
221+
t.Error(err)
222+
}
223+
224+
want := []*scm.Change{}
225+
raw, _ := ioutil.ReadFile("testdata/diffstat.json.golden")
226+
json.Unmarshal(raw, &want)
227+
228+
if diff := cmp.Diff(got, want); diff != "" {
229+
t.Errorf("Unexpected Results")
230+
t.Log(diff)
231+
}
232+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"pagelen":10,"values":[{"path":"packages/activity/build","type":"commit_directory","links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/build/"},"meta":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/build/?format=meta"}},"commit":{"type":"commit","hash":"710db794f15bd187db9e7a7b952aac48ebac08bb","links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/commit/710db794f15bd187db9e7a7b952aac48ebac08bb"},"html":{"href":"https://bitbucket.org/atlassian/atlaskit/commits/710db794f15bd187db9e7a7b952aac48ebac08bb"}}}},{"path":"packages/activity/dist","type":"commit_directory","links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/dist/"},"meta":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/dist/?format=meta"}},"commit":{"type":"commit","hash":"710db794f15bd187db9e7a7b952aac48ebac08bb","links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/commit/710db794f15bd187db9e7a7b952aac48ebac08bb"},"html":{"href":"https://bitbucket.org/atlassian/atlaskit/commits/710db794f15bd187db9e7a7b952aac48ebac08bb"}}}},{"path":"packages/activity/docs","type":"commit_directory","links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/docs/"},"meta":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/docs/?format=meta"}},"commit":{"type":"commit","hash":"710db794f15bd187db9e7a7b952aac48ebac08bb","links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/commit/710db794f15bd187db9e7a7b952aac48ebac08bb"},"html":{"href":"https://bitbucket.org/atlassian/atlaskit/commits/710db794f15bd187db9e7a7b952aac48ebac08bb"}}}},{"path":"packages/activity/src","type":"commit_directory","links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/src/"},"meta":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/src/?format=meta"}},"commit":{"type":"commit","hash":"710db794f15bd187db9e7a7b952aac48ebac08bb","links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/commit/710db794f15bd187db9e7a7b952aac48ebac08bb"},"html":{"href":"https://bitbucket.org/atlassian/atlaskit/commits/710db794f15bd187db9e7a7b952aac48ebac08bb"}}}},{"path":"packages/activity/test","type":"commit_directory","links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/test/"},"meta":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/test/?format=meta"}},"commit":{"type":"commit","hash":"710db794f15bd187db9e7a7b952aac48ebac08bb","links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/commit/710db794f15bd187db9e7a7b952aac48ebac08bb"},"html":{"href":"https://bitbucket.org/atlassian/atlaskit/commits/710db794f15bd187db9e7a7b952aac48ebac08bb"}}}},{"mimetype":null,"links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/.npmignore"},"meta":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/.npmignore?format=meta"},"history":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/filehistory/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/.npmignore"}},"path":"packages/activity/.npmignore","commit":{"type":"commit","hash":"710db794f15bd187db9e7a7b952aac48ebac08bb","links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/commit/710db794f15bd187db9e7a7b952aac48ebac08bb"},"html":{"href":"https://bitbucket.org/atlassian/atlaskit/commits/710db794f15bd187db9e7a7b952aac48ebac08bb"}}},"attributes":[],"type":"commit_file","size":10},{"mimetype":null,"links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/LICENSE"},"meta":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/LICENSE?format=meta"},"history":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/filehistory/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/LICENSE"}},"path":"packages/activity/LICENSE","commit":{"type":"commit","hash":"710db794f15bd187db9e7a7b952aac48ebac08bb","links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/commit/710db794f15bd187db9e7a7b952aac48ebac08bb"},"html":{"href":"https://bitbucket.org/atlassian/atlaskit/commits/710db794f15bd187db9e7a7b952aac48ebac08bb"}}},"attributes":[],"type":"commit_file","size":558},{"mimetype":"text/vnd.trolltech.linguist","links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/index.ts"},"meta":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/index.ts?format=meta"},"history":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/filehistory/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/index.ts"}},"path":"packages/activity/index.ts","commit":{"type":"commit","hash":"710db794f15bd187db9e7a7b952aac48ebac08bb","links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/commit/710db794f15bd187db9e7a7b952aac48ebac08bb"},"html":{"href":"https://bitbucket.org/atlassian/atlaskit/commits/710db794f15bd187db9e7a7b952aac48ebac08bb"}}},"attributes":[],"type":"commit_file","size":494},{"mimetype":"application/json","links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/package.json"},"meta":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/package.json?format=meta"},"history":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/filehistory/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/package.json"}},"path":"packages/activity/package.json","commit":{"type":"commit","hash":"710db794f15bd187db9e7a7b952aac48ebac08bb","links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/commit/710db794f15bd187db9e7a7b952aac48ebac08bb"},"html":{"href":"https://bitbucket.org/atlassian/atlaskit/commits/710db794f15bd187db9e7a7b952aac48ebac08bb"}}},"attributes":[],"type":"commit_file","size":1914},{"mimetype":"text/vnd.trolltech.linguist","links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/package.json.d.ts"},"meta":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/package.json.d.ts?format=meta"},"history":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/filehistory/710db794f15bd187db9e7a7b952aac48ebac08bb/packages/activity/package.json.d.ts"}},"path":"packages/activity/package.json.d.ts","commit":{"type":"commit","hash":"710db794f15bd187db9e7a7b952aac48ebac08bb","links":{"self":{"href":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/commit/710db794f15bd187db9e7a7b952aac48ebac08bb"},"html":{"href":"https://bitbucket.org/atlassian/atlaskit/commits/710db794f15bd187db9e7a7b952aac48ebac08bb"}}},"attributes":[],"type":"commit_file","size":61}],"page":1,"next":"https://api.bitbucket.org/2.0/repositories/atlassian/atlaskit/src/master/packages/activity?page=8xhd"}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
{
3+
"path": "packages/activity/build",
4+
"kind": "directory"
5+
},
6+
{
7+
"path": "packages/activity/dist",
8+
"kind": "directory"
9+
},
10+
{
11+
"path": "packages/activity/docs",
12+
"kind": "directory"
13+
},
14+
{
15+
"path": "packages/activity/src",
16+
"kind": "directory"
17+
},
18+
{
19+
"path": "packages/activity/test",
20+
"kind": "directory"
21+
},
22+
{
23+
"path": "packages/activity/.npmignore",
24+
"kind": "file"
25+
},
26+
{
27+
"path": "packages/activity/LICENSE",
28+
"kind": "file"
29+
},
30+
{
31+
"path": "packages/activity/index.ts",
32+
"kind": "file"
33+
},
34+
{
35+
"path": "packages/activity/package.json",
36+
"kind": "file"
37+
},
38+
{
39+
"path": "packages/activity/package.json.d.ts",
40+
"kind": "file"
41+
}
42+
]

scm/driver/gitea/content.go

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"bytes"
99
"context"
1010
"fmt"
11-
"strings"
1211

1312
"github.com/drone/go-scm/scm"
1413
)
@@ -18,14 +17,12 @@ type contentService struct {
1817
}
1918

2019
func (s *contentService) Find(ctx context.Context, repo, path, ref string) (*scm.Content, *scm.Response, error) {
21-
ref = strings.TrimPrefix(ref, "refs/heads/")
22-
ref = strings.TrimPrefix(ref, "refs/tags/")
23-
endpoint := fmt.Sprintf("api/v1/repos/%s/raw/%s/%s", repo, ref, path)
24-
buf := new(bytes.Buffer)
25-
res, err := s.client.do(ctx, "GET", endpoint, nil, buf)
20+
endpoint := fmt.Sprintf("api/v1/repos/%s/raw/%s/%s", repo, scm.TrimRef(ref), path)
21+
out := new(bytes.Buffer)
22+
res, err := s.client.do(ctx, "GET", endpoint, nil, out)
2623
return &scm.Content{
2724
Path: path,
28-
Data: buf.Bytes(),
25+
Data: out.Bytes(),
2926
}, res, err
3027
}
3128

@@ -40,3 +37,40 @@ func (s *contentService) Update(ctx context.Context, repo, path string, params *
4037
func (s *contentService) Delete(ctx context.Context, repo, path, ref string) (*scm.Response, error) {
4138
return nil, scm.ErrNotSupported
4239
}
40+
41+
func (s *contentService) List(ctx context.Context, repo, path, ref string, _ scm.ListOptions) ([]*scm.ContentInfo, *scm.Response, error) {
42+
endpoint := fmt.Sprintf("api/v1/repos/%s/contents/%s?ref=%s", repo, path, ref)
43+
out := []*content{}
44+
res, err := s.client.do(ctx, "GET", endpoint, nil, &out)
45+
return convertContentInfoList(out), res, err
46+
}
47+
48+
type content struct {
49+
Path string `json:"path"`
50+
Type string `json:"type"`
51+
}
52+
53+
func convertContentInfoList(from []*content) []*scm.ContentInfo {
54+
to := []*scm.ContentInfo{}
55+
for _, v := range from {
56+
to = append(to, convertContentInfo(v))
57+
}
58+
return to
59+
}
60+
61+
func convertContentInfo(from *content) *scm.ContentInfo {
62+
to := &scm.ContentInfo{Path: from.Path}
63+
switch from.Type {
64+
case "file":
65+
to.Kind = scm.ContentKindFile
66+
case "dir":
67+
to.Kind = scm.ContentKindDirectory
68+
case "symlink":
69+
to.Kind = scm.ContentKindSymlink
70+
case "submodule":
71+
to.Kind = scm.ContentKindGitlink
72+
default:
73+
to.Kind = scm.ContentKindUnsupported
74+
}
75+
return to
76+
}

scm/driver/gitea/content_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ package gitea
66

77
import (
88
"context"
9+
"encoding/json"
10+
"io/ioutil"
911
"testing"
1012

1113
"github.com/drone/go-scm/scm"
14+
"github.com/google/go-cmp/cmp"
1215
"github.com/h2non/gock"
1316
)
1417

@@ -63,3 +66,35 @@ func TestContentDelete(t *testing.T) {
6366
t.Errorf("Expect Not Supported error")
6467
}
6568
}
69+
70+
func TestContentList(t *testing.T) {
71+
defer gock.Off()
72+
73+
gock.New("https://try.gitea.io").
74+
Get("/api/v1/repos/go-gitea/gitea/contents/docs/content/doc").
75+
MatchParam("ref", "master").
76+
Reply(200).
77+
Type("application/json").
78+
File("testdata/content_list.json")
79+
80+
client, _ := New("https://try.gitea.io")
81+
got, _, err := client.Contents.List(
82+
context.Background(),
83+
"go-gitea/gitea",
84+
"docs/content/doc",
85+
"master",
86+
scm.ListOptions{},
87+
)
88+
if err != nil {
89+
t.Error(err)
90+
}
91+
92+
want := []*scm.ContentInfo{}
93+
raw, _ := ioutil.ReadFile("testdata/content_list.json.golden")
94+
json.Unmarshal(raw, &want)
95+
96+
if diff := cmp.Diff(got, want); diff != "" {
97+
t.Errorf("Unexpected Results")
98+
t.Log(diff)
99+
}
100+
}

0 commit comments

Comments
 (0)