github_cli 0.2.1 → 0.3.0

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.
Files changed (55) hide show
  1. data/CHANGELOG.md +9 -0
  2. data/Gemfile.lock +3 -3
  3. data/README.md +30 -0
  4. data/bin/ghc +13 -1
  5. data/features/repositories.feature +9 -0
  6. data/github_cli.gemspec +1 -1
  7. data/lib/github_cli.rb +2 -0
  8. data/lib/github_cli/api.rb +7 -2
  9. data/lib/github_cli/apis.rb +4 -0
  10. data/lib/github_cli/apis/authorization.rb +20 -10
  11. data/lib/github_cli/apis/blob.rb +8 -4
  12. data/lib/github_cli/apis/collaborator.rb +34 -0
  13. data/lib/github_cli/apis/commit.rb +8 -4
  14. data/lib/github_cli/apis/download.rb +20 -10
  15. data/lib/github_cli/apis/fork.rb +8 -4
  16. data/lib/github_cli/apis/gist.rb +70 -0
  17. data/lib/github_cli/apis/hook.rb +24 -12
  18. data/lib/github_cli/apis/issue.rb +40 -0
  19. data/lib/github_cli/apis/key.rb +20 -10
  20. data/lib/github_cli/apis/label.rb +40 -18
  21. data/lib/github_cli/apis/pull_request.rb +32 -16
  22. data/lib/github_cli/apis/reference.rb +20 -10
  23. data/lib/github_cli/apis/repository.rb +36 -19
  24. data/lib/github_cli/apis/tag.rb +8 -4
  25. data/lib/github_cli/apis/tree.rb +8 -4
  26. data/lib/github_cli/apis/watching.rb +20 -10
  27. data/lib/github_cli/command.rb +19 -0
  28. data/lib/github_cli/commands.rb +2 -0
  29. data/lib/github_cli/commands/authorizations.rb +5 -5
  30. data/lib/github_cli/commands/blobs.rb +2 -2
  31. data/lib/github_cli/commands/collaborators.rb +37 -0
  32. data/lib/github_cli/commands/commits.rb +2 -2
  33. data/lib/github_cli/commands/downloads.rb +5 -5
  34. data/lib/github_cli/commands/forks.rb +2 -2
  35. data/lib/github_cli/commands/gists.rb +103 -0
  36. data/lib/github_cli/commands/hooks.rb +6 -6
  37. data/lib/github_cli/commands/issues.rb +67 -18
  38. data/lib/github_cli/commands/keys.rb +5 -5
  39. data/lib/github_cli/commands/labels.rb +8 -8
  40. data/lib/github_cli/commands/pull_requests.rb +8 -8
  41. data/lib/github_cli/commands/references.rb +5 -5
  42. data/lib/github_cli/commands/repositories.rb +20 -20
  43. data/lib/github_cli/commands/tags.rb +2 -2
  44. data/lib/github_cli/commands/trees.rb +2 -2
  45. data/lib/github_cli/commands/watching.rb +5 -5
  46. data/lib/github_cli/errors.rb +33 -2
  47. data/lib/github_cli/formatters.rb +8 -0
  48. data/lib/github_cli/formatters/csv.rb +39 -0
  49. data/lib/github_cli/formatters/table.rb +36 -0
  50. data/lib/github_cli/subcommands.rb +6 -0
  51. data/lib/github_cli/terminal.rb +25 -0
  52. data/lib/github_cli/util.rb +35 -0
  53. data/lib/github_cli/version.rb +1 -1
  54. data/spec/github_cli/util_spec.rb +37 -0
  55. metadata +26 -13
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ 0.3.0 (May 13, 2012)
2
+
3
+ * Add output formatting.
4
+ * Add gists api commands.
5
+ * Add collaborators api commands.
6
+ * Add issues api commands.
7
+ * Add error handling for the executable.
8
+ * Setup feature testing environment.
9
+
1
10
  0.2.1 (April 30, 2012)
2
11
 
3
12
  * Add authorizations api commands.
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- github_cli (0.2.1)
5
- github_api (~> 0.5.0)
4
+ github_cli (0.3.0)
5
+ github_api (~> 0.5)
6
6
  thor
7
7
 
8
8
  GEM
@@ -31,7 +31,7 @@ GEM
31
31
  ffi (1.0.11)
32
32
  gherkin (2.9.0)
33
33
  json (>= 1.4.6)
