@@ -331,6 +331,24 @@ func (r *Repository) GetBranch(rbo *RepositoryBranchOptions) (*RepositoryBranch,
331331 return decodeRepositoryBranch (bodyString )
332332}
333333
334+ func (r * Repository ) CreateBranch (rbo * RepositoryBranchCreationOptions ) (* RepositoryBranch , error ) {
335+ urlStr := r .c .requestUrl ("/repositories/%s/%s/refs/branches" , rbo .Owner , rbo .RepoSlug )
336+ data := r .buildBranchBody (rbo )
337+
338+ response , err := r .c .executeRaw ("POST" , urlStr , data )
339+ if err != nil {
340+ return nil , err
341+ }
342+
343+ bodyBytes , err := ioutil .ReadAll (response )
344+ if err != nil {
345+ return nil , err
346+ }
347+
348+ bodyString := string (bodyBytes )
349+ return decodeRepositoryBranchCreated (bodyString )
350+ }
351+
334352func (r * Repository ) ListTags (rbo * RepositoryTagOptions ) (* RepositoryTags , error ) {
335353
336354 params := url.Values {}
@@ -798,6 +816,17 @@ func (r *Repository) buildPipelineBuildNumberBody(rpbno *RepositoryPipelineBuild
798816 return r .buildJsonBody (body )
799817}
800818
819+ func (r * Repository ) buildBranchBody (rbo * RepositoryBranchCreationOptions ) string {
820+ body := map [string ]interface {}{
821+ "name" : rbo .Name ,
822+ "target" : map [string ]string {
823+ "hash" : rbo .Target .Hash ,
824+ },
825+ }
826+
827+ return r .buildJsonBody (body )
828+ }
829+
801830func (r * Repository ) buildTagBody (rbo * RepositoryTagCreationOptions ) string {
802831 body := map [string ]interface {}{
803832 "name" : rbo .Name ,
@@ -949,6 +978,15 @@ func decodeRepositoryBranch(branchResponseStr string) (*RepositoryBranch, error)
949978 return & repositoryBranch , nil
950979}
951980
981+ func decodeRepositoryBranchCreated (branchResponseStr string ) (* RepositoryBranch , error ) {
982+ var responseBranchCreated RepositoryBranch
983+ err := json .Unmarshal ([]byte (branchResponseStr ), & responseBranchCreated )
984+ if err != nil {
985+ return nil , err
986+ }
987+ return & responseBranchCreated , nil
988+ }
989+
952990func decodeRepositoryTagCreated (tagResponseStr string ) (* RepositoryTag , error ) {
953991 var responseTagCreated RepositoryTag
954992 err := json .Unmarshal ([]byte (tagResponseStr ), & responseTagCreated )
0 commit comments