github_issue_stats 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e44a369c67f5f5183e8cd90f26d8fc204e41a4eb
4
- data.tar.gz: 98ac378482af845a7d3b564bb98576c34f6b7112
3
+ metadata.gz: ae17636f4ac0fbedef888f294dc9a493e2dd1c88
4
+ data.tar.gz: 19b0639e7a6341f463dc784f631a9b193af550af
5
5
  SHA512:
6
- metadata.gz: 4d1147b5ccf451cad07c2b455ffe08ad657fdf54d82e95eab9329625a2128ab56c66eb66414d7d8e2c87df18d8251a03a3e66db86e295c4396291c2a11c8782a
7
- data.tar.gz: 293fce8c08876c7207cb30b0662bef63ad392395ac08bbcdafed6c89b033a0f6cc4bd7559b7c8a4ff8a8b00c75d2cae2fdc1d9ce518f87e4d19e395932da275b
6
+ metadata.gz: ab26cc8b8bb2832c6a86fc35e400379e477455a142e06378915cdc4910cb2a6cff2d511b3de999967a3986dbba1e581ddee79d6249d028646cf6971a7a5faa3e
7
+ data.tar.gz: 9eb615a02c1ffd81ba6621def0b510d219d693743e87f3df161898e83491ea4bacf99115de7f38be3a3ad2f3c11e90bc2b3e9c1801ea2a455c520dd8e31a8132
@@ -1,108 +1,65 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require "commander"
3
4
  require "optparse"
4
5
  require "github_issue_stats"
5
6
 
6
7
  ARGV.push('-h') if ARGV.empty?
7
8
 
8
- options = {}
9
+ cli = HighLine.new($stdin, $stderr)
9
10
 
10
- options[:verbose] = false
11
- options[:output_format] = 'text'
12
- options[:token] = ENV["GITHUB_OAUTH_TOKEN"]
13
- options[:labels] = "issues"
14
- options[:interval_length] = "1w"
15
- options[:interval_count] = 4
11
+ Commander.configure do
12
+ program :name, 'GitHub Issue Stats'
13
+ program :version, GitHubIssueStats::VERSION
14
+ program :description, 'Simple program for collecting stats on issues in GitHub repositories.'
16
15
 
17
- opt_parser = OptionParser.new do |opts|
18
- opts.banner = "GitHub Issue Stats -- simple program for collecting stats on issues in GitHub repositories.\n\nUsage: github_issue_stats [options]"
16
+ global_option '--verbose', "Enable output of detailed debugging information to STDERR"
17
+ global_option '--token STRING', String, "GitHub OAuth token for making API calls. If not specified, the GITHUB_OAUTH_TOKEN environment variable is used. Create a token here: https://github.com/settings/token"
19
18
 
20
- opts.separator ""
21
- opts.separator "Specific options:"
19
+ command :history do |c|
20
+ c.syntax = 'github_issue_stats history [options]'
21
+ c.description = 'Collect stats on number of open issues over time'
22
22
 
23
- opts.on("-t", "--token [STRING]", String,
24
- "GitHub OAuth token for making API calls. If not specified,",
25
- "the GITHUB_OAUTH_TOKEN environment variable is used.",
26
- "Create a token here: https://github.com/settings/token", "\n") do |token|
27
- options[:token] = token
28
- end
23
+ c.option '-s', '--scopes x,y,z', Array, "(required) List of scopes for which stats will be collected. A scope is a username or repo name. Example: --scopes github,rails/rails"
24
+ c.option '-l', '--labels [x,y,z]', Array, "List of labels for which stats will be collected for each scope. A label is an issue or pull request label, or special values 'issues' and 'pulls' representing all issues and all pull requests within the scope respectively. Default: 'issues'."
25
+ c.option '-i', '--interval_length [STRING]', String, "Size of interval for which stats will be aggregated. Intervals are defined with N[hdwmy], where h is hour, d is day, w is week m is month, y is year, and N is a positive integer used as a multiplier. Default: '1w'."
26
+ c.option '-n', '--interval_count [INTEGER]', Integer, "Number of intervals for which stats will be collected. Default: 4."
27
+ c.option '-o', '--output_format [STRING]', String, "Format used for output tables with collected stats. Can be 'text' or 'markdown'."
29
28
 
30
- opts.on("-s", "--scopes x,y,z", Array,
31
- "List of scopes for which stats will be collected. A scope is",
32
- "a username or repo name. Example: --scopes github,rails/rails", "\n") do |scopes|
33
- options[:scopes] = scopes
34
- end
29
+ c.example "Statistics for the atom organization, for issues, pull requests, bug and enhancement labels, going back four one-week intervals, with Markdown output", "github_issue_stats history -s atom -l issues,bug,enhancement,pulls -i 1w -n 4 -o markdown"
35
30
 
36
- opts.on("-l", "--labels [x,y,z]", Array,
37
- "List of labels for which stats will be collected for each",
38
- "scope. A label is an issue or pull request label, or special",
39
- "values 'issues' and 'pulls' representing all issues and all",
40
- "pull requests within the scope respectively. Default: 'issues'.",
41
- "Example: --labels issues,bug,pulls", "\n") do |labels|
42
- options[:labels] = labels
43
- end
31
+ c.action do |args, options|
32
+ options.default \
33
+ :verbose => false,
34
+ :token => ENV["GITHUB_OAUTH_TOKEN"],
35
+ :output_format => 'text',
36
+ :labels => "issues",
37
+ :interval_length => "1w",
38
+ :interval_count => 4
44
39
 
45
- opts.on("-i", "--interval_length [STRING]", String,
46
- "Size of interval for which stats will be aggregated. Intervals",
47
- "are defined with N[hdwmy], where h is hour, d is day, w is week",
48
- "m is month, y is year, and N is a positive integer used as a",
49
- "multiplier. Default: '1w'. Example: --interval_length 4d", "\n") do |interval_length|
50
- options[:interval_length] = interval_length
51
- end
40
+ options.scopes = Array(options.scopes)
41
+ options.labels = Array(options.labels)
52
42
 
53
- opts.on("-n", "--interval_count [INTEGER]", Integer,
54
- "Number of intervals for which stats will be collected.",
55
- "Default: 4. Example: --interval_count 2", "\n") do |interval_count|
56
- options[:interval_count] = interval_count
57
- end
43
+ raise ArgumentError.new("--token is required") if options.token.nil?
44
+ raise ArgumentError.new("invalid --token format") unless /\A\h{40}\z/.match(options.token)
45
+ raise ArgumentError.new("--scopes is required") if options.scopes.nil?
46
+ raise ArgumentError.new("invalid --interval_length format") unless /\A\d[hdwmy]\z/.match(options.interval_length)
47
+ raise ArgumentError.new("invalid --interval_count format") if options.interval_count.nil? || options.interval_count < 1
48
+ raise ArgumentError.new("invalid --output_format") unless /\A(text)|(markdown)\z/.match(options.output_format)
58
49
 
59
- opts.on("-o", "--output_format [STRING]", String,
60
- "Format used for output tables with collected stats. Can be",
61
- "'text' or 'markdown'. Default: 'text'. Example: -o markdown", "\n") do |output_format|
62
- options[:output_format] = output_format
63
- end
50
+ github_issue_stats = GitHubIssueStats.new(options.token, options.verbose)
64
51
 
65
- opts.on("--[no-]verbose", "Enable output of detailed debugging information to STDERR", "\n") do |verbose|
66
- options[:verbose] = verbose
67
- end
52
+ STDERR.print "Collecting stats..."
53
+ STDERR.flush
68
54
 
69
- opts.on_tail("-h", "--help", "Show this message", "\n") do
70
- STDERR.puts(opts)
71
- exit
72
- end
55
+ stats = github_issue_stats.get_history_statistics(options.__hash__)
56
+ tables = github_issue_stats.generate_tables(stats, options.__hash__)
73
57
 
74
- opts.on_tail("-v", "--version", "Show version", "\n") do
75
- STDERR.puts(GitHubIssueStats::VERSION)
76
- exit
77
- end
78
- end
58
+ for scope, table in tables
59
+ puts "\n#{scope} stats:\n\n#{table}"
60
+ end
79
61
 
80
- opt_parser.parse!
81
-
82
- def log_input_error(message, opt_parser)
83
- STDERR.puts("ERROR: #{message}\n\n")
84
- STDERR.puts(opt_parser)
85
- exit
86
- end
87
-
88
- log_input_error("--token is required", opt_parser) if options[:token].nil?
89
- log_input_error("invalid --token format", opt_parser) unless /\A\h{40}\z/.match(options[:token])
90
- log_input_error("--scopes is required", opt_parser) if options[:scopes].nil?
91
- log_input_error("invalid --interval_length format", opt_parser) unless /\A\d[hdwmy]\z/.match(options[:interval_length])
92
- log_input_error("invalid --interval_count format", opt_parser) if options[:interval_count].nil? || options[:interval_count] < 1
93
- log_input_error("invalid --output_format", opt_parser) unless /\A(text)|(markdown)\z/.match(options[:output_format])
94
-
95
- options[:scopes] = Array(options[:scopes])
96
- options[:labels] = Array(options[:labels])
97
-
98
- github_issue_stats = GitHubIssueStats.new(options[:token], options[:verbose])
99
-
100
- STDERR.print "Collecting stats..."
101
- STDERR.flush
102
-
103
- stats = github_issue_stats.get_statistics(options)
104
- tables = github_issue_stats.generate_tables(stats, options)
105
-
106
- for scope, table in tables
107
- puts "\n#{scope} stats:\n\n#{table}"
62
+ cli.say("Done!")
63
+ end
64
+ end
108
65
  end
@@ -30,7 +30,7 @@ module Enumerable
30
30
  end
31
31
 
32
32
  class GitHubIssueStats
33
- VERSION = "0.2.0"
33
+ VERSION = "0.3.0"
34
34
 
35
35
  attr_accessor :client, # Octokit client for acesing the API
36
36
  :logger, # Logger for writing debugging info
@@ -89,7 +89,7 @@ class GitHubIssueStats
89
89
  # }
90
90
  # ]
91
91
  #
92
- def get_statistics(options)
92
+ def get_history_statistics(options)
93
93
  # number_of_calls = get_required_number_of_api_calls(options)
94
94
  # @sleep_period = get_api_calls_sleep(number_of_calls)
95
95
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github_issue_stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Zuzak
@@ -10,6 +10,20 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: commander
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.3'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: octokit
15
29
  requirement: !ruby/object:Gem::Requirement