Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

list hooks for the given github repo

  • Loading branch information...
commit 5779b42933ae33cdd8e854a83f4c5f4db0368987 1 parent 927a45a
@georgeguimaraes georgeguimaraes authored
View
1  .gitignore
@@ -1,4 +1,3 @@
*.gem
.bundle
-Gemfile.lock
pkg/*
View
2  .rspec
@@ -0,0 +1,2 @@
+--color
+--format progress
View
3  Gemfile
@@ -2,3 +2,6 @@ source "http://rubygems.org"
# Specify your gem's dependencies in github-hooker.gemspec
gemspec
+
+gem 'rspec'
+gem 'webmock'
View
5 github-hooker.gemspec
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- # specify any dependencies here; for example:
- # s.add_development_dependency "rspec"
- # s.add_runtime_dependency "rest-client"
+ s.add_dependency "rest-client", "~> 1.6.7"
+ s.add_dependency "thor", "~> 0.14.6"
end
View
49 lib/github-hooker.rb
@@ -1,6 +1,55 @@
require "github-hooker/version"
+require 'net/http'
+require 'json'
+require 'yaml'
+require 'restclient'
module Github
module Hooker
+
+ def self.add_hook(options={})
+ payload = {
+ :name => options[:name],
+ :events => options[:events],
+ :active => true,
+ }
+
+ request_options = {
+ :method => :post,
+ :url => "https://api.github.com/repos/#{options[:repo]}/hooks",
+ :user => config[:user],
+ :password => config[:password],
+ :payload => payload
+ }
+ response = RestClient::Request.execute(request_options)
+ response = JSON.parse(response)
+ end
+
+ def self.list_hooks(options={})
+ request_options = {
+ :method => :get,
+ :url => "https://api.github.com/repos/#{options[:repo]}/hooks",
+ :user => config["user"],
+ :password => config["password"],
+ :ssl => true
+ }
+ response = RestClient::Request.execute(request_options)
+ response = JSON.parse(response)
+
+ response.each do |hook|
+ puts "#{hook['url']}"
+ puts "> name: #{hook['name']}"
+ puts "> events: #{hook['events'].join(", ")}"
+ puts
+ end
+ end
+
+ def self.config
+ @config ||= YAML.load_file(File.expand_path("~/.github-hooker.yml"))
+ end
+
+ def self.github_api
+
+ end
end
end
View
1  spec/github_hooker_spec.rb
@@ -0,0 +1 @@
+require 'spec_helper'
View
9 spec/spec_helper.rb
@@ -0,0 +1,9 @@
+require 'webmock/rspec'
+
+RSpec.configure do |config|
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+ config.run_all_when_everything_filtered = true
+ config.filter_run :focus
+end
+
+stub_request(:post, 'https://api.github.com/hooks')
Please sign in to comment.
Something went wrong with that request. Please try again.