github_cli 0.1.2 → 0.1.3
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/Gemfile.lock +1 -1
- data/README.md +28 -0
- data/features/executable.feature +4 -0
- data/features/settings.feature +0 -9
- data/lib/github_cli/api.rb +3 -0
- data/lib/github_cli/apis/commit.rb +18 -0
- data/lib/github_cli/apis/fork.rb +18 -0
- data/lib/github_cli/apis/label.rb +50 -0
- data/lib/github_cli/apis/pull_request.rb +42 -0
- data/lib/github_cli/apis/reference.rb +30 -0
- data/lib/github_cli/apis/repository.rb +2 -2
- data/lib/github_cli/apis/tree.rb +2 -2
- data/lib/github_cli/apis.rb +4 -0
- data/lib/github_cli/cli.rb +21 -9
- data/lib/github_cli/command.rb +1 -1
- data/lib/github_cli/commands/blobs.rb +4 -4
- data/lib/github_cli/commands/commits.rb +23 -0
- data/lib/github_cli/commands/forks.rb +39 -0
- data/lib/github_cli/commands/labels.rb +70 -15
- data/lib/github_cli/commands/pull_requests.rb +65 -0
- data/lib/github_cli/commands/references.rb +46 -0
- data/lib/github_cli/commands.rb +4 -0
- data/lib/github_cli/config.rb +15 -11
- data/lib/github_cli/errors.rb +6 -0
- data/lib/github_cli/helpers.rb +17 -0
- data/lib/github_cli/version.rb +1 -1
- data/lib/github_cli.rb +12 -1
- data/spec/github_cli/api_spec.rb +1 -1
- data/spec/github_cli/config_spec.rb +25 -20
- data/spec/github_cli/helpers_spec.rb +17 -0
- metadata +25 -12
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -49,6 +49,34 @@ You can list all GitHub APIs comamnds:
|
|
49
49
|
$ ghc list
|
50
50
|
```
|
51
51
|
|
52
|
+
### API
|
53
|
+
|
54
|
+
Interact with git data:
|
55
|
+
|
56
|
+
```shell
|
57
|
+
$ ghc blob
|
58
|
+
$ ghc commit
|
59
|
+
$ ghc ref
|
60
|
+
$ ghc tag
|
61
|
+
$ ghc tree
|
62
|
+
```
|
63
|
+
|
64
|
+
Interact with issues:
|
65
|
+
|
66
|
+
```shell
|
67
|
+
$ ghc issue
|
68
|
+
$ ghc label
|
69
|
+
```
|
70
|
+
|
71
|
+
Interact with repositories:
|
72
|
+
|
73
|
+
```shell
|
74
|
+
$ ghc repo
|
75
|
+
$ ghc download
|
76
|
+
$ ghc fork
|
77
|
+
$ ghc keys
|
78
|
+
```
|
79
|
+
|
52
80
|
## Contributing
|
53
81
|
|
54
82
|
1. Fork it
|
data/features/executable.feature
CHANGED
data/features/settings.feature
CHANGED
@@ -32,13 +32,4 @@ Feature: Global Settings
|
|
32
32
|
Please specify your GitHub Authentication Token (register on github.com to get it):
|
33
33
|
"""
|
34
34
|
|
35
|
-
Scenario: Installs Custom Configuration File
|
36
|
-
When I run `ghc init myname` interactively
|
37
|
-
And I type "token"
|
38
|
-
Then a file named "/tmp/fakehome/myname" should exist
|
39
|
-
And the output should contain:
|
40
|
-
"""
|
41
|
-
Writing new configuration file to /tmp/fakehome/myname
|
42
|
-
"""
|
43
|
-
|
44
35
|
Scenario: Check for presence of yaml attribute
|
data/lib/github_cli/api.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module GithubCLI
|
4
|
+
class Commit < API
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def get(user, repo, sha, params)
|
9
|
+
github_api.git_data.commit user, repo, params
|
10
|
+
end
|
11
|
+
|
12
|
+
def create(user, repo, params)
|
13
|
+
github_api.repos.create_commit user, repo, params
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end # Commit
|
18
|
+
end # GithubCLI
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module GithubCLI
|
4
|
+
class Fork < API
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def all(user, repo, params)
|
9
|
+
github_api.repos.forks user, repo, params
|
10
|
+
end
|
11
|
+
|
12
|
+
def create(user, repo, params)
|
13
|
+
github_api.repos.create_fork user, repo, params
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end # Fork
|
18
|
+
end # GithubCLI
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module GithubCLI
|
4
|
+
class Label < API
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def all(params)
|
9
|
+
github_api.issues.labels params
|
10
|
+
end
|
11
|
+
|
12
|
+
def get(user, repo, name, params)
|
13
|
+
github_api.issues.get_label user, repo, name, params
|
14
|
+
end
|
15
|
+
|
16
|
+
def create(user, repo, params)
|
17
|
+
github_api.issues.create_label user, repo, params
|
18
|
+
end
|
19
|
+
|
20
|
+
def update(user, repo, name, params)
|
21
|
+
github_api.issues.update_label user, repo, params
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete(user, repo, name, params)
|
25
|
+
github_api.issues.delete_label user, repo, name, params
|
26
|
+
end
|
27
|
+
|
28
|
+
def issue(user, repo, number, params)
|
29
|
+
github_api.issues.labels_for user, repo, number, params
|
30
|
+
end
|
31
|
+
|
32
|
+
def add(user, repo, number, *args)
|
33
|
+
github_api.issues.add_labels user, repo, args
|
34
|
+
end
|
35
|
+
|
36
|
+
def remove(user, repo, number, name=nil, params)
|
37
|
+
github_api,issues.remove_label user, repo, number, name, params
|
38
|
+
end
|
39
|
+
|
40
|
+
def replace(user, repo, number, *args)
|
41
|
+
github_api.issues.replace_labels user, repo, number, args
|
42
|
+
end
|
43
|
+
|
44
|
+
def milestone(user, repo, number, params)
|
45
|
+
gitub_api.issues.milestone_labels user, repo, number, params
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end # Label
|
50
|
+
end # GithubCLI
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module GithubCLI
|
4
|
+
class PullRequest < API
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def get(user, repo, number, params)
|
9
|
+
github_api.pull_requests.pull_request user, repo, number, params
|
10
|
+
end
|
11
|
+
|
12
|
+
def list(user, repo, ref, params)
|
13
|
+
github_api.pull_requests.pull_requests user, repo, ref, params
|
14
|
+
end
|
15
|
+
|
16
|
+
def create(user, repo, params)
|
17
|
+
github_api.pull_requests.create_request user, repo, params
|
18
|
+
end
|
19
|
+
|
20
|
+
def update(user, repo, number, params)
|
21
|
+
github_api.pull_requests.update_request user, repo, number, params
|
22
|
+
end
|
23
|
+
|
24
|
+
def commits(user, repo, number, params)
|
25
|
+
github_api.pull_requests.commits user, repo, number, params
|
26
|
+
end
|
27
|
+
|
28
|
+
def files(user, repo, number, params)
|
29
|
+
github_api.pull_requests.files user, repo, number, params
|
30
|
+
end
|
31
|
+
|
32
|
+
def merged(user, repo, number, params)
|
33
|
+
github_api.pull_requests.merged user, repo, number, params
|
34
|
+
end
|
35
|
+
|
36
|
+
def merge(user, repo, number, params)
|
37
|
+
github_api.pull_requests.merge user, repo, number, params
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end # PullRequest
|
42
|
+
end # GithubCLI
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module GithubCLI
|
4
|
+
class Reference < API
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def get(user, repo, ref, params)
|
9
|
+
github_api.git_data.reference user, repo, ref, params
|
10
|
+
end
|
11
|
+
|
12
|
+
def list(user, repo, ref, params)
|
13
|
+
github_api.git_data.references user, repo, ref, params
|
14
|
+
end
|
15
|
+
|
16
|
+
def create(user, repo, params)
|
17
|
+
github_api.git_data.create_reference user, repo, params
|
18
|
+
end
|
19
|
+
|
20
|
+
def update(user, repo, ref, params)
|
21
|
+
github_api.git_data.update_reference user, repo, ref, params
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete(user, repo, ref, params)
|
25
|
+
github_api.git_data.delete_reference user, repo, ref, params
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end # Reference
|
30
|
+
end # GithubCLI
|
@@ -6,14 +6,14 @@ module GithubCLI
|
|
6
6
|
class << self
|
7
7
|
|
8
8
|
def all(params)
|
9
|
-
github_api.repos.repos
|
9
|
+
github_api.repos.repos(params)
|
10
10
|
end
|
11
11
|
|
12
12
|
def get(user, repo, params)
|
13
13
|
github_api.repos.get_repo user, repo, params
|
14
14
|
end
|
15
15
|
|
16
|
-
def create
|
16
|
+
def create(user, repo, params)
|
17
17
|
github_api.repos.create_repo user, repo, params
|
18
18
|
end
|
19
19
|
|
data/lib/github_cli/apis/tree.rb
CHANGED
@@ -6,11 +6,11 @@ module GithubCLI
|
|
6
6
|
class << self
|
7
7
|
|
8
8
|
def get(user, repo, sha, params)
|
9
|
-
github_api.repos.
|
9
|
+
github_api.repos.get_tree user, repo, params
|
10
10
|
end
|
11
11
|
|
12
12
|
def create(user, repo, params)
|
13
|
-
github_api.repos.
|
13
|
+
github_api.repos.create_tree user, repo, params
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
data/lib/github_cli/apis.rb
CHANGED
data/lib/github_cli/cli.rb
CHANGED
@@ -13,6 +13,7 @@ module GithubCLI
|
|
13
13
|
end
|
14
14
|
|
15
15
|
map "repository" => :repo,
|
16
|
+
"reference" => :ref,
|
16
17
|
"is" => :issue,
|
17
18
|
"-v" => :version,
|
18
19
|
"ls" => :list
|
@@ -29,7 +30,7 @@ module GithubCLI
|
|
29
30
|
:banner => "Enable verbose output mode."
|
30
31
|
|
31
32
|
|
32
|
-
desc 'init
|
33
|
+
desc 'init', 'Generates a configuration file in your home directory'
|
33
34
|
long_desc <<-DESC
|
34
35
|
Initializes a configuration file where you can set default options for
|
35
36
|
interacting with GitHub API. Both global and per-command options can be
|
@@ -45,15 +46,15 @@ module GithubCLI
|
|
45
46
|
@config_filename = filename
|
46
47
|
end
|
47
48
|
|
48
|
-
config = Config.new(@config_filename)
|
49
|
-
if File.exists?(config.path) && !options[:force]
|
50
|
-
GithubCLI.ui.error "Not overwritting existing config file #{config.path}, use --force to override."
|
49
|
+
# config = Config.new(@config_filename)
|
50
|
+
if File.exists?(GithubCLI.config.path) && !options[:force]
|
51
|
+
GithubCLI.ui.error "Not overwritting existing config file #{GithubCLI.config.path}, use --force to override."
|
51
52
|
exit 1
|
52
53
|
end
|
53
54
|
|
54
55
|
oauth_token = ask "Please specify your GitHub Authentication Token (register on github.com to get it):"
|
55
|
-
config.save({'oauth_token' => oauth_token})
|
56
|
-
GithubCLI.ui.confirm "Writing new configuration file to #{config.path}"
|
56
|
+
GithubCLI.config.save({'oauth_token' => oauth_token, 'basic_auth' => nil })
|
57
|
+
GithubCLI.ui.confirm "Writing new configuration file to #{GithubCLI.config.path}"
|
57
58
|
end
|
58
59
|
|
59
60
|
desc 'list <pattern>', 'List all available commands limited by pattern'
|
@@ -65,8 +66,11 @@ module GithubCLI
|
|
65
66
|
desc "blob <command>", "Leverage Blobs API"
|
66
67
|
subcommand "blob", GithubCLI::Commands::Blobs
|
67
68
|
|
68
|
-
desc "
|
69
|
-
subcommand "
|
69
|
+
desc "commit <command>", "Leverage Commits API"
|
70
|
+
subcommand "commit", GithubCLI::Commands::Commits
|
71
|
+
|
72
|
+
desc "fork <command>", "Leverage Forks API"
|
73
|
+
subcommand "fork", GithubCLI::Commands::Forks
|
70
74
|
|
71
75
|
desc "issue <command>", "Leverage Issues API"
|
72
76
|
subcommand "issue", GithubCLI::Commands::Issues
|
@@ -74,6 +78,15 @@ module GithubCLI
|
|
74
78
|
desc "label <command>", "Leverage Labels API"
|
75
79
|
subcommand "label", GithubCLI::Commands::Labels
|
76
80
|
|
81
|
+
desc "pull <command>", "Leverage Pull Requests API"
|
82
|
+
subcommand "pull", GithubCLI::Commands::PullRequests
|
83
|
+
|
84
|
+
desc "ref <command>", "Leverage References API"
|
85
|
+
subcommand "ref", GithubCLI::Commands::References
|
86
|
+
|
87
|
+
desc "repo <command>", "Leverage Repositories API"
|
88
|
+
subcommand "repo", GithubCLI::Commands::Repositories
|
89
|
+
|
77
90
|
desc "tag <command>", "Leverage Tags API"
|
78
91
|
subcommand "tag", GithubCLI::Commands::Tags
|
79
92
|
|
@@ -82,7 +95,6 @@ module GithubCLI
|
|
82
95
|
|
83
96
|
desc 'version', 'Display Github CLI version.'
|
84
97
|
def version
|
85
|
-
puts "#{GithubCLI.config['oauth_token']}"
|
86
98
|
say "Github CLI #{GithubCLI::VERSION}"
|
87
99
|
end
|
88
100
|
|
data/lib/github_cli/command.rb
CHANGED
@@ -8,15 +8,15 @@ module GithubCLI
|
|
8
8
|
desc 'get <user> <repo> <sha>', 'Get a Blob'
|
9
9
|
method_option :params, :type => :hash, :default => {},
|
10
10
|
:desc => 'Additonal request parameters e.i per_page:100'
|
11
|
-
def get(user, repo)
|
12
|
-
Blob.get user, repo, options[:params]
|
11
|
+
def get(user, repo, sha)
|
12
|
+
Blob.get user, repo, sha, options[:params]
|
13
13
|
end
|
14
14
|
|
15
15
|
desc 'create <user> <repo>', 'Create a new Blob'
|
16
16
|
method_option :params, :type => :hash, :default => {},
|
17
17
|
:desc => 'Additonal request parameters e.i per_page:100'
|
18
|
-
def create(user, repo
|
19
|
-
Blob.create user, repo,
|
18
|
+
def create(user, repo)
|
19
|
+
Blob.create user, repo, options[:params]
|
20
20
|
end
|
21
21
|
|
22
22
|
end # Blobs
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module GithubCLI
|
4
|
+
class Commands::Commits < Command
|
5
|
+
|
6
|
+
namespace :commit
|
7
|
+
|
8
|
+
desc 'get <user> <repo> <sha>', 'Get a Commit'
|
9
|
+
method_option :params, :type => :hash, :default => {},
|
10
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
11
|
+
def get(user, repo, sha)
|
12
|
+
Commit.get user, repo, sha, options[:params]
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'create <user> <repo>', 'Create a Commit'
|
16
|
+
method_option :params, :type => :hash, :default => {},
|
17
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
18
|
+
def create(user, repo)
|
19
|
+
Commit.create user, repo, options[:params]
|
20
|
+
end
|
21
|
+
|
22
|
+
end # Commit
|
23
|
+
end # GithubCLI
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module GithubCLI
|
4
|
+
class Commands::Forks < Command
|
5
|
+
|
6
|
+
namespace :fork
|
7
|
+
|
8
|
+
desc 'list <user> <repo>', 'Lists forks'
|
9
|
+
long_desc <<-DESC
|
10
|
+
List repository forks
|
11
|
+
Parameters
|
12
|
+
sort - newest, oldest, watchers, default: newest
|
13
|
+
DESC
|
14
|
+
method_option :sort, :type => :string, :aliases => ["-s"],
|
15
|
+
:desc => 'Sort by newest, oldest or watchers',
|
16
|
+
:banner => '<sort-category>'
|
17
|
+
method_option :params, :type => :hash, :default => {},
|
18
|
+
:desc => 'Additional request parameters e.i per_page:100'
|
19
|
+
def list(user, repo)
|
20
|
+
if options[:sort]
|
21
|
+
options[:params]['sort'] = options[:sort]
|
22
|
+
end
|
23
|
+
Fork.all user, repo, options[:params]
|
24
|
+
end
|
25
|
+
|
26
|
+
desc 'create <user> <repo>', 'Create a new Blob'
|
27
|
+
method_option :org, :type => :string,
|
28
|
+
:desc => ' Organization login. The repository will be forked into this organization.'
|
29
|
+
method_option :params, :type => :hash, :default => {},
|
30
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
31
|
+
def create(user, repo)
|
32
|
+
if options[:org]
|
33
|
+
options[:params]['org'] = options[:org]
|
34
|
+
end
|
35
|
+
Fork.create user, repo, options[:params]
|
36
|
+
end
|
37
|
+
|
38
|
+
end # Forks
|
39
|
+
end # GithubCLI
|
@@ -5,30 +5,85 @@ module GithubCLI
|
|
5
5
|
|
6
6
|
namespace :label
|
7
7
|
|
8
|
-
desc 'list', 'Listing all labels for this repository.'
|
9
|
-
|
8
|
+
desc 'list <user> <repo>', 'Listing all labels for this repository.'
|
9
|
+
method_option :params, :type => :hash, :default => {},
|
10
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
11
|
+
def list(user, repo)
|
12
|
+
Label.all user, repo, options[:params]
|
10
13
|
end
|
11
14
|
|
12
|
-
desc 'get <user
|
13
|
-
method_option :
|
14
|
-
|
15
|
+
desc 'get <user> <repo> <name>', 'Get a single label.'
|
16
|
+
method_option :params, :type => :hash, :default => {},
|
17
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
18
|
+
def get(user, repo, name)
|
19
|
+
Label.get user, repo, name, options[:params]
|
15
20
|
end
|
16
21
|
|
17
|
-
desc 'create <user
|
18
|
-
|
22
|
+
desc 'create <user> <repo>', 'Create a label.'
|
23
|
+
long_desc <<-DESC
|
24
|
+
Inputs
|
25
|
+
name - Required string
|
26
|
+
color - Required string - 6 character hex code, without leading #
|
27
|
+
DESC
|
28
|
+
method_option :params, :type => :hash, :default => {},
|
29
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
19
30
|
def create(user, repo)
|
31
|
+
Label.create user, repo, options[:params]
|
20
32
|
end
|
21
33
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
def update(user, repo)
|
34
|
+
desc 'update <user> <repo> <name>', 'Update a label.'
|
35
|
+
method_option :params, :type => :hash, :default => {},
|
36
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
37
|
+
def update(user, repo, name)
|
38
|
+
Label.update user, repo, name, options[:params]
|
26
39
|
end
|
27
40
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
def delete(user, repo)
|
41
|
+
desc 'delete <user> <repo> <name>', 'Delete a label.'
|
42
|
+
method_option :params, :type => :hash, :default => {},
|
43
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
44
|
+
def delete(user, repo, name)
|
45
|
+
Label.delete user, repo, name, options[:params]
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'issue <user> <repo> <number>', 'List labels on an issue.'
|
49
|
+
method_option :params, :type => :hash, :default => {},
|
50
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
51
|
+
def issue(user, repo, number)
|
52
|
+
Label.issue user, repo, number, options[:params]
|
53
|
+
end
|
54
|
+
|
55
|
+
desc 'add <user> <repo> <number>', 'Add labels to an issue.'
|
56
|
+
method_option :labels, :type => :string,
|
57
|
+
:desc => 'Labels to be added to this issue.'
|
58
|
+
method_option :params, :type => :hash, :default => {},
|
59
|
+
:desc => 'Additional request parameters e.i per_page:100'
|
60
|
+
def add(user, repo, number)
|
61
|
+
Label.add user, repo, number, options[:labels], options[:params]
|
62
|
+
end
|
63
|
+
|
64
|
+
desc 'remove <user> <repo> <number>', 'List labels on an issue.'
|
65
|
+
method_option :name, :type => :string, :default => nil,
|
66
|
+
:desc => 'Label name'
|
67
|
+
method_option :params, :type => :hash, :default => {},
|
68
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
69
|
+
def remove(user, repo, number)
|
70
|
+
Label.issue user, repo, number, options[:name], options[:params]
|
71
|
+
end
|
72
|
+
|
73
|
+
desc 'replace <user> <repo> <number>', 'Replace all labels for an issue.'
|
74
|
+
method_option :labels, :type => :string,
|
75
|
+
:desc => 'Labels to be replace in this issue.'
|
76
|
+
method_option :params, :type => :hash, :default => {},
|
77
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
78
|
+
def replace(user, repo, number)
|
79
|
+
Label.replace user, repo, number, options[:labels], options[:params]
|
80
|
+
end
|
81
|
+
|
82
|
+
desc 'milestone <user> <repo> <number>', 'Get labels for every issue in a milestone.'
|
83
|
+
method_option :params, :type => :hash, :default => {},
|
84
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
85
|
+
def milestone(user, repo, number)
|
86
|
+
Label.milestone user, repo, number, options[:params]
|
32
87
|
end
|
33
88
|
|
34
89
|
end # Labels
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module GithubCLI
|
4
|
+
class Commands::PullRequests < Command
|
5
|
+
|
6
|
+
namespace :pull
|
7
|
+
|
8
|
+
desc 'get <user> <repo> <number>', 'Get a Pull Request'
|
9
|
+
method_option :params, :type => :hash, :default => {},
|
10
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
11
|
+
def get(user, repo, number)
|
12
|
+
PullRequest.get user, repo, number, options[:params]
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'list <user> <repo>', 'List all Pull Requests'
|
16
|
+
method_option :params, :type => :hash, :default => {},
|
17
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
18
|
+
def list(user, repo)
|
19
|
+
PullRequest.list user, repo, options[:params]
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'create <user> <repo>', 'Create a new Pull Request'
|
23
|
+
method_option :params, :type => :hash, :default => {},
|
24
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
25
|
+
def create(user, repo)
|
26
|
+
PullRequest.create user, repo, options[:params]
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'update <user> <repo> <number>', 'Update a Pull Request'
|
30
|
+
method_option :params, :type => :hash, :default => {},
|
31
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
32
|
+
def update(user, repo, number)
|
33
|
+
PullRequest.update user, repo, number, options[:params]
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'commits <user> <repo> <number>', 'List commits on a Pull Request'
|
37
|
+
method_option :params, :type => :hash, :default => {},
|
38
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
39
|
+
def commits(user, repo, number)
|
40
|
+
PullRequest.commits user, repo, number, options[:params]
|
41
|
+
end
|
42
|
+
|
43
|
+
desc 'files <user> <repo> <number>', 'List Pull Requests Files'
|
44
|
+
method_option :params, :type => :hash, :default => {},
|
45
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
46
|
+
def files(user, repo, number)
|
47
|
+
PullRequest.files user, repo, number, options[:params]
|
48
|
+
end
|
49
|
+
|
50
|
+
desc 'merged <user> <repo> <number>', 'Get if a pull request has been merged'
|
51
|
+
method_option :params, :type => :hash, :default => {},
|
52
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
53
|
+
def merged(user, repo, number)
|
54
|
+
PullRequest.merged user, repo, number, options[:params]
|
55
|
+
end
|
56
|
+
|
57
|
+
desc 'merge <user> <repo> <number>', 'Merge a pull request'
|
58
|
+
method_option :params, :type => :hash, :default => {},
|
59
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
60
|
+
def merge(user, repo, number)
|
61
|
+
PullRequest.merge user, repo, number, options[:params]
|
62
|
+
end
|
63
|
+
|
64
|
+
end # PullRequests
|
65
|
+
end # GithubCLI
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module GithubCLI
|
4
|
+
class Commands::References < Command
|
5
|
+
|
6
|
+
namespace :ref
|
7
|
+
|
8
|
+
desc 'get <user> <repo> <ref>', 'Get a Reference'
|
9
|
+
method_option :params, :type => :hash, :default => {},
|
10
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
11
|
+
def get(user, repo, ref)
|
12
|
+
Reference.get user, repo, ref, options[:params]
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'list <user> <repo> <ref>', 'List all References'
|
16
|
+
method_option :ref, :type => :string, :banner => 'branch reference'
|
17
|
+
method_option :params, :type => :hash, :default => {},
|
18
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
19
|
+
def list(user, repo)
|
20
|
+
ref = options[:ref] ? options[:ref] : nil
|
21
|
+
Reference.list user, repo, ref, options[:params]
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'create <user> <repo>', 'Create a new Reference'
|
25
|
+
method_option :params, :type => :hash, :default => {},
|
26
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
27
|
+
def create(user, repo)
|
28
|
+
Reference.create user, repo, options[:params]
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'update <user> <repo> <ref>', 'Update a Reference'
|
32
|
+
method_option :params, :type => :hash, :default => {},
|
33
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
34
|
+
def update(user, repo, ref)
|
35
|
+
Reference.update user, repo, ref, options[:params]
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'delete <user> <repo> <ref>', 'Delete a Reference'
|
39
|
+
method_option :params, :type => :hash, :default => {},
|
40
|
+
:desc => 'Additonal request parameters e.i per_page:100'
|
41
|
+
def delete(user, repo, ref)
|
42
|
+
Reference.delete user, repo, ref, options[:params]
|
43
|
+
end
|
44
|
+
|
45
|
+
end # References
|
46
|
+
end # GithubCLI
|
data/lib/github_cli/commands.rb
CHANGED
@@ -3,8 +3,12 @@
|
|
3
3
|
module GithubCLI
|
4
4
|
module Commands
|
5
5
|
autoload :Blobs, 'github_cli/commands/blobs'
|
6
|
+
autoload :Commits, 'github_cli/commands/commits'
|
7
|
+
autoload :Forks, 'github_cli/commands/forks'
|
6
8
|
autoload :Issues, 'github_cli/commands/issues'
|
7
9
|
autoload :Labels, 'github_cli/commands/labels'
|
10
|
+
autoload :PullRequests, 'github_cli/commands/pull_requests'
|
11
|
+
autoload :References, 'github_cli/commands/references'
|
8
12
|
autoload :Repositories, 'github_cli/commands/repositories'
|
9
13
|
autoload :Tags, 'github_cli/commands/tags'
|
10
14
|
autoload :Trees, 'github_cli/commands/trees'
|
data/lib/github_cli/config.rb
CHANGED
@@ -5,8 +5,10 @@ module GithubCLI
|
|
5
5
|
COMMAND_KEY = 'commands'
|
6
6
|
COMMAND_HELP = 'help'
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@
|
8
|
+
def initialize(root)
|
9
|
+
@root = root
|
10
|
+
@local_config = local_options_file
|
11
|
+
@global_config = global_options_file
|
10
12
|
end
|
11
13
|
|
12
14
|
def []=(key, value)
|
@@ -15,7 +17,7 @@ module GithubCLI
|
|
15
17
|
end
|
16
18
|
|
17
19
|
def [](key)
|
18
|
-
data[key]
|
20
|
+
data[key] #|| data[COMMAND_KEY][key]
|
19
21
|
end
|
20
22
|
|
21
23
|
def fetch(key, default=nil)
|
@@ -30,6 +32,10 @@ module GithubCLI
|
|
30
32
|
@data ||= self.load
|
31
33
|
end
|
32
34
|
|
35
|
+
def keys
|
36
|
+
data.keys
|
37
|
+
end
|
38
|
+
|
33
39
|
def save(config)
|
34
40
|
config[COMMAND_KEY] = {}
|
35
41
|
Command.all.each do |cmd|
|
@@ -53,24 +59,22 @@ module GithubCLI
|
|
53
59
|
end
|
54
60
|
|
55
61
|
def path
|
56
|
-
|
57
|
-
|
58
|
-
@filename
|
62
|
+
if File.exists?(local_options_file)
|
63
|
+
local_options_file
|
59
64
|
else
|
60
|
-
|
65
|
+
global_options_file
|
61
66
|
end
|
62
67
|
end
|
63
68
|
|
64
|
-
|
65
|
-
end
|
69
|
+
private
|
66
70
|
|
67
71
|
def local_options_file
|
68
|
-
|
72
|
+
Pathname.new "#{@root}/.githubrc"
|
69
73
|
end
|
70
74
|
|
71
75
|
def global_options_file
|
72
76
|
begin
|
73
|
-
File.join
|
77
|
+
Pathname.new File.join(Thor::Util.user_home, ".githubrc")
|
74
78
|
rescue ArgumentError
|
75
79
|
GithubCLI.ui.warn "Unable to find ~/.githubrc because the HOME environment variable is not set"
|
76
80
|
nil
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module GithubCLI
|
4
|
+
module Helpers
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def default_configfile
|
8
|
+
configfile = find_configfile
|
9
|
+
raise ConfigFileNotFound, "Could not locate .githubrc" unless configfile
|
10
|
+
Pathname.new(configfile)
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_configfile
|
14
|
+
current = File.expand_path(Dir.pwd)
|
15
|
+
end
|
16
|
+
end # Helpers
|
17
|
+
end # GithubCLI
|
data/lib/github_cli/version.rb
CHANGED
data/lib/github_cli.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'yaml'
|
4
|
+
require 'pathname'
|
4
5
|
require 'thor'
|
5
6
|
require 'thor/group'
|
6
7
|
require 'github_api'
|
7
8
|
require 'github_cli/version'
|
9
|
+
require 'github_cli/errors'
|
8
10
|
|
9
11
|
module GithubCLI
|
10
12
|
autoload :DSL, 'github_cli/dsl'
|
@@ -14,6 +16,7 @@ module GithubCLI
|
|
14
16
|
autoload :API, 'github_cli/api'
|
15
17
|
autoload :Terminal, 'github_cli/terminal'
|
16
18
|
autoload :Commands, 'github_cli/commands'
|
19
|
+
autoload :Helpers, 'github_cli/helpers'
|
17
20
|
autoload :UI, 'github_cli/ui'
|
18
21
|
|
19
22
|
require 'github_cli/apis'
|
@@ -29,8 +32,16 @@ module GithubCLI
|
|
29
32
|
@ui ||= UI.new
|
30
33
|
end
|
31
34
|
|
35
|
+
def default_configfile
|
36
|
+
Helpers.default_configfile
|
37
|
+
end
|
38
|
+
|
39
|
+
def root
|
40
|
+
default_configfile.expand_path
|
41
|
+
end
|
42
|
+
|
32
43
|
def config
|
33
|
-
@config ||= GithubCLI::Config.new
|
44
|
+
@config ||= GithubCLI::Config.new root
|
34
45
|
end
|
35
46
|
|
36
47
|
def commands
|
data/spec/github_cli/api_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe GithubCLI::API do
|
|
5
5
|
before(:each) { described_class.send(:class_variable_set, :@@api, nil) }
|
6
6
|
|
7
7
|
it 'sets up github api connection' do
|
8
|
-
github_instance = stub
|
8
|
+
github_instance = stub.as_null_object
|
9
9
|
Github.should_receive(:new).and_return github_instance
|
10
10
|
described_class.github_api.should == github_instance
|
11
11
|
end
|
@@ -19,7 +19,8 @@ describe GithubCLI::Config do
|
|
19
19
|
|
20
20
|
context 'array access' do
|
21
21
|
it 'searches in commands' do
|
22
|
-
|
22
|
+
pending
|
23
|
+
# config['issue-list'].should == { 'inputs' => 'ticket' }
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
@@ -72,30 +73,34 @@ describe GithubCLI::Config do
|
|
72
73
|
end
|
73
74
|
end
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
context "#load" do
|
77
|
+
it "loads empty hash if config doesn't exist" do
|
78
|
+
File.stub(:exists?) { false }
|
79
|
+
config.load == {}
|
80
|
+
end
|
79
81
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
it "loads yaml config" do
|
83
|
+
File.stub(:exists?) { true }
|
84
|
+
File.stub(:open).and_yield filename
|
85
|
+
YAML.should_receive(:load).with(filename)
|
86
|
+
config.load
|
87
|
+
end
|
85
88
|
end
|
86
89
|
|
87
|
-
|
88
|
-
config
|
89
|
-
|
90
|
-
|
90
|
+
context "#path" do
|
91
|
+
it 'looks for local config file' do
|
92
|
+
root = "/users/"
|
93
|
+
File.stub(:exists?) { true }
|
94
|
+
config = GithubCLI::Config.new root
|
95
|
+
config.path.to_s.should == "#{root}/.githubrc"
|
96
|
+
end
|
91
97
|
|
92
|
-
|
93
|
-
|
94
|
-
|
98
|
+
it 'reads global file if local is missing ' do
|
99
|
+
File.stub(:exists?) { false }
|
100
|
+
config = GithubCLI::Config.new path
|
101
|
+
config.path.to_s.should == "#{ENV['HOME']}/#{filename}"
|
102
|
+
end
|
95
103
|
end
|
96
104
|
end
|
97
105
|
|
98
|
-
context 'local' do
|
99
|
-
end
|
100
|
-
|
101
106
|
end # GithubCLI::Config
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GithubCLI::Helpers do
|
4
|
+
subject { described_class }
|
5
|
+
|
6
|
+
it 'throws error if config file does not exist' do
|
7
|
+
subject.stub(:find_configfile) { nil }
|
8
|
+
expect {
|
9
|
+
subject.default_configfile
|
10
|
+
}.to raise_error(GithubCLI::ConfigFileNotFound)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'finds current directory' do
|
14
|
+
current = File.expand_path('../../../', __FILE__)
|
15
|
+
described_class.find_configfile.should == current
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: github_api
|
16
|
-
requirement: &
|
16
|
+
requirement: &2151931480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.4.8
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2151931480
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: thor
|
27
|
-
requirement: &
|
27
|
+
requirement: &2151930740 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2151930740
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &2151929860 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2151929860
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: aruba
|
49
|
-
requirement: &
|
49
|
+
requirement: &2151929040 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2151929040
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &2151942440 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2151942440
|
69
69
|
description: CLI-based access to GitHub API v3
|
70
70
|
email:
|
71
71
|
- pmurach@gmail.com
|
@@ -95,6 +95,11 @@ files:
|
|
95
95
|
- lib/github_cli/api.rb
|
96
96
|
- lib/github_cli/apis.rb
|
97
97
|
- lib/github_cli/apis/blob.rb
|
98
|
+
- lib/github_cli/apis/commit.rb
|
99
|
+
- lib/github_cli/apis/fork.rb
|
100
|
+
- lib/github_cli/apis/label.rb
|
101
|
+
- lib/github_cli/apis/pull_request.rb
|
102
|
+
- lib/github_cli/apis/reference.rb
|
98
103
|
- lib/github_cli/apis/repository.rb
|
99
104
|
- lib/github_cli/apis/tag.rb
|
100
105
|
- lib/github_cli/apis/tree.rb
|
@@ -102,13 +107,19 @@ files:
|
|
102
107
|
- lib/github_cli/command.rb
|
103
108
|
- lib/github_cli/commands.rb
|
104
109
|
- lib/github_cli/commands/blobs.rb
|
110
|
+
- lib/github_cli/commands/commits.rb
|
111
|
+
- lib/github_cli/commands/forks.rb
|
105
112
|
- lib/github_cli/commands/issues.rb
|
106
113
|
- lib/github_cli/commands/labels.rb
|
114
|
+
- lib/github_cli/commands/pull_requests.rb
|
115
|
+
- lib/github_cli/commands/references.rb
|
107
116
|
- lib/github_cli/commands/repositories.rb
|
108
117
|
- lib/github_cli/commands/tags.rb
|
109
118
|
- lib/github_cli/commands/trees.rb
|
110
119
|
- lib/github_cli/config.rb
|
111
120
|
- lib/github_cli/dsl.rb
|
121
|
+
- lib/github_cli/errors.rb
|
122
|
+
- lib/github_cli/helpers.rb
|
112
123
|
- lib/github_cli/terminal.rb
|
113
124
|
- lib/github_cli/ui.rb
|
114
125
|
- lib/github_cli/version.rb
|
@@ -116,6 +127,7 @@ files:
|
|
116
127
|
- spec/github_cli/cli_spec.rb
|
117
128
|
- spec/github_cli/command_spec.rb
|
118
129
|
- spec/github_cli/config_spec.rb
|
130
|
+
- spec/github_cli/helpers_spec.rb
|
119
131
|
- spec/spec_helper.rb
|
120
132
|
homepage: http://github.com/peter-murach/github_cli
|
121
133
|
licenses: []
|
@@ -151,4 +163,5 @@ test_files:
|
|
151
163
|
- spec/github_cli/cli_spec.rb
|
152
164
|
- spec/github_cli/command_spec.rb
|
153
165
|
- spec/github_cli/config_spec.rb
|
166
|
+
- spec/github_cli/helpers_spec.rb
|
154
167
|
- spec/spec_helper.rb
|