reponaut 2.0.0 → 2.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 985b9da1a543fc796c3ce12f0905e43cf20abb43
4
- data.tar.gz: 7655ae1f153449137992b2a03f8be9fdcb9cbc77
3
+ metadata.gz: ca3c8d9d91d3d659a13788b5173fc39b670e4124
4
+ data.tar.gz: 7b423f8199715b9d3fe97e33e86e5aaaa82bb7be
5
5
  SHA512:
6
- metadata.gz: 9bc1b74370e8d307a6e297745b3ccc7c983edf91823144c38a5b34a1fe0cd2783fe4ec40843570ba822e6b08c3fe172d27e268294751581f4ab65aea01d54424
7
- data.tar.gz: 1edef2e6384a54b7c907ec4e6d0c62e6b9bda58690baf7a5a237c0a042bbe98c38ad690018e56486f8f0f2207c14954f5a6dd5d8f4479748129e6dc73625f2f8
6
+ metadata.gz: 99ee34463141ccde3352c27b06ab141473af74061cb4a0a2789b0b3b836ffae3db4ca998a8a80352a19ddfa75581a3b3b32ba4e56d97dffb43c0a88eff0feba5
7
+ data.tar.gz: 724c5e848bf24285f45083e5e57255f49f6a77c5063ec418c5deb491c80244278d94da93a88ddfdd76474dd15a59a63168a9307829071aa9807bec107a7b12c1
@@ -62,6 +62,64 @@ Feature: List repos for a given language
62
62
  zanegort
63
63
  """
64
64
 
65
+ Scenario: Show languages for all repositories
66
+ Given the GitHub service returns repository data for the user "mdippery"
67
+ When I run `reponaut ls -l mdippery`
68
+ Then it should pass with:
69
+ """
70
+ 3ddv [Java]
71
+ blackout [Objective-C]
72
+ bucknellbug [Objective-C]
73
+ chameleon [Clojure]
74
+ collections [Objective-C]
75
+ dnsimple-python -> tbunnyman/dnsimple-python [Python]
76
+ dotfiles [Perl]
77
+ glitz [Python]
78
+ homebrew-self [Ruby]
79
+ karmanaut [Clojure]
80
+ libtar [C]
81
+ nginx.vim -> vim-scripts/nginx.vim [VimL]
82
+ rack-pesticide [Ruby]
83
+ rainyday [Objective-C]
84
+ reponaut [Python]
85
+ Smyck-Color-Scheme -> hukl/Smyck-Color-Scheme [VimL]
86
+ snodes [Java]
87
+ squash [Objective-C]
88
+ stackim [JavaScript]
89
+ staticgenerator -> mrj0/staticgenerator [Python]
90
+ usaidwat [Ruby]
91
+ vimfiles [VimL]
92
+ whitman [Clojure]
93
+ zanegort [Erlang]
94
+ """
95
+
96
+ Scenario: Show languages for all repositories without forks
97
+ Given the GitHub service returns repository data for the user "mdippery"
98
+ When I run `reponaut ls -lf mdippery`
99
+ Then it should pass with:
100
+ """
101
+ 3ddv [Java]
102
+ blackout [Objective-C]
103
+ bucknellbug [Objective-C]
104
+ chameleon [Clojure]
105
+ collections [Objective-C]
106
+ dotfiles [Perl]
107
+ glitz [Python]
108
+ homebrew-self [Ruby]
109
+ karmanaut [Clojure]
110
+ libtar [C]
111
+ rack-pesticide [Ruby]
112
+ rainyday [Objective-C]
113
+ reponaut [Python]
114
+ snodes [Java]
115
+ squash [Objective-C]
116
+ stackim [JavaScript]
117
+ usaidwat [Ruby]
118
+ vimfiles [VimL]
119
+ whitman [Clojure]
120
+ zanegort [Erlang]
121
+ """
122
+
65
123
  Scenario: Describe all repositories
66
124
  Given the GitHub service returns repository data for the user "mdippery"
67
125
  When I run `reponaut ls -d mdippery`
@@ -234,11 +292,20 @@ Feature: List repos for a given language
234
292
  vimfiles
235
293
  """
