github.com/google/go-github/v65@v65.0.0/github/gitignore.go (about) 1 // Copyright 2013 The go-github AUTHORS. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 package github 7 8 import ( 9 "context" 10 "fmt" 11 ) 12 13 // GitignoresService provides access to the gitignore related functions in the 14 // GitHub API. 15 // 16 // GitHub API docs: https://docs.github.com/rest/gitignore/ 17 type GitignoresService service 18 19 // Gitignore represents a .gitignore file as returned by the GitHub API. 20 type Gitignore struct { 21 Name *string `json:"name,omitempty"` 22 Source *string `json:"source,omitempty"` 23 } 24 25 func (g Gitignore) String() string { 26 return Stringify(g) 27 } 28 29 // List all available Gitignore templates. 30 // 31 // GitHub API docs: https://docs.github.com/rest/gitignore/gitignore#get-all-gitignore-templates 32 // 33 //meta:operation GET /gitignore/templates 34 func (s *GitignoresService) List(ctx context.Context) ([]string, *Response, error) { 35 req, err := s.client.NewRequest("GET", "gitignore/templates", nil) 36 if err != nil { 37 return nil, nil, err 38 } 39 40 var availableTemplates []string 41 resp, err := s.client.Do(ctx, req, &availableTemplates) 42 if err != nil { 43 return nil, resp, err 44 } 45 46 return availableTemplates, resp, nil 47 } 48 49 // Get a Gitignore by name. 50 // 51 // GitHub API docs: https://docs.github.com/rest/gitignore/gitignore#get-a-gitignore-template 52 // 53 //meta:operation GET /gitignore/templates/{name} 54 func (s *GitignoresService) Get(ctx context.Context, name string) (*Gitignore, *Response, error) { 55 u := fmt.Sprintf("gitignore/templates/%v", name) 56 req, err := s.client.NewRequest("GET", u, nil) 57 if err != nil { 58 return nil, nil, err 59 } 60 61 gitignore := new(Gitignore) 62 resp, err := s.client.Do(ctx, req, gitignore) 63 if err != nil { 64 return nil, resp, err 65 } 66 67 return gitignore, resp, nil 68 }