@@ -276,6 +276,24 @@ func (r *Repository) ListTags(rbo *RepositoryTagOptions) (*RepositoryTags, error
276
276
return decodeRepositoryTags (bodyString )
277
277
}
278
278
279
+ func (r * Repository ) CreateTag (rbo * RepositoryTagCreationOptions ) (* RepositoryTag , error ) {
280
+ urlStr := r .c .requestUrl ("/repositories/%s/%s/refs/tags" , rbo .Owner , rbo .RepoSlug )
281
+ data := r .buildTagBody (rbo )
282
+
283
+ response , err := r .c .executeRaw ("POST" , urlStr , data )
284
+ if err != nil {
285
+ return nil , err
286
+ }
287
+
288
+ bodyBytes , err := ioutil .ReadAll (response )
289
+ if err != nil {
290
+ return nil , err
291
+ }
292
+
293
+ bodyString := string (bodyBytes )
294
+ return decodeRepositoryTagCreated (bodyString )
295
+ }
296
+
279
297
func (r * Repository ) Delete (ro * RepositoryOptions ) (interface {}, error ) {
280
298
urlStr := r .c .requestUrl ("/repositories/%s/%s" , ro .Owner , ro .RepoSlug )
281
299
return r .c .execute ("DELETE" , urlStr , "" )
@@ -480,6 +498,17 @@ func (r *Repository) buildPipelineBuildNumberBody(rpbno *RepositoryPipelineBuild
480
498
return r .buildJsonBody (body )
481
499
}
482
500
501
+ func (r * Repository ) buildTagBody (rbo * RepositoryTagCreationOptions ) string {
502
+ body := map [string ]interface {}{
503
+ "name" : rbo .Name ,
504
+ "target" : map [string ]string {
505
+ "hash" : rbo .Target .Hash ,
506
+ },
507
+ }
508
+
509
+ return r .buildJsonBody (body )
510
+ }
511
+
483
512
func decodeRepository (repoResponse interface {}) (* Repository , error ) {
484
513
repoMap := repoResponse .(map [string ]interface {})
485
514
@@ -579,6 +608,15 @@ func decodeRepositoryBranch(branchResponseStr string) (*RepositoryBranch, error)
579
608
return & repositoryBranch , nil
580
609
}
581
610
611
+ func decodeRepositoryTagCreated (tagResponseStr string ) (* RepositoryTag , error ) {
612
+ var responseTagCreated RepositoryTag
613
+ err := json .Unmarshal ([]byte (tagResponseStr ), & responseTagCreated )
614
+ if err != nil {
615
+ return nil , err
616
+ }
617
+ return & responseTagCreated , nil
618
+ }
619
+
582
620
func decodeRepositoryTags (tagResponseStr string ) (* RepositoryTags , error ) {
583
621
584
622
var tagResponseMap map [string ]interface {}
0 commit comments