summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJonhnny Weslley <jw@jonhnnyweslley.net>2013-02-15 16:35:03 -0300
committerJonhnny Weslley <jw@jonhnnyweslley.net>2013-02-15 16:35:03 -0300
commit836b561a12a6954c5bbc87bc8fbc0f51636f71c5 (patch)
tree45cba42c8a5a30b19666f2558bdc64023ff969bf /lib
parentf9dd547aa7289c59a389ce1393c4b3eb4e0239f4 (diff)
downloadgitlab-ce-836b561a12a6954c5bbc87bc8fbc0f51636f71c5.tar.gz
add rake tasks for web hooks management
Diffstat (limited to 'lib')
-rw-r--r--lib/tasks/gitlab/web_hook.rake65
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/tasks/gitlab/web_hook.rake b/lib/tasks/gitlab/web_hook.rake
new file mode 100644
index 00000000000..f9f586db93c
--- /dev/null
+++ b/lib/tasks/gitlab/web_hook.rake
@@ -0,0 +1,65 @@
+namespace :gitlab do
+ namespace :web_hook do
+ desc "GITLAB | Adds a web hook to the projects"
+ task :add => :environment do
+ web_hook_url = ENV['URL']
+ namespace_path = ENV['NAMESPACE']
+
+ projects = find_projects(namespace_path)
+
+ puts "Adding web hook '#{web_hook_url}' to:"
+ projects.find_each(batch_size: 1000) do |project|
+ print "- #{project.name} ... "
+ web_hook = project.hooks.new(url: web_hook_url)
+ if web_hook.save
+ puts "added".green
+ else
+ print "failed".red
+ puts " [#{web_hook.errors.full_messages.to_sentence}]"
+ end
+ end
+ end
+
+ desc "GITLAB | Remove a web hook from the projects"
+ task :rm => :environment do
+ web_hook_url = ENV['URL']
+ namespace_path = ENV['NAMESPACE']
+
+ projects = find_projects(namespace_path)
+ projects_ids = projects.pluck(:id)
+
+ puts "Removing web hooks with the url '#{web_hook_url}' ... "
+ count = WebHook.where(url: web_hook_url, project_id: projects_ids, type: 'ProjectHook').delete_all
+ puts "#{count} web hooks were removed."
+ end
+
+ desc "GITLAB | List web hooks"
+ task :list => :environment do
+ namespace_path = ENV['NAMESPACE']
+
+ projects = find_projects(namespace_path)
+ web_hooks = projects.all.map(&:hooks).flatten
+ web_hooks.each do |hook|
+ puts "#{hook.project.name.truncate(20).ljust(20)} -> #{hook.url}"
+ end
+
+ puts "\n#{web_hooks.size} web hooks found."
+ end
+ end
+
+ def find_projects(namespace_path)
+ if namespace_path.blank?
+ Project
+ elsif namespace_path == '/'
+ Project.where(namespace_id: nil)
+ else
+ namespace = Namespace.where(path: namespace_path).first
+ if namespace
+ Project.where(namespace_id: namespace.id)
+ else
+ puts "Namespace not found: #{namespace_path}".red
+ exit 2
+ end
+ end
+ end
+end