From 2c3a0cea13f7855742bd6dede8254568cc958dff Mon Sep 17 00:00:00 2001 From: Miguel Jimenez Date: Fri, 15 Mar 2024 22:46:09 +0000 Subject: [PATCH 1/2] remove pub_sub_hubbub module --- lib/octokit/client.rb | 2 - lib/octokit/client/pub_sub_hubbub.rb | 111 --------------------- spec/octokit/client/pub_sub_hubbub_spec.rb | 98 ------------------ 3 files changed, 211 deletions(-) delete mode 100644 lib/octokit/client/pub_sub_hubbub.rb delete mode 100644 spec/octokit/client/pub_sub_hubbub_spec.rb diff --git a/lib/octokit/client.rb b/lib/octokit/client.rb index b4005bf77..cf9236854 100644 --- a/lib/octokit/client.rb +++ b/lib/octokit/client.rb @@ -50,7 +50,6 @@ require 'octokit/client/organizations' require 'octokit/client/pages' require 'octokit/client/projects' -require 'octokit/client/pub_sub_hubbub' require 'octokit/client/pull_requests' require 'octokit/client/rate_limit' require 'octokit/client/reactions' @@ -118,7 +117,6 @@ class Client include Octokit::Client::Organizations include Octokit::Client::Pages include Octokit::Client::Projects - include Octokit::Client::PubSubHubbub include Octokit::Client::PullRequests include Octokit::Client::RateLimit include Octokit::Client::Reactions diff --git a/lib/octokit/client/pub_sub_hubbub.rb b/lib/octokit/client/pub_sub_hubbub.rb deleted file mode 100644 index 28ad171de..000000000 --- a/lib/octokit/client/pub_sub_hubbub.rb +++ /dev/null @@ -1,111 +0,0 @@ -# frozen_string_literal: true - -module Octokit - class Client - # Methods for the PubSubHubbub API - # - # @see https://developer.github.com/v3/repos/hooks/#pubsubhubbub - module PubSubHubbub - # Subscribe to a pubsub topic - # - # @param topic [String] A recoginized and supported pubsub topic - # @param callback [String] A callback url to be posted to when the topic event is fired - # @param secret [String] An optional shared secret used to generate a SHA1 HMAC of the outgoing body content - # @return [Boolean] true if the subscribe was successful, otherwise an error is raised - # @see https://developer.github.com/v3/repos/hooks/#subscribing - # @example Subscribe to push events from one of your repositories, having an email sent when fired - # client = Octokit::Client.new(:oauth_token = "token") - # client.subscribe("https://github.com/joshk/devise_imapable/events/push", "github://Email?address=josh.kalderimis@gmail.com") - def subscribe(topic, callback, secret = nil) - options = { - 'hub.callback': callback, - 'hub.mode': 'subscribe', - 'hub.topic': topic - } - options.merge!('hub.secret': secret) unless secret.nil? - - response = pub_sub_hubbub_request(options) - - response.status == 204 - end - - # Unsubscribe from a pubsub topic - # - # @param topic [String] A recoginized pubsub topic - # @param callback [String] A callback url to be unsubscribed from - # @return [Boolean] true if the unsubscribe was successful, otherwise an error is raised - # @see https://developer.github.com/v3/repos/hooks/#subscribing - # @example Unsubscribe to push events from one of your repositories, no longer having an email sent when fired - # client = Octokit::Client.new(:oauth_token = "token") - # client.unsubscribe("https://github.com/joshk/devise_imapable/events/push", "github://Email?address=josh.kalderimis@gmail.com") - def unsubscribe(topic, callback) - options = { - 'hub.callback': callback, - 'hub.mode': 'unsubscribe', - 'hub.topic': topic - } - response = pub_sub_hubbub_request(options) - - response.status == 204 - end - - # Subscribe to a repository through pubsub - # - # @param repo [String, Repository, Hash] A GitHub repository - # @param service_name [String] service name owner - # @param service_arguments [Hash] params that will be passed by subscribed hook. - # List of services is available @ https://github.com/github/github-services/tree/master/docs. - # Please refer Data node for complete list of arguments. - # @param secret [String] An optional shared secret used to generate a SHA1 HMAC of the outgoing body content - # @return [Boolean] True if subscription successful, false otherwise - # @see https://developer.github.com/v3/repos/hooks/#subscribing - # @example Subscribe to push events to one of your repositories to Travis-CI - # client = Octokit::Client.new(:oauth_token = "token") - # client.subscribe_service_hook('joshk/device_imapable', 'Travis', { :token => "test", :domain => "domain", :user => "user" }) - def subscribe_service_hook(repo, service_name, service_arguments = {}, secret = nil) - topic = "#{Octokit.web_endpoint}#{Repository.new(repo)}/events/push" - callback = "github://#{service_name}?#{service_arguments.collect { |k, v| [k, v].map { |p| URI.encode_www_form_component(p) }.join('=') }.join('&')}" - subscribe(topic, callback, secret) - end - - # Unsubscribe repository through pubsub - # - # @param repo [String, Repository, Hash] A GitHub repository - # @param service_name [String] service name owner - # List of services is available @ https://github.com/github/github-services/tree/master/docs. - # @see https://developer.github.com/v3/repos/hooks/#subscribing - # @example Subscribe to push events to one of your repositories to Travis-CI - # client = Octokit::Client.new(:oauth_token = "token") - # client.unsubscribe_service_hook('joshk/device_imapable', 'Travis') - def unsubscribe_service_hook(repo, service_name) - topic = "#{Octokit.web_endpoint}#{Repository.new(repo)}/events/push" - callback = "github://#{service_name}" - unsubscribe(topic, callback) - end - - private - - def pub_sub_hubbub_request(options = {}) - # This method is janky, bypass normal stack so we don't - # serialize request as JSON - conn = Faraday.new(url: @api_endpoint) do |http| - http.headers[:user_agent] = user_agent - if basic_authenticated? - http.request(*FARADAY_BASIC_AUTH_KEYS, @login, @password) - elsif token_authenticated? - http.request :authorization, 'token', @access_token - end - http.request :url_encoded - http.use Octokit::Response::RaiseError - http.adapter Faraday.default_adapter - end - - conn.post do |req| - req.url 'hub' - req.headers['Content-Type'] = 'application/x-www-form-urlencoded' - req.body = options - end - end - end - end -end diff --git a/spec/octokit/client/pub_sub_hubbub_spec.rb b/spec/octokit/client/pub_sub_hubbub_spec.rb deleted file mode 100644 index c13f1c6e1..000000000 --- a/spec/octokit/client/pub_sub_hubbub_spec.rb +++ /dev/null @@ -1,98 +0,0 @@ -# frozen_string_literal: true - -describe Octokit::Client::PubSubHubbub do - before do - Octokit.reset! - @client = oauth_client - end - - describe '.subscribe' do - it 'subscribes to pull events' do - request = stub_post(github_url('/hub')) - .with(body: { - 'hub.callback': 'github://Travis?token=travistoken', - 'hub.mode': 'subscribe', - 'hub.topic': 'https://github.com/elskwid/github-services/events/push', - 'hub.secret': '12345' - }) - .to_return(status: 204) - result = @client.subscribe('https://github.com/elskwid/github-services/events/push', 'github://Travis?token=travistoken', '12345') - expect(result).to be true - assert_requested request - end - - it 'raises an error when topic is not recognized', :vcr do - subscribe_request_body = { - 'hub.callback': 'github://Travis?token=travistoken', - 'hub.mode': 'subscribe', - 'hub.topic': 'https://github.com/joshk/not_existing_project/events/push' - } - expect do - @client.subscribe('https://github.com/joshk/not_existing_project/events/push', 'github://Travis?token=travistoken') - end.to raise_error Octokit::UnprocessableEntity - assert_requested :post, github_url('/hub'), body: subscribe_request_body, times: 1, - headers: { 'Content-type' => 'application/x-www-form-urlencoded' } - end - end # .subscribe - - describe '.unsubscribe', :vcr do - it 'unsubscribes from pull events' do - unsubscribe_request_body = { - 'hub.callback': 'github://Travis?token=travistoken', - 'hub.mode': 'unsubscribe', - 'hub.topic': "https://github.com/#{@test_repo}/events/push" - } - - result = @client.unsubscribe("https://github.com/#{@test_repo}/events/push", 'github://Travis?token=travistoken') - assert_requested :post, github_url('/hub'), body: unsubscribe_request_body, times: 1, - headers: { 'Content-type' => 'application/x-www-form-urlencoded' } - expect(result).to be true - end - end # .unsubscribe - - describe '.subscribe_service_hook' do - it 'subscribes to pull event on specified topic' do - request = stub_post(github_url('/hub')) - .with(body: { - 'hub.callback': 'github://Travis?token=travistoken', - 'hub.mode': 'subscribe', - 'hub.topic': 'https://github.com/elskwid/github-services/events/push', - 'hub.secret': '12345' - }) - .to_return(status: 204) - result = @client.subscribe_service_hook('elskwid/github-services', 'Travis', { token: 'travistoken' }, '12345') - expect(result).to be true - assert_requested request - end - - it 'encodes URL parameters', :vcr do - irc_request_body = { - 'hub.callback': 'github://irc?server=chat.freenode.org&room=%23myproject', - 'hub.mode': 'subscribe', - 'hub.topic': 'https://github.com/joshk/completeness-fu/events/push' - } - stub_post('/hub') - .with(body: irc_request_body) - .to_return(status: 204) - expect(@client.subscribe_service_hook('joshk/completeness-fu', 'irc', { server: 'chat.freenode.org', room: '#myproject' })).to eql(true) - # Since we can't depend upon hash ordering across the Rubies - assert_requested :post, 'https://api.github.com/hub', times: 1 do |req| - req.body[/hub.callback=github%3A%2F%2Firc%3Froom%3D%2523myproject/] - req.body[/server%3Dchat.freenode.org/] - end - end - end # .subscribe_service_hook - - describe 'unsubscribe_service_hook', :vcr do - it 'unsubscribes to stop receiving events on specified topic' do - unsubscribe_request_body = { - 'hub.callback': 'github://Travis', - 'hub.mode': 'unsubscribe', - 'hub.topic': "https://github.com/#{@test_repo}/events/push" - } - expect(@client.unsubscribe_service_hook(@test_repo, 'Travis')).to eq(true) - assert_requested :post, github_url('/hub'), body: unsubscribe_request_body, times: 1, - headers: { 'Content-type' => 'application/x-www-form-urlencoded' } - end - end -end From cf26c9c82bc8835e3a15a7116f2288e1615e8182 Mon Sep 17 00:00:00 2001 From: Miguel Jimenez Date: Fri, 15 Mar 2024 22:47:13 +0000 Subject: [PATCH 2/2] remove PubSubHubbub cassettes --- .../_subscribe/raises_an_error_when_topic_is_not_recognized.json | 1 - .../_unsubscribe/unsubscribes_from_pull_events.json | 1 - ...unsubscribes_to_stop_receiving_events_on_specified_topic.json | 1 - 3 files changed, 3 deletions(-) delete mode 100644 spec/cassettes/Octokit_Client_PubSubHubbub/_subscribe/raises_an_error_when_topic_is_not_recognized.json delete mode 100644 spec/cassettes/Octokit_Client_PubSubHubbub/_unsubscribe/unsubscribes_from_pull_events.json delete mode 100644 spec/cassettes/Octokit_Client_PubSubHubbub/unsubscribe_service_hook/unsubscribes_to_stop_receiving_events_on_specified_topic.json diff --git a/spec/cassettes/Octokit_Client_PubSubHubbub/_subscribe/raises_an_error_when_topic_is_not_recognized.json b/spec/cassettes/Octokit_Client_PubSubHubbub/_subscribe/raises_an_error_when_topic_is_not_recognized.json deleted file mode 100644 index e32bc778a..000000000 --- a/spec/cassettes/Octokit_Client_PubSubHubbub/_subscribe/raises_an_error_when_topic_is_not_recognized.json +++ /dev/null @@ -1 +0,0 @@ -{"http_interactions":[{"request":{"method":"post","uri":"https://api.github.com/hub","body":{"encoding":"US-ASCII","base64_string":"aHViLm1vZGU9c3Vic2NyaWJlJmh1Yi50b3BpYz1odHRwcyUzQSUyRiUyRmdp\ndGh1Yi5jb20lMkZqb3NoayUyRm5vdF9leGlzdGluZ19wcm9qZWN0JTJGZXZl\nbnRzJTJGcHVzaCZodWIuY2FsbGJhY2s9Z2l0aHViJTNBJTJGJTJGVHJhdmlz\nJTNGdG9rZW4lM0R0cmF2aXN0b2tlbg==\n"},"headers":{"User-Agent":["Octokit Ruby Gem 2.0.0.pre"],"Authorization":["token <>"],"Content-Type":["application/x-www-form-urlencoded"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"],"Accept":["*/*"]}},"response":{"status":{"code":422,"message":"Unprocessable Entity"},"headers":{"Server":["GitHub.com"],"Date":["Mon, 24 Jun 2013 01:16:21 GMT"],"Content-Type":["application/json; charset=utf-8"],"Connection":["keep-alive"],"Status":["422 Unprocessable Entity"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4990"],"X-Oauth-Scopes":["repo, user, gist"],"X-Github-Media-Type":["github.beta"],"X-Content-Type-Options":["nosniff"],"Content-Length":["110"]},"body":{"encoding":"UTF-8","base64_string":"eyJtZXNzYWdlIjoiTm8gcmVwb3NpdG9yeSBmb3VuZCBmb3IgaHViLnRvcGlj\nOiBcImh0dHBzOi8vZ2l0aHViLmNvbS9qb3Noay9ub3RfZXhpc3RpbmdfcHJv\namVjdC9ldmVudHMvcHVzaFwiIn0=\n"},"http_version":null},"recorded_at":"Mon, 24 Jun 2013 01:16:20 GMT"}],"recorded_with":"VCR 2.4.0"} \ No newline at end of file diff --git a/spec/cassettes/Octokit_Client_PubSubHubbub/_unsubscribe/unsubscribes_from_pull_events.json b/spec/cassettes/Octokit_Client_PubSubHubbub/_unsubscribe/unsubscribes_from_pull_events.json deleted file mode 100644 index 4cac716fb..000000000 --- a/spec/cassettes/Octokit_Client_PubSubHubbub/_unsubscribe/unsubscribes_from_pull_events.json +++ /dev/null @@ -1 +0,0 @@ -{"http_interactions":[{"request":{"method":"post","uri":"https://api.github.com/hub","body":{"encoding":"UTF-8","base64_string":"aHViLmNhbGxiYWNrPWdpdGh1YiUzQSUyRiUyRlRyYXZpcyUzRnRva2VuJTNE\ndHJhdmlzdG9rZW4maHViLm1vZGU9dW5zdWJzY3JpYmUmaHViLnRvcGljPWh0\ndHBzJTNBJTJGJTJGZ2l0aHViLmNvbSUyRjxHSVRIVUJfTE9HSU4+JTJGPEdJ\nVEhVQl9URVNUX1JFUE9TSVRPUlk+JTJGZXZlbnRzJTJGcHVzaA==\n"},"headers":{"User-Agent":["Octokit Ruby Gem 3.0.0.pre"],"Authorization":["token <>"],"Content-Type":["application/x-www-form-urlencoded"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"],"Accept":["*/*"]}},"response":{"status":{"code":204,"message":"No Content"},"headers":{"Server":["GitHub.com"],"Date":["Fri, 07 Mar 2014 17:34:48 GMT"],"Status":["204 No Content"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4993"],"X-Ratelimit-Reset":["1394215510"],"X-Oauth-Scopes":["gist, repo, user"],"X-Accepted-Oauth-Scopes":[""],"X-Github-Media-Type":["github.beta"],"X-Content-Type-Options":["nosniff"],"X-Github-Request-Id":["4B413AB6:3BDF:4CB1D79:531A0338"],"Vary":["Accept-Encoding"]},"body":{"encoding":"UTF-8","base64_string":""},"http_version":null},"recorded_at":"Fri, 07 Mar 2014 17:34:46 GMT"}],"recorded_with":"VCR 2.8.0"} \ No newline at end of file diff --git a/spec/cassettes/Octokit_Client_PubSubHubbub/unsubscribe_service_hook/unsubscribes_to_stop_receiving_events_on_specified_topic.json b/spec/cassettes/Octokit_Client_PubSubHubbub/unsubscribe_service_hook/unsubscribes_to_stop_receiving_events_on_specified_topic.json deleted file mode 100644 index d3fb0b5da..000000000 --- a/spec/cassettes/Octokit_Client_PubSubHubbub/unsubscribe_service_hook/unsubscribes_to_stop_receiving_events_on_specified_topic.json +++ /dev/null @@ -1 +0,0 @@ -{"http_interactions":[{"request":{"method":"post","uri":"https://api.github.com/hub","body":{"encoding":"UTF-8","base64_string":"aHViLmNhbGxiYWNrPWdpdGh1YiUzQSUyRiUyRlRyYXZpcyZodWIubW9kZT11\nbnN1YnNjcmliZSZodWIudG9waWM9aHR0cHMlM0ElMkYlMkZnaXRodWIuY29t\nJTJGPEdJVEhVQl9MT0dJTj4lMkY8R0lUSFVCX1RFU1RfUkVQT1NJVE9SWT4l\nMkZldmVudHMlMkZwdXNo\n"},"headers":{"User-Agent":["Octokit Ruby Gem 3.0.0.pre"],"Authorization":["token <>"],"Content-Type":["application/x-www-form-urlencoded"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"],"Accept":["*/*"]}},"response":{"status":{"code":204,"message":"No Content"},"headers":{"Server":["GitHub.com"],"Date":["Fri, 07 Mar 2014 17:34:07 GMT"],"Status":["204 No Content"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4994"],"X-Ratelimit-Reset":["1394215510"],"X-Oauth-Scopes":["gist, repo, user"],"X-Accepted-Oauth-Scopes":[""],"X-Github-Media-Type":["github.beta"],"X-Content-Type-Options":["nosniff"],"X-Github-Request-Id":["4B413AB6:3CF9:5F46889:531A030F"],"Vary":["Accept-Encoding"]},"body":{"encoding":"UTF-8","base64_string":""},"http_version":null},"recorded_at":"Fri, 07 Mar 2014 17:34:04 GMT"}],"recorded_with":"VCR 2.8.0"} \ No newline at end of file