From 56b05e52011665a3d6dca158fccc4df8ba2d0021 Mon Sep 17 00:00:00 2001 From: John Cai Date: Tue, 7 Apr 2020 10:47:43 -0700 Subject: Removing unused methods from GitlabNet --- ruby/gitlab-shell/lib/gitlab_net.rb | 30 ------------- ruby/gitlab-shell/spec/gitlab_net_spec.rb | 73 ------------------------------- 2 files changed, 103 deletions(-) diff --git a/ruby/gitlab-shell/lib/gitlab_net.rb b/ruby/gitlab-shell/lib/gitlab_net.rb index 74996e712..812be9ae8 100644 --- a/ruby/gitlab-shell/lib/gitlab_net.rb +++ b/ruby/gitlab-shell/lib/gitlab_net.rb @@ -41,40 +41,10 @@ class GitlabNet # rubocop:disable Metrics/ClassLength GitAccessStatus.new(false, resp.code, API_INACCESSIBLE_MESSAGE) end - def broadcast_message - resp = get("#{internal_api_endpoint}/broadcast_message") - JSON.parse(resp.body) rescue {} - end - - def merge_request_urls(gl_repository, repo_path, changes) - changes = changes.join("\n") unless changes.is_a?(String) - changes = changes.encode('UTF-8', 'ASCII', invalid: :replace, replace: '') - url = "#{internal_api_endpoint}/merge_request_urls?project=#{URI.escape(repo_path)}&changes=#{URI.escape(changes)}" - url += "&gl_repository=#{URI.escape(gl_repository)}" if gl_repository - resp = get(url) - - if resp.code == '200' - JSON.parse(resp.body) - else - [] - end - rescue - [] - end - def check get("#{internal_api_endpoint}/check", options: { read_timeout: CHECK_TIMEOUT }) end - def notify_post_receive(gl_repository, repo_path) - params = { gl_repository: gl_repository, project: repo_path } - resp = post("#{internal_api_endpoint}/notify_post_receive", params) - - resp.code == '200' - rescue - false - end - def post_receive(gl_repository, gl_id, changes, push_options) params = { gl_repository: gl_repository, diff --git a/ruby/gitlab-shell/spec/gitlab_net_spec.rb b/ruby/gitlab-shell/spec/gitlab_net_spec.rb index a6f3cd8e9..f8161e222 100644 --- a/ruby/gitlab-shell/spec/gitlab_net_spec.rb +++ b/ruby/gitlab-shell/spec/gitlab_net_spec.rb @@ -41,58 +41,6 @@ describe GitlabNet, vcr: true do end end - describe '#broadcast_message' do - context "broadcast message exists" do - it 'should return message' do - VCR.use_cassette("broadcast_message-ok") do - result = gitlab_net.broadcast_message - expect(result["message"]).to eq("Message") - end - end - end - - context "broadcast message doesn't exist" do - it 'should return nil' do - VCR.use_cassette("broadcast_message-none") do - result = gitlab_net.broadcast_message - expect(result).to eq({}) - end - end - end - end - - describe '#merge_request_urls' do - let(:gl_repository) { "project-1" } - let(:changes) { "123456 789012 refs/heads/test\n654321 210987 refs/tags/tag" } - let(:encoded_changes) { "123456%20789012%20refs/heads/test%0A654321%20210987%20refs/tags/tag" } - - it "sends the given arguments as encoded URL parameters" do - expect(gitlab_net).to receive(:get).with("#{internal_api_endpoint}/merge_request_urls?project=#{project}&changes=#{encoded_changes}&gl_repository=#{gl_repository}") - - gitlab_net.merge_request_urls(gl_repository, project, changes) - end - - it "omits the gl_repository parameter if it's nil" do - expect(gitlab_net).to receive(:get).with("#{internal_api_endpoint}/merge_request_urls?project=#{project}&changes=#{encoded_changes}") - - gitlab_net.merge_request_urls(nil, project, changes) - end - - it "returns an empty array when the result cannot be parsed as JSON" do - response = double(:response, code: '200', body: '') - allow(gitlab_net).to receive(:get).and_return(response) - - expect(gitlab_net.merge_request_urls(gl_repository, project, changes)).to eq([]) - end - - it "returns an empty array when the result's status is not 200" do - response = double(:response, code: '500', body: '[{}]') - allow(gitlab_net).to receive(:get).and_return(response) - - expect(gitlab_net.merge_request_urls(gl_repository, project, changes)).to eq([]) - end - end - describe '#pre_receive' do let(:gl_repository) { "project-1" } let(:params) { { gl_repository: gl_repository } } @@ -160,27 +108,6 @@ describe GitlabNet, vcr: true do end end - describe '#notify_post_receive' do - let(:gl_repository) { 'project-1' } - let(:repo_path) { '/path/to/my/repo.git' } - let(:params) do - { gl_repository: gl_repository, project: repo_path } - end - - it 'sets the arguments as form parameters' do - VCR.use_cassette('notify-post-receive') do - expect_any_instance_of(Net::HTTP::Post).to receive(:set_form_data).with(hash_including(params)) - gitlab_net.notify_post_receive(gl_repository, repo_path) - end - end - - it 'returns true if notification was succesful' do - VCR.use_cassette('notify-post-receive') do - expect(gitlab_net.notify_post_receive(gl_repository, repo_path)).to be_truthy - end - end - end - describe '#check_access' do context 'ssh key with access nil, to project' do it 'should allow push access for host' do -- cgit v1.2.3