...

Source file src/github.com/google/go-github/v55/github/admin_orgs.go

Documentation: github.com/google/go-github/v55/github

     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 Enterprise API docs: https://developer.github.com/enterprise/v3/enterprise-admin/orgs/#create-an-organization
    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  // renameOrgRequest is a subset of Organization and is used internally
    49  // by RenameOrg and RenameOrgByName to pass only the known fields for the endpoint.
    50  type renameOrgRequest struct {
    51  	Login *string `json:"login,omitempty"`
    52  }
    53  
    54  // RenameOrgResponse is the response given when renaming an Organization.
    55  type RenameOrgResponse struct {
    56  	Message *string `json:"message,omitempty"`
    57  	URL     *string `json:"url,omitempty"`
    58  }
    59  
    60  // RenameOrg renames an organization in GitHub Enterprise.
    61  //
    62  // GitHub Enterprise API docs: https://developer.github.com/enterprise/v3/enterprise-admin/orgs/#rename-an-organization
    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  // RenameOrgByName renames an organization in GitHub Enterprise using its current name.
    68  //
    69  // GitHub Enterprise API docs: https://developer.github.com/enterprise/v3/enterprise-admin/orgs/#rename-an-organization
    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