1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13
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
21
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
29
30
31 func (s *RepositoriesService) ListInvitations(ctx context.Context, owner, repo string, opts *ListOptions) ([]*RepositoryInvitation, *Response, error) {
32 u := fmt.Sprintf("repos/%v/%v/invitations", owner, repo)
33 u, err := addOptions(u, opts)
34 if err != nil {
35 return nil, nil, err
36 }
37
38 req, err := s.client.NewRequest("GET", u, nil)
39 if err != nil {
40 return nil, nil, err
41 }
42
43 invites := []*RepositoryInvitation{}
44 resp, err := s.client.Do(ctx, req, &invites)
45 if err != nil {
46 return nil, resp, err
47 }
48
49 return invites, resp, nil
50 }
51
52
53
54
55 func (s *RepositoriesService) DeleteInvitation(ctx context.Context, owner, repo string, invitationID int64) (*Response, error) {
56 u := fmt.Sprintf("repos/%v/%v/invitations/%v", owner, repo, invitationID)
57 req, err := s.client.NewRequest("DELETE", u, nil)
58 if err != nil {
59 return nil, err
60 }
61
62 return s.client.Do(ctx, req, nil)
63 }
64
65
66
67
68
69
70
71
72 func (s *RepositoriesService) UpdateInvitation(ctx context.Context, owner, repo string, invitationID int64, permissions string) (*RepositoryInvitation, *Response, error) {
73 opts := &struct {
74 Permissions string `json:"permissions"`
75 }{Permissions: permissions}
76 u := fmt.Sprintf("repos/%v/%v/invitations/%v", owner, repo, invitationID)
77 req, err := s.client.NewRequest("PATCH", u, opts)
78 if err != nil {
79 return nil, nil, err
80 }
81
82 invite := &RepositoryInvitation{}
83 resp, err := s.client.Do(ctx, req, invite)
84 if err != nil {
85 return nil, resp, err
86 }
87
88 return invite, resp, nil
89 }
90
View as plain text