Class: Nailed::Github
- Inherits:
-
Object
- Object
- Nailed::Github
- Defined in:
- lib/nailed.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #get_open_pulls ⇒ Object
-
#initialize ⇒ Github
constructor
A new instance of Github.
- #update_pull_states ⇒ Object
- #write_pull_trends(repo) ⇒ Object
Constructor Details
#initialize ⇒ Github
Returns a new instance of Github.
82 83 84 85 |
# File 'lib/nailed.rb', line 82 def initialize Octokit.auto_paginate = true @client = Octokit::Client.new(:netrc => true) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
80 81 82 |
# File 'lib/nailed.rb', line 80 def client @client end |
Instance Method Details
#get_open_pulls ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/nailed.rb', line 87 def get_open_pulls Nailed.get_config["products"].each do |product,values| organization = values["organization"] repos = values["repos"] repos.each do |repo| pulls = @client.pull_requests("#{organization}/#{repo}") pulls.each do |pr| db_handler = Pullrequest.first_or_create( :pr_number => pr.number, :title => pr.title, :state => pr.state, :url => pr.html_url, :created_at => pr.created_at, :repository_rname => repo ) Nailed.save_state(db_handler) end unless pulls.empty? write_pull_trends(repo) end unless repos.nil? end end |
#update_pull_states ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/nailed.rb', line 110 def update_pull_states pulls = Pullrequest.all pulls.each do |db_pull| number = db_pull.pr_number repo = db_pull.repository_rname org = Repository.get(repo).organization_oname github_pull = @client.pull_request("#{org}/#{repo}", number) if github_pull.state == "closed" db_pull.destroy end end end |
#write_pull_trends(repo) ⇒ Object
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/nailed.rb', line 123 def write_pull_trends(repo) open = Pullrequest.count(:repository_rname => repo) db_handler = Pulltrend.first_or_create( :time => Time.new.strftime("%Y-%m-%d %H:%M:%S"), :open => open, :repository_rname => repo ) Nailed.save_state(db_handler) end |