Commit 6ea3bed9 by Bui Minh Duc

implement detail of issue

parent 360f5138
...@@ -39,6 +39,7 @@ gem 'momentjs-rails', '>= 2.9.0' ...@@ -39,6 +39,7 @@ gem 'momentjs-rails', '>= 2.9.0'
gem 'bootstrap3-datetimepicker-rails', '~> 4.14.30' gem 'bootstrap3-datetimepicker-rails', '~> 4.14.30'
gem 'whenever', '~> 0.9.7' gem 'whenever', '~> 0.9.7'
gem 'redcarpet', '~> 3.3', '>= 3.3.4' gem 'redcarpet', '~> 3.3', '>= 3.3.4'
gem 'bootstrap-growl-rails'
group :development, :test do group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console # Call 'byebug' anywhere in the code to stop execution and get a debugger console
......
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
actioncable (5.0.0.1) actioncable (5.0.1)
actionpack (= 5.0.0.1) actionpack (= 5.0.1)
nio4r (~> 1.2) nio4r (~> 1.2)
websocket-driver (~> 0.6.1) websocket-driver (~> 0.6.1)
actionmailer (5.0.0.1) actionmailer (5.0.1)
actionpack (= 5.0.0.1) actionpack (= 5.0.1)
actionview (= 5.0.0.1) actionview (= 5.0.1)
activejob (= 5.0.0.1) activejob (= 5.0.1)
mail (~> 2.5, >= 2.5.4) mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
actionpack (5.0.0.1) actionpack (5.0.1)
actionview (= 5.0.0.1) actionview (= 5.0.1)
activesupport (= 5.0.0.1) activesupport (= 5.0.1)
rack (~> 2.0) rack (~> 2.0)
rack-test (~> 0.6.3) rack-test (~> 0.6.3)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2) rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.0.0.1) actionview (5.0.1)
activesupport (= 5.0.0.1) activesupport (= 5.0.1)
builder (~> 3.1) builder (~> 3.1)
erubis (~> 2.7.0) erubis (~> 2.7.0)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2) rails-html-sanitizer (~> 1.0, >= 1.0.2)
activejob (5.0.0.1) activejob (5.0.1)
activesupport (= 5.0.0.1) activesupport (= 5.0.1)
globalid (>= 0.3.6) globalid (>= 0.3.6)
activemodel (5.0.0.1) activemodel (5.0.1)
activesupport (= 5.0.0.1) activesupport (= 5.0.1)
activerecord (5.0.0.1) activerecord (5.0.1)
activemodel (= 5.0.0.1) activemodel (= 5.0.1)
activesupport (= 5.0.0.1) activesupport (= 5.0.1)
arel (~> 7.0) arel (~> 7.0)
activesupport (5.0.0.1) activesupport (5.0.1)
concurrent-ruby (~> 1.0, >= 1.0.2) concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7) i18n (~> 0.7)
minitest (~> 5.1) minitest (~> 5.1)
...@@ -41,9 +41,10 @@ GEM ...@@ -41,9 +41,10 @@ GEM
addressable (2.5.0) addressable (2.5.0)
public_suffix (~> 2.0, >= 2.0.2) public_suffix (~> 2.0, >= 2.0.2)
arel (7.1.4) arel (7.1.4)
autoprefixer-rails (6.4.1) autoprefixer-rails (6.6.0)
execjs execjs
bootstrap-sass (3.3.6) bootstrap-growl-rails (3.1.3)
bootstrap-sass (3.3.7)
autoprefixer-rails (>= 5.2.1) autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4) sass (>= 3.3.4)
bootstrap-select-rails (1.6.3) bootstrap-select-rails (1.6.3)
...@@ -59,8 +60,8 @@ GEM ...@@ -59,8 +60,8 @@ GEM
coffee-script (2.4.1) coffee-script (2.4.1)
coffee-script-source coffee-script-source
execjs execjs
coffee-script-source (1.10.0) coffee-script-source (1.12.2)
concurrent-ruby (1.0.2) concurrent-ruby (1.0.4)
debug_inspector (0.0.2) debug_inspector (0.0.2)
erubis (2.7.0) erubis (2.7.0)
execjs (2.7.0) execjs (2.7.0)
...@@ -70,7 +71,7 @@ GEM ...@@ -70,7 +71,7 @@ GEM
globalid (0.3.7) globalid (0.3.7)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
i18n (0.7.0) i18n (0.7.0)
jbuilder (2.6.0) jbuilder (2.6.1)
activesupport (>= 3.0.0, < 5.1) activesupport (>= 3.0.0, < 5.1)
multi_json (~> 1.2) multi_json (~> 1.2)
jquery-rails (4.2.1) jquery-rails (4.2.1)
...@@ -89,50 +90,50 @@ GEM ...@@ -89,50 +90,50 @@ GEM
mime-types-data (~> 3.2015) mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521) mime-types-data (3.2016.0521)
mini_portile2 (2.1.0) mini_portile2 (2.1.0)
minitest (5.9.1) minitest (5.10.1)
momentjs-rails (2.15.1) momentjs-rails (2.15.1)
railties (>= 3.1) railties (>= 3.1)
multi_json (1.12.1) multi_json (1.12.1)
multipart-post (2.0.0) multipart-post (2.0.0)
nio4r (1.2.1) nio4r (1.2.1)
nokogiri (1.6.8.1) nokogiri (1.7.0)
mini_portile2 (~> 2.1.0) mini_portile2 (~> 2.1.0)
octokit (4.6.2) octokit (4.6.2)
sawyer (~> 0.8.0, >= 0.5.3) sawyer (~> 0.8.0, >= 0.5.3)
public_suffix (2.0.4) public_suffix (2.0.4)
puma (3.6.1) puma (3.6.2)
rack (2.0.1) rack (2.0.1)
rack-test (0.6.3) rack-test (0.6.3)
rack (>= 1.0) rack (>= 1.0)
rails (5.0.0.1) rails (5.0.1)
actioncable (= 5.0.0.1) actioncable (= 5.0.1)
actionmailer (= 5.0.0.1) actionmailer (= 5.0.1)
actionpack (= 5.0.0.1) actionpack (= 5.0.1)
actionview (= 5.0.0.1) actionview (= 5.0.1)
activejob (= 5.0.0.1) activejob (= 5.0.1)
activemodel (= 5.0.0.1) activemodel (= 5.0.1)
activerecord (= 5.0.0.1) activerecord (= 5.0.1)
activesupport (= 5.0.0.1) activesupport (= 5.0.1)
bundler (>= 1.3.0, < 2.0) bundler (>= 1.3.0, < 2.0)
railties (= 5.0.0.1) railties (= 5.0.1)
sprockets-rails (>= 2.0.0) sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.1) rails-dom-testing (2.0.2)
activesupport (>= 4.2.0, < 6.0) activesupport (>= 4.2.0, < 6.0)
nokogiri (~> 1.6.0) nokogiri (~> 1.6)
rails-html-sanitizer (1.0.3) rails-html-sanitizer (1.0.3)
loofah (~> 2.0) loofah (~> 2.0)
railties (5.0.0.1) railties (5.0.1)
actionpack (= 5.0.0.1) actionpack (= 5.0.1)
activesupport (= 5.0.0.1) activesupport (= 5.0.1)
method_source method_source
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
rake (11.3.0) rake (12.0.0)
rb-fsevent (0.9.8) rb-fsevent (0.9.8)
rb-inotify (0.9.7) rb-inotify (0.9.7)
ffi (>= 0.5.0) ffi (>= 0.5.0)
redcarpet (3.3.4) redcarpet (3.4.0)
sass (3.4.22) sass (3.4.23)
sass-rails (5.0.6) sass-rails (5.0.6)
railties (>= 4.0.0, < 6) railties (>= 4.0.0, < 6)
sass (~> 3.1) sass (~> 3.1)
...@@ -147,7 +148,7 @@ GEM ...@@ -147,7 +148,7 @@ GEM
spring-watcher-listen (2.0.1) spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0) listen (>= 2.7, < 4.0)
spring (>= 1.2, < 3.0) spring (>= 1.2, < 3.0)
sprockets (3.7.0) sprockets (3.7.1)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
rack (> 1, < 3) rack (> 1, < 3)
sprockets-rails (3.2.0) sprockets-rails (3.2.0)
...@@ -155,12 +156,12 @@ GEM ...@@ -155,12 +156,12 @@ GEM
activesupport (>= 4.0) activesupport (>= 4.0)
sprockets (>= 3.0.0) sprockets (>= 3.0.0)
sqlite3 (1.3.12) sqlite3 (1.3.12)
thor (0.19.1) thor (0.19.4)
thread_safe (0.3.5) thread_safe (0.3.5)
tilt (2.0.5) tilt (2.0.5)
tzinfo (1.2.2) tzinfo (1.2.2)
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (3.0.3) uglifier (3.0.4)
execjs (>= 0.3.0, < 3) execjs (>= 0.3.0, < 3)
web-console (3.4.0) web-console (3.4.0)
actionview (>= 5.0) actionview (>= 5.0)
...@@ -178,6 +179,7 @@ PLATFORMS ...@@ -178,6 +179,7 @@ PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
bootstrap-growl-rails
bootstrap-sass (~> 3.3.6) bootstrap-sass (~> 3.3.6)
bootstrap-select-rails (~> 1.6, >= 1.6.3) bootstrap-select-rails (~> 1.6, >= 1.6.3)
bootstrap-table-rails (~> 1.11) bootstrap-table-rails (~> 1.11)
......
...@@ -21,3 +21,4 @@ ...@@ -21,3 +21,4 @@
//= require extensions/bootstrap-table-export.js //= require extensions/bootstrap-table-export.js
//= require moment //= require moment
//= require bootstrap-datetimepicker //= require bootstrap-datetimepicker
//= require bootstrap-notify
...@@ -13,5 +13,6 @@ ...@@ -13,5 +13,6 @@
*= require_tree . *= require_tree .
*= require_self *= require_self
*= require bootstrap-table *= require bootstrap-table
*= require animate
*/ */
class IssuesController < ApplicationController class IssuesController < ApplicationController
require 'ostruct'
def index def index
# need some params: repo, label, filter(include from date, label) # need some params: repo, label, filter(include from date, label)
...@@ -34,6 +35,31 @@ class IssuesController < ApplicationController ...@@ -34,6 +35,31 @@ class IssuesController < ApplicationController
def show def show
@issue = Issue.find_by(id: params[:id]) @issue = Issue.find_by(id: params[:id])
@pulls = @issue.pull_requests
@comments = @issue.comments
@rv_comments = @issue.review_comments
@options = [
{id: 0, type: "None"},
{id: 1, type: "Small"},
{id: 2, type: "Medium"},
{id: 3, type: "Large"}]
end
def update
unless params[:comment].nil?
@comment = Comment.find_by(id: params[:comment][:id])
@comment.score = params[:comment][:score]
@comment.save
render json: {comment: @comment.id, score: @comment.score}
else
@rv_comment = ReviewComment.find_by(id: params[:rv_comment][:id])
@rv_comment.score = params[:rv_comment][:score]
@rv_comment.save
render json: {comment: @rv_comment.id, score: @rv_comment.score}
end
end end
end end
class RepositoryController < ApplicationController class RepositoriesController < ApplicationController
def index def index
@repos = Repository.paginate(:page => params[:page], :per_page => 10) @repos = Repository.all
end
def update
end end
end end
...@@ -5,4 +5,7 @@ class Issue < ApplicationRecord ...@@ -5,4 +5,7 @@ class Issue < ApplicationRecord
has_and_belongs_to_many :users # assignees has_and_belongs_to_many :users # assignees
has_many :comments has_many :comments
has_many :review_comments has_many :review_comments
has_many :pull_requests, class_name: "Issue", foreign_key: "issue_id"
belongs_to :issue, class_name: "Issue"
end end
class Timeline < ApplicationRecord
belongs_to :issue
end
...@@ -2,24 +2,171 @@ ...@@ -2,24 +2,171 @@
<h2><%= @issue.repository.name + "/" + @issue.title %></h2> <h2><%= @issue.repository.name + "/" + @issue.title %></h2>
<div class="row"> <div class="row">
<div class="col-md-8"> <div class="col-md-8">
<div class="panel panel-default">
<div class="panel-body">
<%= $markdown.render(@issue.body).html_safe %> <%= $markdown.render(@issue.body).html_safe %>
</div> </div>
</div>
<!-- <h2>List Comments in Issue</h2> -->
<% @comments.each do |comment| %>
<%= form_for :comment, method: :patch, html: { class: "form-inline" } do |f| %>
<div class="panel panel-default">
<%= f.hidden_field "id", value: comment.id %>
<div class="panel-heading"><h4><%= link_to comment.user.login %></h4></div>
<div class="panel-body"><%= $markdown.render(comment.body).html_safe %></div>
<div class="panel-footer">
<div class="form-group">
<% @comment = OpenStruct.new({ score: comment.score }) %>
<%= f.select("score", @options.collect { |x| [ x[:type], x[:id] ] }, {}, { class: 'form-control' }) %>
<%= f.submit "Save", class: "btn btn-default" %>
</div>
</div>
</div>
<% end %>
<% end %>
<!-- <h2>List Review Comments in Pull Request</h2> -->
<% @rv_comments.each do |rv_comment| %>
<%= form_for :rv_comment, method: :patch, html: { class: "form-inline" } do |f| %>
<div class="panel panel-default">
<%= f.hidden_field "id", value: rv_comment.id %>
<div class="panel-heading"><h4><%= link_to rv_comment.user.login %></h4></div>
<div class="panel-body"><%= $markdown.render(rv_comment.body).html_safe %></div>
<div class="panel-footer">
<div class="form-group">
<% @rv_comment = OpenStruct.new({ score: rv_comment.score }) %>
<%= f.select("score", @options.collect { |x| [ x[:type], x[:id] ] }, {}, { class: 'form-control' }) %>
<%= f.submit "Save", class: "btn btn-default" %>
</div>
</div>
</div>
<% end %>
<% end %>
</div>
<div class="col-md-4"> <div class="col-md-4">
<div> <div>
<h3>Assignee</h3> <div class="panel panel-default">
<div class="panel-heading">
<h4>Assignee</h4>
</div>
<ul class="list-group">
<% @issue.users.each do |user| %> <% @issue.users.each do |user| %>
<p><%= user.login %></p> <li class="list-group-item"><%= user.login %></li>
<% end %> <% end %>
<h3>Label</h3> </ul>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4>Label</h4>
</div>
<ul class="list-group">
<% @issue.labels.each do |label| %> <% @issue.labels.each do |label| %>
<p><%= label.name %></p> <li class="list-group-item"><%= label.name %></li>
<% end %> <% end %>
</ul>
</div>
<table class="table table-bordered">
<!-- <thead>
<tr>
<th class="col-md-6">Started Time</th>
<th class="col-md-6">End Time</th>
</tr>
</thead> -->
<tbody>
<tr>
<td class="col-md-4">Started Time</td>
<td class="col-md-8">20/12/2016</td>
</tr>
<tr>
<td class="col-md-4">End Time</td>
<td class="col-md-8">---</td>
</tr>
<tr>
<td class="col-md-4">Duration</td>
<td class="col-md-8">10 days (66.67%)</td>
</tr>
<tr>
<td class="col-md-4">Estimate</td>
<td class="col-md-8">15 days</td>
</tr>
</tbody>
</table>
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-4">Label</th>
<th class="col-md-8">Duration</th>
</tr>
</thead>
<tbody>
<tr>
<td>discussion</td>
<td>10 hours</td>
</tr>
<tr>
<td>todo</td>
<td>10 hours</td>
</tr>
<tr>
<td>inprogress</td>
<td>3 hours</td>
</tr>
<tr>
<td>vnreview</td>
<td>3 hours</td>
</tr>
<tr>
<td>jpreview</td>
<td>3 hours</td>
</tr>
<tr>
<td>ready</td>
<td>3 hours</td>
</tr>
<tr>
<td>done</td>
<td>3 hours</td>
</tr>
</tbody>
</table>
<div>
<div class="panel panel-default">
<div class="panel-heading">
<h4>Pull Requests</h4>
</div>
<ul class="list-group">
<% unless @pulls.nil? %>
<% @pulls.each do |pull| %>
<li class="list-group-item"><%= link_to pull.title, issue_path(pull) %></li>
<% end %>
<% end %>
</ul>
</div> </div>
</div> </div>
</div> </div>
<div class="row">
</div> </div>
</div> </div>
<script type="text/javascript">
$("form").submit(function() {
var submitVar = $(this).serialize();
$.ajax({
type: "POST",
url: $(this).attr("action"),
data: submitVar,
dataType: "JSON"
}).success(function(json) {
console.log(json);
$.notify({
title: "Success!",
message: "Comment score changed successfully.",
},{
type: "success",
delay: 100,
timer: 1000,
});
});
return false;
});
</script>
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<div id="navbar" class="navbar-collapse collapse"> <div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li><%= link_to "User", user_path %></li> <li><%= link_to "User", user_path %></li>
<li><%= link_to "Repository", repo_path %></li> <li><%= link_to "Repository", repositories_path %></li>
</ul> </ul>
</div> </div>
</div> </div>
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'tableExport' %> <%= javascript_include_tag 'tableExport' %>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head> </head>
<body> <body>
......
<div class="container">
<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-3">Repository</th>
<th class="col-md-7">Description</th>
<th class="col-md-2"></th>
</tr>
</thead>
<tbody>
<% @repos.each do |repo| %>
<tr>
<td><%= repo.name %></td>
<td><%= repo.description %></td>
<td>
<button>Update</button>
<i class="fa fa-refresh fa-spin" style="font-size:18px; visibility: hidden"></i>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<div class="container">
<% @repos.each do |repo| %>
<li>
<div>
<h3><%= link_to repo.name, repo.html_url %></h3>
</div>
<div>
<p><%= repo.description %></p>
</div>
</li>
<% end %>
<%= will_paginate @repos %>
</div>
$markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true) $markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,
tables: true,
fenced_code_blocks: true,
autolink: true,
disable_indented_code_blocks: true,
strikethrough: true,
lax_spacing: true,
space_after_headers: true,
superscript: true,
underline: true,
highlight: true,
quote: true,
footnotes: true)
Rails.application.routes.draw do Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root "main#index" root "main#index"
get "/repo", to: "repository#index"
post "/update_repo_selected", to: "main#update_repo_selected" post "/update_repo_selected", to: "main#update_repo_selected"
post "/update_params_selected", to: "main#update_params_selected" post "/update_params_selected", to: "main#update_params_selected"
post "/load_repo_selected", to: "main#load_repo_selected" post "/load_repo_selected", to: "main#load_repo_selected"
get "/user", to: "user#index" get "/user", to: "user#index"
resources :issues resources :issues
resources :pulls
resources :repositories
end end
class CreateTimelines < ActiveRecord::Migration[5.0]
def change
create_table :timelines do |t|
t.integer :duration
t.references :issue, foreign_key: true
t.string :label
t.date :started_time
t.date :end_time
t.timestamps
end
end
end
class AddScoreToComment < ActiveRecord::Migration[5.0]
def change
add_column :comments, :score, :integer
end
end
class AddIssueIdToPullRequest < ActiveRecord::Migration[5.0]
def change
add_reference :issues, :issue, index: true
end
end
class AddScoreToReviewComment < ActiveRecord::Migration[5.0]
def change
add_column :review_comments, :score, :integer
end
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20161207022421) do ActiveRecord::Schema.define(version: 20161228040705) do
create_table "comments", force: :cascade do |t| create_table "comments", force: :cascade do |t|
t.string "html_url" t.string "html_url"
...@@ -19,6 +19,7 @@ ActiveRecord::Schema.define(version: 20161207022421) do ...@@ -19,6 +19,7 @@ ActiveRecord::Schema.define(version: 20161207022421) do
t.integer "user_id" t.integer "user_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "score"
t.index ["issue_id"], name: "index_comments_on_issue_id" t.index ["issue_id"], name: "index_comments_on_issue_id"
t.index ["user_id"], name: "index_comments_on_user_id" t.index ["user_id"], name: "index_comments_on_user_id"
end end
...@@ -37,6 +38,8 @@ ActiveRecord::Schema.define(version: 20161207022421) do ...@@ -37,6 +38,8 @@ ActiveRecord::Schema.define(version: 20161207022421) do
t.boolean "open" t.boolean "open"
t.date "closed_at" t.date "closed_at"
t.boolean "is_pull" t.boolean "is_pull"
t.integer "issue_id"
t.index ["issue_id"], name: "index_issues_on_issue_id"
t.index ["repository_id"], name: "index_issues_on_repository_id" t.index ["repository_id"], name: "index_issues_on_repository_id"
t.index ["user_id"], name: "index_issues_on_user_id" t.index ["user_id"], name: "index_issues_on_user_id"
end end
...@@ -100,10 +103,22 @@ ActiveRecord::Schema.define(version: 20161207022421) do ...@@ -100,10 +103,22 @@ ActiveRecord::Schema.define(version: 20161207022421) do
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "rv_comment_id" t.integer "rv_comment_id"
t.string "commit_id" t.string "commit_id"
t.integer "score"
t.index ["issue_id"], name: "index_review_comments_on_issue_id" t.index ["issue_id"], name: "index_review_comments_on_issue_id"
t.index ["user_id"], name: "index_review_comments_on_user_id" t.index ["user_id"], name: "index_review_comments_on_user_id"
end end
create_table "timelines", force: :cascade do |t|
t.integer "duration"
t.integer "issue_id"
t.string "label"
t.date "started_time"
t.date "end_time"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["issue_id"], name: "index_timelines_on_issue_id"
end
create_table "users", force: :cascade do |t| create_table "users", force: :cascade do |t|
t.string "login" t.string "login"
t.string "url" t.string "url"
......
...@@ -282,3 +282,38 @@ I, [2016-12-23T16:40:30.534747 #14255] INFO -- : Insert comments ...@@ -282,3 +282,38 @@ 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.274630 #14255] INFO -- : Size list_db_comment: 3823
I, [2016-12-23T16:46:05.274699 #14255] INFO -- : Insert review comments I, [2016-12-23T16:46:05.274699 #14255] INFO -- : Insert review comments
I, [2016-12-23T16:52:05.582564 #14255] INFO -- : begin transaction I, [2016-12-23T16:52:05.582564 #14255] INFO -- : begin transaction
I, [2016-12-27T10:42:34.043907 #28951] INFO -- : Begin task insert comments
I, [2016-12-27T10:42:34.142280 #28951] INFO -- : Insert comments
I, [2016-12-27T10:43:05.160846 #29040] INFO -- : Begin task insert comments
I, [2016-12-27T10:43:05.260547 #29040] INFO -- : Insert comments
I, [2016-12-27T10:48:22.743855 #29040] INFO -- : Size list_db_comment: 3597
I, [2016-12-27T10:48:22.743928 #29040] INFO -- : Insert review comments
I, [2016-12-27T10:54:19.231241 #29040] INFO -- : Finished transaction in 4.258707679s
I, [2016-12-27T10:54:19.231296 #29040] INFO -- : Finished task import comments in 674.070370137s
I, [2016-12-27T11:09:04.574390 #31284] INFO -- : Begin task insert comments
I, [2016-12-27T11:09:04.691629 #31284] INFO -- : Insert comments
I, [2016-12-27T11:14:22.249420 #31284] INFO -- : Size list_db_comment: 3598
I, [2016-12-27T11:14:22.249493 #31284] INFO -- : Insert review comments
I, [2016-12-27T11:20:17.739881 #31284] INFO -- : Finished transaction in 4.186514473s
I, [2016-12-27T11:20:17.739971 #31284] INFO -- : Finished task import comments in 673.16547195s
I, [2016-12-27T13:34:39.330551 #5332] INFO -- : Begin task insert database from github
I, [2016-12-27T13:34:39.436167 #5332] INFO -- : Insert issues
I, [2016-12-27T13:37:39.697059 #5624] INFO -- : Begin task insert database from github
I, [2016-12-27T13:37:39.803551 #5624] INFO -- : Insert issues
I, [2016-12-28T16:22:33.104422 #11520] INFO -- : Begin task insert comments
I, [2016-12-28T16:22:33.232381 #11520] INFO -- : Insert comments
I, [2016-12-28T16:31:54.685759 #12013] INFO -- : Begin task insert database from github
I, [2016-12-28T16:31:54.797388 #12013] INFO -- : Insert issues
I, [2016-12-28T16:32:07.010102 #12013] INFO -- : Insert comments
I, [2016-12-28T16:32:11.797415 #12013] INFO -- : Size list_db_comment: 80
I, [2016-12-28T16:32:11.797491 #12013] INFO -- : Insert review comments
I, [2016-12-28T16:32:14.103878 #12013] INFO -- : begin transaction
I, [2016-12-28T16:32:14.385961 #12013] INFO -- : Finished transaction in 0.28197489s
I, [2016-12-28T16:33:02.316042 #12126] INFO -- : Begin task insert database from github
I, [2016-12-28T16:33:02.430848 #12126] INFO -- : Insert issues
I, [2016-12-28T16:33:14.875111 #12126] INFO -- : Insert comments
I, [2016-12-28T16:33:19.504494 #12126] INFO -- : Size list_db_comment: 80
I, [2016-12-28T16:33:19.504551 #12126] INFO -- : Insert review comments
I, [2016-12-28T16:33:21.796289 #12126] INFO -- : begin transaction
I, [2016-12-28T16:33:22.051691 #12126] INFO -- : Finished transaction in 0.255322035s
I, [2016-12-28T16:33:22.051784 #12126] INFO -- : Finished task import in 19.735731442s
class GithubLoader
$org = "ZIGExN"
$logger = Logger.new("github.log")
def insert_repos(client)
$logger.info "Insert repos"
repos = client.org_repos($org)
last_page = 1
unless client.last_response.headers[:link].nil?
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i
end
list_db_repo = []
for i in (1..last_page)
repos = client.org_repos($org, {type: 'all', page: i})
repos.each do |repo|
db_repo = Repository.find_by(id: repo.id)
if db_repo.nil?
db_repo = Repository.new
db_repo.id = repo.id
db_repo.name = repo.name
db_repo.full_name = repo.full_name
db_repo.private = repo.private
db_repo.description = repo.description
db_repo.url = repo.url
db_repo.html_url = repo.html_url
db_repo.created_at = repo.created_at
db_repo.updated_at = repo.updated_at
end
list_db_repo.append(db_repo)
end
end
list_db_repo
end
def insert_labels(client, db_repos)
$logger.info "Insert labels"
list_db_label = []
db_repos.each do |repo|
labels = client.labels($org + "/" + repo.name)
last_page = 1
unless client.last_response.headers[:link].nil?
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i
end
for i in (1..last_page)
labels = client.labels($org + "/" + repo.name, {page: i})
labels.each do |label|
db_label = Label.find_by(id: label.id)
if db_label.nil?
db_label = Label.new
db_label.id = label.id
db_label.url = label.url
db_label.repository_id = repo.id
end
db_label.name = label.name.gsub(/[^0-9A-Za-z]/, "").downcase # normalize string
db_label.color = label.color
db_label.default = label.default
list_db_label.append(db_label)
end
end
end
list_db_label
end
def insert_users(client)
$logger.info "Insert users"
users = client.org_members($org)
last_page = 1
unless client.last_response.headers[:link].nil?
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i
end
list_db_user = []
for i in (1..last_page)
users = client.org_members($org, {page: i})
users.each do |user|
db_user = User.find_by(id: user.id)
if db_user.nil?
db_user = User.new
db_user.id = user.id
db_user.login = user.login
db_user.url = user.url
db_user.html_url = user.html_url
end
list_db_user.append(db_user)
end
end
list_db_user
end
def insert_issues(client, list_db_user, list_db_label, db_repos)
$logger.info "Insert issues"
list_db_issue = []
db_repos.each do |repo|
issues = client.list_issues($org + "/" + repo.name, { state: "all" })
last_page = 1
unless client.last_response.headers[:link].nil?
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i
end
for i in (1..last_page)
issues = client.list_issues($org + "/" + repo.name, { state: "all", page: i })
issues.each do |issue|
db_issue = Issue.find_by(id: issue.id)
if db_issue.nil?
db_issue = Issue.new
db_issue.id = issue.id
db_issue.url = issue.url
db_issue.repository_url = issue.repository_url
db_issue.number = issue.number
db_issue.repository_id = repo.id
db_issue.user_id = issue.user.id
db_issue.created_at = issue.created_at
db_issue.html_url = issue.html_url
if issue[:pull_request].nil?
db_issue.is_pull = false
else
db_issue.is_pull = true
end
end
db_issue.title = issue.title
db_issue.body = issue.body
db_issue.updated_at = issue.updated_at
db_issue.closed_at = issue.closed_at
db_issue.labels.clear
issue.labels.each do |label|
list_db_label.each do |db_label|
if db_label.id == label.id
db_issue.labels.append(db_label)
break
end
end
end
db_issue.users.clear
issue.assignees.each do |assignee|
list_db_user.each do |db_user|
if db_user.id == assignee.id
db_issue.users.append(db_user)
break
end
end
end
list_db_issue.append(db_issue)
end
end
end
list_db_issue
end
def insert_comments(client, list_db_repo)
$logger.info "Insert comments"
list_db_comment = []
list_db_repo.each do |db_repo|
comments = client.issues_comments($org + "/" + db_repo.name)
last_page = 1
unless client.last_response.headers[:link].nil?
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i
end
for i in (1..last_page)
comments = client.issues_comments($org + "/" + db_repo.name, { page: i })
comments.each do |comment|
db_comment = Comment.find_by(html_url: comment.html_url)
if db_comment.nil?
db_comment = Comment.new
# db_comment.id = comment.id
db_comment.html_url = comment.html_url
issue_url = comment[:issue_url].split("/")
issue = Repository.find_by(name: issue_url[-3]).issues.find_by(number: issue_url[-1])
unless issue.nil?
db_comment.issue_id = issue.id
end
db_comment.user_id = comment.user.id
end
db_comment.body = comment.body
list_db_comment.append(db_comment)
end
end
end
$logger.info "Size list_db_comment: " + list_db_comment.size.to_s
list_db_comment
end
def insert_review_comments(client, list_db_repo)
$logger.info "Insert review comments"
list_db_rv_comment = []
list_db_repo.each do |db_repo|
rv_comments = client.pull_requests_comments($org + "/" + db_repo.name)
last_page = 1
unless client.last_response.headers[:link].nil?
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i
end
for i in (1..last_page)
rv_comments = client.pull_requests_comments($org + "/" + db_repo.name, { page: i })
rv_comments.each do |rv_comment|
db_rv_comment = ReviewComment.find_by(commit_id: rv_comment.commit_id)
if db_rv_comment.nil?
db_rv_comment = ReviewComment.new
# db_rv_comment.rv_comment_id = rv_comment.id
db_rv_comment.commit_id = rv_comment.commit_id
db_rv_comment.url = rv_comment.url
db_rv_comment.diff_hunk = rv_comment.diff_hunk
db_rv_comment.path = rv_comment.path
db_rv_comment.html_url = rv_comment.html_url
db_rv_comment.pull_request_url = rv_comment.pull_request_url
db_rv_comment.created_at = rv_comment.created_at
unless rv_comment.user.nil?
db_rv_comment.user_id = rv_comment.user.id
end
pull_request_url_split = rv_comment.pull_request_url.split("/")
issue = Repository.find_by(name: pull_request_url_split[-3]).issues.find_by(number: pull_request_url_split[-1])
unless issue.nil?
db_rv_comment.issue_id = issue.id
end
end
db_rv_comment.updated_at = rv_comment.updated_at
db_rv_comment.body = rv_comment.body
list_db_rv_comment.append(db_rv_comment)
end
end
end
list_db_rv_comment
end
def update_issue_pull_association
issues = Issue.all.includes(:issue, :pull_requests)
pulls = issues.where(is_pull: true)
pulls.each do |pull|
if pull.issue.nil?
content = pull.comments.first
unless content.nil?
issue_number = /#[0-9]+/.match(content.body)
unless issue_number.nil?
issue = issues.where(repository_id: pull.repository_id).find_by(number: issue_number.to_s[1..-1])
pull.issue = issue
puts pull.save
end
end
end
end
end
def update_repo(repositories)
repositories.each do |repo|
end
end
end
No preview for this file type
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
duration: 1
issue: one
label: MyString
started_time: 2016-12-27
end_time: 2016-12-27
two:
duration: 1
issue: two
label: MyString
started_time: 2016-12-27
end_time: 2016-12-27
require 'test_helper'
class TimelineTest < ActiveSupport::TestCase
# 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