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