github_cli 0.5.9 → 0.6.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 (127) hide show
  1. data/.travis.yml +1 -0
  2. data/CHANGELOG.md +12 -1
  3. data/Gemfile.lock +12 -10
  4. data/README.md +18 -0
  5. data/features/authorization.feature +53 -0
  6. data/features/blob.feature +1 -1
  7. data/features/download.feature +13 -11
  8. data/features/gist.feature +9 -1
  9. data/features/label.feature +11 -12
  10. data/features/member.feature +5 -4
  11. data/features/merging.feature +5 -4
  12. data/features/organization.feature +5 -4
  13. data/features/repository.feature +9 -1
  14. data/features/search.feature +5 -4
  15. data/github_cli.gemspec +1 -1
  16. data/lib/github_cli/api.rb +56 -49
  17. data/lib/github_cli/apis/assignee.rb +6 -6
  18. data/lib/github_cli/apis/authorization.rb +5 -5
  19. data/lib/github_cli/apis/blob.rb +6 -6
  20. data/lib/github_cli/apis/collaborator.rb +12 -12
  21. data/lib/github_cli/apis/commit.rb +6 -6
  22. data/lib/github_cli/apis/content.rb +9 -9
  23. data/lib/github_cli/apis/download.rb +15 -15
  24. data/lib/github_cli/apis/email.rb +9 -9
  25. data/lib/github_cli/apis/event.rb +24 -24
  26. data/lib/github_cli/apis/follower.rb +16 -15
  27. data/lib/github_cli/apis/fork.rb +6 -6
  28. data/lib/github_cli/apis/gist.rb +31 -30
  29. data/lib/github_cli/apis/hook.rb +6 -6
  30. data/lib/github_cli/apis/issue.rb +12 -12
  31. data/lib/github_cli/apis/key.rb +15 -15
  32. data/lib/github_cli/apis/label.rb +24 -26
  33. data/lib/github_cli/apis/member.rb +15 -27
  34. data/lib/github_cli/apis/merging.rb +3 -3
  35. data/lib/github_cli/apis/milestone.rb +15 -15
  36. data/lib/github_cli/apis/notification.rb +18 -18
  37. data/lib/github_cli/apis/organization.rb +9 -9
  38. data/lib/github_cli/apis/pull_request.rb +24 -24
  39. data/lib/github_cli/apis/reference.rb +15 -15
  40. data/lib/github_cli/apis/repository.rb +13 -12
  41. data/lib/github_cli/apis/search.rb +12 -12
  42. data/lib/github_cli/apis/starring.rb +15 -15
  43. data/lib/github_cli/apis/status.rb +6 -6
  44. data/lib/github_cli/apis/tag.rb +6 -6
  45. data/lib/github_cli/apis/team.rb +39 -39
  46. data/lib/github_cli/apis/tree.rb +6 -6
  47. data/lib/github_cli/apis/user.rb +9 -9
  48. data/lib/github_cli/apis/watching.rb +15 -15
  49. data/lib/github_cli/cli.rb +24 -16
  50. data/lib/github_cli/commands/assignees.rb +8 -2
  51. data/lib/github_cli/commands/authorizations.rb +10 -13
  52. data/lib/github_cli/commands/blobs.rb +9 -3
  53. data/lib/github_cli/commands/collaborators.rb +16 -4
  54. data/lib/github_cli/commands/commits.rb +11 -6
  55. data/lib/github_cli/commands/contents.rb +9 -6
  56. data/lib/github_cli/commands/downloads.rb +30 -6
  57. data/lib/github_cli/commands/emails.rb +12 -3
  58. data/lib/github_cli/commands/events.rb +30 -8
  59. data/lib/github_cli/commands/followers.rb +20 -5
  60. data/lib/github_cli/commands/forks.rb +6 -4
  61. data/lib/github_cli/commands/gists.rb +39 -12
  62. data/lib/github_cli/commands/hooks.rb +1 -1
  63. data/lib/github_cli/commands/issues.rb +15 -4
  64. data/lib/github_cli/commands/keys.rb +20 -5
  65. data/lib/github_cli/commands/labels.rb +53 -14
  66. data/lib/github_cli/commands/members.rb +28 -9
  67. data/lib/github_cli/commands/merging.rb +3 -2
  68. data/lib/github_cli/commands/milestones.rb +27 -15
  69. data/lib/github_cli/commands/notifications.rb +19 -11
  70. data/lib/github_cli/commands/organizations.rb +24 -5
  71. data/lib/github_cli/commands/pull_requests.rb +30 -8
  72. data/lib/github_cli/commands/references.rb +17 -5
  73. data/lib/github_cli/commands/repositories.rb +6 -4
  74. data/lib/github_cli/commands/search.rb +24 -6
  75. data/lib/github_cli/commands/starring.rb +19 -5
  76. data/lib/github_cli/commands/statuses.rb +7 -3
  77. data/lib/github_cli/commands/tags.rb +7 -3
  78. data/lib/github_cli/commands/teams.rb +52 -17
  79. data/lib/github_cli/commands/trees.rb +6 -2
  80. data/lib/github_cli/commands/users.rb +9 -3
  81. data/lib/github_cli/commands/watching.rb +19 -5
  82. data/lib/github_cli/vendor/thor/actions/directory.rb +2 -0
  83. data/lib/github_cli/vendor/thor/actions/empty_directory.rb +3 -19
  84. data/lib/github_cli/vendor/thor/actions/file_manipulation.rb +4 -1
  85. data/lib/github_cli/vendor/thor/actions.rb +1 -1
  86. data/lib/github_cli/vendor/thor/base.rb +20 -18
  87. data/lib/github_cli/vendor/thor/command.rb +1 -1
  88. data/lib/github_cli/vendor/thor/error.rb +0 -4
  89. data/lib/github_cli/vendor/thor/group.rb +4 -9
  90. data/lib/github_cli/vendor/thor/runner.rb +1 -1
  91. data/lib/github_cli/vendor/thor/shell/basic.rb +25 -7
  92. data/lib/github_cli/vendor/thor/version.rb +1 -1
  93. data/lib/github_cli/vendor/thor.rb +17 -2
  94. data/lib/github_cli/version.rb +1 -1
  95. data/spec/github_cli/api/configure_spec.rb +50 -0
  96. data/spec/github_cli/api/github_api_spec.rb +19 -0
  97. data/spec/github_cli/commands/assignees_spec.rb +1 -1
  98. data/spec/github_cli/commands/blobs_spec.rb +1 -1
  99. data/spec/github_cli/commands/collaborators_spec.rb +1 -1
  100. data/spec/github_cli/commands/commits_spec.rb +1 -1
  101. data/spec/github_cli/commands/contents_spec.rb +1 -1
  102. data/spec/github_cli/commands/downloads_spec.rb +35 -0
  103. data/spec/github_cli/commands/emails_spec.rb +1 -1
  104. data/spec/github_cli/commands/events_spec.rb +1 -1
  105. data/spec/github_cli/commands/followers_spec.rb +1 -1
  106. data/spec/github_cli/commands/forks_spec.rb +1 -1
  107. data/spec/github_cli/commands/gists_spec.rb +6 -1
  108. data/spec/github_cli/commands/issues_spec.rb +1 -1
  109. data/spec/github_cli/commands/keys_spec.rb +1 -1
  110. data/spec/github_cli/commands/labels_spec.rb +13 -3
  111. data/spec/github_cli/commands/members_spec.rb +46 -0
  112. data/spec/github_cli/commands/merging_spec.rb +1 -1
  113. data/spec/github_cli/commands/milestones_spec.rb +1 -1
  114. data/spec/github_cli/commands/notifications_spec.rb +1 -1
  115. data/spec/github_cli/commands/organizations_spec.rb +30 -0
  116. data/spec/github_cli/commands/pull_requests_spec.rb +1 -1
  117. data/spec/github_cli/commands/references_spec.rb +1 -1
  118. data/spec/github_cli/commands/repositories_spec.rb +5 -0
  119. data/spec/github_cli/commands/starring_spec.rb +1 -1
  120. data/spec/github_cli/commands/statuses_spec.rb +1 -1
  121. data/spec/github_cli/commands/tags_spec.rb +1 -1
  122. data/spec/github_cli/commands/teams_spec.rb +1 -1
  123. data/spec/github_cli/commands/trees_spec.rb +1 -1
  124. data/spec/github_cli/commands/users_spec.rb +1 -1
  125. data/spec/github_cli/commands/watching_spec.rb +1 -1
  126. metadata +27 -17
  127. data/spec/github_cli/api_spec.rb +0 -19
