Skip to content

Commit 7f78ca0

Browse files
author
TP Honey
authored
Merge pull request #183 from DeepakPatankar/deepak/PL-25812
Remove the null value de-reference issue when the bitbucket server url is nil
2 parents bb2f62e + a262104 commit 7f78ca0

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package integration
2+
3+
import (
4+
"context"
5+
"net/http"
6+
"testing"
7+
8+
"github.com/drone/go-scm/scm"
9+
"github.com/drone/go-scm/scm/driver/stash"
10+
"github.com/drone/go-scm/scm/transport"
11+
)
12+
13+
func TestListRepos(t *testing.T) {
14+
if token == "" {
15+
t.Skip("Skipping, Acceptance test")
16+
}
17+
client, _ = stash.New(endpoint)
18+
client.Client = &http.Client{
19+
Transport: &transport.BasicAuth{
20+
Username: username,
21+
Password: token,
22+
},
23+
}
24+
25+
repos, response, listerr := client.Repositories.List(context.Background(), scm.ListOptions{})
26+
if listerr != nil {
27+
t.Errorf("List Repos got an error %v", listerr)
28+
}
29+
if response.Status != http.StatusOK {
30+
t.Errorf("List Repos did not get a 200 back %v", response.Status)
31+
}
32+
33+
if len(repos) == 0 {
34+
t.Errorf("Got Empty repo list")
35+
}
36+
37+
}

scm/driver/stash/repo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func (s *repositoryService) List(ctx context.Context, opts scm.ListOptions) ([]*
161161
path := fmt.Sprintf("rest/api/1.0/repos?%s", encodeListRoleOptions(opts))
162162
out := new(repositories)
163163
res, err := s.client.do(ctx, "GET", path, nil, &out)
164-
if !out.pagination.LastPage.Bool {
164+
if res != nil && !out.pagination.LastPage.Bool {
165165
res.Page.First = 1
166166
res.Page.Next = opts.Page + 1
167167
}
@@ -183,7 +183,7 @@ func (s *repositoryService) ListHooks(ctx context.Context, repo string, opts scm
183183
path := fmt.Sprintf("rest/api/1.0/projects/%s/repos/%s/webhooks?%s", namespace, name, encodeListOptions(opts))
184184
out := new(hooks)
185185
res, err := s.client.do(ctx, "GET", path, nil, out)
186-
if !out.pagination.LastPage.Bool {
186+
if res != nil && !out.pagination.LastPage.Bool {
187187
res.Page.First = 1
188188
res.Page.Next = opts.Page + 1
189189
}

0 commit comments

Comments
 (0)