github.com/google/go-github/v64@v64.0.0/github/meta.go (about) 1 // Copyright 2014 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 "bytes" 10 "context" 11 "fmt" 12 "net/url" 13 ) 14 15 // MetaService provides access to functions in the GitHub API that GitHub categorizes as "meta". 16 type MetaService service 17 18 // APIMeta represents metadata about the GitHub API. 19 type APIMeta struct { 20 // An array of IP addresses in CIDR format specifying the addresses 21 // that incoming service hooks will originate from on GitHub.com. 22 Hooks []string `json:"hooks,omitempty"` 23 24 // An array of IP addresses in CIDR format specifying the Git servers 25 // for GitHub.com. 26 Git []string `json:"git,omitempty"` 27 28 // Whether authentication with username and password is supported. 29 // (GitHub Enterprise instances using CAS or OAuth for authentication 30 // will return false. Features like Basic Authentication with a 31 // username and password, sudo mode, and two-factor authentication are 32 // not supported on these servers.) 33 VerifiablePasswordAuthentication *bool `json:"verifiable_password_authentication,omitempty"` 34 35 // An array of IP addresses in CIDR format specifying the addresses 36 // which serve GitHub Packages. 37 Packages []string `json:"packages,omitempty"` 38 39 // An array of IP addresses in CIDR format specifying the addresses 40 // which serve GitHub Pages websites. 41 Pages []string `json:"pages,omitempty"` 42 43 // An array of IP addresses specifying the addresses that source imports 44 // will originate from on GitHub.com. 45 Importer []string `json:"importer,omitempty"` 46 47 // An array of IP addresses specifying the addresses that source imports 48 // will originate from on GitHub Enterprise Cloud. 49 GithubEnterpriseImporter []string `json:"github_enterprise_importer,omitempty"` 50 51 // An array of IP addresses in CIDR format specifying the IP addresses 52 // GitHub Actions will originate from. 53 Actions []string `json:"actions,omitempty"` 54 55 // An array of IP addresses in CIDR format specifying the IP addresses 56 // Dependabot will originate from. 57 Dependabot []string `json:"dependabot,omitempty"` 58 59 // A map of algorithms to SSH key fingerprints. 60 SSHKeyFingerprints map[string]string `json:"ssh_key_fingerprints,omitempty"` 61 62 // An array of SSH keys. 63 SSHKeys []string `json:"ssh_keys,omitempty"` 64 65 // An array of IP addresses in CIDR format specifying the addresses 66 // which serve GitHub websites. 67 Web []string `json:"web,omitempty"` 68 69 // An array of IP addresses in CIDR format specifying the addresses 70 // which serve GitHub APIs. 71 API []string `json:"api,omitempty"` 72 73 // A map of GitHub services and their associated domains. Note that many 74 // of these domains are represented as wildcards (e.g. "*.github.com"). 75 Domains map[string][]string `json:"domains,omitempty"` 76 } 77 78 // Get returns information about GitHub.com, the service. Or, if you access 79 // this endpoint on your organization’s GitHub Enterprise installation, this 80 // endpoint provides information about that installation. 81 // 82 // GitHub API docs: https://docs.github.com/rest/meta/meta#get-github-meta-information 83 // 84 //meta:operation GET /meta 85 func (s *MetaService) Get(ctx context.Context) (*APIMeta, *Response, error) { 86 req, err := s.client.NewRequest("GET", "meta", nil) 87 if err != nil { 88 return nil, nil, err 89 } 90 91 meta := new(APIMeta) 92 resp, err := s.client.Do(ctx, req, meta) 93 if err != nil { 94 return nil, resp, err 95 } 96 97 return meta, resp, nil 98 } 99 100 // APIMeta returns information about GitHub.com. 101 // 102 // Deprecated: Use MetaService.Get instead. 103 func (c *Client) APIMeta(ctx context.Context) (*APIMeta, *Response, error) { 104 return c.Meta.Get(ctx) 105 } 106 107 // Octocat returns an ASCII art octocat with the specified message in a speech 108 // bubble. If message is empty, a random zen phrase is used. 109 // 110 // GitHub API docs: https://docs.github.com/rest/meta/meta#get-octocat 111 // 112 //meta:operation GET /octocat 113 func (s *MetaService) Octocat(ctx context.Context, message string) (string, *Response, error) { 114 u := "octocat" 115 if message != "" { 116 u = fmt.Sprintf("%s?s=%s", u, url.QueryEscape(message)) 117 } 118 119 req, err := s.client.NewRequest("GET", u, nil) 120 if err != nil { 121 return "", nil, err 122 } 123 124 buf := new(bytes.Buffer) 125 resp, err := s.client.Do(ctx, req, buf) 126 if err != nil { 127 return "", resp, err 128 } 129 130 return buf.String(), resp, nil 131 } 132 133 // Octocat returns an ASCII art octocat with the specified message in a speech 134 // bubble. If message is empty, a random zen phrase is used. 135 // 136 // Deprecated: Use MetaService.Octocat instead. 137 func (c *Client) Octocat(ctx context.Context, message string) (string, *Response, error) { 138 return c.Meta.Octocat(ctx, message) 139 } 140 141 // Zen returns a random line from The Zen of GitHub. 142 // 143 // See also: http://warpspire.com/posts/taste/ 144 // 145 // GitHub API docs: https://docs.github.com/rest/meta/meta#get-the-zen-of-github 146 // 147 //meta:operation GET /zen 148 func (s *MetaService) Zen(ctx context.Context) (string, *Response, error) { 149 req, err := s.client.NewRequest("GET", "zen", nil) 150 if err != nil { 151 return "", nil, err 152 } 153 154 buf := new(bytes.Buffer) 155 resp, err := s.client.Do(ctx, req, buf) 156 if err != nil { 157 return "", resp, err 158 } 159 160 return buf.String(), resp, nil 161 } 162 163 // Zen returns a random line from The Zen of GitHub. 164 // 165 // Deprecated: Use MetaService.Zen instead. 166 func (c *Client) Zen(ctx context.Context) (string, *Response, error) { 167 return c.Meta.Zen(ctx) 168 }