data/.travis.yml CHANGED
@@ -16,6 +16,7 @@ matrix:
16
16
  - rvm: ruby-head
17
17
  - rvm: jruby-head
18
18
  - rvm: jruby-18mode
19
+ - rvm: rbx-18mode
19
20
  - rvm: jruby-19mode
20
21
  branches:
21
22
  only: master
data/CHANGELOG.md CHANGED
@@ -1,8 +1,19 @@
1
- 0.5.9 (April , 2013)
1
+ 0.6.0 (June 1, 2013)
2
+
3
+ * Add authorize command to ease pain with getting authenticated
4
+ * Add 'every' flag to repository listing command
5
+ * Add 'public' flag to gist listing command
6
+ * Change all commands to pass through global options to configure api requests
7
+ * Update vendor dependencies
8
+ * Add ability to configure all github api request options
9
+
10
+ 0.5.9 (April 17, 2013)
2
11
 
3
12
  * Change API class configure to take options and allow for basic auth,
4
13
  stop using class api variable
5
14
  * Change API commands to take and pass options for global configuration
15
+ * Add --quiet option for supressing output only for repo/hook/auth commands
16
+ * Fix problem with repo create command and boolean option flags
6
17
 
7
18
  0.5.8 (April 14, 2013)
8
19
 
