github.com/google/go-github/v74@v74.0.0/github/repos_invitations.go (about) 1 // Copyright 2016 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 // RepositoryInvitation represents an invitation to collaborate on a repo. 14 type RepositoryInvitation struct { 15 ID *int64 `json:"id,omitempty"` 16 Repo *Repository `json:"repository,omitempty"` 17 Invitee *User `json:"invitee,omitempty"` 18 Inviter *User `json:"inviter,omitempty"` 19 20 // Permissions represents the permissions that the associated user will have 21 // on the repository. Possible values are: "read", "write", "admin". 22 Permissions *string `json:"permissions,omitempty"` 23 CreatedAt *Timestamp `json:"created_at,omitempty"` 24 URL *string `json:"url,omitempty"` 25 HTMLURL *string `json:"html_url,omitempty"` 26 Expired *bool `json:"expired,omitempty"` 27 } 28 29 // ListInvitations lists all currently-open repository invitations. 30 // 31 // GitHub API docs: https://docs.github.com/rest/collaborators/invitations#list-repository-invitations 32 // 33 //meta:operation GET /repos/{owner}/{repo}/invitations 34 func (s *RepositoriesService) ListInvitations(ctx context.Context, owner, repo string, opts *ListOptions) ([]*RepositoryInvitation, *Response, error) { 35 u := fmt.Sprintf("repos/%v/%v/invitations", owner, repo) 36 u, err := addOptions(u, opts) 37 if err != nil { 38 return nil, nil, err 39 } 40 41 req, err := s.client.NewRequest("GET", u, nil) 42 if err != nil { 43 return nil, nil, err 44 } 45 46 invites := []*RepositoryInvitation{} 47 resp, err := s.client.Do(ctx, req, &invites) 48 if err != nil { 49 return nil, resp, err 50 } 51 52 return invites, resp, nil 53 } 54 55 // DeleteInvitation deletes a repository invitation. 56 // 57 // GitHub API docs: https://docs.github.com/rest/collaborators/invitations#delete-a-repository-invitation 58 // 59 //meta:operation DELETE /repos/{owner}/{repo}/invitations/{invitation_id} 60 func (s *RepositoriesService) DeleteInvitation(ctx context.Context, owner, repo string, invitationID int64) (*Response, error) { 61 u := fmt.Sprintf("repos/%v/%v/invitations/%v", owner, repo, invitationID) 62 req, err := s.client.NewRequest("DELETE", u, nil) 63 if err != nil { 64 return nil, err 65 } 66 67 return s.client.Do(ctx, req, nil) 68 } 69 70 // UpdateInvitation updates the permissions associated with a repository 71 // invitation. 72 // 73 // permissions represents the permissions that the associated user will have 74 // on the repository. Possible values are: "read", "write", "admin". 75 // 76 // GitHub API docs: https://docs.github.com/rest/collaborators/invitations#update-a-repository-invitation 77 // 78 //meta:operation PATCH /repos/{owner}/{repo}/invitations/{invitation_id} 79 func (s *RepositoriesService) UpdateInvitation(ctx context.Context, owner, repo string, invitationID int64, permissions string) (*RepositoryInvitation, *Response, error) { 80 opts := &struct { 81 Permissions string `json:"permissions"` 82 }{Permissions: permissions} 83 u := fmt.Sprintf("repos/%v/%v/invitations/%v", owner, repo, invitationID) 84 req, err := s.client.NewRequest("PATCH", u, opts) 85 if err != nil { 86 return nil, nil, err 87 } 88 89 invite := &RepositoryInvitation{} 90 resp, err := s.client.Do(ctx, req, invite) 91 if err != nil { 92 return nil, resp, err 93 } 94 95 return invite, resp, nil 96 }