123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- package github
- import (
- "bytes"
- "context"
- "fmt"
- "net/url"
- )
- type MarkdownOptions struct {
-
-
-
-
-
-
-
-
-
-
- Mode string
-
-
- Context string
- }
- type markdownRequest struct {
- Text *string `json:"text,omitempty"`
- Mode *string `json:"mode,omitempty"`
- Context *string `json:"context,omitempty"`
- }
- func (c *Client) Markdown(ctx context.Context, text string, opt *MarkdownOptions) (string, *Response, error) {
- request := &markdownRequest{Text: String(text)}
- if opt != nil {
- if opt.Mode != "" {
- request.Mode = String(opt.Mode)
- }
- if opt.Context != "" {
- request.Context = String(opt.Context)
- }
- }
- req, err := c.NewRequest("POST", "markdown", request)
- if err != nil {
- return "", nil, err
- }
- buf := new(bytes.Buffer)
- resp, err := c.Do(ctx, req, buf)
- if err != nil {
- return "", resp, err
- }
- return buf.String(), resp, nil
- }
- func (c *Client) ListEmojis(ctx context.Context) (map[string]string, *Response, error) {
- req, err := c.NewRequest("GET", "emojis", nil)
- if err != nil {
- return nil, nil, err
- }
- var emoji map[string]string
- resp, err := c.Do(ctx, req, &emoji)
- if err != nil {
- return nil, resp, err
- }
- return emoji, resp, nil
- }
- type CodeOfConduct struct {
- Name *string `json:"name,omitempty"`
- Key *string `json:"key,omitempty"`
- URL *string `json:"url,omitempty"`
- Body *string `json:"body,omitempty"`
- }
- func (c *CodeOfConduct) String() string {
- return Stringify(c)
- }
- func (c *Client) ListCodesOfConduct(ctx context.Context) ([]*CodeOfConduct, *Response, error) {
- req, err := c.NewRequest("GET", "codes_of_conduct", nil)
- if err != nil {
- return nil, nil, err
- }
-
- req.Header.Set("Accept", mediaTypeCodesOfConductPreview)
- var cs []*CodeOfConduct
- resp, err := c.Do(ctx, req, &cs)
- if err != nil {
- return nil, resp, err
- }
- return cs, resp, nil
- }
- func (c *Client) GetCodeOfConduct(ctx context.Context, key string) (*CodeOfConduct, *Response, error) {
- u := fmt.Sprintf("codes_of_conduct/%s", key)
- req, err := c.NewRequest("GET", u, nil)
- if err != nil {
- return nil, nil, err
- }
-
- req.Header.Set("Accept", mediaTypeCodesOfConductPreview)
- coc := new(CodeOfConduct)
- resp, err := c.Do(ctx, req, coc)
- if err != nil {
- return nil, resp, err
- }
- return coc, resp, nil
- }
- type APIMeta struct {
-
-
- Hooks []string `json:"hooks,omitempty"`
-
-
- Git []string `json:"git,omitempty"`
-
-
-
-
-
- VerifiablePasswordAuthentication *bool `json:"verifiable_password_authentication,omitempty"`
-
-
- Pages []string `json:"pages,omitempty"`
-
-
- Importer []string `json:"importer,omitempty"`
- }
- func (c *Client) APIMeta(ctx context.Context) (*APIMeta, *Response, error) {
- req, err := c.NewRequest("GET", "meta", nil)
- if err != nil {
- return nil, nil, err
- }
- meta := new(APIMeta)
- resp, err := c.Do(ctx, req, meta)
- if err != nil {
- return nil, resp, err
- }
- return meta, resp, nil
- }
- func (c *Client) Octocat(ctx context.Context, message string) (string, *Response, error) {
- u := "octocat"
- if message != "" {
- u = fmt.Sprintf("%s?s=%s", u, url.QueryEscape(message))
- }
- req, err := c.NewRequest("GET", u, nil)
- if err != nil {
- return "", nil, err
- }
- buf := new(bytes.Buffer)
- resp, err := c.Do(ctx, req, buf)
- if err != nil {
- return "", resp, err
- }
- return buf.String(), resp, nil
- }
- func (c *Client) Zen(ctx context.Context) (string, *Response, error) {
- req, err := c.NewRequest("GET", "zen", nil)
- if err != nil {
- return "", nil, err
- }
- buf := new(bytes.Buffer)
- resp, err := c.Do(ctx, req, buf)
- if err != nil {
- return "", resp, err
- }
- return buf.String(), resp, nil
- }
- type ServiceHook struct {
- Name *string `json:"name,omitempty"`
- Events []string `json:"events,omitempty"`
- SupportedEvents []string `json:"supported_events,omitempty"`
- Schema [][]string `json:"schema,omitempty"`
- }
- func (s *ServiceHook) String() string {
- return Stringify(s)
- }
- func (c *Client) ListServiceHooks(ctx context.Context) ([]*ServiceHook, *Response, error) {
- u := "hooks"
- req, err := c.NewRequest("GET", u, nil)
- if err != nil {
- return nil, nil, err
- }
- var hooks []*ServiceHook
- resp, err := c.Do(ctx, req, &hooks)
- if err != nil {
- return nil, resp, err
- }
- return hooks, resp, nil
- }
|