Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Octokit::Client#delete_organization to support org deletion #1558

Merged
merged 9 commits into from
Mar 31, 2023
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
16 changes: 16 additions & 0 deletions lib/octokit/client/organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ def update_organization(org, values, options = {})
end
alias update_org update_organization

# Delete an organization.
#
# Requires authenticated organization owner.
#
# @param org [String, Integer] Organization login or ID.
# @return [Boolean] True if deletion successful, otherwise false.
# @see https://docs.github.com/rest/orgs/orgs#delete-an-organization
# @example
# @client.delete_organization("my-org")
# @example
# @client.delete_org("my-org")
def delete_organization(org)
boolean_from_response :delete, Organization.path(org)
end
alias delete_org delete_organization

# Get organizations for a user.
#
# Nonauthenticated calls to this method will return organizations that
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"http_interactions": [
{
"request": {
"method": "delete",
"uri": "https://api.github.com/orgs/random-org-to-be-deleted",
"body": {
"encoding": "UTF-8",
"base64_string": "e30=\n"
},
"headers": {
"Accept": [
"application/vnd.github.v3+json"
],
"User-Agent": [
"Octokit Ruby Gem 6.1.0"
],
"Content-Type": [
"application/json"
],
"Authorization": [
"token <<ACCESS_TOKEN>>"
],
"Accept-Encoding": [
"gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
]
}
},
"response": {
"status": {
"code": 202,
"message": "Accepted"
},
"headers": {
"Server": [
"GitHub.com"
],
"Date": [
"Fri, 24 Mar 2023 16:19:28 GMT"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Content-Length": [
"2"
],
"X-Oauth-Scopes": [
"admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, admin:ssh_signing_key, audit_log, codespace, delete:packages, delete_repo, gist, notifications, project, repo, site_admin, user, workflow, write:discussion, write:packages"
],
"X-Accepted-Oauth-Scopes": [
"admin:org"
],
"Github-Authentication-Token-Expiration": [
"2023-04-26 23:27:37 UTC"
],
"X-Github-Media-Type": [
"github.v3; format=json"
],
"X-Github-Api-Version-Selected": [
"2022-11-28"
],
"X-Ratelimit-Limit": [
"5000"
],
"X-Ratelimit-Remaining": [
"4996"
],
"X-Ratelimit-Reset": [
"1679676295"
],
"X-Ratelimit-Used": [
"4"
],
"X-Ratelimit-Resource": [
"core"
],
"Access-Control-Expose-Headers": [
"ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset"
],
"Access-Control-Allow-Origin": [
"*"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubdomains; preload"
],
"X-Frame-Options": [
"deny"
],
"X-Content-Type-Options": [
"nosniff"
],
"X-Xss-Protection": [
"0"
],
"Referrer-Policy": [
"origin-when-cross-origin, strict-origin-when-cross-origin"
],
"Content-Security-Policy": [
"default-src 'none'"
],
"Vary": [
"Accept-Encoding, Accept, X-Requested-With"
],
"X-Github-Request-Id": [
"1D45:3E5D:57C414:596DB8:641DCD90"
]
},
"body": {
"encoding": "UTF-8",
"base64_string": "e30=\n"
}
},
"recorded_at": "Fri, 24 Mar 2023 16:19:28 GMT"
}
],
"recorded_with": "VCR 6.1.0"
}
7 changes: 7 additions & 0 deletions spec/octokit/client/organizations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
end
end # .update_organization

describe '#delete_organization', :vcr do
it 'deletes an organization' do
@client.delete_organization('random-org-to-be-deleted')
assert_requested :delete, github_url('/orgs/random-org-to-be-deleted')
end
end

describe '.organizations', :vcr do
it 'returns all organizations for a user' do
organizations = @client.organizations(test_github_login)
Expand Down