Debian Codegraph @

github/repos_invitations.go

raw
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 }
27
28 // ListInvitations lists all currently-open repository invitations.
29 //
30 // GitHub API docs: https://docs.github.com/rest/collaborators/invitations#list-repository-invitations
31 //
32 //meta:operation GET /repos/{owner}/{repo}/invitations
33 func (s *RepositoriesService) ListInvitations(ctx context.Context, owner, repo string, opts *ListOptions) ([]*RepositoryInvitation, *Response, error) {
34 u := fmt.Sprintf("repos/%v/%v/invitations", owner, repo)
35 u, err := addOptions(u, opts)
36 if err != nil {
37 return nil, nil, err
38 }
39
40 req, err := s.client.NewRequest("GET", u, nil)
41 if err != nil {
42 return nil, nil, err
43 }
44
45 invites := []*RepositoryInvitation{}
46 resp, err := s.client.Do(ctx, req, &invites)
47 if err != nil {
48 return nil, resp, err
49 }
50
51 return invites, resp, nil
52 }
53
54 // DeleteInvitation deletes a repository invitation.
55 //
56 // GitHub API docs: https://docs.github.com/rest/collaborators/invitations#delete-a-repository-invitation
57 //
58 //meta:operation DELETE /repos/{owner}/{repo}/invitations/{invitation_id}
59 func (s *RepositoriesService) DeleteInvitation(ctx context.Context, owner, repo string, invitationID int64) (*Response, error) {
60 u := fmt.Sprintf("repos/%v/%v/invitations/%v", owner, repo, invitationID)
61 req, err := s.client.NewRequest("DELETE", u, nil)
62 if err != nil {
63 return nil, err
64 }
65
66 return s.client.Do(ctx, req, nil)
67 }
68
69 // UpdateInvitation updates the permissions associated with a repository
70 // invitation.
71 //
72 // permissions represents the permissions that the associated user will have
73 // on the repository. Possible values are: "read", "write", "admin".
74 //
75 // GitHub API docs: https://docs.github.com/rest/collaborators/invitations#update-a-repository-invitation
76 //
77 //meta:operation PATCH /repos/{owner}/{repo}/invitations/{invitation_id}
78 func (s *RepositoriesService) UpdateInvitation(ctx context.Context, owner, repo string, invitationID int64, permissions string) (*RepositoryInvitation, *Response, error) {
79 opts := &struct {
80 Permissions string `json:"permissions"`
81 }{Permissions: permissions}
82 u := fmt.Sprintf("repos/%v/%v/invitations/%v", owner, repo, invitationID)
83 req, err := s.client.NewRequest("PATCH", u, opts)
84 if err != nil {
85 return nil, nil, err
86 }
87
88 invite := &RepositoryInvitation{}
89 resp, err := s.client.Do(ctx, req, invite)
90 if err != nil {
91 return nil, resp, err
92 }
93
94 return invite, resp, nil
95 }