Does not need to disable GitHub webhooks since PRs are check out locally

This commit is contained in:
Douglas Barbosa Alexandre 2016-08-02 13:46:02 -03:00
parent ceff0c9170
commit 51cf14b37c
4 changed files with 0 additions and 123 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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