34
- github_api (0.5.0)
34
+ github_api (0.5.1)
35
35
  faraday (~> 0.7.6)
36
36
  hashie (~> 1.2.0)
37
37
  multi_json (~> 1.3)
data/README.md CHANGED
@@ -71,12 +71,14 @@ Interact with issues:
71
71
  ```shell
72
72
  $ ghc issue
73
73
  $ ghc label
74
+ $ ghc milestone
74
75
  ```
75
76
 
76
77
  Interact with repositories:
77
78
 
78
79
  ```shell
79
80
  $ ghc repo
81
+ $ ghc collab
80
82
  $ ghc download
81
83
  $ ghc fork
82
84
  $ ghc hook
@@ -84,6 +86,34 @@ $ ghc key
84
86
  $ ghc watching
85
87
  ```
86
88
 
89
+ Interact with gists:
90
+
91
+ ```shell
92
+ $ ghc gist
93
+ ```
94
+
95
+ Interact with authorizations:
96
+
97
+ ```shell
98
+ $ ghc auth
99
+ ```
100
+
101
+ ### Output Format
102
+
103
+ The API responses can be formattaed as `csv`, `json`, `pretty`, `table`.
104
+
105
+ By default responses are in tabular format. Run the following
106
+
107
+ ```shell
108
+ ghc repo get peter-murach github_cli
109
+ ```
110
+
111
+ To get `csv` formatting for easy command piping do
112
+
113
+ ```shell
114
+ ghc repo ls -u wycats --format=csv
115
+ ```
116
+
87
117
  ### Examples
88
118
 
89
119
  You can create repository by supplying required parameters
data/bin/ghc CHANGED
@@ -3,4 +3,16 @@ lib_dir = File.expand_path("../../lib", __FILE__)
3
3
  $LOAD_PATH.unshift lib_dir if File.directory?(lib_dir)
4
4
 
5
5
  require "github_cli"
6
- GithubCLI::CLI.start
6
+ begin
7
+ GithubCLI::CLI.start
8
+ rescue Interrupt => e
9
+ GithubCLI.ui.error "\nQuitting..."
10
+ GithubCLI.ui.debug e.backtrace.join("\n")
11
+ exit 1
12
+ rescue SystemExit => e
13
+ exit e.status
14
+ rescue Exception => e
15
+ GithubCLI.ui.error "Fatal error has occurred." + e.message
16
+ GithubCLI.ui.debug e.backtrace.join("\n")
17
+ exit 1
18
+ end
@@ -0,0 +1,9 @@
1
+ @repositories
2
+ Feature: Repository Commands
3
+
4
+ As a developer who wants to interact with GitHub Repository API
5
+ I have access to commands
6
+
7
+ Scenario: List repositories
8
+ When I run `ghc repo list --user=wycats`
9
+ Then the exit status should be 0
data/github_cli.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = GithubCLI::VERSION
17
17
 
18
- gem.add_dependency 'github_api', '~> 0.5.0'
18
+ gem.add_dependency 'github_api', '~> 0.5'
19
19
  gem.add_dependency 'thor'
20
20
 
21
21
  gem.add_development_dependency 'rspec'
data/lib/github_cli.rb CHANGED
@@ -17,7 +17,9 @@ module GithubCLI
17
17
  autoload :Terminal, 'github_cli/terminal'
18
18
  autoload :Commands, 'github_cli/commands'
19
19
  autoload :Helpers, 'github_cli/helpers'
20
+ autoload :Formatters,'github_cli/formatters'
20
21
  autoload :UI, 'github_cli/ui'
22
+ autoload :Util, 'github_cli/util'
21
23
 
22
24
  require 'github_cli/apis'
23
25
 
@@ -21,9 +21,14 @@ module GithubCLI
21
21
  def self.configure_api
22
22
  end
23
23
 
24
+ def self.output(format=:table, &block)
25
+ response = block.call
26
+ GithubCLI::Terminal.render_output response, :format => format
27
+ end
28
+
24
29
  class All
25
- def initialize
26
- github_api
30
+ def initialize(params)
31
+ puts Github::Repos.new.all params
27
32
  end
28
33
  end
29
34
 
