ghrh 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +18 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +38 -0
- data/LICENSE +7 -0
- data/README.md +136 -0
- data/bin/ghrh +5 -0
- data/ghrh.gemspec +32 -0
- data/lib/ghrh/auth.rb +12 -0
- data/lib/ghrh/cli.rb +5 -0
- data/lib/ghrh/client.rb +14 -0
- data/lib/ghrh/command/auth.rb +28 -0
- data/lib/ghrh/command/create.rb +63 -0
- data/lib/ghrh/command/delete.rb +16 -0
- data/lib/ghrh/command/edit.rb +67 -0
- data/lib/ghrh/command/get.rb +15 -0
- data/lib/ghrh/command/hooks.rb +23 -0
- data/lib/ghrh/command/list.rb +19 -0
- data/lib/ghrh/command/test.rb +16 -0
- data/lib/ghrh/command.rb +24 -0
- data/lib/ghrh/config.rb +63 -0
- data/lib/ghrh/version.rb +3 -0
- data/lib/ghrh.rb +15 -0
- metadata +166 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ghrh (0.0.1)
|
5
|
+
clamp (~> 0.6.1)
|
6
|
+
highline (~> 1.6.19)
|
7
|
+
httparty (~> 0.11.0)
|
8
|
+
json (~> 1.7.7)
|
9
|
+
tabularize (~> 0.2.9)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
clamp (0.6.1)
|
15
|
+
coderay (1.0.9)
|
16
|
+
highline (1.6.19)
|
17
|
+
httparty (0.11.0)
|
18
|
+
multi_json (~> 1.0)
|
19
|
+
multi_xml (>= 0.5.2)
|
20
|
+
json (1.7.7)
|
21
|
+
method_source (0.8.1)
|
22
|
+
multi_json (1.7.3)
|
23
|
+
multi_xml (0.5.3)
|
24
|
+
pry (0.9.12.1)
|
25
|
+
coderay (~> 1.0.5)
|
26
|
+
method_source (~> 0.8)
|
27
|
+
slop (~> 3.4)
|
28
|
+
slop (3.4.4)
|
29
|
+
tabularize (0.2.9)
|
30
|
+
unicode-display_width (~> 0.1.1)
|
31
|
+
unicode-display_width (0.1.1)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
ruby
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
ghrh!
|
38
|
+
pry
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (C) 2013 Pranay Kanwar
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
# GHRH
|
2
|
+
|
3
|
+
Manage GitHub repository [hooks](http://developer.github.com/v3/repos/hooks/) easily on the command line.
|
4
|
+
|
5
|
+
# Installation
|
6
|
+
|
7
|
+
Install the ruby gem:
|
8
|
+
|
9
|
+
```
|
10
|
+
$ gem install ghrh
|
11
|
+
```
|
12
|
+
|
13
|
+
# Usage
|
14
|
+
|
15
|
+
## General help
|
16
|
+
```
|
17
|
+
$ ghrh --help
|
18
|
+
Usage:
|
19
|
+
ghrh [OPTIONS] SUBCOMMAND [ARG] ...
|
20
|
+
|
21
|
+
Parameters:
|
22
|
+
SUBCOMMAND subcommand
|
23
|
+
[ARG] ... subcommand arguments
|
24
|
+
|
25
|
+
Subcommands:
|
26
|
+
auth get auth token from github
|
27
|
+
create create hook
|
28
|
+
delete delete hook
|
29
|
+
edit edit hook
|
30
|
+
get get information for a hook
|
31
|
+
hooks list known hooks and their parameters
|
32
|
+
list list hooks
|
33
|
+
test test hook
|
34
|
+
|
35
|
+
Options:
|
36
|
+
-h, --help print help
|
37
|
+
```
|
38
|
+
Pass `--help` to each sub command for its usage.
|
39
|
+
|
40
|
+
## Setting up
|
41
|
+
The Github token (`ghrh.token`), repository (`github.repo`), user (`github.user`) and host (`github.host`) are set and picked up from
|
42
|
+
the local or global git config. Environment variables work too `GITHUB_REPO`, `GITHUB_USER`, etc.
|
43
|
+
|
44
|
+
```
|
45
|
+
# fetch and set GitHub token, also can be set repository specific (pass --local)
|
46
|
+
$ ghrh auth r4um
|
47
|
+
Enter password for user r4um (never stored):
|
48
|
+
ghrh.token set to xyz012345 in global git config
|
49
|
+
```
|
50
|
+
|
51
|
+
## Managing hooks
|
52
|
+
|
53
|
+
ghrh caches the hooks metadata from GitHub host in `~/.ghrh`.
|
54
|
+
|
55
|
+
To see a list of hooks available
|
56
|
+
```
|
57
|
+
$ ghrh hooks
|
58
|
+
activecollab
|
59
|
+
acunote
|
60
|
+
agilebench
|
61
|
+
agilezen
|
62
|
+
amazonsns
|
63
|
+
apiary
|
64
|
+
apoio
|
65
|
+
appharbor
|
66
|
+
asana
|
67
|
+
backlog
|
68
|
+
---cut---
|
69
|
+
```
|
70
|
+
|
71
|
+
To see what paramaters (the schema ) a hook expects
|
72
|
+
```
|
73
|
+
$ ghrh hooks email
|
74
|
+
{"name"=>"email",
|
75
|
+
"events"=>["push"],
|
76
|
+
"supported_events"=>["public", "push"],
|
77
|
+
"schema"=>
|
78
|
+
[["string", "address"],
|
79
|
+
["password", "secret"],
|
80
|
+
["boolean", "send_from_author"]]}
|
81
|
+
```
|
82
|
+
|
83
|
+
The parameters are passed as key=value pairs, for example create an email and web hook
|
84
|
+
```
|
85
|
+
$ ghrh create -r r4um/dotfiles email address=pranay.kanwar@gmail.com send_from_author=1
|
86
|
+
201 Created
|
87
|
+
$ ghrh create -r r4um/dotfiles web url=http://foo.com content_type=text/json
|
88
|
+
201 Created
|
89
|
+
```
|
90
|
+
Events can be selected via `-e` switch.
|
91
|
+
|
92
|
+
If no repository is provided its picked up from `github.repo` git config setting.
|
93
|
+
|
94
|
+
Too see a list of hooks
|
95
|
+
|
96
|
+
```
|
97
|
+
$ ghrh list r4um/dotfiles
|
98
|
+
-------------------------------
|
99
|
+
id name active events
|
100
|
+
-------------------------------
|
101
|
+
954777 email true push
|
102
|
+
956443 web true push
|
103
|
+
-------------------------------
|
104
|
+
```
|
105
|
+
|
106
|
+
Hooks can be viewed, edited or deleted by their id from the list above.
|
107
|
+
|
108
|
+
```
|
109
|
+
$ ghrh edit -r r4um/dotfiles 954777 address=nobody@localhost
|
110
|
+
200 OK
|
111
|
+
$ ghrh get -r r4um/dotfiles 954777
|
112
|
+
200 OK
|
113
|
+
{"url"=>"https://api.github.com/repos/r4um/dotfiles/hooks/954777",
|
114
|
+
"test_url"=>"https://api.github.com/repos/r4um/dotfiles/hooks/954777/test",
|
115
|
+
"id"=>954777,
|
116
|
+
"name"=>"email",
|
117
|
+
"active"=>true,
|
118
|
+
"events"=>["push"],
|
119
|
+
"config"=>{"address"=>"nobody@localhost"},
|
120
|
+
"last_response"=>{"code"=>200, "status"=>"ok", "message"=>"OK"},
|
121
|
+
"updated_at"=>"2013-05-14T12:19:30Z",
|
122
|
+
"created_at"=>"2013-05-13T19:52:50Z"}
|
123
|
+
$ ghrh delete -r r4um/dotfiles 954777
|
124
|
+
204 No Content
|
125
|
+
|
126
|
+
Deleted
|
127
|
+
```
|
128
|
+
|
129
|
+
To refresh the hooks cache
|
130
|
+
```
|
131
|
+
$ ghrh hooks --refresh
|
132
|
+
Wrote hooks cache to /Users/pranay.kanwar/.ghrh/hooks_api.github.com.json
|
133
|
+
```
|
134
|
+
|
135
|
+
# LICENSE
|
136
|
+
[MIT](LICENSE)
|
data/bin/ghrh
ADDED
data/ghrh.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
require 'ghrh/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "ghrh"
|
8
|
+
s.version = GHRH::VERSION
|
9
|
+
|
10
|
+
s.authors = ["Pranay Kanwar"]
|
11
|
+
s.email = "pranay.kanwar@gmail.com"
|
12
|
+
s.homepage = "https://github.com/r4um/ghrh"
|
13
|
+
|
14
|
+
s.summary = "Manage GitHub repository hooks"
|
15
|
+
s.description = "Manage GitHub repository hooks easily on the commandline"
|
16
|
+
|
17
|
+
s.required_rubygems_version = ">= 1.3.6"
|
18
|
+
|
19
|
+
s.files = %x{git ls-files}.split("\n")
|
20
|
+
s.test_files = %x{git ls-files -- spec/*}.split("\n")
|
21
|
+
|
22
|
+
s.add_runtime_dependency 'clamp', "~> 0.6.1"
|
23
|
+
s.add_runtime_dependency 'highline', '~> 1.6.19'
|
24
|
+
s.add_runtime_dependency 'httparty', "~> 0.11.0"
|
25
|
+
s.add_runtime_dependency 'json', '~> 1.7.7'
|
26
|
+
s.add_runtime_dependency 'tabularize', '~> 0.2.9'
|
27
|
+
|
28
|
+
s.add_development_dependency 'pry'
|
29
|
+
|
30
|
+
s.extra_rdoc_files = ['README.md', 'LICENSE']
|
31
|
+
s.license = 'MIT'
|
32
|
+
end
|
data/lib/ghrh/auth.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module GHRH
|
2
|
+
class Auth
|
3
|
+
def self.perform(user, pass)
|
4
|
+
GHRH::Client.basic_auth user, pass
|
5
|
+
body = GHRH::Client.post('/authorizations',
|
6
|
+
{ :body => {:scopes => %w{public_repo repo},
|
7
|
+
:note => 'ghrh',
|
8
|
+
:note_url => 'https://github.com/r4um/ghrh'}.to_json})
|
9
|
+
token = body['token']
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/ghrh/cli.rb
ADDED
data/lib/ghrh/client.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module GHRH
|
2
|
+
class Client
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
base_uri GHRH::Config::API_URL
|
6
|
+
|
7
|
+
headers "User-Agent" => GHRH::Config::USER_AGENT
|
8
|
+
|
9
|
+
headers "Authorization" => "token #{GHRH::Config.token}"
|
10
|
+
|
11
|
+
format :json
|
12
|
+
debug_output if $DEBUG
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module GHRH
|
2
|
+
module Command
|
3
|
+
class Auth < Clamp::Command
|
4
|
+
parameter '[USER]', 'GitHub User name', :default => GHRH::Config.get('github.user')
|
5
|
+
option '--local', :flag, 'Update local git config', :default => false
|
6
|
+
|
7
|
+
def execute
|
8
|
+
user = GHRH::Config.get('github.user') if not user
|
9
|
+
|
10
|
+
raise "No GitHub user given or set" if not user
|
11
|
+
|
12
|
+
pass = ask("Enter password for user #{user} (never stored): ") do |q|
|
13
|
+
q.echo = ''
|
14
|
+
end
|
15
|
+
|
16
|
+
token = GHRH::Auth.perform(user, pass)
|
17
|
+
|
18
|
+
if token
|
19
|
+
scope = local? == true ? "local" : "global"
|
20
|
+
GHRH::Config.set("ghrh.token", token, scope)
|
21
|
+
puts "ghrh.token set to #{token} in #{scope} git config"
|
22
|
+
else
|
23
|
+
puts "Authentication failed, invalid user or password"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module GHRH
|
2
|
+
module Command
|
3
|
+
class Create < Clamp::Command
|
4
|
+
|
5
|
+
parameter 'NAME', 'Hook name' do |hook|
|
6
|
+
raise "No such hook #{hook}" if not GHRH::Config.hooks[hook]
|
7
|
+
hook
|
8
|
+
end
|
9
|
+
|
10
|
+
parameter 'CONFIG ...', 'Key=Value settings'
|
11
|
+
option '--no-active', :flag, 'Do not activate', :default => false
|
12
|
+
option ['-e', '--events'], 'EVENTS', 'Comma separated event names to trigger this hook for'
|
13
|
+
option ['-r', '--repo'], 'REPO', 'Repo to create hook for', :default => GHRH::Config.get('github.repo')
|
14
|
+
|
15
|
+
def execute
|
16
|
+
raise "No repo specified (-r) or set (github.repo)" if not repo
|
17
|
+
|
18
|
+
hook = GHRH::Config.hooks[name]
|
19
|
+
|
20
|
+
# hook schema, build a hash for easy lookup name -> format
|
21
|
+
schema = {}
|
22
|
+
hook['schema'].each do |s|
|
23
|
+
format, name = s
|
24
|
+
schema[name] = format
|
25
|
+
end
|
26
|
+
|
27
|
+
default_events = hook['events']
|
28
|
+
supported_events = hook['supported_events']
|
29
|
+
|
30
|
+
# hook config that will be sent
|
31
|
+
config = {}
|
32
|
+
|
33
|
+
# make sure config settings given exist in the schema
|
34
|
+
config_list.each do |arg|
|
35
|
+
k,v = arg.split(/=/,2)
|
36
|
+
raise "Invalid setting #{k} for hook #{name}" if not schema[k]
|
37
|
+
config[k]=v
|
38
|
+
end
|
39
|
+
|
40
|
+
# make sure events given are in supported events
|
41
|
+
events_list = default_events
|
42
|
+
if events
|
43
|
+
events_list = events.split(/,/)
|
44
|
+
events_list.each do |event|
|
45
|
+
raise "Invalid event #{event} for hook #{name}" if not supported_events.index(event)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
hook_input = {
|
50
|
+
'name' => name,
|
51
|
+
'events' => events_list,
|
52
|
+
'config' => config,
|
53
|
+
'active' => !no_active?,
|
54
|
+
}.to_json
|
55
|
+
|
56
|
+
resp = GHRH::Client.post("/repos/#{repo}/hooks", { :body => hook_input })
|
57
|
+
|
58
|
+
puts "#{resp.code} #{resp.message}"
|
59
|
+
pp "#{resp.body}" if $DEBUG
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module GHRH
|
2
|
+
module Command
|
3
|
+
class Delete < Clamp::Command
|
4
|
+
parameter 'ID', 'Hook ID to get'
|
5
|
+
option ['-r', '--repo'], 'REPO', 'The repo, ID belongs too', :default => GHRH::Config.get('github.repo')
|
6
|
+
|
7
|
+
def execute
|
8
|
+
raise "No repo specified (-r) or set (github.repo)" if not repo
|
9
|
+
resp = GHRH::Client.delete("/repos/#{repo}/hooks/#{id}")
|
10
|
+
puts "#{resp.code} #{resp.message}"
|
11
|
+
puts resp.body
|
12
|
+
puts "Deleted" if resp.code == 204
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module GHRH
|
2
|
+
module Command
|
3
|
+
class Edit < Clamp::Command
|
4
|
+
|
5
|
+
parameter 'ID', 'Hook ID to edit'
|
6
|
+
parameter '[CONFIG] ...', 'Key=Value settings'
|
7
|
+
option '--no-active', :flag, 'Do not activate', :default => false
|
8
|
+
option ['-e', '--events'], 'EVENTS', 'Comma separated event names to trigger this hook for'
|
9
|
+
option ['-r', '--repo'], 'REPO', 'Repo to create hook for', :default => GHRH::Config.get('github.repo')
|
10
|
+
|
11
|
+
def execute
|
12
|
+
raise "No repo specified (-r) or set (github.repo)" if not repo
|
13
|
+
|
14
|
+
hooks = GHRH::Config.hooks
|
15
|
+
|
16
|
+
res = GHRH::Client.get("/repos/#{repo}/hooks/#{id}")
|
17
|
+
|
18
|
+
if not res['name']
|
19
|
+
puts "Invalid hook ID #{id}"
|
20
|
+
puts res
|
21
|
+
exit 1
|
22
|
+
end
|
23
|
+
|
24
|
+
name = res['name']
|
25
|
+
hook = hooks[name]
|
26
|
+
|
27
|
+
# hook schema, build a hash for easy lookup name -> format
|
28
|
+
schema = {}
|
29
|
+
hook['schema'].each do |s|
|
30
|
+
format, name = s
|
31
|
+
schema[name] = format
|
32
|
+
end
|
33
|
+
|
34
|
+
supported_events = hook['supported_events']
|
35
|
+
|
36
|
+
# hook config that will be sent
|
37
|
+
config = {}
|
38
|
+
|
39
|
+
# make sure config settings given exist in the schema
|
40
|
+
config_list.each do |arg|
|
41
|
+
k,v = arg.split(/=/,2)
|
42
|
+
raise "Invalid setting #{k} for hook #{name}" if not schema[k]
|
43
|
+
config[k]=v
|
44
|
+
end
|
45
|
+
|
46
|
+
# make sure events given are in supported events
|
47
|
+
events_list = []
|
48
|
+
if events
|
49
|
+
events_list = events.split(/,/)
|
50
|
+
events_list.each do |event|
|
51
|
+
raise "Invalid event #{event} for hook #{id}" if not supported_events.index(event)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
hook_input = {}
|
56
|
+
hook_input['events'] = events_list if not events_list.empty?
|
57
|
+
hook_input['config'] = config if not config.empty?
|
58
|
+
hook_input['active'] = !no_active?
|
59
|
+
|
60
|
+
resp = GHRH::Client.patch("/repos/#{repo}/hooks/#{id}", { :body => hook_input.to_json })
|
61
|
+
|
62
|
+
puts "#{resp.code} #{resp.message}"
|
63
|
+
pp "#{resp.body}" if $DEBUG
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module GHRH
|
2
|
+
module Command
|
3
|
+
class Get < Clamp::Command
|
4
|
+
parameter 'ID', 'Hook ID to get'
|
5
|
+
option ['-r', '--repo'], 'REPO', 'The repo, ID belongs too', :default => GHRH::Config.get('github.repo')
|
6
|
+
|
7
|
+
def execute
|
8
|
+
raise "No repo specified (-r) or set (github.repo)" if not repo
|
9
|
+
resp = GHRH::Client.get("/repos/#{repo}/hooks/#{id}")
|
10
|
+
puts "#{resp.code} #{resp.message}"
|
11
|
+
pp resp
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module GHRH
|
2
|
+
module Command
|
3
|
+
class Hooks < Clamp::Command
|
4
|
+
parameter "[HOOK]", "Show parameters for HOOK"
|
5
|
+
option "--refresh", :flag, "Refresh hooks cache"
|
6
|
+
|
7
|
+
def execute
|
8
|
+
if refresh?
|
9
|
+
GHRH::Config.fetch_hooks
|
10
|
+
exit 0
|
11
|
+
end
|
12
|
+
|
13
|
+
hooks = GHRH::Config.hooks
|
14
|
+
|
15
|
+
if hook
|
16
|
+
pp hooks[hook]
|
17
|
+
else
|
18
|
+
puts hooks.keys.sort
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module GHRH
|
2
|
+
module Command
|
3
|
+
class List < Clamp::Command
|
4
|
+
parameter "[REPO]", "repo", :default => GHRH::Config.get('github.repo')
|
5
|
+
|
6
|
+
def execute
|
7
|
+
resp = GHRH::Client.get("/repos/#{repo}/hooks")
|
8
|
+
tbl = Tabularize.new :vborder => '', :iborder => ''
|
9
|
+
tbl << %w(id name active events)
|
10
|
+
tbl.separator!
|
11
|
+
resp.each do |p|
|
12
|
+
tbl << [ p['id'], p['name'], p['active'], p['events'].join(',')
|
13
|
+
]
|
14
|
+
end
|
15
|
+
puts tbl
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module GHRH
|
2
|
+
module Command
|
3
|
+
class Test < Clamp::Command
|
4
|
+
parameter 'ID', 'Hook ID to post test'
|
5
|
+
option ['-r', '--repo'], 'REPO', 'The repo, ID belongs too', :default => GHRH::Config.get('github.repo')
|
6
|
+
|
7
|
+
def execute
|
8
|
+
raise "No repo specified (-r) or set (github.repo)" if not repo
|
9
|
+
|
10
|
+
resp = GHRH::Client.post("/repos/#{repo}/hooks/#{id}/tests")
|
11
|
+
puts "#{resp.code} #{resp.message}"
|
12
|
+
pp resp
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/ghrh/command.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'ghrh/command/auth'
|
2
|
+
require 'ghrh/command/create'
|
3
|
+
require 'ghrh/command/delete'
|
4
|
+
require 'ghrh/command/edit'
|
5
|
+
require 'ghrh/command/get'
|
6
|
+
require 'ghrh/command/hooks'
|
7
|
+
require 'ghrh/command/list'
|
8
|
+
require 'ghrh/command/test'
|
9
|
+
|
10
|
+
module GHRH
|
11
|
+
module Command
|
12
|
+
class Main < Clamp::Command
|
13
|
+
subcommand "auth", "get auth token from github", GHRH::Command::Auth
|
14
|
+
subcommand "create", "create hook", GHRH::Command::Create
|
15
|
+
subcommand "delete", "delete hook", GHRH::Command::Delete
|
16
|
+
subcommand "edit", "edit hook", GHRH::Command::Edit
|
17
|
+
subcommand "get", "get information for a hook", GHRH::Command::Get
|
18
|
+
subcommand "hooks", "list known hooks and their parameters", GHRH::Command::Hooks
|
19
|
+
subcommand "list", "list hooks", GHRH::Command::List
|
20
|
+
subcommand "test", "test hook", GHRH::Command::Test
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
data/lib/ghrh/config.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
module GHRH
|
2
|
+
module Config
|
3
|
+
|
4
|
+
def self.scope
|
5
|
+
File.exists?(File.join(Dir.pwd,'.git/config')) == true ? "local" : "global"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.get(setting, default=nil)
|
9
|
+
# Check environment first, if setting is x.y env is X_Y
|
10
|
+
value = ENV[setting.upcase.gsub('.', '_')] || ""
|
11
|
+
|
12
|
+
# Check local git config
|
13
|
+
value = %x{git config --local #{setting} 2>/dev/null}.strip if value.empty?
|
14
|
+
|
15
|
+
# Check global git config
|
16
|
+
value = %x{git config --global #{setting} 2>/dev/null}.strip if value.empty?
|
17
|
+
|
18
|
+
# Return default if all above failed to return anything
|
19
|
+
value = default if value.empty?
|
20
|
+
|
21
|
+
value
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.token
|
25
|
+
get('ghrh.token')
|
26
|
+
end
|
27
|
+
|
28
|
+
DEFAULT_HOST = 'api.github.com'
|
29
|
+
HOST = get("github.host", DEFAULT_HOST)
|
30
|
+
USER_AGENT = "ghrh/#{GHRH::VERSION}"
|
31
|
+
API_URL = HOST == DEFAULT_HOST ? "https://#{HOST}" : "https://#{HOST}/api/v3"
|
32
|
+
|
33
|
+
CACHE_DIR = File.expand_path '~/.ghrh'
|
34
|
+
CACHE_FILE = File.join CACHE_DIR, "hooks_#{HOST}.json"
|
35
|
+
|
36
|
+
def self.set(setting, value, config_scope=scope)
|
37
|
+
# Set config setting, if user specified scope use that, else detect
|
38
|
+
%x{git config --#{config_scope} #{setting} #{value}}
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.fetch_hooks
|
42
|
+
resp = GHRH::Client.get("/hooks", :headers => {"User-Agent" => USER_AGENT})
|
43
|
+
hooks_h = {}
|
44
|
+
resp.each do |hook|
|
45
|
+
hooks_h[hook['name']]=hook
|
46
|
+
end
|
47
|
+
File.open(CACHE_FILE, 'w').write(hooks_h.to_json)
|
48
|
+
puts "Wrote hooks cache to #{CACHE_FILE}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.hooks
|
52
|
+
if not File.directory? CACHE_DIR
|
53
|
+
Dir.mkdir CACHE_DIR
|
54
|
+
end
|
55
|
+
|
56
|
+
if not File.exists? CACHE_FILE
|
57
|
+
puts "No hooks cache found fetching"
|
58
|
+
fetch_hooks
|
59
|
+
end
|
60
|
+
JSON.load File.read CACHE_FILE
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/ghrh/version.rb
ADDED
data/lib/ghrh.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'clamp'
|
4
|
+
require 'highline/import'
|
5
|
+
require 'httparty'
|
6
|
+
require 'json'
|
7
|
+
require 'pp'
|
8
|
+
require 'tabularize'
|
9
|
+
|
10
|
+
require 'ghrh/version'
|
11
|
+
|
12
|
+
require 'ghrh/auth'
|
13
|
+
require 'ghrh/config'
|
14
|
+
require 'ghrh/client'
|
15
|
+
require 'ghrh/command'
|
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ghrh
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Pranay Kanwar
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: clamp
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.6.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.6.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: highline
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.6.19
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.6.19
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: httparty
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.11.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.11.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: json
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.7.7
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.7.7
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: tabularize
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.2.9
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.2.9
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: pry
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: Manage GitHub repository hooks easily on the commandline
|
111
|
+
email: pranay.kanwar@gmail.com
|
112
|
+
executables: []
|
113
|
+
extensions: []
|
114
|
+
extra_rdoc_files:
|
115
|
+
- README.md
|
116
|
+
- LICENSE
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- Gemfile
|
120
|
+
- Gemfile.lock
|
121
|
+
- LICENSE
|
122
|
+
- README.md
|
123
|
+
- bin/ghrh
|
124
|
+
- ghrh.gemspec
|
125
|
+
- lib/ghrh.rb
|
126
|
+
- lib/ghrh/auth.rb
|
127
|
+
- lib/ghrh/cli.rb
|
128
|
+
- lib/ghrh/client.rb
|
129
|
+
- lib/ghrh/command.rb
|
130
|
+
- lib/ghrh/command/auth.rb
|
131
|
+
- lib/ghrh/command/create.rb
|
132
|
+
- lib/ghrh/command/delete.rb
|
133
|
+
- lib/ghrh/command/edit.rb
|
134
|
+
- lib/ghrh/command/get.rb
|
135
|
+
- lib/ghrh/command/hooks.rb
|
136
|
+
- lib/ghrh/command/list.rb
|
137
|
+
- lib/ghrh/command/test.rb
|
138
|
+
- lib/ghrh/config.rb
|
139
|
+
- lib/ghrh/version.rb
|
140
|
+
homepage: https://github.com/r4um/ghrh
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
none: false
|
149
|
+
requirements:
|
150
|
+
- - ! '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ! '>='
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: 1.3.6
|
159
|
+
requirements: []
|
160
|
+
rubyforge_project:
|
161
|
+
rubygems_version: 1.8.25
|
162
|
+
signing_key:
|
163
|
+
specification_version: 3
|
164
|
+
summary: Manage GitHub repository hooks
|
165
|
+
test_files: []
|
166
|
+
has_rdoc:
|