Debian Codegraph @

github/meta.go

raw
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 in CIDR format specifying the IP addresses
48 // GitHub Actions will originate from.
49 Actions []string `json:"actions,omitempty"`
50
51 // An array of IP addresses in CIDR format specifying the IP addresses
52 // Dependabot will originate from.
53 Dependabot []string `json:"dependabot,omitempty"`
54
55 // A map of algorithms to SSH key fingerprints.
56 SSHKeyFingerprints map[string]string `json:"ssh_key_fingerprints,omitempty"`
57
58 // An array of SSH keys.
59 SSHKeys []string `json:"ssh_keys,omitempty"`
60
61 // An array of IP addresses in CIDR format specifying the addresses
62 // which serve GitHub websites.
63 Web []string `json:"web,omitempty"`
64
65 // An array of IP addresses in CIDR format specifying the addresses
66 // which serve GitHub APIs.
67 API []string `json:"api,omitempty"`
68 }
69
70 // Get returns information about GitHub.com, the service. Or, if you access
71 // this endpoint on your organization’s GitHub Enterprise installation, this
72 // endpoint provides information about that installation.
73 //
74 // GitHub API docs: https://docs.github.com/rest/meta/meta#get-github-meta-information
75 //
76 //meta:operation GET /meta
77 func (s *MetaService) Get(ctx context.Context) (*APIMeta, *Response, error) {
78 req, err := s.client.NewRequest("GET", "meta", nil)
79 if err != nil {
80 return nil, nil, err
81 }
82
83 meta := new(APIMeta)
84 resp, err := s.client.Do(ctx, req, meta)
85 if err != nil {
86 return nil, resp, err
87 }
88
89 return meta, resp, nil
90 }
91
92 // APIMeta returns information about GitHub.com.
93 //
94 // Deprecated: Use MetaService.Get instead.
95 func (c *Client) APIMeta(ctx context.Context) (*APIMeta, *Response, error) {
96 return c.Meta.Get(ctx)
97 }
98
99 // Octocat returns an ASCII art octocat with the specified message in a speech
100 // bubble. If message is empty, a random zen phrase is used.
101 //
102 // GitHub API docs: https://docs.github.com/rest/meta/meta#get-octocat
103 //
104 //meta:operation GET /octocat
105 func (s *MetaService) Octocat(ctx context.Context, message string) (string, *Response, error) {
106 u := "octocat"
107 if message != "" {
108 u = fmt.Sprintf("%s?s=%s", u, url.QueryEscape(message))
109 }
110
111 req, err := s.client.NewRequest("GET", u, nil)
112 if err != nil {
113 return "", nil, err
114 }
115
116 buf := new(bytes.Buffer)
117 resp, err := s.client.Do(ctx, req, buf)
118 if err != nil {
119 return "", resp, err
120 }
121
122 return buf.String(), resp, nil
123 }
124
125 // Octocat returns an ASCII art octocat with the specified message in a speech
126 // bubble. If message is empty, a random zen phrase is used.
127 //
128 // Deprecated: Use MetaService.Octocat instead.
129 func (c *Client) Octocat(ctx context.Context, message string) (string, *Response, error) {
130 return c.Meta.Octocat(ctx, message)
131 }
132
133 // Zen returns a random line from The Zen of GitHub.
134 //
135 // See also: http://warpspire.com/posts/taste/
136 //
137 // GitHub API docs: https://docs.github.com/rest/meta/meta#get-the-zen-of-github
138 //
139 //meta:operation GET /zen
140 func (s *MetaService) Zen(ctx context.Context) (string, *Response, error) {
141 req, err := s.client.NewRequest("GET", "zen", nil)
142 if err != nil {
143 return "", nil, err
144 }
145
146 buf := new(bytes.Buffer)
147 resp, err := s.client.Do(ctx, req, buf)
148 if err != nil {
149 return "", resp, err
150 }
151
152 return buf.String(), resp, nil
153 }
154
155 // Zen returns a random line from The Zen of GitHub.
156 //
157 // Deprecated: Use MetaService.Zen instead.
158 func (c *Client) Zen(ctx context.Context) (string, *Response, error) {
159 return c.Meta.Zen(ctx)
160 }