data/Gemfile.lock CHANGED
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- github_cli (0.5.9)
5
- github_api (~> 0.9)
4
+ github_cli (0.6.0)
5
+ github_api (~> 0.10)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ addressable (2.3.4)
10
11
  aruba (0.5.1)
11
12
  childprocess (~> 0.3.6)
12
13
  cucumber (>= 1.1.1)
@@ -24,28 +25,29 @@ GEM
24
25
  gherkin (~> 2.11.0)
25
26
  json (>= 1.4.6)
26
27
  diff-lcs (1.2.1)
27
- faraday (0.8.6)
28
+ faraday (0.8.7)
28
29
  multipart-post (~> 1.1)
29
30
  ffi (1.3.1)
30
31
  gherkin (2.11.6)
31
32
  json (>= 1.7.6)
32
- github_api (0.9.3)
33
+ github_api (0.10.1)
34
+ addressable
33
35
  faraday (~> 0.8.1)
34
- hashie (~> 2.0)
36
+ hashie (>= 1.2)
35
37
  multi_json (~> 1.4)
36
38
  nokogiri (~> 1.5.2)
37
39
  oauth2
38
- hashie (2.0.2)
40
+ hashie (2.0.5)
39
41
  hpricot (0.8.6)
40
42
  httpauth (0.2.0)
41
- json (1.7.6)
42
- jwt (0.1.7)
43
+ json (1.8.0)
44
+ jwt (0.1.8)
43
45
  multi_json (>= 1.5)
44
- multi_json (1.6.1)
46
+ multi_json (1.7.4)
45
47
  multi_xml (0.5.3)
46
48
  multipart-post (1.2.0)
47
49
  mustache (0.99.4)
48
- nokogiri (1.5.6)
50
+ nokogiri (1.5.9)
49
51
  oauth2 (0.9.1)
50
52
  faraday (~> 0.8)
51
53
  httpauth (~> 0.1)
data/README.md CHANGED
@@ -54,8 +54,12 @@ user.name # Default user name
54
54
  user.repo # Default repo name
55
55
  user.org # Default organization name
56
56
  core.editor # Editor to be opened
57
+ core.endpoint # The api endpoint, by deafult https://api.github.com
58
+ core.site # The web endpoint, by default https://github.com
57
59
  core.pager # Pager to be used, by default less
58
60
  core.format # Output formating
61
+ core.quiet # Surpass output to show only response status
62
+ core.ssl # SSL settings
59
63
  core.auto_pagination # Switch on default results pagination, default false
60
64
  ```
61
65
 
@@ -181,6 +185,14 @@ to limit returned results pass `pattern`
181
185
  $ gcli list re* # Returns all commands matching the pattern
182
186
  ```
183
187
 
188
+ ### Subcommands
189
+
190
+ To see a list of subcommands that a given command provides just type top-level command like so
191
+
192
+ ```shell
193
+ $ gcli repo
194
+ ```
195
+
184
196
  ### Output Format
185
197
 
186
198
  The API responses can be formatted as `csv`, `json`, `pretty`, `table`.
@@ -196,6 +208,12 @@ To get `csv` formatting for easy command piping do
196
208
  gcli repo ls -u wycats --format=csv
197
209
  ```
198
210
 
211
+ To suppress output pass `--quiet` option like so
212
+
213
+ ```shell
214
+ gcli repo create ... --quiet=true
215
+ ```
216
+
199
217
  ### Output Paging
200
218
 
201
219
  By default all responses are paged. You can switch off paging by supplying `no-pager` flag.
@@ -0,0 +1,53 @@
1
+ Feature: gcli auth
2
+
3
+ @ci-run
4
+ Scenario: Available commands
5
+
6
+ When I run `gcli auth`
7
+ Then the exit status should be 0
8
+ And the output should contain "auth list"
9
+ And the output should contain "auth get"
10
+ And the output should contain "auth create"
11
+ And the output should contain "auth update"
12
+ And the output should contain "auth delete"
13
+
14
+ Scenario: List authorizations
15
+ Given the Github API server:
16
+ """
17
+ get('/authorizations') { status 200 }
18
+ """
19
+ When I run `gcli auth ls --login=piotr --password=secret`
20
+ Then the exit status should be 0
21
+
22
+ Scenario: Get authorization
23
+ Given the Github API server:
24
+ """
25
+ get('/authorizations/1') { status 200 }
26
+ """
27
+ When I run `gcli auth get 1 --login=piotr --password=secret`
28
+ Then the exit status should be 0
29
+
30
+ Scenario: Create authorization
31
+ Given the Github API server:
32
+ """
33
+ post('/authorizations') { status 200 }
34
+ """
35
+ When I run `gcli auth create --scopes=repo --login=piotr --password=secret`
36
+ Then the exit status should be 0
37
+
38
+ Scenario: Update authorization
39
+ Given the Github API server:
40
+ """
41
+ patch('/authorizations/1') { status 200 }
42
+ """
43
+ When I run `gcli auth update 1 --scopes=repo --login=piotr --password=secret`
44
+ Then the exit status should be 0
45
+
46
+ Scenario: Delete authorization
47
+ Given the Github API server:
48
+ """
49
+ delete('/authorizations/1') { status 200 }
50
+ """
51
+ When I run `gcli auth delete 1 --login=piotr --password=secret`
52
+ Then the exit status should be 0
53
+
@@ -21,5 +21,5 @@ Feature: gcli blob
21
21
  """
22
22
  post('/repos/wycats/thor/git/blobs') { status 200 }
23
23
  """
24
- When I run `gcli blob create wycats thor --params=content:'Content' encoding:'utf-8'`
24
+ When I run `gcli blob create wycats thor --content=Content --encoding='utf-8'`
25
25
  Then the exit status should be 0
@@ -1,14 +1,15 @@
1
1
  Feature: gcli download
2
2
 
3
+ @ci-run
3
4
  Scenario: Available commands
4
5
 
5
6
  When I run `gcli download`
6
7
  Then the exit status should be 0
7
- And the output should contain "gcli download create"
8
- And the output should contain "gcli download delete"
9
- And the output should contain "gcli download get"
10
- And the output should contain "gcli download list"
11
- And the output should contain "gcli download upload"
8
+ And the output should contain "download create"
9
+ And the output should contain "download delete"
10
+ And the output should contain "download get"
11
+ And the output should contain "download list"
12
+ And the output should contain "download upload"
12
13
 
13
14
  Scenario: List downloads
14
15
  Given the GitHub API server:
@@ -26,18 +27,19 @@ Feature: gcli download
26
27
  When I run `gcli download get wycats thor 1`
27
28
  Then the exit status should be 0
28
29
 
29
- Scenario: Delete download
30
+ Scenario: Create download
30
31
  Given the GitHub API server:
31
32
  """
32
- delete('/repos/wycats/thor/downloads/1') { status 200 }
33
+ post('/repos/wycats/thor/downloads') { status 200 }
33
34
  """
34
- When I run `gcli download delete wycats thor 1`
35
+ When I run `gcli download create wycats thor --name=octo.jpg --size=113410`
35
36
  Then the exit status should be 0
36
37
 
37
- Scenario: Create download
38
+ Scenario: Delete download
38
39
  Given the GitHub API server:
39
40
  """
40
- post('/repos/wycats/thor/downloads') { status 200 }
41
+ delete('/repos/wycats/thor/downloads/1') { status 200 }
41
42
  """
42
- When I run `gcli download create wycats thor --params=name:octo.jpg size:113410`
43
+ When I run `gcli download delete wycats thor 1`
43
44
  Then the exit status should be 0
45
+
@@ -32,11 +32,19 @@ Feature: gcli gist
32
32
  Then the exit status should be 0
33
33
 
34
34
  Scenario: List public gists for the authenticated user
35
+ Given the GitHub API server:
36
+ """
37
+ get('/gists') { status 200 }
38
+ """
39
+ When I run `gcli gist ls --login=piotr --password=secret`
40
+ Then the exit status should be 0
41
+
42
+ Scenario: List all public gists
35
43
  Given the GitHub API server:
36
44
  """
37
45
  get('/gists/public') { status 200 }
38
46
  """
39
- When I run `gcli gist ls`
47
+ When I run `gcli gist ls --public`
40
48
  Then the exit status should be 0
41
49
 
42
50
  Scenario: Get gist
@@ -1,19 +1,18 @@
1
1
  Feature: gcli label
2
2
 
3
+ @ci-run
3
4
  Scenario: Available commands
4
5
 
5
6
  When I run `gcli label`
6
7
  Then the exit status should be 0
7
- And the output should contain "gcli label add"
8
- And the output should contain "gcli label create"
9
- And the output should contain "gcli label delete"
10
- And the output should contain "gcli label get"
11
- And the output should contain "gcli label issue"
12
- And the output should contain "gcli label list"
13
- And the output should contain "gcli label milestone"
14
- And the output should contain "gcli label remove"
15
- And the output should contain "gcli label replace"
16
- And the output should contain "gcli label update"
8
+ And the output should contain "label add"
9
+ And the output should contain "label create"
10
+ And the output should contain "label delete"
11
+ And the output should contain "label get"
12
+ And the output should contain "label list"
13
+ And the output should contain "label remove"
14
+ And the output should contain "label replace"
15
+ And the output should contain "label update"
17
16
 
18
17
  Scenario: List labels
19
18
  Given the GitHub API server:
@@ -36,7 +35,7 @@ Feature: gcli label
36
35
  """
37
36
  post('/repos/wycats/thor/labels') { status 200 }
38
37
  """
39
- When I run `gcli label create wycats thor --params=name:bug color:f3f3f3`
38
+ When I run `gcli label create wycats thor --name=bug --color=f3f3f3`
40
39
  Then the exit status should be 0
41
40
 
42
41
  Scenario: Update label
@@ -44,7 +43,7 @@ Feature: gcli label
44
43
  """
45
44
  patch('/repos/wycats/thor/labels/1') { status 200 }
46
45
  """
47
- When I run `gcli label update wycats thor 1 --params=name:bug color:f3f3f3`
46
+ When I run `gcli label update wycats thor 1 --name=bug --color=f3f3f3`
48
47
  Then the exit status should be 0
49
48
 
50
49
  Scenario: Delete label
@@ -1,13 +1,14 @@
1
1
  Feature: gcli member
2
2
 
3
+ @ci-run
3
4
  Scenario: Available commands
4
5
 
5
6
  When I run `gcli member`
6
7
  Then the exit status should be 0
7
- And the output should contain "gcli member delete"
8
- And the output should contain "gcli member list"
9
- And the output should contain "gcli member member"
10
- And the output should contain "gcli member publicize"
8
+ And the output should contain "member delete"
9
+ And the output should contain "member list"
10
+ And the output should contain "member member"
11
+ And the output should contain "member publicize"
11
12
 
12
13
  Scenario: List members
13
14
  Given the GitHub API server:
@@ -1,10 +1,11 @@
1
1
  Feature: gcli merge
2
2
 
3
+ @ci-run
3
4
  Scenario: Available commands
4
5
 
5
6
  When I run `gcli merge`
6
7
  Then the exit status should be 0
7
- And the output should contain "gcli merge perform"
8
+ And the output should contain "merge perform"
8
9
 
9
10
  Scenario: Merge success
10
11
  Given the GitHub API server:
@@ -15,7 +16,7 @@ Feature: gcli merge
15
16
  status 201
16
17
  }
17
18
  """
18
- When I successfully run `gcli merge perform wycats thor --params=base:master head:cool_feature`
19
+ When I successfully run `gcli merge perform wycats thor --base=master --head=cool_feature`
19
20
  Then the stdout should contain "octokit"
20
21
  And the stdout should contain "201"
21
22
 
@@ -26,7 +27,7 @@ Feature: gcli merge
26
27
  status 204
27
28
  }
28
29
  """
29
- When I successfully run `gcli merge perform wycats thor --params=base:master head:cool_feature`
30
+ When I successfully run `gcli merge perform wycats thor --base=master --head=cool_feature`
30
31
  Then the stdout should contain "204"
31
32
 
32
33
  Scenario: Merge conflict
@@ -37,7 +38,7 @@ Feature: gcli merge
37
38
  status 409
38
39
  }
39
40
  """
40
- When I run `gcli merge perform wycats thor --params=base:master head:cool_feature`
41
+ When I run `gcli merge perform wycats thor --base=master --head=cool_feature`
41
42
  Then the exit status should be 1
42
43
  Then the stdout should contain "Merge conflict"
43
44
  And the stdout should contain "409"
@@ -1,12 +1,13 @@
1
1
  Feature: gcli org
2
2
 
3
+ @ci-run
3
4
  Scenario: Available commands
4
5
 
5
6
  When I run `gcli org`
6
7
  Then the exit status should be 0
7
- And the output should contain "gcli org edit"
8
- And the output should contain "gcli org list"
9
- And the output should contain "gcli org get"
8
+ And the output should contain "org edit"
9
+ And the output should contain "org list"
10
+ And the output should contain "org get"
10
11
 
11
12
  Scenario: List public organizations for a user
12
13
  Given the GitHub API server:
@@ -37,5 +38,5 @@ Feature: gcli org
37
38
  """
38
39
  patch('/orgs/rails') { status 200 }
39
40
  """
40
- When I run `gcli org edit rails --params=name:github company:GitHub email:support@github.com`
41
+ When I run `gcli org edit rails --name=github --company=GitHub --email=support@github.com`
41
42
  Then the exit status should be 0
@@ -21,7 +21,15 @@ Feature: gcli repository
21
21
  """
22
22
  get('/repositories') { status 200 }
23
23
  """
24
- When I run `gcli repo ls`
24
+ When I run `gcli repo ls --every`
25
+ Then the exit status should be 0
26
+
27
+ Scenario: List all repositories for the authenticated user
28
+ Given the GitHub API server:
29
+ """
30
+ get('/user/repos') { status 200 }
31
+ """
32
+ When I run `gcli repo ls --login=piotr --password=secret`
25
33
  Then the exit status should be 0
26
34
 
27
35
  Scenario: List repositories for user
@@ -1,13 +1,14 @@
1
1
  Feature: gcli search
2
2
 
3
+ @ci-run
3
4
  Scenario: Available commands
4
5
 
5
6
  When I run `gcli search`
6
7
  Then the exit status should be 0
7
- And the output should contain "gcli search email"
8
- And the output should contain "gcli search issue"
9
- And the output should contain "gcli search repo"
10
- And the output should contain "gcli search user"
8
+ And the output should contain "search email"
9
+ And the output should contain "search issue"
10
+ And the output should contain "search repo"
11
+ And the output should contain "search user"
11
12
 
12
13
  Scenario: Search issues
13
14
  Given the GitHub API server:
data/github_cli.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.require_paths = ["lib"]
18
18
  gem.version = GithubCLI::VERSION
19
19
 
20
- gem.add_dependency 'github_api', '~> 0.9'
20
+ gem.add_dependency 'github_api', '~> 0.10'
21
21
 
22
22
  gem.add_development_dependency 'rspec'
23
23
  gem.add_development_dependency 'aruba'
@@ -5,64 +5,71 @@ module GithubCLI
5
5
  # The API class is the main entry point for creating GithubCLI APIs.
6
6
  class API
7
7
 
8
- class << self
9
-
10
- # Access or initialize Github API client
11
- #
12
- # @api public
13
- def github_api(options={})
14
- @github_api ||= begin
15
- @github_api = configure(options)
16
- end
17
- end
18
-
19
- # this could become a command such as configure that gets class options
20
- #
21
- # @api public
22
- def configure(options={})
23
- api = Github.new
24
- config = GithubCLI.config.data
25
-
26
- api.oauth_token = config['user.token'] if config['user.token']
8
+ # Access or initialize Github API client
9
+ #
10
+ # @api public
11
+ def self.github_api(options={})
12
+ @github_api ||= configure(options)
13
+ end
27
14
 
28
- api.basic_auth = set_basic_auth(config, options)
15
+ # Configures api options if provided in the configuration file
16
+ #
17
+ # @api public
18
+ def self.configure(options={})
19
+ api = Github.new
20
+ config = GithubCLI.config
29
21
 
30
- api.endpoint = config['core.endpoint'] if config['core.endpoint']
22
+ api.basic_auth = set_basic_auth(config, options)
23
+ api.ssl = config['core.ssl'] if config['core.ssl']
24
+ api.adapter = config['core.adapter'] if config['core.adapter']
25
+ api.oauth_token = config['user.token'] if config['user.token']
26
+ api.site = config['core.site'] if config['core.site']
27
+ api.endpoint = config['core.endpoint'] if config['core.endpoint']
28
+ api.auto_pagination = options['auto_pagination'] || config['core.auto_pagination']
31
29
 
32
- if ENV['TEST_HOST']
33
- api.endpoint = 'http://' + ENV['TEST_HOST']
34
- end
35
- api
30
+ if (test_env = ENV['TEST_HOST'])
31
+ api.endpoint = 'http://' + test_env
36
32
  end
33
+ api
34
+ end
37
35
 
38
- # Set user basic authentication
39
- #
40
- # @api public
41
- def set_basic_auth(config, options)
42
- if options['login'] && options['password']
43
- "#{options['login']}:#{options['password']}"
44
- elsif config['user.login'] && config['user.password']
45
- "#{config['user.login']}:#{config['user.password']}"
46
- else
47
- nil
48
- end
36
+ # Set user basic authentication
37
+ #
38
+ # @api public
39
+ def self.set_basic_auth(config, options)
40
+ if (login = options['login']) && (password = options['password'])
41
+ "#{login}:#{password}"
42
+ elsif (login = config['user.login']) && (password = config['user.password'])
43
+ "#{login}:#{password}"
44
+ else
45
+ nil
49
46
  end
47
+ end
50
48
 
51
- # Procoess response and output to shell
52
- # TODO: change to take options
53
- # @api public
54
- def output(format=:table, quiet=false, &block)
55
- GithubCLI.on_error do
56
- response = block.call
57
- if response.respond_to?(:body)
58
- formatter = Formatter.new response, :format => format, :quiet => quiet
59
- formatter.render_output
60
- else
61
- response
62
- end
49
+ # Procoess response and output to shell
50
+ #
51
+ # @param [Hash] options the options to format the output
52
+ # @option options [String] :format
53
+ # The format type
54
+ # @option options [String] :quiet
55
+ # The flag for reducing the output
56
+ #
57
+ # @api public
58
+ def self.output(options, &block)
59
+ config = GithubCLI.config
60
+ format = options.fetch(:format) { config['core.format'] || :table }
61
+ quiet = options.fetch(:quiet) { config['core.quiet'] }
62
+
63
+ GithubCLI.on_error do
64
+ response = block.call
65
+ if response.respond_to?(:body)
66
+ formatter = Formatter.new response, :format => format, :quiet => quiet
67
+ formatter.render_output
68
+ else
69
+ Terminal.line response
63
70
  end
71
+ response
64
72
  end
65
-
66
73
  end
67
74
 
68
75
  end # API
@@ -5,15 +5,15 @@ module GithubCLI
5
5
 
6
6
  class << self
7
7
 
8
- def all(user, repo, params, format)
9
- output format do
10
- github_api.issues.assignees.list user, repo, params
8
+ def all(user, repo, params, options)
9
+ output options do
10
+ github_api(options).issues.assignees.list user, repo, params
11
11
  end
12
12
  end
13
13
 
14
- def check(user, repo, assignee, params, format)
15
- output format do
16
- github_api.issues.assignees.check user, repo, assignee, params
14
+ def check(user, repo, assignee, params, options)
15
+ output options do
16
+ github_api(options).issues.assignees.check user, repo, assignee, params
17
17
  end
18
18
  end
19
19
  end
@@ -6,31 +6,31 @@ module GithubCLI
6
6
  class << self
7
7
 
8
8
  def all(params, options)
9
- output options[:format], options[:quiet] do
9
+ output options do
10
10
  github_api(options).oauth.list params
11
11
  end
12
12
  end
13
13
 
14
14
  def get(id, params, options)
15
- output options[:format], options[:quiet] do
15
+ output options do
16
16
  github_api(options).oauth.get id, params
17
17
  end
18
18
  end
19
19
 
20
20
  def create(params, options)
21
- output options[:format], options[:quiet] do
21
+ output options do
22
22
  github_api(options).oauth.create params
23
23
  end
24
24
  end
25
25
 
26
26
  def update(id, params, options)
27
- output options[:format], options[:quiet] do
27
+ output options do
28
28
  github_api(options).oauth.update id, params
29
29
  end
30
30
  end
31
31
 
32
32
  def delete(id, params, options)
33
- output options[:format], options[:quiet] do
33
+ output options do
34
34
  github_api(options).oauth.delete id, params
35
35
  end
36
36
  end
@@ -5,15 +5,15 @@ module GithubCLI
5
5
 
6
6
  class << self
7
7
 
8
- def get(user, repo, sha, params, format)
9
- output format do
10
- github_api.git_data.blobs.get user, repo, sha, params
8
+ def get(user, repo, sha, params, options)
9
+ output options do
10
+ github_api(options).git_data.blobs.get user, repo, sha, params
11
11
  end
12
12
  end
13
13
 
14
- def create(user, repo, params, format)
15
- output format do
16
- github_api.git_data.blobs.create user, repo, params
14
+ def create(user, repo, params, options)
15
+ output options do
16
+ github_api(options).git_data.blobs.create user, repo, params
17
17
  end
18
18
  end
19
19
  end