Debian Codegraph @

github/codesofconduct.go

raw
1 // Copyright 2023 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 "context"
10 "fmt"
11 )
12
13 // CodesOfConductService provides access to code-of-conduct-related functions in the GitHub API.
14 type CodesOfConductService service
15
16 // CodeOfConduct represents a code of conduct.
17 type CodeOfConduct struct {
18 Name *string `json:"name,omitempty"`
19 Key *string `json:"key,omitempty"`
20 URL *string `json:"url,omitempty"`
21 Body *string `json:"body,omitempty"`
22 }
23
24 func (c *CodeOfConduct) String() string {
25 return Stringify(c)
26 }
27
28 // List returns all codes of conduct.
29 //
30 // GitHub API docs: https://docs.github.com/rest/codes-of-conduct/codes-of-conduct#get-all-codes-of-conduct
31 //
32 //meta:operation GET /codes_of_conduct
33 func (s *CodesOfConductService) List(ctx context.Context) ([]*CodeOfConduct, *Response, error) {
34 req, err := s.client.NewRequest("GET", "codes_of_conduct", nil)
35 if err != nil {
36 return nil, nil, err
37 }
38
39 // TODO: remove custom Accept header when this API fully launches.
40 req.Header.Set("Accept", mediaTypeCodesOfConductPreview)
41
42 var cs []*CodeOfConduct
43 resp, err := s.client.Do(ctx, req, &cs)
44 if err != nil {
45 return nil, resp, err
46 }
47
48 return cs, resp, nil
49 }
50
51 // ListCodesOfConduct returns all codes of conduct.
52 //
53 // Deprecated: Use CodesOfConductService.List instead
54 func (c *Client) ListCodesOfConduct(ctx context.Context) ([]*CodeOfConduct, *Response, error) {
55 return c.CodesOfConduct.List(ctx)
56 }
57
58 // Get returns an individual code of conduct.
59 //
60 // GitHub API docs: https://docs.github.com/rest/codes-of-conduct/codes-of-conduct#get-a-code-of-conduct
61 //
62 //meta:operation GET /codes_of_conduct/{key}
63 func (s *CodesOfConductService) Get(ctx context.Context, key string) (*CodeOfConduct, *Response, error) {
64 u := fmt.Sprintf("codes_of_conduct/%s", key)
65 req, err := s.client.NewRequest("GET", u, nil)
66 if err != nil {
67 return nil, nil, err
68 }
69
70 // TODO: remove custom Accept header when this API fully launches.
71 req.Header.Set("Accept", mediaTypeCodesOfConductPreview)
72
73 coc := new(CodeOfConduct)
74 resp, err := s.client.Do(ctx, req, coc)
75 if err != nil {
76 return nil, resp, err
77 }
78
79 return coc, resp, nil
80 }
81
82 // GetCodeOfConduct returns an individual code of conduct.
83 //
84 // Deprecated: Use CodesOfConductService.Get instead
85 func (c *Client) GetCodeOfConduct(ctx context.Context, key string) (*CodeOfConduct, *Response, error) {
86 return c.CodesOfConduct.Get(ctx, key)
87 }