@@ -2,6 +2,7 @@ package bitbucket
2
2
3
3
import (
4
4
"encoding/json"
5
+ "errors"
5
6
"io/ioutil"
6
7
"net/url"
7
8
"os"
@@ -214,8 +215,29 @@ func (r *Repository) ListBranches(rbo *RepositoryBranchOptions) (*RepositoryBran
214
215
if err != nil {
215
216
return nil , err
216
217
}
218
+ bodyBytes , err := ioutil .ReadAll (response )
219
+ if err != nil {
220
+ return nil , err
221
+ }
222
+ bodyString := string (bodyBytes )
223
+ return decodeRepositoryBranches (bodyString )
224
+ }
217
225
218
- return decodeRepositoryBranches (response )
226
+ func (r * Repository ) GetBranch (rbo * RepositoryBranchOptions ) (* RepositoryBranch , error ) {
227
+ if rbo .BranchName == "" {
228
+ return nil , errors .New ("Error: Branch Name is empty" )
229
+ }
230
+ urlStr := r .c .requestUrl ("/repositories/%s/%s/refs/branches/%s" , rbo .Owner , rbo .RepoSlug , rbo .BranchName )
231
+ response , err := r .c .executeRaw ("GET" , urlStr , "" )
232
+ if err != nil {
233
+ return nil , err
234
+ }
235
+ bodyBytes , err := ioutil .ReadAll (response )
236
+ if err != nil {
237
+ return nil , err
238
+ }
239
+ bodyString := string (bodyBytes )
240
+ return decodeRepositoryBranch (bodyString )
219
241
}
220
242
221
243
func (r * Repository ) ListTags (rbo * RepositoryTagOptions ) (* RepositoryTags , error ) {
@@ -486,10 +508,10 @@ func decodeRepositoryFiles(repoResponse interface{}) ([]RepositoryFile, error) {
486
508
return * repositoryFiles , nil
487
509
}
488
510
489
- func decodeRepositoryBranches (branchResponse interface {} ) (* RepositoryBranches , error ) {
511
+ func decodeRepositoryBranches (branchResponseStr string ) (* RepositoryBranches , error ) {
490
512
491
513
var branchResponseMap map [string ]interface {}
492
- err := json .Unmarshal (branchResponse .( []byte ), & branchResponseMap )
514
+ err := json .Unmarshal ([]byte ( branchResponseStr ), & branchResponseMap )
493
515
if err != nil {
494
516
return nil , err
495
517
}
@@ -538,6 +560,21 @@ func decodeRepositoryBranches(branchResponse interface{}) (*RepositoryBranches,
538
560
return & repositoryBranches , nil
539
561
}
540
562
563
+ func decodeRepositoryBranch (branchResponseStr string ) (* RepositoryBranch , error ) {
564
+
565
+ var branchResponseMap map [string ]interface {}
566
+ err := json .Unmarshal ([]byte (branchResponseStr ), & branchResponseMap )
567
+ if err != nil {
568
+ return nil , err
569
+ }
570
+ var repositoryBranch RepositoryBranch
571
+ err = mapstructure .Decode (branchResponseMap , & repositoryBranch )
572
+ if err != nil {
573
+ return nil , err
574
+ }
575
+ return & repositoryBranch , nil
576
+ }
577
+
541
578
func decodeRepositoryTags (tagResponse interface {}) (* RepositoryTags , error ) {
542
579
543
580
var tagResponseMap map [string ]interface {}
0 commit comments