github-control 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/github-control.rb +2 -10
- data/lib/github-control/action.rb +8 -0
- data/lib/github-control/actions/add_collaborators.rb +4 -2
- data/lib/github-control/actions/collaborators.rb +8 -2
- data/lib/github-control/actions/remove_collaborators.rb +4 -2
- data/lib/github-control/actions/repositories.rb +2 -0
- data/lib/github-control/actions/shell.rb +2 -0
- data/lib/github-control/cli.rb +23 -23
- data/lib/github-control/collaborators.rb +16 -0
- data/lib/github-control/console.rb +2 -16
- data/lib/github-control/repositories.rb +4 -0
- data/lib/github-control/version.rb +1 -1
- metadata +16 -11
- data/lib/github-control/post_receive_urls.rb +0 -54
- data/spec/github_control_spec.rb +0 -53
- data/spec/models/post_receive_urls_spec.rb +0 -46
- data/spec/models/user_spec.rb +0 -0
- data/spec/spec_helper.rb +0 -12
data/lib/github-control.rb
CHANGED
@@ -1,14 +1,7 @@
|
|
1
1
|
require 'yaml'
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'json'
|
5
|
-
rescue LoadError
|
6
|
-
require 'rubygems'
|
7
|
-
require 'json'
|
8
|
-
end
|
9
|
-
|
10
|
-
require 'rest_client'
|
2
|
+
require 'json'
|
11
3
|
require 'nokogiri'
|
4
|
+
require 'rack/client'
|
12
5
|
|
13
6
|
module GithubControl
|
14
7
|
class Error < StandardError; end
|
@@ -25,7 +18,6 @@ require 'github-control/user'
|
|
25
18
|
require 'github-control/repository'
|
26
19
|
require 'github-control/repositories'
|
27
20
|
require 'github-control/collaborators'
|
28
|
-
require 'github-control/post_receive_urls'
|
29
21
|
|
30
22
|
require 'github-control/action'
|
31
23
|
require 'github-control/actions/repositories'
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module GithubControl
|
2
2
|
module Actions
|
3
3
|
class AddCollaborators < Action
|
4
|
+
register :add_collab
|
5
|
+
|
4
6
|
def add_options(parser)
|
5
7
|
parser.on("-R name", "--repository name", "The repository on Github") do |repository_name|
|
6
8
|
options[:repository_name] = repository_name
|
@@ -17,13 +19,13 @@ module GithubControl
|
|
17
19
|
if repository.collaborators.include?(user)
|
18
20
|
puts "#{user.name} is already a collaborator"
|
19
21
|
else
|
20
|
-
repository.collaborators
|
22
|
+
repository.collaborators.create(user.name)
|
21
23
|
puts "Done"
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
27
|
def repository
|
26
|
-
@cli.console.current_user.
|
28
|
+
@cli.console.current_user.repositories.get(options[:repository_name] || raise(ProblemWithOptions, "Please specify a repository"))
|
27
29
|
end
|
28
30
|
|
29
31
|
def user
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module GithubControl
|
2
2
|
module Actions
|
3
3
|
class Collaborators < Action
|
4
|
+
register :collab
|
5
|
+
|
4
6
|
def add_options(parser)
|
5
7
|
parser.on("-R name", "--repository name", "The repository on Github") do |repository_name|
|
6
8
|
options[:repository_name] = repository_name
|
@@ -20,11 +22,15 @@ module GithubControl
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def repository
|
23
|
-
user.
|
25
|
+
user.repositories.get(options[:repository_name] || raise(ProblemWithOptions, "Please specify a repository"))
|
24
26
|
end
|
25
27
|
|
26
28
|
def user
|
27
|
-
|
29
|
+
if options[:user_name]
|
30
|
+
@cli.console.user_for(options[:user_name])
|
31
|
+
else
|
32
|
+
@cli.console.current_user
|
33
|
+
end
|
28
34
|
end
|
29
35
|
end
|
30
36
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module GithubControl
|
2
2
|
module Actions
|
3
3
|
class RemoveCollaborators < Action
|
4
|
+
register :remove_collab
|
5
|
+
|
4
6
|
def add_options(parser)
|
5
7
|
parser.on("-R name", "--repository name", "The repository on Github") do |repository_name|
|
6
8
|
options[:repository_name] = repository_name
|
@@ -17,13 +19,13 @@ module GithubControl
|
|
17
19
|
unless repository.collaborators.include?(user)
|
18
20
|
puts "#{user.name} is not a collaborator"
|
19
21
|
else
|
20
|
-
repository.collaborators.delete(user)
|
22
|
+
repository.collaborators.delete(user.name)
|
21
23
|
puts "Done"
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
27
|
def repository
|
26
|
-
@cli.console.current_user.
|
28
|
+
@cli.console.current_user.repositories.get(options[:repository_name] || raise(ProblemWithOptions, "Please specify a repository"))
|
27
29
|
end
|
28
30
|
|
29
31
|
def user
|
data/lib/github-control/cli.rb
CHANGED
@@ -15,8 +15,6 @@ module GithubControl
|
|
15
15
|
option_parser.parse!(@args)
|
16
16
|
current_action.call
|
17
17
|
rescue ProblemWithOptions, OptionParser::ParseError => e
|
18
|
-
puts e.backtrace
|
19
|
-
$stderr.puts
|
20
18
|
$stderr.puts e.message
|
21
19
|
$stderr.puts
|
22
20
|
$stderr.puts option_parser
|
@@ -28,46 +26,44 @@ module GithubControl
|
|
28
26
|
end
|
29
27
|
|
30
28
|
def create_action
|
31
|
-
|
32
|
-
|
33
|
-
Actions::Repositories.new(self)
|
34
|
-
when "shell"
|
35
|
-
Actions::Shell.new(self)
|
36
|
-
when "collab"
|
37
|
-
Actions::Collaborators.new(self)
|
38
|
-
when "add_collab"
|
39
|
-
Actions::AddCollaborators.new(self)
|
40
|
-
when "remove_collab"
|
41
|
-
Actions::RemoveCollaborators.new(self)
|
29
|
+
if action = Action.set[action_name]
|
30
|
+
action.new(self)
|
42
31
|
else
|
43
|
-
raise ProblemWithOptions, "#{action_name} is not a valid action"
|
32
|
+
raise ProblemWithOptions, "#{action_name} is not a valid action\nChoose one of #{available_actions}"
|
44
33
|
end
|
45
34
|
end
|
46
35
|
|
47
36
|
def action_name
|
48
|
-
@action_name ||= @args.shift || raise(ProblemWithOptions,
|
37
|
+
@action_name ||= @args.shift || raise(ProblemWithOptions,
|
38
|
+
"Please provide an action to run\nChoose one of #{available_actions}")
|
39
|
+
end
|
40
|
+
|
41
|
+
def available_actions
|
42
|
+
Action.set.keys.join(", ")
|
49
43
|
end
|
50
44
|
|
51
45
|
def console
|
52
|
-
@console ||= Console.new(
|
46
|
+
@console ||= Console.new(config)
|
53
47
|
end
|
54
48
|
|
55
|
-
def
|
56
|
-
|
49
|
+
def environment
|
50
|
+
@env ||= options[:environment] || raise(ProblemWithOptions,
|
51
|
+
"Please provide an environment to use")
|
57
52
|
end
|
58
53
|
|
59
54
|
def config
|
60
|
-
@config ||= YAML.load_file(
|
55
|
+
@config ||= YAML.load_file(config_file)[environment]
|
61
56
|
end
|
62
57
|
|
63
|
-
def
|
64
|
-
options[:
|
58
|
+
def config_file
|
59
|
+
options[:config] || raise(ProblemWithOptions,
|
60
|
+
"You need to provide the path to the YAML filename")
|
65
61
|
end
|
66
62
|
|
67
63
|
def options
|
68
64
|
@options ||= {
|
69
65
|
:debug => false,
|
70
|
-
:argv
|
66
|
+
:argv => @args,
|
71
67
|
}
|
72
68
|
end
|
73
69
|
|
@@ -86,7 +82,11 @@ module GithubControl
|
|
86
82
|
}
|
87
83
|
|
88
84
|
opts.on("-c filename", "--config filename", "Load the config from this YAML file") do |filename|
|
89
|
-
options[:
|
85
|
+
options[:config] = filename
|
86
|
+
end
|
87
|
+
|
88
|
+
opts.on("-e ENV", "Access this environment") do |env|
|
89
|
+
options[:environment] = env
|
90
90
|
end
|
91
91
|
|
92
92
|
opts.on("-v", "--version", "Display the github version, and exit.") do
|
@@ -11,17 +11,33 @@ module GithubControl
|
|
11
11
|
def create(user)
|
12
12
|
@repository.owner.cli.post("/repos/collaborators/" \
|
13
13
|
"#{@repository.name}/add/#{user}")
|
14
|
+
if loaded?
|
15
|
+
set << @repository.owner.cli.user_for(user)
|
16
|
+
else
|
17
|
+
set
|
18
|
+
end
|
14
19
|
end
|
15
20
|
|
16
21
|
def delete(user)
|
17
22
|
@repository.owner.cli.post("/repos/collaborators/" \
|
18
23
|
"#{@repository.name}/remove/#{user}")
|
24
|
+
if loaded?
|
25
|
+
set.delete_if { |u| u.name == user }
|
26
|
+
end
|
19
27
|
end
|
20
28
|
|
21
29
|
def each(&block)
|
22
30
|
set.each(&block)
|
23
31
|
end
|
24
32
|
|
33
|
+
def size
|
34
|
+
set.size
|
35
|
+
end
|
36
|
+
|
37
|
+
def loaded?
|
38
|
+
@set
|
39
|
+
end
|
40
|
+
|
25
41
|
def set
|
26
42
|
@set ||= json_data["collaborators"].map { |name|
|
27
43
|
@repository.owner.cli.user_for(name)
|
@@ -15,32 +15,18 @@ module GithubControl
|
|
15
15
|
|
16
16
|
def post(path, params={})
|
17
17
|
params.merge!(:login => user_name, :token => user_token)
|
18
|
-
data = JSON.parse(
|
18
|
+
data = JSON.parse(Rack::Client.post(url_for(path), params).body)
|
19
19
|
if error = data["error"]
|
20
|
-
raise APIError, error.
|
20
|
+
raise APIError, error.inspect
|
21
21
|
else
|
22
22
|
data
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
def get(path, params={})
|
27
|
-
RestClient.get(url_for(path), params)
|
28
|
-
end
|
29
|
-
|
30
26
|
def url_for(path)
|
31
27
|
"http://github.com/api/v2/json#{path}"
|
32
28
|
end
|
33
29
|
|
34
|
-
def cookies
|
35
|
-
@cookies ||= session_cookie
|
36
|
-
end
|
37
|
-
|
38
|
-
def session_cookie
|
39
|
-
response = raw_post("/session", {:login => user_name,
|
40
|
-
:password => user_password}, {}, :auto_redirect => false)
|
41
|
-
response.headers[:set_cookie].split(";").first
|
42
|
-
end
|
43
|
-
|
44
30
|
def user_name
|
45
31
|
@user_config["name"] ||
|
46
32
|
raise(ProblemWithOptions, "You need to provide the user name in the YAML file")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-control
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Carey-Smith
|
@@ -9,28 +9,38 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-29 00:00:00 +13:00
|
13
13
|
default_executable: github-control
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: json
|
17
17
|
type: :runtime
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0
|
23
|
+
version: "0"
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
26
|
+
name: nokogiri
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rack-client
|
27
37
|
type: :runtime
|
28
38
|
version_requirement:
|
29
39
|
version_requirements: !ruby/object:Gem::Requirement
|
30
40
|
requirements:
|
31
41
|
- - ">="
|
32
42
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
43
|
+
version: 0.2.2
|
34
44
|
version:
|
35
45
|
description: github-control allows you to interact with Github through a nice ruby interface
|
36
46
|
email: tim@spork.in
|
@@ -51,16 +61,11 @@ files:
|
|
51
61
|
- lib/github-control/cli.rb
|
52
62
|
- lib/github-control/collaborators.rb
|
53
63
|
- lib/github-control/console.rb
|
54
|
-
- lib/github-control/post_receive_urls.rb
|
55
64
|
- lib/github-control/repositories.rb
|
56
65
|
- lib/github-control/repository.rb
|
57
66
|
- lib/github-control/user.rb
|
58
67
|
- lib/github-control/version.rb
|
59
68
|
- lib/github-control.rb
|
60
|
-
- spec/github_control_spec.rb
|
61
|
-
- spec/models/post_receive_urls_spec.rb
|
62
|
-
- spec/models/user_spec.rb
|
63
|
-
- spec/spec_helper.rb
|
64
69
|
has_rdoc: true
|
65
70
|
homepage: http://github.com/halorgium/github-control
|
66
71
|
licenses: []
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module GithubControl
|
2
|
-
class PostReceiveUrls
|
3
|
-
include Enumerable
|
4
|
-
|
5
|
-
def initialize(repository)
|
6
|
-
@repository = repository
|
7
|
-
end
|
8
|
-
attr_reader :repository
|
9
|
-
|
10
|
-
def <<(url)
|
11
|
-
update_with(set + [url])
|
12
|
-
end
|
13
|
-
|
14
|
-
def delete(url)
|
15
|
-
update_with(set - [url])
|
16
|
-
end
|
17
|
-
|
18
|
-
def clear
|
19
|
-
update_with([])
|
20
|
-
end
|
21
|
-
|
22
|
-
def update_with(urls)
|
23
|
-
form_data = []
|
24
|
-
urls.each do |url|
|
25
|
-
value = URI.escape(url.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
26
|
-
form_data << "urls[]=#{value}"
|
27
|
-
end
|
28
|
-
@repository.owner.cli.scrape_post("/#{@repository.owner.name}/#{@repository.name}/edit/postreceive_urls",
|
29
|
-
form_data.join("&"), :accept => 'text/javascript')
|
30
|
-
end
|
31
|
-
|
32
|
-
def empty?
|
33
|
-
set.empty?
|
34
|
-
end
|
35
|
-
|
36
|
-
def each(&block)
|
37
|
-
set.each(&block)
|
38
|
-
end
|
39
|
-
|
40
|
-
def set
|
41
|
-
set = []
|
42
|
-
doc = Nokogiri::HTML(html_data)
|
43
|
-
doc.search("fieldset#postreceive_urls.service-hook form p input[name='urls[]']").each do |input|
|
44
|
-
set << input["value"] if input["value"]
|
45
|
-
end
|
46
|
-
set
|
47
|
-
end
|
48
|
-
|
49
|
-
def html_data
|
50
|
-
@repository.owner.cli.scrape_get("/#{@repository.owner.name}/#{@repository.name}/edit/hooks")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
data/spec/github_control_spec.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "Github Control" do
|
4
|
-
def config
|
5
|
-
@config ||= YAML.load_file("spec/config.yml")["user"]
|
6
|
-
end
|
7
|
-
|
8
|
-
def console
|
9
|
-
@console ||= GithubControl::Console.new(config)
|
10
|
-
end
|
11
|
-
|
12
|
-
def current_user
|
13
|
-
@user ||= console.current_user
|
14
|
-
end
|
15
|
-
|
16
|
-
before(:all) do
|
17
|
-
RestClient.log = "restclient.log"
|
18
|
-
end
|
19
|
-
|
20
|
-
before(:each) do
|
21
|
-
current_user.repositories.destroy
|
22
|
-
end
|
23
|
-
|
24
|
-
it "creates a public repository" do
|
25
|
-
current_user.should have(:no).repositories
|
26
|
-
current_user.repositories.create("public-repo", :public)
|
27
|
-
current_user.should have(1).repositories
|
28
|
-
current_user.repositories["public-repo"].should be_public
|
29
|
-
end
|
30
|
-
|
31
|
-
it "creates a private repository" do
|
32
|
-
current_user.should have(:no).private_repositories
|
33
|
-
current_user.repositories.create("private-repo", :private)
|
34
|
-
current_user.should have(1).private_repositories
|
35
|
-
current_user.repositories["private-repo"].should be_private
|
36
|
-
end
|
37
|
-
|
38
|
-
it "creates and destroys collaborators on a repository" do
|
39
|
-
repo = current_user.repositories.create("test-repo", :public)
|
40
|
-
repo.collaborators << GithubControl::User.new("atmos", console)
|
41
|
-
repo.collaborators << GithubControl::User.new("tim", console)
|
42
|
-
repo.collaborators << GithubControl::User.new("ben", console)
|
43
|
-
repo.collaborators << GithubControl::User.new("sr", console)
|
44
|
-
|
45
|
-
repo.should have(4).collaborators
|
46
|
-
|
47
|
-
# sorry dude :(
|
48
|
-
repo.collaborators.delete("atmos")
|
49
|
-
repo.should have(3).collaborators
|
50
|
-
end
|
51
|
-
|
52
|
-
it "adds and remove post-receive urls"
|
53
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe "Post-receive URLs" do
|
4
|
-
describe "for a repository with a single URL" do
|
5
|
-
before(:each) do
|
6
|
-
@repo = @console.current_user.repo_for("with-one-post-receive-url")
|
7
|
-
end
|
8
|
-
|
9
|
-
it "can be fetched" do
|
10
|
-
@repo.post_receive_urls.to_a.should == ["http://github-control.r.spork.in/post-receive"]
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "for a repository with no URLs" do
|
15
|
-
before(:each) do
|
16
|
-
@repo = @console.current_user.repo_for("with-no-post-receive-urls")
|
17
|
-
@repo.post_receive_urls.clear
|
18
|
-
end
|
19
|
-
|
20
|
-
it "can be fetched" do
|
21
|
-
@repo.post_receive_urls.should be_empty
|
22
|
-
end
|
23
|
-
|
24
|
-
it "adds a new URL" do
|
25
|
-
@repo.post_receive_urls << "http://example.org"
|
26
|
-
@repo.post_receive_urls.to_a.should == ["http://example.org"]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "for a repository with 3 URLs" do
|
31
|
-
before(:each) do
|
32
|
-
@repo = @console.current_user.repo_for("with-three-post-receive-urls")
|
33
|
-
urls = ["http://example.com/1", "http://example.com/2", "http://example.com/3"]
|
34
|
-
@repo.post_receive_urls.update_with(urls)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "can be fetched" do
|
38
|
-
@repo.post_receive_urls.to_a.should == ["http://example.com/1", "http://example.com/2", "http://example.com/3"]
|
39
|
-
end
|
40
|
-
|
41
|
-
it "adds a new URL" do
|
42
|
-
@repo.post_receive_urls.delete("http://example.com/1")
|
43
|
-
@repo.post_receive_urls.to_a.should == ["http://example.com/2", "http://example.com/3"]
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
data/spec/models/user_spec.rb
DELETED
File without changes
|
data/spec/spec_helper.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'spec'
|
2
|
-
require 'randexp'
|
3
|
-
require "pp"
|
4
|
-
|
5
|
-
require File.dirname(__FILE__) + '/../lib/github-control'
|
6
|
-
|
7
|
-
Spec::Runner.configure do |config|
|
8
|
-
config.mock_with(:rr)
|
9
|
-
config.before(:all) do
|
10
|
-
@console = GithubControl::Console.new(YAML.load_file(File.dirname(__FILE__) + '/config.yml')["user"])
|
11
|
-
end
|
12
|
-
end
|