Class: WorkReport::GithubActivity
- Inherits:
-
Object
- Object
- WorkReport::GithubActivity
- Defined in:
- lib/work_report.rb
Instance Method Summary (collapse)
- - (Object) commits_to_csv
- - (Object) commits_to_hash
-
- (GithubActivity) initialize(user, github_token)
constructor
A new instance of GithubActivity.
- - (Object) releases_to_csv
- - (Object) releases_to_hash
Constructor Details
- (GithubActivity) initialize(user, github_token)
Returns a new instance of GithubActivity
11 12 13 14 |
# File 'lib/work_report.rb', line 11 def initialize(user, github_token) @user = user @github_token = github_token end |
Instance Method Details
- (Object) commits_to_csv
33 34 35 36 37 38 39 40 41 |
# File 'lib/work_report.rb', line 33 def commits_to_csv commits = commits_to_hash csv = CSV.generate do |line| commits.each do |commit| line << [commit["date"].strftime("%F"), commit["count"]] end end end |
- (Object) commits_to_hash
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/work_report.rb', line 16 def commits_to_hash # get contributions url = "https://github-contributions-api.now.sh/v1/#{@user}" json = open(url) do |f| JSON.load(f.read) end # convert summary counts = json["contributions"].map do |contribution| { "date" => Time.parse(contribution["date"]), "count" => contribution["count"] } end end |
- (Object) releases_to_csv
68 69 70 71 72 73 74 75 76 |
# File 'lib/work_report.rb', line 68 def releases_to_csv releases = releases_to_hash csv = CSV.generate do |line| releases.each do |release| line << [release["url"], release["name"], release["created_at"].strftime("%F %T")] end end end |
- (Object) releases_to_hash
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/work_report.rb', line 43 def releases_to_hash # get repos repos_url = "https://api.github.com/users/#{@user}/repos" repos = get_github_data(repos_url) # get releases releases = repos.flat_map do |repo| releases_url = "https://api.github.com/repos/#{@user}/#{repo["name"]}/releases" releases = get_github_data(releases_url) end releases.compact! # convert release summary release_summaries = releases.map do |release| { "url" => release["html_url"], "name" => release["name"], "created_at" => Time.parse(release["created_at"]) } end end |