Class: GitHubIssueStats
- Inherits:
-
Object
- Object
- GitHubIssueStats
- Defined in:
- lib/github_issue_stats.rb
Constant Summary collapse
- VERSION =
"0.4.0"
Instance Attribute Summary collapse
-
#client ⇒ Object
Octokit client for acesing the API.
-
#logger ⇒ Object
Octokit client for acesing the API.
-
#sleep_period ⇒ Object
Octokit client for acesing the API.
Instance Method Summary collapse
-
#compute_previous_time(current_time, period) ⇒ Object
Computes the the beginning of the period based on the end of a period.
- #generate_breakdown_tables(stats, options) ⇒ Object
-
#generate_history_tables(stats, options) ⇒ Object
Generates tables for collected statistics, for easy copy-pasting.
- #generate_markdown_table_string(data) ⇒ Object
- #generate_text_table_string(data) ⇒ Object
-
#get_beginning_of_current_period(current_time, period) ⇒ Object
Returns the timestamps for the beginning of the current period.
- #get_breakdown_statistics(options) ⇒ Object
- #get_breakdown_stats_for_interval(interval, current_timestamp, previous_slice, options) ⇒ Object
- #get_difference_string(stats) ⇒ Object
- #get_headers(labels, scope, output_format) ⇒ Object
-
#get_history_statistics(options) ⇒ Object
Collect and return statistics.
- #get_interval_humanized_name(interval) ⇒ Object
- #get_period_date(timestamp, period_type) ⇒ Object
- #get_period_humanized_name(slice, period_type, index) ⇒ Object
- #get_period_name(slice, intervals, index, type) ⇒ Object
- #get_period_stats(slice, labels, scope, type) ⇒ Object
-
#get_required_number_of_api_calls(options) ⇒ Object
Computes the number of search API calls to collect all the data.
-
#get_search_query_string(options) ⇒ Object
Construct the search query string based on different options.
-
#get_search_total_results(query_string) ⇒ Object
Call Search API for a query and return total number of results.
-
#get_search_url(query_string) ⇒ Object
Returns the github.com URL for viewing the list of issues which match the given query string.
- #get_smallest_period_type(interval_types) ⇒ Object
-
#get_stats_for_interval(previous_slice, options) ⇒ Object
Collects statistics for a single interval.
-
#initialize(token, verbose = false) ⇒ GitHubIssueStats
constructor
A new instance of GitHubIssueStats.
-
#sleep_before_api_call ⇒ Object
Computes the required sleep period to avoid hitting the API rate limits.
Constructor Details
#initialize(token, verbose = false) ⇒ GitHubIssueStats
Returns a new instance of GitHubIssueStats.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/github_issue_stats.rb', line 39 def initialize(token, verbose=false) @logger = Logger.new(STDERR) @logger.sev_threshold = verbose ? Logger::DEBUG : Logger::WARN @logger.debug "Creating new GitHubIssueStats instance." @logger.debug "Creating a new Octokit client with token #{token[0..5]}" begin @client = Octokit::Client.new( :access_token => token, :auto_paginate => true, :user_agent => "GitHubIssueStats/#{VERSION} (@izuzak) #{Octokit.user_agent}" ) @client.rate_limit rescue Octokit:: => exception @logger.error "Token #{token[0..5]} is not valid" raise ArgumentError.new("Token #{token[0..5]} is not valid") end @logger.debug "Token #{token[0..5]} is valid" end |
Instance Attribute Details
#client ⇒ Object
Octokit client for acesing the API
35 36 37 |
# File 'lib/github_issue_stats.rb', line 35 def client @client end |
#logger ⇒ Object
Octokit client for acesing the API
35 36 37 |
# File 'lib/github_issue_stats.rb', line 35 def logger @logger end |
#sleep_period ⇒ Object
Octokit client for acesing the API
35 36 37 |
# File 'lib/github_issue_stats.rb', line 35 def sleep_period @sleep_period end |
Instance Method Details
#compute_previous_time(current_time, period) ⇒ Object
Computes the the beginning of the period based on the end of a period
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/github_issue_stats.rb', line 236 def compute_previous_time(current_time, period) period_number, period_type = [period[0..-2], period[-1]] period_number = Integer(period_number) if period_type == "h" return current_time - period_number * 3600 elsif period_type == "d" return current_time - period_number * 3600 * 24 elsif period_type == "w" return current_time - period_number * 7 * 3600 * 24 elsif period_type == "m" current_date = Date.new(current_time.year, current_time.month, current_time.day) temp_date = current_date for i in 1..period_number previous_date = temp_date.prev_month temp_date = previous_date end previous_time = Time.utc(previous_date.year, previous_date.month, previous_date.day, current_time.hour, current_time.min, current_time.sec) elsif period_type == "y" return Time.utc(current_time.year - period_number, current_time.month, current_time.day, current_time.hour, current_time.min, current_time.sec) else # TODO throw error end end |
#generate_breakdown_tables(stats, options) ⇒ Object
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 |
# File 'lib/github_issue_stats.rb', line 495 def generate_breakdown_tables(stats, ) def get_headers(labels, scope, output_format) if output_format == "markdown" return labels.map do |label| query_string = get_search_query_string({:scope => scope, :label => label, :state => "open"}) "[#{label}](#{get_search_url(query_string)})" end else return labels end end def get_interval_humanized_name(interval) period_number, period_type = [interval[0..-2], interval[-1]] period_number = Integer(period_number) names = { "h" => ["hour", "hours"], "d" => ["day", "days"], "w" => ["week", "weeks"], "m" => ["month", "months"], "y" => ["year", "years"] } if period_number == 1 return "#{period_number} #{names[period_type][0]}" else return "#{period_number} #{names[period_type][1]}" end end def get_period_date(, period_type) if period_type == "h" return .strftime "%Y-%m-%d %H:00" elsif period_type == "d" return .strftime "%Y-%m-%d" elsif period_type == "w" return .strftime "%Y-%m-%d" elsif period_type == "m" return .strftime "%Y-%m" elsif period_type == "y" return .strftime "%Y" else # TODO throw error end end def get_smallest_period_type(interval_types) intervals = ["h", "d", "w", "m", "y"] interval_types_indexes = interval_types.map { |interval_type| intervals.index(interval_type) } interval_types_indexes << 1 return intervals[interval_types_indexes.min] end def get_period_name(slice, intervals, index, type) current_interval = intervals[index] current_period_number, current_period_type = [current_interval[0..-2], current_interval[-1]] current_period_number = Integer(current_period_number) if index == 0 smaller_period_type = get_smallest_period_type([current_period_type]) return "< #{get_interval_humanized_name(current_interval)} (#{get_period_date(slice[:previous_timestamp], smaller_period_type)})" else previous_interval = intervals[index-1] previous_period_number, previous_period_type = [previous_interval[0..-2], previous_interval[-1]] previous_period_number = Integer(previous_period_number) smaller_period_type = get_smallest_period_type([current_period_type, previous_period_type]) return "> #{get_interval_humanized_name(previous_interval)}, < #{get_interval_humanized_name(current_interval)} (#{get_period_date(slice[:previous_timestamp], smaller_period_type)})" end end def get_period_stats(slice, labels, scope, type) return labels.map do |label| if type == "markdown" "[#{slice[scope][label][:interval_still_open_total]}](#{slice[scope][label][:interval_still_open_total_url]})" else "#{slice[scope][label][:interval_still_open_total]}" end end end tables = {} for scope in [:scopes] data = [] data << ["period"] + get_headers([:labels], scope, [:output_format]) stats.each_with_index do |slice, index| data << [get_period_name(slice, [:intervals], index, [:output_format])] + get_period_stats(slice, [:labels], scope, [:output_format]) end tables[scope] = [:output_format] == "markdown" ? generate_markdown_table_string(data) : generate_text_table_string(data) end return tables end |
#generate_history_tables(stats, options) ⇒ Object
Generates tables for collected statistics, for easy copy-pasting
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
# File 'lib/github_issue_stats.rb', line 339 def generate_history_tables(stats, ) def get_headers(labels, scope, output_format) if output_format == "markdown" return labels.map do |label| query_string = get_search_query_string({:scope => scope, :label => label, :state => "open"}) "[#{label}](#{get_search_url(query_string)})" end else return labels end end def get_period_humanized_name(slice, period_type, index) names = { "h" => ["Now", "1 hour ago", "hours"], "d" => ["Today", "Yesterday", "days"], "w" => ["This week", "Last week", "weeks"], "m" => ["This month", "Last month", "months"], "y" => ["This year", "Last year", "years"] } if index < 2 return names[period_type][index] else return "#{index} #{names[period_type][2]} ago" end end def get_period_date(slice, period_type) if period_type == "h" return slice[:previous_timestamp].strftime "%Y-%m-%d %H:00" elsif period_type == "d" return slice[:previous_timestamp].strftime "%Y-%m-%d" elsif period_type == "w" return slice[:previous_timestamp].strftime "%Y-%m-%d" elsif period_type == "m" return slice[:previous_timestamp].strftime "%Y-%m" elsif period_type == "y" return slice[:previous_timestamp].strftime "%Y" else # TODO throw error end end def get_period_name(slice, interval, index, type) period_number, period_type = interval.chars if type == "markdown" return "**#{get_period_humanized_name(slice, period_type, index)}** <br>(#{get_period_date(slice, period_type)})" else return "#{get_period_humanized_name(slice, period_type, index)} (#{get_period_date(slice, period_type)})" end end def get_period_stats(slice, labels, scope, type) def get_difference_string(stats) difference_string = "+#{stats[:interval_new_total]}, -#{stats[:interval_closed_total]}" # TODO: maybe something like this in the future # difference = stats[:interval_new_total] - stats[:interval_closed_total] # difference_string = "#{difference}, +#{stats[:interval_new_total]}, -#{stats[:interval_closed_total]}" # # return "▲" + difference_string if difference > 0 # return "▼" + difference_string if difference < 0 # return "▶" + difference_string end if type == "markdown" return labels.map do |label| "**#{slice[scope][label][:interval_end_total]}** <br>(#{get_difference_string(slice[scope][label])})" end else return labels.map do |label| "#{slice[scope][label][:interval_end_total]} (#{get_difference_string(slice[scope][label])})" end end end tables = {} for scope in [:scopes] data = [] data << ["period"] + get_headers([:labels], scope, [:output_format]) stats.each_with_index do |slice, index| data << [get_period_name(slice, [:interval_length], index, [:output_format])] + get_period_stats(slice, [:labels], scope, [:output_format]) end tables[scope] = [:output_format] == "markdown" ? generate_markdown_table_string(data) : generate_text_table_string(data) end return tables end |
#generate_markdown_table_string(data) ⇒ Object
436 437 438 |
# File 'lib/github_issue_stats.rb', line 436 def generate_markdown_table_string(data) data.to_markdown_table end |
#generate_text_table_string(data) ⇒ Object
432 433 434 |
# File 'lib/github_issue_stats.rb', line 432 def generate_text_table_string(data) return data.to_table(:first_row_is_head => true).to_s end |
#get_beginning_of_current_period(current_time, period) ⇒ Object
Returns the timestamps for the beginning of the current period
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/github_issue_stats.rb', line 213 def get_beginning_of_current_period(current_time, period) period_type = period[1] if period_type == "h" return Time.utc(current_time.year, current_time.month, current_time.day, current_time.hour, 0, 0) elsif period_type == "d" return Time.utc(current_time.year, current_time.month, current_time.day, 0, 0, 0) elsif period_type == "w" current_date = Date.new(current_time.year, current_time.month, current_time.day) previous_date = current_date - (current_date.cwday - 1) previous_time = Time.utc(previous_date.year, previous_date.month, previous_date.day, 0, 0, 0) elsif period_type == "m" return Time.utc(current_time.year, current_time.month, 1, 0, 0, 0) elsif period_type == "y" return Time.utc(current_time.year, 1, 1, 0, 0, 0) else # TODO throw error end end |
#get_breakdown_statistics(options) ⇒ Object
440 441 442 443 444 445 446 447 448 |
# File 'lib/github_issue_stats.rb', line 440 def get_breakdown_statistics() stats = [] = Time.now.utc for interval in [:intervals] stats << get_breakdown_stats_for_interval(interval, , stats[-1], ) end return stats end |
#get_breakdown_stats_for_interval(interval, current_timestamp, previous_slice, options) ⇒ Object
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
# File 'lib/github_issue_stats.rb', line 450 def get_breakdown_stats_for_interval(interval, , previous_slice, ) slice = {} # set timestamps if previous_slice.nil? # initial slice[:current_timestamp] = else # not initial slice[:current_timestamp] = previous_slice[:previous_timestamp] end slice[:previous_timestamp] = compute_previous_time(, interval) for scope in [:scopes] scope_stats = {} slice[scope] = scope_stats for label in [:labels] label_stats = {} scope_stats[label] = label_stats # number of open issues in period = { :scope => scope, :label => label, :state => "open", :created_at => { :from => slice[:previous_timestamp], :until => slice[:current_timestamp] } } query_string = get_search_query_string() label_stats[:interval_still_open_total_url] = get_search_url(query_string) label_stats[:interval_still_open_total] = get_search_total_results(query_string) @logger.debug "Computed total for interval: #{label_stats[:interval_still_open_total]}" end end return slice end |
#get_difference_string(stats) ⇒ Object
393 394 395 396 397 398 399 400 401 402 403 |
# File 'lib/github_issue_stats.rb', line 393 def get_difference_string(stats) difference_string = "+#{stats[:interval_new_total]}, -#{stats[:interval_closed_total]}" # TODO: maybe something like this in the future # difference = stats[:interval_new_total] - stats[:interval_closed_total] # difference_string = "#{difference}, +#{stats[:interval_new_total]}, -#{stats[:interval_closed_total]}" # # return "▲" + difference_string if difference > 0 # return "▼" + difference_string if difference < 0 # return "▶" + difference_string end |
#get_headers(labels, scope, output_format) ⇒ Object
340 341 342 343 344 345 346 347 348 349 |
# File 'lib/github_issue_stats.rb', line 340 def get_headers(labels, scope, output_format) if output_format == "markdown" return labels.map do |label| query_string = get_search_query_string({:scope => scope, :label => label, :state => "open"}) "[#{label}](#{get_search_url(query_string)})" end else return labels end end |
#get_history_statistics(options) ⇒ Object
Collect and return statistics
Input:
options =
:interval_length => "1w", # 1 week interval
:interval_count => 2, # 2 intervals to collect data for
:scopes => ["atom", "atom/atom"], # atom user and atom/atom repo
:labels => ["issues", "pulls", "bug"] # issues, pulls, and bug label
Output:
[
{ # each interval will be represented as hash
:interval_end_timestamp => Time, # end of interval
:interval_start_timestamp => Time, # beginning of interval
"atom" => { # each scope will have a key and hash value
"issues" => { # each label will have a key and hash value
:interval_end_total => 1, # number of items at end of period
:interval_beginning_total => 2,# number of items at beginning of period
:interval_new_total => 3, # number of new items during period
:interval_closed_total => 4 # number of closed items during period
}
}
}
]
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/github_issue_stats.rb', line 92 def get_history_statistics() # number_of_calls = get_required_number_of_api_calls(options) # @sleep_period = get_api_calls_sleep(number_of_calls) stats = [] for i in 1..[:interval_count] stats << get_stats_for_interval(stats[-1], ) end return stats end |
#get_interval_humanized_name(interval) ⇒ Object
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'lib/github_issue_stats.rb', line 507 def get_interval_humanized_name(interval) period_number, period_type = [interval[0..-2], interval[-1]] period_number = Integer(period_number) names = { "h" => ["hour", "hours"], "d" => ["day", "days"], "w" => ["week", "weeks"], "m" => ["month", "months"], "y" => ["year", "years"] } if period_number == 1 return "#{period_number} #{names[period_type][0]}" else return "#{period_number} #{names[period_type][1]}" end end |
#get_period_date(timestamp, period_type) ⇒ Object
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/github_issue_stats.rb', line 367 def get_period_date(slice, period_type) if period_type == "h" return slice[:previous_timestamp].strftime "%Y-%m-%d %H:00" elsif period_type == "d" return slice[:previous_timestamp].strftime "%Y-%m-%d" elsif period_type == "w" return slice[:previous_timestamp].strftime "%Y-%m-%d" elsif period_type == "m" return slice[:previous_timestamp].strftime "%Y-%m" elsif period_type == "y" return slice[:previous_timestamp].strftime "%Y" else # TODO throw error end end |
#get_period_humanized_name(slice, period_type, index) ⇒ Object
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/github_issue_stats.rb', line 351 def get_period_humanized_name(slice, period_type, index) names = { "h" => ["Now", "1 hour ago", "hours"], "d" => ["Today", "Yesterday", "days"], "w" => ["This week", "Last week", "weeks"], "m" => ["This month", "Last month", "months"], "y" => ["This year", "Last year", "years"] } if index < 2 return names[period_type][index] else return "#{index} #{names[period_type][2]} ago" end end |
#get_period_name(slice, intervals, index, type) ⇒ Object
383 384 385 386 387 388 389 390 |
# File 'lib/github_issue_stats.rb', line 383 def get_period_name(slice, interval, index, type) period_number, period_type = interval.chars if type == "markdown" return "**#{get_period_humanized_name(slice, period_type, index)}** <br>(#{get_period_date(slice, period_type)})" else return "#{get_period_humanized_name(slice, period_type, index)} (#{get_period_date(slice, period_type)})" end end |
#get_period_stats(slice, labels, scope, type) ⇒ Object
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/github_issue_stats.rb', line 392 def get_period_stats(slice, labels, scope, type) def get_difference_string(stats) difference_string = "+#{stats[:interval_new_total]}, -#{stats[:interval_closed_total]}" # TODO: maybe something like this in the future # difference = stats[:interval_new_total] - stats[:interval_closed_total] # difference_string = "#{difference}, +#{stats[:interval_new_total]}, -#{stats[:interval_closed_total]}" # # return "▲" + difference_string if difference > 0 # return "▼" + difference_string if difference < 0 # return "▶" + difference_string end if type == "markdown" return labels.map do |label| "**#{slice[scope][label][:interval_end_total]}** <br>(#{get_difference_string(slice[scope][label])})" end else return labels.map do |label| "#{slice[scope][label][:interval_end_total]} (#{get_difference_string(slice[scope][label])})" end end end |
#get_required_number_of_api_calls(options) ⇒ Object
Computes the number of search API calls to collect all the data
266 267 268 |
# File 'lib/github_issue_stats.rb', line 266 def get_required_number_of_api_calls() return [:scopes].size * [:labels].size * (2 * [:interval_count] + 1) end |
#get_search_query_string(options) ⇒ Object
Construct the search query string based on different options.
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/github_issue_stats.rb', line 296 def get_search_query_string() query = "" if [:scope].include?("/") query += "repo:#{options[:scope]} " else query += "user:#{options[:scope]} " end if [:label] == "issues" query += "is:issue " elsif [:label] == "pulls" query += "is:pr " else query += "label:#{options[:label]} " end if ![:state].nil? query += "is:#{options[:state]} " end if ![:created_at].nil? query += "created:#{options[:created_at][:from].iso8601()}..#{options[:created_at][:until].iso8601()} " end if ![:closed_at].nil? query += "closed:#{options[:closed_at][:from].iso8601()}..#{options[:closed_at][:until].iso8601()} " end return query.strip end |
#get_search_total_results(query_string) ⇒ Object
Call Search API for a query and return total number of results
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/github_issue_stats.rb', line 189 def get_search_total_results(query_string) sleep_before_api_call() @logger.debug "Getting search results for query: #{query_string}" # Print something just so the user know something is going on if @logger.sev_threshold != Logger::DEBUG STDERR.print(".") STDERR.flush end result = @client.search_issues(query_string) @logger.debug "Total count: #{result.total_count}" if result.incomplete_results @logger.error "Incomplete search API results for query #{query_string}" end return result.total_count end |
#get_search_url(query_string) ⇒ Object
Returns the github.com URL for viewing the list of issues which match the given query string
332 333 334 |
# File 'lib/github_issue_stats.rb', line 332 def get_search_url(query_string) return "https://github.com/issues?q=#{query_string}" end |
#get_smallest_period_type(interval_types) ⇒ Object
542 543 544 545 546 547 548 |
# File 'lib/github_issue_stats.rb', line 542 def get_smallest_period_type(interval_types) intervals = ["h", "d", "w", "m", "y"] interval_types_indexes = interval_types.map { |interval_type| intervals.index(interval_type) } interval_types_indexes << 1 return intervals[interval_types_indexes.min] end |
#get_stats_for_interval(previous_slice, options) ⇒ Object
Collects statistics for a single interval
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/github_issue_stats.rb', line 107 def get_stats_for_interval(previous_slice, ) slice = {} # set timestamps if previous_slice.nil? # initial slice[:current_timestamp] = Time.now.utc slice[:previous_timestamp] = get_beginning_of_current_period(slice[:current_timestamp], [:interval_length]) else # not initial slice[:current_timestamp] = previous_slice[:previous_timestamp] slice[:previous_timestamp] = compute_previous_time(slice[:current_timestamp], [:interval_length]) end for scope in [:scopes] scope_stats = {} slice[scope] = scope_stats for label in [:labels] label_stats = {} scope_stats[label] = label_stats # current state = { :scope => scope, :label => label, :state => "open" } if previous_slice.nil? query_string = get_search_query_string() label_stats[:interval_end_total_url] = get_search_url(query_string) label_stats[:interval_end_total] = get_search_total_results(query_string) else label_stats[:interval_end_total] = previous_slice[scope][label][:interval_beginning_total] end # number of new issues in period = { :scope => scope, :label => label, :created_at => { :from => slice[:previous_timestamp], :until => slice[:current_timestamp] } } query_string = get_search_query_string() label_stats[:interval_new_total_url] = get_search_url(query_string) label_stats[:interval_new_total] = get_search_total_results(query_string) # number of closed issues in period = { :scope => scope, :label => label, :state => "closed", :closed_at => { :from => slice[:previous_timestamp], :until => slice[:current_timestamp] } } query_string = get_search_query_string() label_stats[:interval_closed_total_url] = get_search_url(query_string) label_stats[:interval_closed_total] = get_search_total_results(query_string) # number of issues in previous period label_stats[:interval_beginning_total] = label_stats[:interval_end_total] + label_stats[:interval_closed_total] - label_stats[:interval_new_total] @logger.debug "Computed total at beginning of interval: #{label_stats[:interval_beginning_total]}" end end return slice end |
#sleep_before_api_call ⇒ Object
Computes the required sleep period to avoid hitting the API rate limits
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/github_issue_stats.rb', line 273 def sleep_before_api_call() @logger.debug "Calculating sleep period for next search API call" rate_limit_data = @client.get("https://api.github.com/rate_limit") if rate_limit_data[:resources][:core][:remaining] == 0 = rate_limit_data[:resources][:core][:reset] sleep_seconds = - Time.now.to_i @logger.warn "Remaining regular API rate limit is 0, sleeping for #{sleep_seconds} seconds." sleep(sleep_seconds) elsif rate_limit_data[:resources][:search][:remaining] == 0 = rate_limit_data[:resources][:search][:reset] sleep_seconds = - Time.now.to_i @logger.warn "Remaining search API rate limit is 0, sleeping for #{sleep_seconds} seconds." sleep(sleep_seconds) elsif sleep(1) end end |