236
294
 
295
+ Scenario: List repositories for a given user with no results
296
+ Given the GitHub service returns repository data for the user "emptyuser"
297
+ When I run `reponaut ls emptyuser`
298
+ Then the exit status should not be 0
299
+ And the output should contain exactly:
300
+ """
301
+ emptyuser has no repositories
302
+ """
303
+
237
304
  Scenario: List repositories in a given language with no results
238
305
  Given the GitHub service returns repository data for the user "mdippery"
239
306
  When I run `reponaut ls mdippery C++`
240
307
  Then the exit status should not be 0
241
- And the output should contain:
308
+ And the output should contain exactly:
242
309
  """
243
310
  mdippery has no repositories written in C++
244
311
  """
@@ -251,3 +318,12 @@ Feature: List repos for a given language
251
318
  """
252
319
  GitHub rate limit exceeded. Try your request again later.
253
320
  """
321
+
322
+ Scenario: List both descriptions and languages for a given user
323
+ Given the GitHub service returns repository data for the user "mdippery"
324
+ When I run `reponaut ls -ld mdippery`
325
+ Then the exit status should not be 0
326
+ And the output should contain exactly:
327
+ """
328
+ Only one of -l and -d may be specified
329
+ """
@@ -8,6 +8,7 @@ module Reponaut
8
8
  c.description "List a user's repos"
9
9
  c.option 'ignore_forks', '-f', 'Ignore forks'
10
10
  c.option 'show_description', '-d', 'Show repo description'
11
+ c.option 'show_language', '-l', 'Show repo language'
11
12
 
12
13
  c.action do |args, options|
13
14
  process(options, args)
@@ -20,9 +21,15 @@ module Reponaut
20
21
 
21
22
  language = args[1]
22
23
 
24
+ quit 6, 'Only one of -l and -d may be specified' if options['show_description'] && options['show_language']
25
+
23
26
  filtered_repos = repos
24
27
  filtered_repos = filtered_repos.select { |r| r.language.downcase == language.downcase } if language
25
- quit 4, "#{username} has no repositories written in #{language}" if filtered_repos.empty?
28
+ if filtered_repos.empty?
29
+ msg = "#{username} has no repositories"
30
+ msg += " written in #{language}" if language
31
+ quit 4, msg
32
+ end
26
33
 
27
34
  formatter = formatter_class(options).new
28
35
  filtered_repos.sort.each do |r|
@@ -33,7 +40,13 @@ module Reponaut
33
40
  private
34
41
 
35
42
  def formatter_class(options)
36
- options['show_description'] ? LongPresenter : SimplePresenter
43
+ if options['show_description']
44
+ LongPresenter
45
+ elsif options['show_language']
46
+ LanguagePresenter
47
+ else
48
+ SimplePresenter
49
+ end
37
50
  end
38
51
  end
39
52
  end
@@ -17,7 +17,7 @@ module Reponaut
17
17
  end
18
18
 
19
19
  def repos
20
- JSON.parse(repo_data).map { |e| Repository.new(self, e) }
20
+ repo_data.map { |e| Repository.new(self, e) }
21
21
  end
22
22
 
23
23
  def to_s
@@ -35,10 +35,31 @@ module Reponaut
35
35
  private
36
36
 
37
37
  def real_repo_data
38
- resp = get("/users/#{username}/repos")
38
+ resp = request_repo_data("/users/#{username}/repos")
39
+ body = JSON.parse(resp.body)
40
+ parse_linked_data(resp, body)
41
+ end
42
+
43
+ def request_repo_data(url)
44
+ resp = get(url)
39
45
  raise NoSuchUserError, username if resp.code == 404
40
46
  raise RateLimitExceededError if resp.code == 403
