Skip to content

Commit dea28a3

Browse files
Add CancelInvite method to cancel an org invitation by ID (#3263)
1 parent eafd379 commit dea28a3

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

github/orgs_members.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,20 @@ func (s *OrganizationsService) RemoveMember(ctx context.Context, org, user strin
151151
return s.client.Do(ctx, req, nil)
152152
}
153153

154+
// CancelInvite cancels an organization invitation.
155+
//
156+
// GitHub API docs: https://docs.github.com/rest/orgs/members#cancel-an-organization-invitation
157+
//
158+
//meta:operation DELETE /orgs/{org}/invitations/{invitation_id}
159+
func (s *OrganizationsService) CancelInvite(ctx context.Context, org string, invitationID int64) (*Response, error) {
160+
u := fmt.Sprintf("orgs/%v/invitations/%v", org, invitationID)
161+
req, err := s.client.NewRequest("DELETE", u, nil)
162+
if err != nil {
163+
return nil, err
164+
}
165+
return s.client.Do(ctx, req, nil)
166+
}
167+
154168
// PublicizeMembership publicizes a user's membership in an organization. (A
155169
// user cannot publicize the membership for another user.)
156170
//

github/orgs_members_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,32 @@ func TestOrganizationsService_RemoveMember(t *testing.T) {
284284
})
285285
}
286286

287+
func TestOrganizationsService_CancelInvite(t *testing.T) {
288+
client, mux, _, teardown := setup()
289+
defer teardown()
290+
291+
mux.HandleFunc("/orgs/o/invitations/1", func(w http.ResponseWriter, r *http.Request) {
292+
testMethod(t, r, "DELETE")
293+
w.WriteHeader(http.StatusNoContent)
294+
})
295+
296+
ctx := context.Background()
297+
_, err := client.Organizations.CancelInvite(ctx, "o", 1)
298+
if err != nil {
299+
t.Errorf("Organizations.CancelInvite returned error: %v", err)
300+
}
301+
302+
const methodName = "CancelInvite"
303+
testBadOptions(t, methodName, func() (err error) {
304+
_, err = client.Organizations.CancelInvite(ctx, "\n", 1)
305+
return err
306+
})
307+
308+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
309+
return client.Organizations.CancelInvite(ctx, "o", 1)
310+
})
311+
}
312+
287313
func TestOrganizationsService_RemoveMember_invalidOrg(t *testing.T) {
288314
client, _, _, teardown := setup()
289315
defer teardown()

0 commit comments

Comments
 (0)