Class: GithubOrgReports
- Inherits:
-
Object
- Object
- GithubOrgReports
- Defined in:
- lib/github_org_reports.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#ob ⇒ Object
readonly
Returns the value of attribute ob.
-
#repos ⇒ Object
readonly
Returns the value of attribute repos.
Class Method Summary collapse
Instance Method Summary collapse
- #add_repo(repo) ⇒ Object
-
#initialize(args = {}) ⇒ GithubOrgReports
constructor
A new instance of GithubOrgReports.
- #scan ⇒ Object
- #scan_for_time_and_orgs(str) ⇒ Object
- #scan_hash(str) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ GithubOrgReports
Returns a new instance of GithubOrgReports.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/github_org_reports.rb', line 14 def initialize(args = {}) @args = args @repos = [] @db = @args[:db] raise "No ':db' was given." unless @db Baza::Revision.new.init_db(:db => @db, :schema => GithubOrgReports::Dbschema::SCHEMA) @ob = Baza::ModelHandler.new( :db => @db, :class_path => "#{File.dirname(__FILE__)}/../models", :class_pre => "", :module => GithubOrgReports::Models, :require_all => true ) @ob.data[:github_org_reports] = self end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
6 7 8 |
# File 'lib/github_org_reports.rb', line 6 def db @db end |
#ob ⇒ Object (readonly)
Returns the value of attribute ob.
6 7 8 |
# File 'lib/github_org_reports.rb', line 6 def ob @ob end |
#repos ⇒ Object (readonly)
Returns the value of attribute repos.
6 7 8 |
# File 'lib/github_org_reports.rb', line 6 def repos @repos end |
Class Method Details
.const_missing(name) ⇒ Object
8 9 10 11 12 |
# File 'lib/github_org_reports.rb', line 8 def self.const_missing(name) require "#{File.dirname(__FILE__)}/../include/github_org_reports_#{name.to_s.downcase}.rb" raise "Still not defined: '#{name}'." unless GithubOrgReports.const_defined?(name) return GithubOrgReports.const_get(name) end |
Instance Method Details
#add_repo(repo) ⇒ Object
32 33 34 35 |
# File 'lib/github_org_reports.rb', line 32 def add_repo(repo) raise "Invalid class: '#{repo.class.name}'." unless repo.is_a?(GithubOrgReports::Repo) @repos << repo end |
#scan ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/github_org_reports.rb', line 48 def scan @repos.each do |repo| gh_args = {} gh_args[:login] = repo.args[:login] if repo.args[:login] gh_args[:password] = repo.args[:password] if repo.args[:password] gh = ::Github.new(gh_args) commits = gh.repos.commits.all(repo.args[:user], repo.args[:name]) commits.each do |commit_data| commit = init_commit_from_data(commit_data) end prs = gh.pull_requests.list(repo.args[:user], repo.args[:name]) prs.each do |pr_data| text = pr_data.body_text user = @ob.get_or_add(:User, { :name => pr_data.user }) pr = @ob.get_or_add(:PullRequest, { :github_id => pr_data.id }) pr[:user_id] = user.id pr[:text] = pr_data.body_text pr[:html] = pr_data.body_html pr.scan commits = gh.pull_requests.commits(:repo => repo.args[:name], :user => repo.args[:user], :number => pr_data.number) commits.each do |commit_data| commit = init_commit_from_data(commit_data) commit[:pull_request_id] = pr.id end end end end |
#scan_for_time_and_orgs(str) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/github_org_reports.rb', line 88 def scan_for_time_and_orgs(str) res = {:secs => 0, :orgs => [], :orgs_time => {}} self.scan_hash(str) do |hash| #Parse time. if hash["time"] and match_time = hash["time"].to_s.match(/^(\d{1,2}):(\d{1,2})$/) secs = 0 secs += match_time[1].to_i * 3600 secs += match_time[2].to_i * 60 res[:secs] += secs #Parse organizations. if orgs = hash["orgs"] orgs = [orgs] if !orgs.is_a?(Hash) orgs.each do |org_name_short| org_name_short_dc = org_name_short.to_s.downcase next if org_name_short_dc.strip.empty? org = self.ob.get_or_add(:Organization, {:name_short => org_name_short_dc}) link = self.ob.get_or_add(:PullRequestOrganizationLink, { :organization_id => org.id, :pull_request_id => self.id }) res[:orgs] << org unless res[:orgs].include?(org) res[:orgs_time][org.id] = {:secs => 0} unless res[:orgs].key?(org.id) res[:orgs_time][org.id][:secs] += match_time end end end end return res end |
#scan_hash(str) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/github_org_reports.rb', line 37 def scan_hash(str) str.to_s.scan(/!(\{(.+?)\})!/) do |match| begin yield JSON.parse(match[1]) rescue JSON::ParserError => e $stderr.puts e.inspect $stderr.puts e.backtrace end end end |