41
- resp.body
47
+ resp
48
+ end
49
+
50
+ def parse_linked_data(resp, acc)
51
+ return acc unless resp.headers.include?('link')
52
+ links = resp.headers['link'].split(/,/).map { |l| l.strip }
53
+ next_url = links.find { |l| l =~ link_url_re }
54
+ return acc unless next_url
55
+ next_url = next_url.match(link_url_re).captures.first
56
+ resp = request_repo_data(next_url)
57
+ acc += JSON.parse(resp.body)
58
+ parse_linked_data(resp, acc)
59
+ end
60
+
61
+ def link_url_re
62
+ /^<(.+)>; rel="next"$/
42
63
  end
43
64
 
44
65
  def mock_repo_data
@@ -47,7 +68,7 @@ module Reponaut
47
68
  raw_data = IO.read(path)
48
69
  data = YAML.load(raw_data)
49
70
  raise NoSuchUserError, username if data['http_interactions'][0]['response']['status']['code'] == 404
50
- data['http_interactions'][0]['response']['body']['string']
71
+ JSON.parse(data['http_interactions'][0]['response']['body']['string'])
51
72
  end
52
73
 
53
74
  define_method(:repo_data, instance_method(ENV.cucumber? ? :mock_repo_data : :real_repo_data))
@@ -10,6 +10,13 @@ module Reponaut
10
10
 
11
11
  class SimplePresenter < Presenter; end
12
12
 
13
+ class LanguagePresenter < Presenter
14
+ def format(repo)
15
+ line = super
16
+ line += " [#{repo.language}]"
17
+ end
18
+ end
19
+
13
20
  class LongPresenter < Presenter
14
21
  attr_reader :count
15
22
 
@@ -1,3 +1,3 @@
1
1
  module Reponaut
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -4,12 +4,14 @@ module Reponaut
4
4
  module Application
5
5
  describe 'Presenters' do
6
6
  let (:repo) { double('repo', :name => '3ddv',
7
- :description => 'NEES 3D Data Viewer from the Center for Earthquake Engineering Simulation at RPI',
8
- :fork? => false) }
7
+ :description => 'NEES 3D Data Viewer from the Center for Earthquake Engineering Simulation at RPI',
8
+ :fork? => false,
9
+ :language => 'Java') }
9
10
  let (:fork) { double('repo', :name => 'mercenary',
10
- :description => 'An easier way to build your command-line scripts in Ruby.',
11
- :fork? => true,
12
- :upstream => 'jekyll/mercenary') }
11
+ :description => 'An easier way to build your command-line scripts in Ruby.',
12
+ :fork? => true,
13
+ :upstream => 'jekyll/mercenary',
14
+ :language => 'Ruby') }
13
15
 
14
16
  describe SimplePresenter do
15
17
  let (:formatter) { SimplePresenter.new }
@@ -23,6 +25,18 @@ module Reponaut
23
25
  end
24
26
  end
25
27
 
28
+ describe LanguagePresenter do
29
+ let (:formatter) { LanguagePresenter.new }
30
+
31
+ it "prints the repo's name and language" do
32
+ expect(formatter.format(repo)).to eq('3ddv [Java]')
33
+ end
34
+
35
+ it "prints the repo's name and language and the name of the upstream repo if the repo is a fork" do
36
+ expect(formatter.format(fork)).to eq('mercenary -> jekyll/mercenary [Ruby]')
37
+ end
38
+ end
39
+
26
40
  describe LongPresenter do
27
41
  let (:formatter) { LongPresenter.new }
28
42
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reponaut
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Dippery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-29 00:00:00.000000000 Z
11
+ date: 2017-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -183,9 +183,9 @@ homepage: https://github.com/mdippery/reponaut
183
183
  licenses:
184
184
  - MIT
185
185
  metadata:
186
- build_date: 2016-08-28 17:52:49 PDT
187
- commit: v2.0.0
188
- commit_hash: df5fa0aefe17ed3033928aad6e6ea2b0450416b1
186
+ build_date: 2017-03-05 18:44:49 PST
187
+ commit: v2.1.0
188
+ commit_hash: 3c46cd939ddbc9ae8d3fd06ce6d3c86b153533f6
189
189
  post_install_message:
190
190
  rdoc_options: []
191
191
  require_paths: