...

Source file src/github.com/xanzy/go-gitlab/dockerfile_templates.go

Documentation: github.com/xanzy/go-gitlab

     1  //
     2  // Copyright 2022, FantasyTeddy
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package gitlab
    18  
    19  import (
    20  	"fmt"
    21  	"net/http"
    22  	"net/url"
    23  )
    24  
    25  // DockerfileTemplatesService handles communication with the Dockerfile
    26  // templates related methods of the GitLab API.
    27  //
    28  // GitLab API docs: https://docs.gitlab.com/ee/api/templates/dockerfiles.html
    29  type DockerfileTemplatesService struct {
    30  	client *Client
    31  }
    32  
    33  // DockerfileTemplate represents a GitLab Dockerfile template.
    34  //
    35  // GitLab API docs: https://docs.gitlab.com/ee/api/templates/dockerfiles.html
    36  type DockerfileTemplate struct {
    37  	Name    string `json:"name"`
    38  	Content string `json:"content"`
    39  }
    40  
    41  // DockerfileTemplateListItem represents a GitLab Dockerfile template from the list.
    42  //
    43  // GitLab API docs: https://docs.gitlab.com/ee/api/templates/dockerfiles.html
    44  type DockerfileTemplateListItem struct {
    45  	Key  string `json:"key"`
    46  	Name string `json:"name"`
    47  }
    48  
    49  // ListDockerfileTemplatesOptions represents the available ListAllTemplates() options.
    50  //
    51  // GitLab API docs:
    52  // https://docs.gitlab.com/ee/api/templates/dockerfiles.html#list-dockerfile-templates
    53  type ListDockerfileTemplatesOptions ListOptions
    54  
    55  // ListTemplates get a list of available Dockerfile templates.
    56  //
    57  // GitLab API docs:
    58  // https://docs.gitlab.com/ee/api/templates/dockerfiles.html#list-dockerfile-templates
    59  func (s *DockerfileTemplatesService) ListTemplates(opt *ListDockerfileTemplatesOptions, options ...RequestOptionFunc) ([]*DockerfileTemplateListItem, *Response, error) {
    60  	req, err := s.client.NewRequest(http.MethodGet, "templates/dockerfiles", opt, options)
    61  	if err != nil {
    62  		return nil, nil, err
    63  	}
    64  
    65  	var gs []*DockerfileTemplateListItem
    66  	resp, err := s.client.Do(req, &gs)
    67  	if err != nil {
    68  		return nil, resp, err
    69  	}
    70  
    71  	return gs, resp, nil
    72  }
    73  
    74  // GetTemplate get a single Dockerfile template.
    75  //
    76  // GitLab API docs:
    77  // https://docs.gitlab.com/ee/api/templates/dockerfiles.html#single-dockerfile-template
    78  func (s *DockerfileTemplatesService) GetTemplate(key string, options ...RequestOptionFunc) (*DockerfileTemplate, *Response, error) {
    79  	u := fmt.Sprintf("templates/dockerfiles/%s", url.PathEscape(key))
    80  
    81  	req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
    82  	if err != nil {
    83  		return nil, nil, err
    84  	}
    85  
    86  	g := new(DockerfileTemplate)
    87  	resp, err := s.client.Do(req, g)
    88  	if err != nil {
    89  		return nil, resp, err
    90  	}
    91  
    92  	return g, resp, nil
    93  }
    94  

View as plain text