From 51cf14b37c64b1afab25b10dfe94e281ff58d288 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Tue, 2 Aug 2016 13:46:02 -0300 Subject: [PATCH] Does not need to disable GitHub webhooks since PRs are check out locally --- app/views/import/github/status.html.haml | 4 -- lib/gitlab/github_import/hook_formatter.rb | 23 ------- lib/gitlab/github_import/importer.rb | 31 --------- .../github_import/hook_formatter_spec.rb | 65 ------------------- 4 files changed, 123 deletions(-) delete mode 100644 lib/gitlab/github_import/hook_formatter.rb delete mode 100644 spec/lib/gitlab/github_import/hook_formatter_spec.rb diff --git a/app/views/import/github/status.html.haml b/app/views/import/github/status.html.haml index deaaf9af875..54ff1d27c67 100644 --- a/app/views/import/github/status.html.haml +++ b/app/views/import/github/status.html.haml @@ -4,10 +4,6 @@ %i.fa.fa-github Import projects from GitHub -%p - %i.fa.fa-warning - To import GitHub pull requests, any pull request source branches that had been deleted are temporarily restored on GitHub. To prevent any connected CI services from being overloaded with dozens of irrelevant branches being created and deleted again, GitHub webhooks are temporarily disabled during the import process, but only if you have admin access to the GitHub repository. - %p.light Select projects you want to import. %hr diff --git a/lib/gitlab/github_import/hook_formatter.rb b/lib/gitlab/github_import/hook_formatter.rb deleted file mode 100644 index db1fabaa18a..00000000000 --- a/lib/gitlab/github_import/hook_formatter.rb +++ /dev/null @@ -1,23 +0,0 @@ -module Gitlab - module GithubImport - class HookFormatter - EVENTS = %w[* create delete pull_request push].freeze - - attr_reader :raw - - delegate :id, :name, :active, to: :raw - - def initialize(raw) - @raw = raw - end - - def config - raw.config.attrs - end - - def valid? - (EVENTS & raw.events).any? && active - end - end - end -end diff --git a/lib/gitlab/github_import/importer.rb b/lib/gitlab/github_import/importer.rb index 3b501533ffb..294e44b7124 100644 --- a/lib/gitlab/github_import/importer.rb +++ b/lib/gitlab/github_import/importer.rb @@ -66,8 +66,6 @@ module Gitlab end def import_pull_requests - disable_webhooks - pull_requests = client.pull_requests(repo, state: :all, sort: :created, direction: :asc, per_page: 100) pull_requests = pull_requests.map { |raw| PullRequestFormatter.new(project, raw) }.select(&:valid?) @@ -90,35 +88,6 @@ module Gitlab raise Projects::ImportService::Error, e.message ensure clean_up_restored_branches(branches_removed) - clean_up_disabled_webhooks - end - - def disable_webhooks - update_webhooks(hooks, active: false) - end - - def clean_up_disabled_webhooks - update_webhooks(hooks, active: true) - end - - def update_webhooks(hooks, options) - hooks.each do |hook| - client.edit_hook(repo, hook.id, hook.name, hook.config, options) - end - end - - def hooks - @hooks ||= - begin - client.hooks(repo).map { |raw| HookFormatter.new(raw) }.select(&:valid?) - - # The GitHub Repository Webhooks API returns 404 for users - # without admin access to the repository when listing hooks. - # In this case we just want to return gracefully instead of - # spitting out an error and stop the import process. - rescue Octokit::NotFound - [] - end end def restore_source_branches(branches) diff --git a/spec/lib/gitlab/github_import/hook_formatter_spec.rb b/spec/lib/gitlab/github_import/hook_formatter_spec.rb deleted file mode 100644 index 110ba428258..00000000000 --- a/spec/lib/gitlab/github_import/hook_formatter_spec.rb +++ /dev/null @@ -1,65 +0,0 @@ -require 'spec_helper' - -describe Gitlab::GithubImport::HookFormatter, lib: true do - describe '#id' do - it 'returns raw id' do - raw = double(id: 100000) - formatter = described_class.new(raw) - expect(formatter.id).to eq 100000 - end - end - - describe '#name' do - it 'returns raw id' do - raw = double(name: 'web') - formatter = described_class.new(raw) - expect(formatter.name).to eq 'web' - end - end - - describe '#config' do - it 'returns raw config.attrs' do - raw = double(config: double(attrs: { url: 'http://something.com/webhook' })) - formatter = described_class.new(raw) - expect(formatter.config).to eq({ url: 'http://something.com/webhook' }) - end - end - - describe '#valid?' do - it 'returns true when events contains the wildcard event' do - raw = double(events: ['*', 'commit_comment'], active: true) - formatter = described_class.new(raw) - expect(formatter.valid?).to eq true - end - - it 'returns true when events contains the create event' do - raw = double(events: ['create', 'commit_comment'], active: true) - formatter = described_class.new(raw) - expect(formatter.valid?).to eq true - end - - it 'returns true when events contains delete event' do - raw = double(events: ['delete', 'commit_comment'], active: true) - formatter = described_class.new(raw) - expect(formatter.valid?).to eq true - end - - it 'returns true when events contains pull_request event' do - raw = double(events: ['pull_request', 'commit_comment'], active: true) - formatter = described_class.new(raw) - expect(formatter.valid?).to eq true - end - - it 'returns false when events does not contains branch related events' do - raw = double(events: ['member', 'commit_comment'], active: true) - formatter = described_class.new(raw) - expect(formatter.valid?).to eq false - end - - it 'returns false when hook is not active' do - raw = double(events: ['pull_request', 'commit_comment'], active: false) - formatter = described_class.new(raw) - expect(formatter.valid?).to eq false - end - end -end