Skip to content

Instantly share code, notes, and snippets.

@rkh
Created August 9, 2012 10:38
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkh/3303121 to your computer and use it in GitHub Desktop.
Save rkh/3303121 to your computer and use it in GitHub Desktop.
begin
require 'highline/import'
rescue LoadError
puts "we need highline, please run:", "", "\tgem install highline", ""
exit 1
end
begin
require 'gh'
rescue LoadError
puts "we need gh, please run:", "", "\tgem install gh", ""
exit 1
end
def self.our_hook?(hook)
return true if hook['name'] == 'travis'
return false if hook['name'] != 'web'
return false if hook['config'].nil?
hook['config']['url'] =~ /travis-ci\.(com|org)/
end
def self.check_user
user = GH['user']
puts "", "Successfully logged in as #{user['name'] || user['login']}!"
rescue
puts "", "Login failed"
exit 1
end
def self.check_repo
puts
repo = ask('repository: ')
repo = "#{@login}/#{repo}" unless repo.include? '/'
found = false
GH["repos/#{repo}/hooks"].each do |hook|
next unless our_hook? hook
url = hook['_links']['self']['href']
GH.post(url, add_events: %w[push pull_request issue_comment public member])
found = true
end
if found
puts "Successfully enabled #{repo}!"
else
puts "#{repo} seems not to be using Travis CI :("
end
rescue Faraday::Error::ClientError
puts "Either #{repo} does not exist or you don't have access to it."
end
begin
puts "No data will be sent to Travis CI", "", "GitHub login (password will not be displayed nor stored)"
@login = ask('login: ')
@password = ask('password: ') { |q| q.echo = false }
GH.with(username: @login, password: @password) do
check_user
loop { check_repo }
end
rescue EOFError
exit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment