1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13
14
15 type createOrgRequest struct {
16 Login *string `json:"login,omitempty"`
17 Admin *string `json:"admin,omitempty"`
18 }
19
20
21
22
23
24
25
26 func (s *AdminService) CreateOrg(ctx context.Context, org *Organization, admin string) (*Organization, *Response, error) {
27 u := "admin/organizations"
28
29 orgReq := &createOrgRequest{
30 Login: org.Login,
31 Admin: &admin,
32 }
33
34 req, err := s.client.NewRequest("POST", u, orgReq)
35 if err != nil {
36 return nil, nil, err
37 }
38
39 o := new(Organization)
40 resp, err := s.client.Do(ctx, req, o)
41 if err != nil {
42 return nil, resp, err
43 }
44
45 return o, resp, nil
46 }
47
48
49
50 type renameOrgRequest struct {
51 Login *string `json:"login,omitempty"`
52 }
53
54
55 type RenameOrgResponse struct {
56 Message *string `json:"message,omitempty"`
57 URL *string `json:"url,omitempty"`
58 }
59
60
61
62
63 func (s *AdminService) RenameOrg(ctx context.Context, org *Organization, newName string) (*RenameOrgResponse, *Response, error) {
64 return s.RenameOrgByName(ctx, *org.Login, newName)
65 }
66
67
68
69
70 func (s *AdminService) RenameOrgByName(ctx context.Context, org, newName string) (*RenameOrgResponse, *Response, error) {
71 u := fmt.Sprintf("admin/organizations/%v", org)
72
73 orgReq := &renameOrgRequest{
74 Login: &newName,
75 }
76
77 req, err := s.client.NewRequest("PATCH", u, orgReq)
78 if err != nil {
79 return nil, nil, err
80 }
81
82 o := new(RenameOrgResponse)
83 resp, err := s.client.Do(ctx, req, o)
84 if err != nil {
85 return nil, resp, err
86 }
87
88 return o, resp, nil
89 }
90
View as plain text