Commit be85533e by Bui Minh Duc

fix github not load all of the issues

parent 71b3eb9f
class UsersController < ApplicationController class UsersController < ApplicationController
require 'ostruct'
def index def index
@date = OpenStruct.new(params[:date]) if params[:date]
@users = User.where(team_ventura: true)#.includes(own_issues: [:review_comments, :comments]).where(issues: {is_pull: true, comments: { comment_type: 1 }}, ) @users = User.where(team_ventura: true)#.includes(own_issues: [:review_comments, :comments]).where(issues: {is_pull: true, comments: { comment_type: 1 }}, )
@score = Hash.new @score = Hash.new
@users.each do |user| @users.each do |user|
...@@ -8,7 +11,19 @@ class UsersController < ApplicationController ...@@ -8,7 +11,19 @@ class UsersController < ApplicationController
user_score[:before] = {0 => 0, 1 => 0, 2 => 0, 3 => 0} user_score[:before] = {0 => 0, 1 => 0, 2 => 0, 3 => 0}
user_score[:after] = {0 => 0, 1 => 0, 2 => 0, 3 => 0} user_score[:after] = {0 => 0, 1 => 0, 2 => 0, 3 => 0}
pulls = user.own_issues.includes(:review_comments, :comments).where(is_pull: true, comments: { comment_type: 1 }) # byebug
pulls = user.own_issues
if !@date.nil?
if !@date.from.blank? && !@date.to.blank?
pulls = pulls.where("issues.created_at > ? AND issues.created_at < ?", Date.parse(@date.from), Date.parse(@date.to))
elsif !@date.from.blank?
pulls = pulls.where("issues.created_at > ?", Date.parse(@date.from))
elsif !@date.to.blank?
pulls = pulls.where("issues.created_at < ?", Date.parse(@date.to))
end
end
pulls = pulls.includes(:review_comments, :comments).where(is_pull: true, comments: { comment_type: 1 })
pulls.each do |pull| pulls.each do |pull|
rv_comments = pull.review_comments rv_comments = pull.review_comments
rv_comments.each do |rv_comment| rv_comments.each do |rv_comment|
......
<div class="container"> <div class="container">
<div class="page-header">
<h3>KPI for User</h3>
<p>
KPI is calculated from comments on pull requests.
From and To fields are used to filter pull requests of user on this range of date.
</p>
</div>
<div id="toolbar"> <div id="toolbar">
<form class="form-inline"> <%= form_for :date, html: { class: "form-inline" }, method: :get do |f| %>
<div class="form-group"> <div class="form-group">
<label for="from">From</label> <%= f.label :from %>
<div class='input-group date' id='from_date'> <div class='input-group date' id='from_date'>
<input type='text' class="form-control" /> <%= f.text_field :from, class: "form-control" %>
<span class="input-group-addon"> <span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span> <span class="glyphicon glyphicon-calendar"></span>
</span> </span>
</div> </div>
<label for="to">To</label> <%= f.label :to %>
<div class='input-group date' id='to_date'> <div class='input-group date' id='to_date'>
<input type='text' class="form-control" /> <%= f.text_field :to, class: "form-control" %>
<span class="input-group-addon"> <span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span> <span class="glyphicon glyphicon-calendar"></span>
</span> </span>
</div>
<div class="input-group">
<input type="submit" name="Filter" class="btn btn-default">
</div> </div>
<%= f.submit "Submit", class: "btn btn-default" %>
</div> </div>
</form> <% end %>
</div> </div>
<div> <div>
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -8,7 +8,8 @@ class GithubLoader ...@@ -8,7 +8,8 @@ class GithubLoader
repos = client.org_repos($org) repos = client.org_repos($org)
last_page = 1 last_page = 1
unless client.last_response.headers[:link].nil? unless client.last_response.headers[:link].nil?
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i last_page = client.last_response.headers[:link].split(' ')[2]
last_page = last_page[-6..-1][/\d+/].to_i
end end
for i in (1..last_page) for i in (1..last_page)
...@@ -39,7 +40,8 @@ class GithubLoader ...@@ -39,7 +40,8 @@ class GithubLoader
labels = client.labels($org + "/" + repo.name) labels = client.labels($org + "/" + repo.name)
last_page = 1 last_page = 1
unless client.last_response.headers[:link].nil? unless client.last_response.headers[:link].nil?
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i last_page = client.last_response.headers[:link].split(' ')[2]
last_page = last_page[-6..-1][/\d+/].to_i
end end
for i in (1..last_page) for i in (1..last_page)
...@@ -76,7 +78,8 @@ class GithubLoader ...@@ -76,7 +78,8 @@ class GithubLoader
users = client.org_members($org) users = client.org_members($org)
last_page = 1 last_page = 1
unless client.last_response.headers[:link].nil? unless client.last_response.headers[:link].nil?
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i last_page = client.last_response.headers[:link].split(' ')[2]
last_page = last_page[-6..-1][/\d+/].to_i
end end
for i in (1..last_page) for i in (1..last_page)
...@@ -106,7 +109,8 @@ class GithubLoader ...@@ -106,7 +109,8 @@ class GithubLoader
members = client.team_members(team.id) members = client.team_members(team.id)
last_page = 1 last_page = 1
unless client.last_response.headers[:link].nil? unless client.last_response.headers[:link].nil?
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i last_page = client.last_response.headers[:link].split(' ')[2]
last_page = last_page[-6..-1][/\d+/].to_i
end end
# byebug # byebug
for i in (1..last_page) for i in (1..last_page)
...@@ -125,12 +129,14 @@ class GithubLoader ...@@ -125,12 +129,14 @@ class GithubLoader
$logger.info "Insert issues" $logger.info "Insert issues"
list_db_user = User.all list_db_user = User.all
list_db_label = Label.all list_db_label = Label.all
count = 0
db_repos.each do |repo| db_repos.each do |repo|
issues = client.list_issues($org + "/" + repo.name, { state: "all" }) issues = client.list_issues($org + "/" + repo.name, { state: "all" })
last_page = 1 last_page = 1
unless client.last_response.headers[:link].nil? unless client.last_response.headers[:link].nil?
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i last_page = client.last_response.headers[:link].split(' ')[2]
last_page = last_page[-6..-1][/\d+/].to_i
end end
for i in (1..last_page) for i in (1..last_page)
...@@ -219,10 +225,15 @@ class GithubLoader ...@@ -219,10 +225,15 @@ class GithubLoader
end end
end end
end end
db_issue.save
x = db_issue.save
# if x
count += 1
# end
end end
end end
end end
$logger.info "Count " + count.to_s
end end
def insert_comments(client, list_db_repo) def insert_comments(client, list_db_repo)
...@@ -232,7 +243,8 @@ class GithubLoader ...@@ -232,7 +243,8 @@ class GithubLoader
comments = client.issues_comments($org + "/" + db_repo.name) comments = client.issues_comments($org + "/" + db_repo.name)
last_page = 1 last_page = 1
unless client.last_response.headers[:link].nil? unless client.last_response.headers[:link].nil?
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i last_page = client.last_response.headers[:link].split(' ')[2]
last_page = last_page[-6..-1][/\d+/].to_i
end end
for i in (1..last_page) for i in (1..last_page)
...@@ -264,7 +276,8 @@ class GithubLoader ...@@ -264,7 +276,8 @@ class GithubLoader
rv_comments = client.pull_requests_comments($org + "/" + db_repo.name) rv_comments = client.pull_requests_comments($org + "/" + db_repo.name)
last_page = 1 last_page = 1
unless client.last_response.headers[:link].nil? unless client.last_response.headers[:link].nil?
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i last_page = client.last_response.headers[:link].split(' ')[2]
last_page = last_page[-6..-1][/\d+/].to_i
end end
for i in (1..last_page) for i in (1..last_page)
...@@ -309,13 +322,30 @@ class GithubLoader ...@@ -309,13 +322,30 @@ class GithubLoader
pulls = issues.where(is_pull: true) pulls = issues.where(is_pull: true)
pulls.each do |pull| pulls.each do |pull|
if pull.issue.nil? if pull.issue.nil?
content = pull.comments.first content = ""
if pull.body
content = pull.body + " "
end
if pull.comments.first
content += pull.comments.first.body
end
unless content.nil? unless content.nil?
issue_number = /#[0-9]+/.match(content.body) issue_number = /#[0-9]+/.match(content)
unless issue_number.nil? if !issue_number.nil?
issue = issues.where(repository_id: pull.repository_id).find_by(number: issue_number.to_s[1..-1]) issue = issues.where(repository_id: pull.repository_id).find_by(number: issue_number.to_s[1..-1])
pull.issue = issue pull.issue = issue
# puts pull.save puts pull.save
else
# TODO fix logic bug here
lst_url = URI.extract(content, ['http', 'https'])
lst_url.each do |url|
if url.include?("github.com") && url.include?("issues")
# byebug
issue = issues.where(repository_id: pull.repository_id).find_by(number: url.split("/").last)
pull.issue = issue
puts pull.save
end
end
end end
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment