...

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

Documentation: github.com/xanzy/go-gitlab

     1  //
     2  // Copyright 2021, Sander van Harmelen
     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  )
    23  
    24  // LicenseTemplate represents a license template.
    25  //
    26  // GitLab API docs:
    27  // https://docs.gitlab.com/ee/api/templates/licenses.html
    28  type LicenseTemplate struct {
    29  	Key         string   `json:"key"`
    30  	Name        string   `json:"name"`
    31  	Nickname    string   `json:"nickname"`
    32  	Featured    bool     `json:"featured"`
    33  	HTMLURL     string   `json:"html_url"`
    34  	SourceURL   string   `json:"source_url"`
    35  	Description string   `json:"description"`
    36  	Conditions  []string `json:"conditions"`
    37  	Permissions []string `json:"permissions"`
    38  	Limitations []string `json:"limitations"`
    39  	Content     string   `json:"content"`
    40  }
    41  
    42  // LicenseTemplatesService handles communication with the license templates
    43  // related methods of the GitLab API.
    44  //
    45  // GitLab API docs: https://docs.gitlab.com/ee/api/templates/licenses.html
    46  type LicenseTemplatesService struct {
    47  	client *Client
    48  }
    49  
    50  // ListLicenseTemplatesOptions represents the available
    51  // ListLicenseTemplates() options.
    52  //
    53  // GitLab API docs:
    54  // https://docs.gitlab.com/ee/api/templates/licenses.html#list-license-templates
    55  type ListLicenseTemplatesOptions struct {
    56  	ListOptions
    57  	Popular *bool `url:"popular,omitempty" json:"popular,omitempty"`
    58  }
    59  
    60  // ListLicenseTemplates get all license templates.
    61  //
    62  // GitLab API docs:
    63  // https://docs.gitlab.com/ee/api/templates/licenses.html#list-license-templates
    64  func (s *LicenseTemplatesService) ListLicenseTemplates(opt *ListLicenseTemplatesOptions, options ...RequestOptionFunc) ([]*LicenseTemplate, *Response, error) {
    65  	req, err := s.client.NewRequest(http.MethodGet, "templates/licenses", opt, options)
    66  	if err != nil {
    67  		return nil, nil, err
    68  	}
    69  
    70  	var lts []*LicenseTemplate
    71  	resp, err := s.client.Do(req, &lts)
    72  	if err != nil {
    73  		return nil, resp, err
    74  	}
    75  
    76  	return lts, resp, nil
    77  }
    78  
    79  // GetLicenseTemplateOptions represents the available
    80  // GetLicenseTemplate() options.
    81  //
    82  // GitLab API docs:
    83  // https://docs.gitlab.com/ee/api/templates/licenses.html#single-license-template
    84  type GetLicenseTemplateOptions struct {
    85  	Project  *string `url:"project,omitempty" json:"project,omitempty"`
    86  	Fullname *string `url:"fullname,omitempty" json:"fullname,omitempty"`
    87  }
    88  
    89  // GetLicenseTemplate get a single license template. You can pass parameters
    90  // to replace the license placeholder.
    91  //
    92  // GitLab API docs:
    93  // https://docs.gitlab.com/ee/api/templates/licenses.html#single-license-template
    94  func (s *LicenseTemplatesService) GetLicenseTemplate(template string, opt *GetLicenseTemplateOptions, options ...RequestOptionFunc) (*LicenseTemplate, *Response, error) {
    95  	u := fmt.Sprintf("templates/licenses/%s", template)
    96  
    97  	req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
    98  	if err != nil {
    99  		return nil, nil, err
   100  	}
   101  
   102  	lt := new(LicenseTemplate)
   103  	resp, err := s.client.Do(req, lt)
   104  	if err != nil {
   105  		return nil, resp, err
   106  	}
   107  
   108  	return lt, resp, nil
   109  }
   110  

View as plain text