Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions github/orgs_members.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ func (s *OrganizationsService) RemoveMember(ctx context.Context, org, user strin
return s.client.Do(ctx, req, nil)
}

// CancelInvite cancels an organization invitation.
//
// GitHub API docs: https://docs.github.com/rest/orgs/members#cancel-an-organization-invitation
//
//meta:operation DELETE /orgs/{org}/invitations/{invitation_id}
func (s *OrganizationsService) CancelInvite(ctx context.Context, org string, invitationID int64) (*Response, error) {
u := fmt.Sprintf("orgs/%v/invitations/%v", org, invitationID)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}

// PublicizeMembership publicizes a user's membership in an organization. (A
// user cannot publicize the membership for another user.)
//
Expand Down
26 changes: 26 additions & 0 deletions github/orgs_members_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,32 @@ func TestOrganizationsService_RemoveMember(t *testing.T) {
})
}

func TestOrganizationsService_CancelInvite(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/orgs/o/invitations/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
w.WriteHeader(http.StatusNoContent)
})

ctx := context.Background()
_, err := client.Organizations.CancelInvite(ctx, "o", 1)
if err != nil {
t.Errorf("Organizations.CancelInvite returned error: %v", err)
}

const methodName = "CancelInvite"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Organizations.CancelInvite(ctx, "\n", 1)
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Organizations.CancelInvite(ctx, "o", 1)
})
}

func TestOrganizationsService_RemoveMember_invalidOrg(t *testing.T) {
client, _, _, teardown := setup()
defer teardown()
Expand Down