1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package gitlab
18
19 import (
20 "fmt"
21 "net/http"
22 "time"
23 )
24
25
26
27
28
29 type InvitesService struct {
30 client *Client
31 }
32
33
34
35
36 type PendingInvite struct {
37 ID int `json:"id"`
38 InviteEmail string `json:"invite_email"`
39 CreatedAt *time.Time `json:"created_at"`
40 AccessLevel AccessLevelValue `json:"access_level"`
41 ExpiresAt *time.Time `json:"expires_at"`
42 UserName string `json:"user_name"`
43 CreatedByName string `json:"created_by_name"`
44 }
45
46
47
48
49
50
51 type ListPendingInvitationsOptions struct {
52 ListOptions
53 Query *string `url:"query,omitempty" json:"query,omitempty"`
54 }
55
56
57
58
59
60 func (s *InvitesService) ListPendingGroupInvitations(gid interface{}, opt *ListPendingInvitationsOptions, options ...RequestOptionFunc) ([]*PendingInvite, *Response, error) {
61 group, err := parseID(gid)
62 if err != nil {
63 return nil, nil, err
64 }
65 u := fmt.Sprintf("groups/%s/invitations", PathEscape(group))
66
67 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
68 if err != nil {
69 return nil, nil, err
70 }
71
72 var pis []*PendingInvite
73 resp, err := s.client.Do(req, &pis)
74 if err != nil {
75 return nil, resp, err
76 }
77
78 return pis, resp, nil
79 }
80
81
82
83
84
85 func (s *InvitesService) ListPendingProjectInvitations(pid interface{}, opt *ListPendingInvitationsOptions, options ...RequestOptionFunc) ([]*PendingInvite, *Response, error) {
86 project, err := parseID(pid)
87 if err != nil {
88 return nil, nil, err
89 }
90 u := fmt.Sprintf("projects/%s/invitations", PathEscape(project))
91
92 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
93 if err != nil {
94 return nil, nil, err
95 }
96
97 var pis []*PendingInvite
98 resp, err := s.client.Do(req, &pis)
99 if err != nil {
100 return nil, resp, err
101 }
102
103 return pis, resp, nil
104 }
105
106
107
108
109
110
111 type InvitesOptions struct {
112 ID interface{} `url:"id,omitempty" json:"id,omitempty"`
113 Email *string `url:"email,omitempty" json:"email,omitempty"`
114 UserID interface{} `url:"user_id,omitempty" json:"user_id,omitempty"`
115 AccessLevel *AccessLevelValue `url:"access_level,omitempty" json:"access_level,omitempty"`
116 ExpiresAt *ISOTime `url:"expires_at,omitempty" json:"expires_at,omitempty"`
117 }
118
119
120
121
122
123 type InvitesResult struct {
124 Status string `json:"status"`
125 Message map[string]string `json:"message,omitempty"`
126 }
127
128
129
130
131
132 func (s *InvitesService) GroupInvites(gid interface{}, opt *InvitesOptions, options ...RequestOptionFunc) (*InvitesResult, *Response, error) {
133 group, err := parseID(gid)
134 if err != nil {
135 return nil, nil, err
136 }
137 u := fmt.Sprintf("groups/%s/invitations", PathEscape(group))
138
139 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
140 if err != nil {
141 return nil, nil, err
142 }
143
144 ir := new(InvitesResult)
145 resp, err := s.client.Do(req, ir)
146 if err != nil {
147 return nil, resp, err
148 }
149
150 return ir, resp, nil
151 }
152
153
154
155
156
157 func (s *InvitesService) ProjectInvites(pid interface{}, opt *InvitesOptions, options ...RequestOptionFunc) (*InvitesResult, *Response, error) {
158 project, err := parseID(pid)
159 if err != nil {
160 return nil, nil, err
161 }
162 u := fmt.Sprintf("projects/%s/invitations", PathEscape(project))
163
164 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
165 if err != nil {
166 return nil, nil, err
167 }
168
169 ir := new(InvitesResult)
170 resp, err := s.client.Do(req, ir)
171 if err != nil {
172 return nil, resp, err
173 }
174
175 return ir, resp, nil
176 }
177
View as plain text