@@ -94,6 +94,15 @@ type Pipeline struct {
94
94
Repository Repository
95
95
}
96
96
97
+ type PipelineVariables struct {
98
+ Page int
99
+ Pagelen int
100
+ MaxDepth int
101
+ Size int
102
+ Next string
103
+ Variables []PipelineVariable
104
+ }
105
+
97
106
type PipelineVariable struct {
98
107
Type string
99
108
Uuid string
@@ -331,6 +340,42 @@ func (r *Repository) UpdatePipelineConfig(rpo *RepositoryPipelineOptions) (*Pipe
331
340
return decodePipelineRepository (response )
332
341
}
333
342
343
+ func (r * Repository ) ListPipelineVariables (opt * RepositoryPipelineVariablesOptions ) (* PipelineVariables , error ) {
344
+
345
+ params := url.Values {}
346
+ if opt .Query != "" {
347
+ params .Add ("q" , opt .Query )
348
+ }
349
+
350
+ if opt .Sort != "" {
351
+ params .Add ("sort" , opt .Sort )
352
+ }
353
+
354
+ if opt .PageNum > 0 {
355
+ params .Add ("page" , strconv .Itoa (opt .PageNum ))
356
+ }
357
+
358
+ if opt .Pagelen > 0 {
359
+ params .Add ("pagelen" , strconv .Itoa (opt .Pagelen ))
360
+ }
361
+
362
+ if opt .MaxDepth > 0 {
363
+ params .Add ("max_depth" , strconv .Itoa (opt .MaxDepth ))
364
+ }
365
+
366
+ urlStr := r .c .requestUrl ("/repositories/%s/%s/pipelines_config/variables/?%s" , opt .Owner , opt .RepoSlug , params .Encode ())
367
+ response , err := r .c .executeRaw ("GET" , urlStr , "" )
368
+ if err != nil {
369
+ return nil , err
370
+ }
371
+ bodyBytes , err := ioutil .ReadAll (response )
372
+ if err != nil {
373
+ return nil , err
374
+ }
375
+ bodyString := string (bodyBytes )
376
+ return decodePipelineVariables (bodyString )
377
+ }
378
+
334
379
func (r * Repository ) AddPipelineVariable (rpvo * RepositoryPipelineVariableOptions ) (* PipelineVariable , error ) {
335
380
data := r .buildPipelineVariableBody (rpvo )
336
381
urlStr := r .c .requestUrl ("/repositories/%s/%s/pipelines_config/variables/" , rpvo .Owner , rpvo .RepoSlug )
@@ -696,6 +741,58 @@ func decodePipelineRepository(repoResponse interface{}) (*Pipeline, error) {
696
741
return pipeline , nil
697
742
}
698
743
744
+ func decodePipelineVariables (responseStr string ) (* PipelineVariables , error ) {
745
+
746
+ var responseMap map [string ]interface {}
747
+ err := json .Unmarshal ([]byte (responseStr ), & responseMap )
748
+ if err != nil {
749
+ return nil , err
750
+ }
751
+
752
+ values := responseMap ["values" ].([]interface {})
753
+ var variables []PipelineVariable
754
+ for _ , variable := range values {
755
+ var pipelineVariable PipelineVariable
756
+ err = mapstructure .Decode (variable , & pipelineVariable )
757
+ if err == nil {
758
+ variables = append (variables , pipelineVariable )
759
+ }
760
+ }
761
+
762
+ page , ok := responseMap ["page" ].(float64 )
763
+ if ! ok {
764
+ page = 0
765
+ }
766
+
767
+ pagelen , ok := responseMap ["pagelen" ].(float64 )
768
+ if ! ok {
769
+ pagelen = 0
770
+ }
771
+ max_depth , ok := responseMap ["max_depth" ].(float64 )
772
+ if ! ok {
773
+ max_depth = 0
774
+ }
775
+ size , ok := responseMap ["size" ].(float64 )
776
+ if ! ok {
777
+ size = 0
778
+ }
779
+
780
+ next , ok := responseMap ["next" ].(string )
781
+ if ! ok {
782
+ next = ""
783
+ }
784
+
785
+ pipelineVariables := PipelineVariables {
786
+ Page : int (page ),
787
+ Pagelen : int (pagelen ),
788
+ MaxDepth : int (max_depth ),
789
+ Size : int (size ),
790
+ Next : next ,
791
+ Variables : variables ,
792
+ }
793
+ return & pipelineVariables , nil
794
+ }
795
+
699
796
func decodePipelineVariableRepository (repoResponse interface {}) (* PipelineVariable , error ) {
700
797
repoMap := repoResponse .(map [string ]interface {})
701
798
0 commit comments