gitlab-org--gitlab-foss/lib/tasks/gitlab/web_hook.rake
Connor Shea 903946c78a
Replace colorize gem with rainbow.
Colorize is a gem licensed under the GPLv2, so we can’t use it in GitLab without relicensing GitLab under the terms of the GPL. Rainbow is licensed under the MIT license and does the exact same thing as Colorize, so Rainbow was added in place of Colorize.

The syntax is slightly different for Rainbow vs. Colorize, and was updated in accordance.

The gem is still a dependency of Spinach, so it’s included in the development/test environments, but won’t be packaged with the actual product, and therefore doesn’t require we relicense the product.

An attempt at relicensing Colorize was made, but didn’t succeed as the library owner never responded.

Rainbow library: https://github.com/sickill/rainbow
Relevant issue regarding licensing in GitLab's gems: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3775
2016-06-03 10:37:09 -06:00

65 lines
1.9 KiB
Ruby

namespace :gitlab do
namespace :web_hook do
desc "GitLab | Adds a webhook to the projects"
task :add => :environment do
web_hook_url = ENV['URL']
namespace_path = ENV['NAMESPACE']
projects = find_projects(namespace_path)
puts "Adding webhook '#{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".color(:green)
else
print "failed".color(:red)
puts " [#{web_hook.errors.full_messages.to_sentence}]"
end
end
end
desc "GitLab | Remove a webhook 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 webhooks with the url '#{web_hook_url}' ... "
count = WebHook.where(url: web_hook_url, project_id: projects_ids, type: 'ProjectHook').delete_all
puts "#{count} webhooks were removed."
end
desc "GitLab | List webhooks"
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} webhooks found."
end
end
def find_projects(namespace_path)
if namespace_path.blank?
Project
elsif namespace_path == '/'
Project.in_namespace(nil)
else
namespace = Namespace.where(path: namespace_path).first
if namespace
Project.in_namespace(namespace.id)
else
puts "Namespace not found: #{namespace_path}".color(:red)
exit 2
end
end
end
end