@@ -11,9 +11,13 @@ end
11
11
  %w[
12
12
  authorization
13
13
  blob
14
+ collaborator
14
15
  commit
15
16
  download
16
17
  fork
18
+ gist
19
+ hook
20
+ issue
17
21
  key
18
22
  label
19
23
  pull_request
@@ -5,24 +5,34 @@ module GithubCLI
5
5
 
6
6
  class << self
7
7
 
8
- def all(params)
9
- github_api.oauth.list params
8
+ def all(params, format)
9
+ output format do
10
+ github_api.oauth.list params
11
+ end
10
12
  end
11
13
 
12
- def get(id, params)
13
- github_api.oauth.get id, params
14
+ def get(id, params, format)
15
+ output format do
16
+ github_api.oauth.get id, params
17
+ end
14
18
  end
15
19
 
16
- def create(params)
17
- github_api.oauth.create params
20
+ def create(params, format)
21
+ output format do
22
+ github_api.oauth.create params
23
+ end
18
24
  end
19
25
 
20
- def update(id, params)
21
- github_api.oauth.update id, params
26
+ def update(id, params, format)
27
+ output format do
28
+ github_api.oauth.update id, params
29
+ end
22
30
  end
23
31
 
24
- def delete(id, params)
25
- github_api.oauth.delete id, params
32
+ def delete(id, params, format)
33
+ output format do
34
+ github_api.oauth.delete id, params
35
+ end
26
36
  end
27
37
  end
28
38
 
@@ -5,12 +5,16 @@ module GithubCLI
5
5
 
6
6
  class << self
7
7
 
8
- def get(user, repo, sha, params)
9
- github_api.git_data.blobs.get user, repo, params
8
+ def get(user, repo, sha, params, format)
9
+ output format do
10
+ github_api.git_data.blobs.get user, repo, params
11
+ end
10
12
  end
11
13
 
12
- def create(user, repo, params)
13
- github_api.git_data.blobs.create user, repo, params
14
+ def create(user, repo, params, format)
15
+ output format do
16
+ github_api.git_data.blobs.create user, repo, params
17
+ end
14
18
  end
15
19
  end
16
20
 
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ module GithubCLI
4
+ class Collaborator < API
5
+
6
+ class << self
7
+
8
+ def all(user, repo, params, format)
9
+ output format do
10
+ github_api.repos.collaborators.list user, repo, params
11
+ end
12
+ end
13
+
14
+ def add(user, repo, collab, params, format)
15
+ output format do
16
+ github_api.repos.collaborators.add user, repo, collab, params
17
+ end
18
+ end
19
+
20
+ def collaborator?(user, repo, collab, params, format)
21
+ output format do
22
+ github_api.repos.collaborators.collaborator? user, repo, collab, params
23
+ end
24
+ end
25
+
26
+ def remove(user, repo, collab, params, format)
27
+ output format do
28
+ github_api.repos.collaborators.remove user, repo, collab, params
29
+ end
30
+ end
31
+ end
32
+
33
+ end # Collaborator
34
+ end # GithubCLI
@@ -5,12 +5,16 @@ module GithubCLI
5
5
 
6
6
  class << self
7
7
 
8
- def get(user, repo, sha, params)
9
- github_api.git_data.commits.get user, repo, params
8
+ def get(user, repo, sha, params, format)
9
+ output format do
10
+ github_api.git_data.commits.get user, repo, params
11
+ end
10
12
  end
11
13
 
12
- def create(user, repo, params)
13
- github_api.git_data.commits.create user, repo, params
14
+ def create(user, repo, params, format)
15
+ output format do
16
+ github_api.git_data.commits.create user, repo, params
17
+ end
14
18
  end
15
19
  end
16
20
 
@@ -5,24 +5,34 @@ module GithubCLI
5
5
 
6
6
  class << self
7
7
 
8
- def all(user, repo, params)
9
- github_api.repos.downloads.list user, repo, params
8
+ def all(user, repo, params, format)
9
+ output format do
10
+ github_api.repos.downloads.list user, repo, params
11
+ end
10
12
  end
11
13
 
12
- def get(user, repo, id, params)
13
- github_api.repos.downloads.get user, repo, id, params
14
+ def get(user, repo, id, params, format)
15
+ output format do
16
+ github_api.repos.downloads.get user, repo, id, params
17
+ end
14
18
  end
15
19
 
16
- def create(user, repo, params)
17
- github_api.repos.downloads.create user, repo, params
20
+ def create(user, repo, params, format)
21
+ output format do
22
+ github_api.repos.downloads.create user, repo, params
23
+ end
18
24
  end
19
25
 
20
- def upload(resource, filename)
21
- github_api.repos.downloads.upload resource, filename
26
+ def upload(resource, filename, format)
27
+ output format do
28
+ github_api.repos.downloads.upload resource, filename
29
+ end
22
30
  end
23
31
 
24
- def delete(user, repo, id, params)
25
- github_api.repos.downloads.delete user, repo, id, params
32
+ def delete(user, repo, id, params, format)
33
+ output format do
34
+ github_api.repos.downloads.delete user, repo, id, params
35
+ end
26
36
  end
27
37
  end
28
38
 
@@ -5,12 +5,16 @@ module GithubCLI
5
5
 
6
6
  class << self
7
7
 
8
- def all(user, repo, params)
9
- github_api.repos.forks.list user, repo, params
8
+ def all(user, repo, params, format)
9
+ output format do
10
+ github_api.repos.forks.list user, repo, params
11
+ end
10
12
  end
11
13
 
12
- def create(user, repo, params)
13
- github_api.repos.forks.create user, repo, params
14
+ def create(user, repo, params, format)
15
+ output format do
16
+ github_api.repos.forks.create user, repo, params
17
+ end
14
18
  end
15
19
  end
16
20
 
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+
3
+ module GithubCLI
4
+ class Gist < API
5
+
6
+ class << self
7
+
8
+ def all(params, format)
9
+ output format do
10
+ github_api.gists.list params
11
+ end
12
+ end
13
+
14
+ def starred(params, format)
15
+ output format do
16
+ github_api.gists.starred params
17
+ end
18
+ end
19
+
20
+ def get(id, params, format)
21
+ output format do
22
+ github_api.gists.get id, params
23
+ end
24
+ end
25
+
26
+ def create(params, format)
27
+ output format do
28
+ github_api.gists.create params
29
+ end
30
+ end
31
+
32
+ def edit(id, params, format)
33
+ output format do
34
+ github_api.gists.edit id, params
35
+ end
36
+ end
37
+
38
+ def star(id, params, format)
39
+ output format do
40
+ github_api.gists.star id, params
41
+ end
42
+ end
43
+
44
+ def unstar(id, params, format)
45
+ output format do
46
+ github_api.gists.unstar id, params
47
+ end
48
+ end
49
+
50
+ def starred?(id, params, format)
51
+ output format do
52
+ github_api.gists.starred? id, params
53
+ end
54
+ end
55
+
56
+ def fork(id, params, format)
57
+ output format do
58
+ github_api.gists.fork id, params
59
+ end
60
+ end
61
+
62
+ def delete(id, params, format)
63
+ output format do
64
+ github_api.gists.delete id, params
65
+ end
66
+ end
67
+ end
68
+
69
+ end # Gist
70
+ end # GithubCLI
@@ -5,28 +5,40 @@ module GithubCLI
5
5
 
6
6
  class << self
7
7
 
8
- def all(user, repo, params)
9
- github_api.repos.hooks.list user, repo, params
8
+ def all(user, repo, params, format)
9
+ output format do
10
+ github_api.repos.hooks.list user, repo, params
11
+ end
10
12
  end
11
13
 
12
- def get(user, repo, id, params)
13
- github_api.repos.hooks.get user, repo, id, params
14
+ def get(user, repo, id, params, format)
15
+ output format do
16
+ github_api.repos.hooks.get user, repo, id, params
17
+ end
14
18
  end
15
19
 
16
- def create(user, repo, params)
17
- github_api.repos.hooks.create user, repo, params
20
+ def create(user, repo, params, format)
21
+ output format do
22
+ github_api.repos.hooks.create user, repo, params
23
+ end
18
24
  end
19
25
 
20
- def edit(user, repo, id, params)
21
- github_api.repos.hooks.edit user, repo, id, params
26
+ def edit(user, repo, id, params, format)
27
+ output format do
28
+ github_api.repos.hooks.edit user, repo, id, params
29
+ end
22
30
  end
23
31
 
24
- def test(user, repo, id, params)
25
- github_api.repos.hooks.test user, repo, id, params
32
+ def test(user, repo, id, params, format)
33
+ output format do
34
+ github_api.repos.hooks.test user, repo, id, params
35
+ end
26
36
  end
27
37
 
28
- def delete(user, repo, id, params)
29
- github_api.repos.hooks.delete user, repo, id, params
38
+ def delete(user, repo, id, params, format)
39
+ output format do
40
+ github_api.repos.hooks.delete user, repo, id, params
41
+ end
30
42
  end
31
43
  end
32
44