github.com/google/go-github/v74@v74.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 // GitHub Action macOS runner will originate from. 57 ActionsMacos []string `json:"actions_macos,omitempty"` 58 59 // An array of IP addresses in CIDR format specifying the IP addresses 60 // Dependabot will originate from. 61 Dependabot []string `json:"dependabot,omitempty"` 62 63 // A map of algorithms to SSH key fingerprints. 64 SSHKeyFingerprints map[string]string `json:"ssh_key_fingerprints,omitempty"` 65 66 // An array of SSH keys. 67 SSHKeys []string `json:"ssh_keys,omitempty"` 68 69 // An array of IP addresses in CIDR format specifying the addresses 70 // which serve GitHub websites. 71 Web []string `json:"web,omitempty"` 72 73 // An array of IP addresses in CIDR format specifying the addresses 74 // which serve GitHub APIs. 75 API []string `json:"api,omitempty"` 76 77 // GitHub services and their associated domains. Note that many of these domains 78 // are represented as wildcards (e.g. "*.github.com"). 79 Domains *APIMetaDomains `json:"domains,omitempty"` 80 } 81 82 // APIMetaDomains represents the domains associated with GitHub services. 83 type APIMetaDomains struct { 84 Website []string `json:"website,omitempty"` 85 Codespaces []string `json:"codespaces,omitempty"` 86 Copilot []string `json:"copilot,omitempty"` 87 Packages []string `json:"packages,omitempty"` 88 Actions []string `json:"actions,omitempty"` 89 ArtifactAttestations *APIMetaArtifactAttestations `json:"artifact_attestations,omitempty"` 90 } 91 92 // APIMetaArtifactAttestations represents the artifact attestation services domains. 93 type APIMetaArtifactAttestations struct { 94 TrustDomain string `json:"trust_domain,omitempty"` 95 Services []string `json:"services,omitempty"` 96 } 97 98 // Get returns information about GitHub.com, the service. Or, if you access 99 // this endpoint on your organization’s GitHub Enterprise installation, this 100 // endpoint provides information about that installation. 101 // 102 // GitHub API docs: https://docs.github.com/rest/meta/meta#get-github-meta-information 103 // 104 //meta:operation GET /meta 105 func (s *MetaService) Get(ctx context.Context) (*APIMeta, *Response, error) { 106 req, err := s.client.NewRequest("GET", "meta", nil) 107 if err != nil { 108 return nil, nil, err 109 } 110 111 meta := new(APIMeta) 112 resp, err := s.client.Do(ctx, req, meta) 113 if err != nil { 114 return nil, resp, err 115 } 116 117 return meta, resp, nil 118 } 119 120 // APIMeta returns information about GitHub.com. 121 // 122 // Deprecated: Use MetaService.Get instead. 123 func (c *Client) APIMeta(ctx context.Context) (*APIMeta, *Response, error) { 124 return c.Meta.Get(ctx) 125 } 126 127 // Octocat returns an ASCII art octocat with the specified message in a speech 128 // bubble. If message is empty, a random zen phrase is used. 129 // 130 // GitHub API docs: https://docs.github.com/rest/meta/meta#get-octocat 131 // 132 //meta:operation GET /octocat 133 func (s *MetaService) Octocat(ctx context.Context, message string) (string, *Response, error) { 134 u := "octocat" 135 if message != "" { 136 u = fmt.Sprintf("%s?s=%s", u, url.QueryEscape(message)) 137 } 138 139 req, err := s.client.NewRequest("GET", u, nil) 140 if err != nil { 141 return "", nil, err 142 } 143 144 buf := new(bytes.Buffer) 145 resp, err := s.client.Do(ctx, req, buf) 146 if err != nil { 147 return "", resp, err 148 } 149 150 return buf.String(), resp, nil 151 } 152 153 // Octocat returns an ASCII art octocat with the specified message in a speech 154 // bubble. If message is empty, a random zen phrase is used. 155 // 156 // Deprecated: Use MetaService.Octocat instead. 157 func (c *Client) Octocat(ctx context.Context, message string) (string, *Response, error) { 158 return c.Meta.Octocat(ctx, message) 159 } 160 161 // Zen returns a random line from The Zen of GitHub. 162 // 163 // See also: http://warpspire.com/posts/taste/ 164 // 165 // GitHub API docs: https://docs.github.com/rest/meta/meta#get-the-zen-of-github 166 // 167 //meta:operation GET /zen 168 func (s *MetaService) Zen(ctx context.Context) (string, *Response, error) { 169 req, err := s.client.NewRequest("GET", "zen", nil) 170 if err != nil { 171 return "", nil, err 172 } 173 174 buf := new(bytes.Buffer) 175 resp, err := s.client.Do(ctx, req, buf) 176 if err != nil { 177 return "", resp, err 178 } 179 180 return buf.String(), resp, nil 181 } 182 183 // Zen returns a random line from The Zen of GitHub. 184 // 185 // Deprecated: Use MetaService.Zen instead. 186 func (c *Client) Zen(ctx context.Context) (string, *Response, error) { 187 return c.Meta.Zen(ctx) 188 }