Skip to content

Commit ed38664

Browse files
authored
Merge pull request #24 from rcchopra/hyp-17516-v4
Bitbucket Find Function Fixed ( Synced with drone go-scm version )
1 parent e137de1 commit ed38664

File tree

5 files changed

+24
-26
lines changed

5 files changed

+24
-26
lines changed

scm/driver/bitbucket/repo.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,7 @@ func (s *repositoryService) Find(ctx context.Context, repo string) (*scm.Reposit
9292
path := fmt.Sprintf("2.0/repositories/%s", repo)
9393
out := new(repository)
9494
res, err := s.client.do(ctx, "GET", path, nil, out)
95-
if err != nil {
96-
return nil, res, err
97-
}
98-
repoPerm, _, err := s.FindPerms(ctx, repo)
99-
return convertRepository2(out, repoPerm), res, err
95+
return convertRepository(out), res, err
10096
}
10197

10298
// FindHook returns a repository hook.

scm/driver/bitbucket/repo_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ func TestRepositoryFind(t *testing.T) {
2525
Type("application/json").
2626
File("testdata/repo.json")
2727

28-
gock.New("https://api.bitbucket.org").
29-
Get("/2.0/user/permissions/repositories").
30-
MatchParam("q", `repository.full_name="atlassian/stash-example-plugin"`).
31-
Reply(200).
32-
Type("application/json").
33-
File("testdata/perms.json")
28+
3429

3530
client, _ := New("https://api.bitbucket.org")
3631
got, _, err := client.Repositories.Find(context.Background(), "atlassian/stash-example-plugin")

scm/driver/bitbucket/testdata/repo.json.golden

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
"ID": "{7dd600e6-0d9c-4801-b967-cb4cc17359ff}",
33
"Namespace": "atlassian",
44
"Name": "stash-example-plugin",
5-
"Perm": {
6-
"Pull": true,
7-
"Push": true,
8-
"Admin": true
9-
},
5+
106
"Branch": "master",
117
"Private": true,
128
"Clone": "https://bitbucket.org/atlassian/stash-example-plugin.git",

scm/transport/proxy/proxy.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ func NewTransport(base http.RoundTripper, proxyURL string) (http.RoundTripper, e
6666
if err != nil {
6767
return nil, err
6868
}
69-
70-
return &Transport{
71-
Base: base,
72-
ProxyURL: parsedURL,
69+
return &http.Transport{
70+
Proxy: http.ProxyURL(parsedURL),
7371
}, nil
7472
}

scm/transport/proxy/proxy_test.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,28 @@ func TestNewTransport_ValidProxyURL(t *testing.T) {
3737
if err != nil {
3838
t.Fatalf("Expected no error for valid proxy URL, got: %v", err)
3939
}
40-
41-
proxyTransport, ok := transport.(*Transport)
40+
41+
proxyTransport, ok := transport.(*http.Transport)
4242
if !ok {
43-
t.Fatal("Expected transport to be of type *Transport")
43+
t.Fatal("Expected transport to be of type *http.Transport")
44+
}
45+
46+
// Test that the proxy function is set correctly
47+
if proxyTransport.Proxy == nil {
48+
t.Fatal("Expected proxy function to be set")
4449
}
45-
50+
51+
// Test the proxy function with a sample request
52+
testURL, _ := url.Parse("http://example.com")
53+
req := &http.Request{URL: testURL}
54+
proxyURLResult, err := proxyTransport.Proxy(req)
55+
if err != nil {
56+
t.Fatalf("Expected no error from proxy function, got: %v", err)
57+
}
58+
4659
expectedURL, _ := url.Parse(proxyURL)
47-
if proxyTransport.ProxyURL.String() != expectedURL.String() {
48-
t.Errorf("Expected proxy URL %s, got %s", expectedURL.String(), proxyTransport.ProxyURL.String())
60+
if proxyURLResult.String() != expectedURL.String() {
61+
t.Errorf("Expected proxy URL %s, got %s", expectedURL.String(), proxyURLResult.String())
4962
}
5063
}
5164

0 commit comments

Comments
 (0)