New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option for file/STDIN to allow for third party chart data #31

Merged
merged 12 commits into from Sep 2, 2014

Conversation

Projects
None yet
3 participants
@Stantheman
Contributor

Stantheman commented Sep 1, 2014

This adds a -i/--input flag that takes a file or STDIN. In concert with something like fakehubstats, this would allow githubchart to create graphs of non-public or even non-git related streaks.

This is basically my first foray into Ruby, so I'm looking forward to feedback. I still need to add tests.

Stantheman added some commits Sep 1, 2014

@@ -9,8 +9,37 @@ OptionParser.new do |opts|
"Usage: githubchart (-u username) (-t type) path/for/new/image\n"
opts.banner << 'Supported types: ' + GithubChart.supported.join(' ')
opts.on('-uUSER', '--user=USER', 'Specify GitHub user to graph') do |user|
if options.has_key?(:input)

This comment has been minimized.

@akerl

akerl Sep 1, 2014

Owner

This should probably be "options.include? :input". has_key works, but include is the more conventional way for testing inclusion.

@coveralls

This comment has been minimized.

coveralls commented Sep 1, 2014

Coverage Status

Coverage remained the same when pulling 536a5dc on Stantheman:stdin into faaa886 on akerl:master.

exit 1
end
unless (input.eql? '-') || (File.exists?(input))

This comment has been minimized.

@akerl

akerl Sep 1, 2014

Owner

You may want to check "If file exists or (input equals '-' and stdin isn't a TTY", for sanity

exit 1
end
if input.eql? '-'

This comment has been minimized.

@akerl

akerl Sep 1, 2014

Owner

You may want to make this and the preceding check one larger block. You can also use "fail "string"" to do the error message and exiting, so you could do something like:

if input.eql? '-'
  fail 'No data provided on stdin' if STDIN.tty?
  contents = STDIN.read
else
  fail 'file does not exist' unless File.exists? input
  contents = File.read input
end
end
begin
contents = JSON.parse(contents)

This comment has been minimized.

@akerl

akerl Sep 1, 2014

Owner

Shadowing variables like this is frowned upon; variables are cheap, I might make them "raw" and "parsed" or similar

params = { username: params } unless params.is_a? Hash
@stats = GithubStats.new(params[:username])
params = { user: params } unless params.is_a? Hash
@stats = params.fetch(:data) { GithubStats.new(params[:user]).data }

This comment has been minimized.

@akerl

akerl Sep 1, 2014

Owner

I'm not 100% sure if I used attributes of GithubStats in the rest of this lib. If I did, you may need to do some cute magic now that it's a GithubStats::Data object.

This comment has been minimized.

@Stantheman

Stantheman Sep 1, 2014

Contributor

I've tried to find where it happens, I'll take a second gander. So far in my flexing of it, I haven't seen it

This comment has been minimized.

@Stantheman

Stantheman Sep 1, 2014

Contributor

Used in a test, coming up

edit: fixed the tests

@coveralls

This comment has been minimized.

coveralls commented Sep 1, 2014

Coverage Status

Coverage remained the same when pulling 8cb998f on Stantheman:stdin into faaa886 on akerl:master.

@coveralls

This comment has been minimized.

coveralls commented Sep 1, 2014

Coverage Status

Coverage remained the same when pulling 01a2a73 on Stantheman:stdin into faaa886 on akerl:master.

@coveralls

This comment has been minimized.

coveralls commented Sep 1, 2014

Coverage Status

Coverage remained the same when pulling ad1bbef on Stantheman:stdin into faaa886 on akerl:master.

Stantheman added some commits Sep 1, 2014

add example input data and replace old username test with tests for c…
…onsuming external data and checking for data creation without external data
@coveralls

This comment has been minimized.

coveralls commented Sep 1, 2014

Coverage Status

Coverage remained the same when pulling 26f3105 on Stantheman:stdin into faaa886 on akerl:master.

@coveralls

This comment has been minimized.

coveralls commented Sep 1, 2014

Coverage Status

Coverage remained the same when pulling 1bc0dff on Stantheman:stdin into faaa886 on akerl:master.

@akerl

This comment has been minimized.

Owner

akerl commented Sep 2, 2014

Welcome to Ruby Club 👍

akerl added a commit that referenced this pull request Sep 2, 2014

Merge pull request #31 from Stantheman/stdin
Add an option for file/STDIN to allow for third party chart data

@akerl akerl merged commit 4b5635c into akerl:master Sep 2, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment