Class: Github::Pulse::GithubClient
- Inherits:
-
Object
- Object
- Github::Pulse::GithubClient
- Defined in:
- lib/github/pulse/github_client.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Instance Method Summary collapse
- #commit_activity ⇒ Object
- #contributors_stats ⇒ Object
-
#initialize(repo:, token: nil) ⇒ GithubClient
constructor
A new instance of GithubClient.
- #pull_requests(since: nil, until_date: nil, state: "all") ⇒ Object
- #repository_info ⇒ Object
Constructor Details
#initialize(repo:, token: nil) ⇒ GithubClient
Returns a new instance of GithubClient.
11 12 13 14 15 16 17 18 19 |
# File 'lib/github/pulse/github_client.rb', line 11 def initialize(repo:, token: nil) @repo = repo @client = if token Octokit::Client.new(access_token: token) else Octokit::Client.new end @client.auto_paginate = true end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/github/pulse/github_client.rb', line 9 def client @client end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
9 10 11 |
# File 'lib/github/pulse/github_client.rb', line 9 def repo @repo end |
Instance Method Details
#commit_activity ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/github/pulse/github_client.rb', line 67 def commit_activity activity = client.commit_activity_stats(repo) return [] unless activity activity.map do |week| { week_start: Time.at(week.week).to_date, days: week.days, total: week.total } end rescue Octokit::Accepted => e sleep 2 retry end |
#contributors_stats ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/github/pulse/github_client.rb', line 44 def contributors_stats stats = client.contributors_stats(repo) return [] unless stats stats.map do |contributor| { author: contributor..login, total_commits: contributor.total, weeks: contributor.weeks.map do |week| { week_start: Time.at(week.w).to_date, additions: week.a, deletions: week.d, commits: week.c } end } end rescue Octokit::Accepted => e sleep 2 retry end |
#pull_requests(since: nil, until_date: nil, state: "all") ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/github/pulse/github_client.rb', line 21 def pull_requests(since: nil, until_date: nil, state: "all") prs = client.pull_requests(repo, state: state) if since || until_date prs = filter_by_date(prs, since, until_date, &:created_at) end prs.map do |pr| { number: pr.number, title: pr.title, author: pr.user.login, created_at: pr.created_at, closed_at: pr.closed_at, merged_at: pr.merged_at, state: pr.state, additions: pr.additions || 0, deletions: pr.deletions || 0, changed_files: pr.changed_files || 0 } end end |
#repository_info ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/github/pulse/github_client.rb', line 83 def repository_info repo_data = client.repository(repo) { name: repo_data.name, full_name: repo_data.full_name, description: repo_data.description, created_at: repo_data.created_at, updated_at: repo_data.updated_at, language: repo_data.language, default_branch: repo_data.default_branch, size: repo_data.size, stars: repo_data.stargazers_count, forks: repo_data.forks_count, open_issues: repo_data.open_issues_count } end |