This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

list hooks for the given github repo

  • Loading branch information...
georgeguimaraes committed Jan 30, 2012
1 parent 927a45a commit 5779b42933ae33cdd8e854a83f4c5f4db0368987
Showing with 66 additions and 4 deletions.
  1. +0 −1 .gitignore
  2. +2 −0 .rspec
  3. +3 −0 Gemfile
  4. +2 −3 github-hooker.gemspec
  5. +49 −0 lib/github-hooker.rb
  6. +1 −0 spec/github_hooker_spec.rb
  7. +9 −0 spec/spec_helper.rb
View
@@ -1,4 +1,3 @@
*.gem
.bundle
-Gemfile.lock
pkg/*
View
2 .rspec
@@ -0,0 +1,2 @@
+--color
+--format progress
View
@@ -2,3 +2,6 @@ source "http://rubygems.org"
# Specify your gem's dependencies in github-hooker.gemspec
gemspec
+
+gem 'rspec'
+gem 'webmock'
View
@@ -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
@@ -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
@@ -0,0 +1 @@
+require 'spec_helper'
View
@@ -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')

0 comments on commit 5779b42

Please sign in to comment.