From 3b70dd70bbaf66d6c593cbc4e56af726dea99732 Mon Sep 17 00:00:00 2001 From: James Dennes Date: Fri, 24 Mar 2023 16:55:23 +0100 Subject: [PATCH 1/9] Implement delete org endpoint --- lib/octokit/client/organizations.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/octokit/client/organizations.rb b/lib/octokit/client/organizations.rb index 5f218b673..895ac10e4 100644 --- a/lib/octokit/client/organizations.rb +++ b/lib/octokit/client/organizations.rb @@ -50,6 +50,22 @@ def update_organization(org, values, options = {}) end alias update_org update_organization + # Delete an organization. + # + # Requires authenticated client with proper organization permissions. + # + # @param org [String, Integer] Organization GitHub login or id. + # @return [Boolean] True if deletion successful, otherwise false. + # @see https://docs.github.com/rest/reference/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 From ed59dec00ca7cc17458571f3ae7304eb7e9fa180 Mon Sep 17 00:00:00 2001 From: James Dennes Date: Fri, 24 Mar 2023 16:56:22 +0100 Subject: [PATCH 2/9] Improve docs --- lib/octokit/client/organizations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/octokit/client/organizations.rb b/lib/octokit/client/organizations.rb index 895ac10e4..7260daed1 100644 --- a/lib/octokit/client/organizations.rb +++ b/lib/octokit/client/organizations.rb @@ -52,7 +52,7 @@ def update_organization(org, values, options = {}) # Delete an organization. # - # Requires authenticated client with proper organization permissions. + # Requires authenticated organization owner. # # @param org [String, Integer] Organization GitHub login or id. # @return [Boolean] True if deletion successful, otherwise false. From aaa4e0f04ea977126e15057e76feb2f4bb31a500 Mon Sep 17 00:00:00 2001 From: James Dennes Date: Fri, 24 Mar 2023 17:01:18 +0100 Subject: [PATCH 3/9] Add tests for #delete_organization --- spec/octokit/client/organizations_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/octokit/client/organizations_spec.rb b/spec/octokit/client/organizations_spec.rb index 8dac44c04..7db866eea 100644 --- a/spec/octokit/client/organizations_spec.rb +++ b/spec/octokit/client/organizations_spec.rb @@ -22,6 +22,13 @@ end end # .update_organization + describe ".delete_organization", :vcr do + it "deletes an organization" do + @client.delete_organization(test_github_org) + assert_requested :delete, github_url("/orgs/#{test_github_org}") + end + end # .delete_organization + describe '.organizations', :vcr do it 'returns all organizations for a user' do organizations = @client.organizations(test_github_login) From 7e3d4cf20d7bcd63c4f3407cc5b9cbce8e94ed96 Mon Sep 17 00:00:00 2001 From: James Dennes Date: Fri, 24 Mar 2023 17:18:44 +0100 Subject: [PATCH 4/9] Use an org that I can delete --- spec/octokit/client/organizations_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/octokit/client/organizations_spec.rb b/spec/octokit/client/organizations_spec.rb index 7db866eea..1a92056b4 100644 --- a/spec/octokit/client/organizations_spec.rb +++ b/spec/octokit/client/organizations_spec.rb @@ -24,10 +24,10 @@ describe ".delete_organization", :vcr do it "deletes an organization" do - @client.delete_organization(test_github_org) - assert_requested :delete, github_url("/orgs/#{test_github_org}") + @client.delete_organization("random-org-to-be-deleted") + assert_requested :delete, github_url("/orgs/random-org-to-be-deleted") end - end # .delete_organization + end describe '.organizations', :vcr do it 'returns all organizations for a user' do From 73eafd4ae4dae79f78017e127dc2b61f823c0704 Mon Sep 17 00:00:00 2001 From: James Dennes Date: Fri, 24 Mar 2023 17:21:24 +0100 Subject: [PATCH 5/9] Add cassette for delete org op --- .../deletes_an_organization.json | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 spec/cassettes/Octokit_Client_Organizations/_delete_organization/deletes_an_organization.json diff --git a/spec/cassettes/Octokit_Client_Organizations/_delete_organization/deletes_an_organization.json b/spec/cassettes/Octokit_Client_Organizations/_delete_organization/deletes_an_organization.json new file mode 100644 index 000000000..108ea9a1b --- /dev/null +++ b/spec/cassettes/Octokit_Client_Organizations/_delete_organization/deletes_an_organization.json @@ -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 <>" + ], + "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" +} \ No newline at end of file From 7e24679cf8f6de21d02b1281ee731e743bdbc96b Mon Sep 17 00:00:00 2001 From: James Dennes Date: Fri, 24 Mar 2023 17:27:40 +0100 Subject: [PATCH 6/9] Improve docs --- lib/octokit/client/organizations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/octokit/client/organizations.rb b/lib/octokit/client/organizations.rb index 7260daed1..227fd0fc2 100644 --- a/lib/octokit/client/organizations.rb +++ b/lib/octokit/client/organizations.rb @@ -54,7 +54,7 @@ def update_organization(org, values, options = {}) # # Requires authenticated organization owner. # - # @param org [String, Integer] Organization GitHub login or id. + # @param org [String, Integer] Organization login or ID. # @return [Boolean] True if deletion successful, otherwise false. # @see https://docs.github.com/rest/reference/orgs/#delete-an-organization # @example From 8f7081648eed31e167e040b23a375bdebf3457c8 Mon Sep 17 00:00:00 2001 From: James Dennes Date: Sun, 26 Mar 2023 12:46:54 +0200 Subject: [PATCH 7/9] Fix docs link --- lib/octokit/client/organizations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/octokit/client/organizations.rb b/lib/octokit/client/organizations.rb index 227fd0fc2..324c4f470 100644 --- a/lib/octokit/client/organizations.rb +++ b/lib/octokit/client/organizations.rb @@ -56,7 +56,7 @@ def update_organization(org, values, options = {}) # # @param org [String, Integer] Organization login or ID. # @return [Boolean] True if deletion successful, otherwise false. - # @see https://docs.github.com/rest/reference/orgs/#delete-an-organization + # @see https://docs.github.com/rest/orgs/orgs#delete-an-organization # @example # @client.delete_organization("my-org") # @example From 96fb295fc4d797dcc132c7f2d7c463c7bb4e0839 Mon Sep 17 00:00:00 2001 From: James Dennes Date: Tue, 28 Mar 2023 15:25:20 +0200 Subject: [PATCH 8/9] Be more conventional --- spec/octokit/client/organizations_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/octokit/client/organizations_spec.rb b/spec/octokit/client/organizations_spec.rb index 1a92056b4..bdaa30d0f 100644 --- a/spec/octokit/client/organizations_spec.rb +++ b/spec/octokit/client/organizations_spec.rb @@ -22,7 +22,7 @@ end end # .update_organization - describe ".delete_organization", :vcr do + 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") From 8f71094250616c2fd409af50060f4a8d7d343e98 Mon Sep 17 00:00:00 2001 From: James Dennes Date: Thu, 30 Mar 2023 19:12:36 +0200 Subject: [PATCH 9/9] Prefer single quotes Why? --- spec/octokit/client/organizations_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/octokit/client/organizations_spec.rb b/spec/octokit/client/organizations_spec.rb index bdaa30d0f..daee77119 100644 --- a/spec/octokit/client/organizations_spec.rb +++ b/spec/octokit/client/organizations_spec.rb @@ -22,10 +22,10 @@ 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") + 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