Commit 360f5138 by Bui Minh Duc

fix database comment

parent eb0afb2f
......@@ -38,6 +38,7 @@ gem 'bootstrap-table-rails', '~> 1.11'
gem 'momentjs-rails', '>= 2.9.0'
gem 'bootstrap3-datetimepicker-rails', '~> 4.14.30'
gem 'whenever', '~> 0.9.7'
gem 'redcarpet', '~> 3.3', '>= 3.3.4'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
......
......@@ -131,6 +131,7 @@ GEM
rb-fsevent (0.9.8)
rb-inotify (0.9.7)
ffi (>= 0.5.0)
redcarpet (3.3.4)
sass (3.4.22)
sass-rails (5.0.6)
railties (>= 4.0.0, < 6)
......@@ -190,6 +191,7 @@ DEPENDENCIES
octokit (~> 4.6, >= 4.6.2)
puma (~> 3.0)
rails (~> 5.0.0, >= 5.0.0.1)
redcarpet (~> 3.3, >= 3.3.4)
sass-rails (~> 5.0)
spring
spring-watcher-listen (~> 2.0.0)
......
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
// Place all the styles related to the issue controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def standardize_string(str)
str.gsub!(/[^0-9A-Za-z]/, "")
str.downcase!
str
end
# check if issue have all label in label_filter_params
def filter_issue(issue, label_filter_params)
number = 0
label_filter_params.each do |label_filter_param|
issue.labels.each do |label|
label_name = standardize_string(label[:name])
if label_filter_param == label_name
number = number + 1
break
end
end
end
if number == label_filter_params.size
true
else
false
end
end
end
class IssuesController < ApplicationController
def index
# need some params: repo, label, filter(include from date, label)
@from_date = params[:date].empty? ? "" : Date.parse(params[:date])
@filter_labels = params[:filter]
@type_of_issue = params[:type]
type_of_issue_query = nil
if @type_of_issue == "0"
type_of_issue_query = [false]
elsif @type_of_issue == "1"
type_of_issue_query = [true]
else
type_of_issue_query = [true, false]
end
@repo_name = params[:repo]
issues_query = Issue.joins(:repository).joins(:labels).where(
"repositories.name = ? AND labels.name = ? AND issues.is_pull IN (?) AND issues.created_at >= ?",
params[:repo], params[:label], type_of_issue_query, @from_date)
if @filter_labels.nil?
@issues = issues_query
else
@issues = []
issues_query.each do |issue|
if filter_issue(issue, @filter_labels)
@issues.append(issue)
end
end
end
end
def show
@issue = Issue.find_by(id: params[:id])
end
end
class MainController < ApplicationController
def index
@from_date = session[:filter_date]
@label_filter_params = session[:filter_label]
if @label_filter_params.nil? || @label_filter_params.empty?
@label_filter_params = []
end
@type_of_issue = session[:type_of_issue] || "0" # default show issue only
type_of_issue_query = nil
if @type_of_issue == "0"
type_of_issue_query = [false]
elsif @type_of_issue == "1"
type_of_issue_query = [true]
else
type_of_issue_query = [true, false]
end
@col_label_names = [
"discussion", "todo", "inprogress",
"vnreview", "jpreview", "ready",
......@@ -9,9 +26,7 @@ class MainController < ApplicationController
@repos = @repos || Repository.all
@selected_repos_name = Other.where(data_type: 0).map{ |other| other.data }
@selected_repos = Repository.where(name: @selected_repos_name).includes(issues: [:labels]).where("issues.closed_at IS NULL").references(:issues)
@label_filter_params = Other.where(data_type: 1).map { |e| e.data }
# @label_filter_params
@selected_repos = Repository.where(name: @selected_repos_name).includes(issues: [:labels]).where("issues.closed_at IS NULL AND issues.is_pull IN (?)", type_of_issue_query).references(:issues)
@data_table = []
@selected_repos.each do |repo|
......@@ -65,17 +80,10 @@ class MainController < ApplicationController
redirect_to action: "index"
end
def update_label_selected
Other.where(data_type: 1).delete_all
if params[:selected].class == Array
params[:selected].each do |selected_label_name|
db_selected = Other.new
db_selected.data = selected_label_name
db_selected.data_type = 1
db_selected.save
end
end
def update_params_selected
session[:filter_label] = params[:selected]
session[:filter_date] = params[:date]
session[:type_of_issue] = params[:issue_type]
redirect_to action: "index"
end
......@@ -87,29 +95,4 @@ class MainController < ApplicationController
def list_issues(label, repo)
end
def standardize_string(str)
str.gsub!(/[^0-9A-Za-z]/, '')
str.downcase!
str
end
# check if issue have all label in label_filter_params
def filter_issue(issue, label_filter_params)
number = 0
label_filter_params.each do |label_filter_param|
issue.labels.each do |label|
label_name = standardize_string(label[:name])
if label_filter_param == label_name
number = number + 1
break
end
end
end
if number == label_filter_params.size
true
else
false
end
end
end
module IssueHelper
end
<div class="container">
<h2><%= @repo_name %></h2>
<div>
<table data-toolbar="#toolbar"
data-toggle="table"
data-search="true"
data-show-export="true"
data-show-columns="true"
data-show-export="true"
data-minimum-count-columns="2"
data-show-pagination-switch="true"
data-pagination="true"
data-id-field="id"
data-page-list="[10, 25, 50, 100, ALL]">
<thead>
<tr>
<th class="col-md-6">Issue</th>
<th class="col-md-2">Assignee</th>
<th class="col-md-2">Started Date</th>
<th class="col-md-2"></th>
</tr>
</thead>
<tbody>
<% @issues.each do |issue| %>
<tr>
<td>
<%= link_to issue.title, issue_path(issue) %>
<% issue.labels.each do |label| %>
<span class="label label-default" style="background-color: #<%= label.color %>; color: #<%= get_text_color(label.color) %>;"><%= label.name %></span>
<% end %>
</td>
<td>
<% issue.users.each do |assignee| %>
<%= link_to assignee.login, assignee.html_url %>
<br>
<% end %>
</td>
<td><%= issue.created_at %></td>
<td><%= format_time(Time.now - issue[:created_at]) %></td>
</tr>
<% end %>
</table>
</div>
</div>
<div class="container">
<h2><%= @issue.repository.name + "/" + @issue.title %></h2>
<div class="row">
<div class="col-md-8">
<%= $markdown.render(@issue.body).html_safe %>
</div>
<div class="col-md-4">
<div>
<h3>Assignee</h3>
<% @issue.users.each do |user| %>
<p><%= user.login %></p>
<% end %>
<h3>Label</h3>
<% @issue.labels.each do |label| %>
<p><%= label.name %></p>
<% end %>
</div>
</div>
</div>
<div class="row">
</div>
</div>
......@@ -29,7 +29,13 @@
<% end %>
</select>
</div>
<!-- <input type="submit" class="btn btn-default"> -->
<div class="form-group">
<select class="form-control" id="issue_type">
<option value="0">Issue Only</option>
<option value="1">Pull Request Only</option>
<option value="2">Both</option>
</select>
</div>
<button id="submit_filter" class="btn btn-default">Submit</button>
</form>
</div>
......@@ -61,7 +67,8 @@
<% if row[label].nil? %>
<td class="col-md-1">0</td>
<% else %>
<td class="col-md-1"><a href="" data-toggle="modal" data-target="#<%= format_html_id(row[:name] + label) %>"><%= row[label][:count] %></a></td>
<!-- <td class="col-md-1"><a href="" data-toggle="modal" data-target="#<%= format_html_id(row[:name] + label) %>"><%= row[label][:count] %></a></td> -->
<td class="col-md-1"><%= link_to row[label][:count], issues_path(repo: row[:name], label: label, date: @from_date, filter: @label_filter_params, type: @type_of_issue), target: "_blank" %></td>
<% end %>
<% end %>
......@@ -116,7 +123,7 @@
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#issue_type").val(<%= @type_of_issue %>);
});
$("#repo_apply").click(function() {
......@@ -135,13 +142,14 @@
$("#submit_filter").click(function() {
var selected_labels = $('#selectpicker2').selectpicker('val');
var from_date = $("#from_date").val();
var issue_type = $("#issue_type").val();
$.ajax({
method: "POST",
url: "<%= update_label_selected_path %>",
data: { selected: selected_labels, date: from_date },
url: "<%= update_params_selected_path %>",
data: { selected: selected_labels, date: from_date, issue_type: issue_type },
success: function(res) {
location.reload();
// location.reload();
}
});
});
......
$markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)
......@@ -3,10 +3,10 @@ Rails.application.routes.draw do
root "main#index"
get "/repo", to: "repository#index"
post "/update_repo_selected", to: "main#update_repo_selected"
post "/update_label_selected", to: "main#update_label_selected"
post "/update_params_selected", to: "main#update_params_selected"
post "/load_repo_selected", to: "main#load_repo_selected"
get "/user", to: "user#index"
resources :issues
# resource :repository
end
......@@ -227,3 +227,58 @@ I, [2016-12-07T09:58:57.123754 #13694] INFO -- : Insert review comments
I, [2016-12-07T10:04:45.465724 #13694] INFO -- : begin transaction
I, [2016-12-07T10:04:59.357685 #13694] INFO -- : Finished transaction in 13.891879991s
I, [2016-12-07T10:04:59.357747 #13694] INFO -- : Finished task import in 1705.414241185s
I, [2016-12-23T11:03:55.819033 #28571] INFO -- : Begin task insert database from github
I, [2016-12-23T11:03:55.843721 #28571] INFO -- : Insert repos
I, [2016-12-23T11:13:19.261791 #28860] INFO -- : Begin task insert database from github
I, [2016-12-23T11:13:19.261935 #28860] INFO -- : Insert repos
I, [2016-12-23T11:13:25.594951 #28860] INFO -- : Insert users
I, [2016-12-23T11:15:34.935803 #28984] INFO -- : Begin task insert database from github
I, [2016-12-23T11:15:34.935885 #28984] INFO -- : Insert repos
I, [2016-12-23T11:15:41.276191 #28984] INFO -- : Insert users
I, [2016-12-23T11:15:46.788758 #28984] INFO -- : Insert labels
I, [2016-12-23T11:19:09.026134 #28984] INFO -- : Insert issues
I, [2016-12-23T11:26:15.883788 #28984] INFO -- : begin transaction
I, [2016-12-23T11:26:30.001688 #28984] INFO -- : Finished transaction in 14.117724494s
I, [2016-12-23T11:26:30.001794 #28984] INFO -- : Finished task import in 655.065903817s
I, [2016-12-23T16:14:21.208164 #13960] INFO -- : Begin task insert database from github
I, [2016-12-23T16:14:21.208262 #13960] INFO -- : Insert repos
I, [2016-12-23T16:14:27.502846 #13960] INFO -- : Insert users
I, [2016-12-23T16:14:33.154009 #13960] INFO -- : Insert labels
I, [2016-12-23T16:14:33.154057 #13960] INFO -- : Insert issues
I, [2016-12-23T16:14:33.154073 #13960] INFO -- : Insert comments
I, [2016-12-23T16:14:33.154089 #13960] INFO -- : Size list_db_comment: 0
I, [2016-12-23T16:14:33.154102 #13960] INFO -- : Insert review comments
I, [2016-12-23T16:14:33.154113 #13960] INFO -- : begin transaction
I, [2016-12-23T16:14:33.154390 #13960] INFO -- : Finished transaction in 0.000241678s
I, [2016-12-23T16:14:33.154417 #13960] INFO -- : Finished task import in 11.946155681s
I, [2016-12-23T16:15:01.111782 #14015] INFO -- : Begin task insert database from github
I, [2016-12-23T16:15:01.111872 #14015] INFO -- : Insert repos
I, [2016-12-23T16:15:08.195215 #14015] INFO -- : Insert users
I, [2016-12-23T16:15:13.942559 #14015] INFO -- : Insert labels
I, [2016-12-23T16:15:13.942666 #14015] INFO -- : Insert issues
I, [2016-12-23T16:15:13.942710 #14015] INFO -- : Insert comments
I, [2016-12-23T16:15:13.942748 #14015] INFO -- : Size list_db_comment: 0
I, [2016-12-23T16:15:13.942778 #14015] INFO -- : Insert review comments
I, [2016-12-23T16:15:13.942804 #14015] INFO -- : begin transaction
I, [2016-12-23T16:15:13.943513 #14015] INFO -- : Finished transaction in 0.0006551s
I, [2016-12-23T16:15:13.943587 #14015] INFO -- : Finished task import in 12.831703086s
I, [2016-12-23T16:15:36.601371 #14070] INFO -- : Begin task insert database from github
I, [2016-12-23T16:15:36.601448 #14070] INFO -- : Insert repos
I, [2016-12-23T16:15:42.983593 #14070] INFO -- : Insert users
I, [2016-12-23T16:15:48.578764 #14070] INFO -- : Insert labels
I, [2016-12-23T16:15:48.578828 #14070] INFO -- : Insert issues
I, [2016-12-23T16:15:48.578851 #14070] INFO -- : Insert comments
I, [2016-12-23T16:15:48.578870 #14070] INFO -- : Size list_db_comment: 0
I, [2016-12-23T16:15:48.578886 #14070] INFO -- : Insert review comments
I, [2016-12-23T16:15:48.578902 #14070] INFO -- : begin transaction
I, [2016-12-23T16:15:48.579270 #14070] INFO -- : Finished transaction in 0.000342237s
I, [2016-12-23T16:15:48.579309 #14070] INFO -- : Finished task import in 11.977856241s
I, [2016-12-23T16:22:56.342217 #14255] INFO -- : Begin task insert database from github
I, [2016-12-23T16:22:56.352231 #14255] INFO -- : Insert repos
I, [2016-12-23T16:23:02.918760 #14255] INFO -- : Insert users
I, [2016-12-23T16:23:08.599700 #14255] INFO -- : Insert labels
I, [2016-12-23T16:26:30.938607 #14255] INFO -- : Insert issues
I, [2016-12-23T16:40:30.534747 #14255] INFO -- : Insert comments
I, [2016-12-23T16:46:05.274630 #14255] INFO -- : Size list_db_comment: 3823
I, [2016-12-23T16:46:05.274699 #14255] INFO -- : Insert review comments
I, [2016-12-23T16:52:05.582564 #14255] INFO -- : begin transaction
......@@ -55,6 +55,17 @@ namespace :github do
$logger.info "Finished task import in #{Time.now - start_time}s"
end
desc "Insert comments only"
task insert_comment_data: :environment do
$logger.info "Begin task insert comments"
start_time = Time.now
list_db_repo = Repository.all
list_db_comment = insert_comments($client, list_db_repo)
list_db_rv_comment = insert_review_comments($client, list_db_repo)
#TODO
end
def insert_repos(client)
$logger.info "Insert repos"
repos = client.org_repos($org)
......@@ -63,7 +74,7 @@ namespace :github do
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i
end
list_db_repo = Repository.all
list_db_repo = []
for i in (1..last_page)
repos = client.org_repos($org, {type: 'all', page: i})
repos.each do |repo|
......@@ -80,8 +91,8 @@ namespace :github do
db_repo.created_at = repo.created_at
db_repo.updated_at = repo.updated_at
list_db_repo.append(db_repo)
end
list_db_repo.append(db_repo)
end
end
list_db_repo
......@@ -107,7 +118,7 @@ namespace :github do
db_label.url = label.url
db_label.repository_id = repo.id
end
db_label.name = label.name
db_label.name = label.name.gsub(/[^0-9A-Za-z]/, "").downcase # normalize string
db_label.color = label.color
db_label.default = label.default
......@@ -126,7 +137,7 @@ namespace :github do
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i
end
list_db_user = User.all
list_db_user = []
for i in (1..last_page)
users = client.org_members($org, {page: i})
users.each do |user|
......@@ -138,8 +149,8 @@ namespace :github do
db_user.url = user.url
db_user.html_url = user.html_url
list_db_user.append(db_user)
end
list_db_user.append(db_user)
end
end
list_db_user
......
require 'test_helper'
class IssueControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# 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