summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2016-06-17 22:03:57 +0000
committerRobert Speicher <robert@gitlab.com>2016-06-17 22:03:57 +0000
commit5ef749b7ad940945340a726777a83f9098ed8791 (patch)
tree972fb39b1266706e3e2c4987ed360bcc002f5f74
parent6980489ca8f953fa61a15ae1b2c1035103cea85a (diff)
parent6ec5044f74a7b5817465f6a8e26d0e77b9860b78 (diff)
downloadgitlab-ce-5ef749b7ad940945340a726777a83f9098ed8791.tar.gz
Merge branch 'gh-webhooks' into 'master'
Avoid that GitHub import fails when retrieving Webhooks for non GitHub admins Closes #18729 See merge request !4723
-rw-r--r--app/views/import/github/status.html.haml2
-rw-r--r--lib/gitlab/github_import/importer.rb23
2 files changed, 19 insertions, 6 deletions
diff --git a/app/views/import/github/status.html.haml b/app/views/import/github/status.html.haml
index 6c4a9d68d1f..7486b1423e2 100644
--- a/app/views/import/github/status.html.haml
+++ b/app/views/import/github/status.html.haml
@@ -6,7 +6,7 @@
%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.
+ 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.
diff --git a/lib/gitlab/github_import/importer.rb b/lib/gitlab/github_import/importer.rb
index e5cf66a0371..2286ac8829c 100644
--- a/lib/gitlab/github_import/importer.rb
+++ b/lib/gitlab/github_import/importer.rb
@@ -66,8 +66,7 @@ module Gitlab
end
def import_pull_requests
- hooks = client.hooks(repo).map { |raw| HookFormatter.new(raw) }.select(&:valid?)
- disable_webhooks(hooks)
+ 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,14 +89,14 @@ module Gitlab
raise Projects::ImportService::Error, e.message
ensure
clean_up_restored_branches(branches_removed)
- clean_up_disabled_webhooks(hooks)
+ clean_up_disabled_webhooks
end
- def disable_webhooks(hooks)
+ def disable_webhooks
update_webhooks(hooks, active: false)
end
- def clean_up_disabled_webhooks(hooks)
+ def clean_up_disabled_webhooks
update_webhooks(hooks, active: true)
end
@@ -107,6 +106,20 @@ module Gitlab
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_branches(branches)
branches.each do |name, sha|
client.create_ref(repo, "refs/heads/#{name}", sha)