Debian Codegraph @

github/admin_orgs.go

raw
1 // Copyright 2019 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 // createOrgRequest is a subset of Organization and is used internally
14 // by CreateOrg to pass only the known fields for the endpoint.
15 type createOrgRequest struct {
16 Login *string `json:"login,omitempty"`
17 Admin *string `json:"admin,omitempty"`
18 }
19
20 // CreateOrg creates a new organization in GitHub Enterprise.
21 //
22 // Note that only a subset of the org fields are used and org must
23 // not be nil.
24 //
25 // GitHub API docs: https://docs.github.com/[email protected]/rest/enterprise-admin/orgs#create-an-organization
26 //
27 //meta:operation POST /admin/organizations
28 func (s *AdminService) CreateOrg(ctx context.Context, org *Organization, admin string) (*Organization, *Response, error) {
29 u := "admin/organizations"
30
31 orgReq := &createOrgRequest{
32 Login: org.Login,
33 Admin: &admin,
34 }
35
36 req, err := s.client.NewRequest("POST", u, orgReq)
37 if err != nil {
38 return nil, nil, err
39 }
40
41 o := new(Organization)
42 resp, err := s.client.Do(ctx, req, o)
43 if err != nil {
44 return nil, resp, err
45 }
46
47 return o, resp, nil
48 }
49
50 // renameOrgRequest is a subset of Organization and is used internally
51 // by RenameOrg and RenameOrgByName to pass only the known fields for the endpoint.
52 type renameOrgRequest struct {
53 Login *string `json:"login,omitempty"`
54 }
55
56 // RenameOrgResponse is the response given when renaming an Organization.
57 type RenameOrgResponse struct {
58 Message *string `json:"message,omitempty"`
59 URL *string `json:"url,omitempty"`
60 }
61
62 // RenameOrg renames an organization in GitHub Enterprise.
63 //
64 // GitHub API docs: https://docs.github.com/[email protected]/rest/enterprise-admin/orgs#update-an-organization-name
65 //
66 //meta:operation PATCH /admin/organizations/{org}
67 func (s *AdminService) RenameOrg(ctx context.Context, org *Organization, newName string) (*RenameOrgResponse, *Response, error) {
68 return s.RenameOrgByName(ctx, *org.Login, newName)
69 }
70
71 // RenameOrgByName renames an organization in GitHub Enterprise using its current name.
72 //
73 // GitHub API docs: https://docs.github.com/[email protected]/rest/enterprise-admin/orgs#update-an-organization-name
74 //
75 //meta:operation PATCH /admin/organizations/{org}
76 func (s *AdminService) RenameOrgByName(ctx context.Context, org, newName string) (*RenameOrgResponse, *Response, error) {
77 u := fmt.Sprintf("admin/organizations/%v", org)
78
79 orgReq := &renameOrgRequest{
80 Login: &newName,
81 }
82
83 req, err := s.client.NewRequest("PATCH", u, orgReq)
84 if err != nil {
85 return nil, nil, err
86 }
87
88 o := new(RenameOrgResponse)
89 resp, err := s.client.Do(ctx, req, o)
90 if err != nil {
91 return nil, resp, err
92 }
93
94 return o, resp, nil
95 }