Commit 3d7b1ef9 by Bui Minh Duc

implement repositories controller

parent 6ea3bed9
...@@ -40,6 +40,7 @@ gem 'bootstrap3-datetimepicker-rails', '~> 4.14.30' ...@@ -40,6 +40,7 @@ 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' gem 'bootstrap-growl-rails'
gem 'sidekiq', '~> 4.2', '>= 4.2.7'
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
......
...@@ -62,6 +62,7 @@ GEM ...@@ -62,6 +62,7 @@ GEM
execjs execjs
coffee-script-source (1.12.2) coffee-script-source (1.12.2)
concurrent-ruby (1.0.4) concurrent-ruby (1.0.4)
connection_pool (2.2.1)
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)
...@@ -103,6 +104,8 @@ GEM ...@@ -103,6 +104,8 @@ GEM
public_suffix (2.0.4) public_suffix (2.0.4)
puma (3.6.2) puma (3.6.2)
rack (2.0.1) rack (2.0.1)
rack-protection (1.5.3)
rack
rack-test (0.6.3) rack-test (0.6.3)
rack (>= 1.0) rack (>= 1.0)
rails (5.0.1) rails (5.0.1)
...@@ -133,6 +136,7 @@ GEM ...@@ -133,6 +136,7 @@ GEM
rb-inotify (0.9.7) rb-inotify (0.9.7)
ffi (>= 0.5.0) ffi (>= 0.5.0)
redcarpet (3.4.0) redcarpet (3.4.0)
redis (3.3.2)
sass (3.4.23) sass (3.4.23)
sass-rails (5.0.6) sass-rails (5.0.6)
railties (>= 4.0.0, < 6) railties (>= 4.0.0, < 6)
...@@ -143,6 +147,11 @@ GEM ...@@ -143,6 +147,11 @@ GEM
sawyer (0.8.1) sawyer (0.8.1)
addressable (>= 2.3.5, < 2.6) addressable (>= 2.3.5, < 2.6)
faraday (~> 0.8, < 1.0) faraday (~> 0.8, < 1.0)
sidekiq (4.2.7)
concurrent-ruby (~> 1.0)
connection_pool (~> 2.2, >= 2.2.0)
rack-protection (>= 1.5.0)
redis (~> 3.2, >= 3.2.1)
spring (2.0.0) spring (2.0.0)
activesupport (>= 4.2) activesupport (>= 4.2)
spring-watcher-listen (2.0.1) spring-watcher-listen (2.0.1)
...@@ -195,6 +204,7 @@ DEPENDENCIES ...@@ -195,6 +204,7 @@ DEPENDENCIES
rails (~> 5.0.0, >= 5.0.0.1) rails (~> 5.0.0, >= 5.0.0.1)
redcarpet (~> 3.3, >= 3.3.4) redcarpet (~> 3.3, >= 3.3.4)
sass-rails (~> 5.0) sass-rails (~> 5.0)
sidekiq (~> 4.2, >= 4.2.7)
spring spring
spring-watcher-listen (~> 2.0.0) spring-watcher-listen (~> 2.0.0)
sqlite3 sqlite3
......
...@@ -5,6 +5,10 @@ class RepositoriesController < ApplicationController ...@@ -5,6 +5,10 @@ class RepositoriesController < ApplicationController
end end
def update def update
@repo = Repository.find_by(id: params[:id])
RepositoryJob.perform_now(@repo.name)
@repos = Repository.all
render "index"
end end
end end
class RepositoryJob < ApplicationJob
queue_as :default
def perform(*args)
# Do something later
Dir.glob('lib/github_loader.rb').each { |r| load r}
logger = Logger.new("github.log")
loader = GithubLoader.new
start_time = Time.now
logger.info "Begin task update " + args.first
list_db_repo = Repository.where(name: args.first)
list_db_user = User.all
list_db_label = Label.all
list_db_issue = loader.insert_issues($client, list_db_user, list_db_label, list_db_repo)
list_db_comment = loader.insert_comments($client, list_db_repo)
list_db_rv_comment = loader.insert_review_comments($client, list_db_repo)
logger.info "begin transaction"
start_time_transaction = Time.now
ActiveRecord::Base.transaction do
list_db_issue.each do |db_issue|
db_issue.save
end
list_db_comment.each do |db_comment|
db_comment.save
end
list_db_rv_comment.each do |db_rv_comment|
db_rv_comment.save
end
end
logger.info "Finished transaction in #{Time.now - start_time_transaction}s"
logger.info "Finished task update in #{Time.now - start_time}s"
end
end
<div class="container"> <div class="container">
<% unless @repo.nil? %>
<div class="alert alert-success alert-dismissable">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<%= @repo.name %> updated successfully
</div>
<% end %>
<table data-toolbar="#toolbar" <table data-toolbar="#toolbar"
data-toggle="table" data-toggle="table"
data-search="true" data-search="true"
...@@ -23,8 +31,10 @@ ...@@ -23,8 +31,10 @@
<td><%= repo.name %></td> <td><%= repo.name %></td>
<td><%= repo.description %></td> <td><%= repo.description %></td>
<td> <td>
<button>Update</button> <%= form_for :repo, url: { action: "update", id: repo.id }, method: :patch, html: { class: "form-inline" } do |f| %>
<i class="fa fa-refresh fa-spin" style="font-size:18px; visibility: hidden"></i> <%= f.submit "Update" %>
<i class="fa fa-refresh fa-spin" style="font-size:18px; visibility: hidden;"></i>
<% end %>
</td> </td>
</tr> </tr>
<% end %> <% end %>
......
...@@ -11,5 +11,6 @@ module VenturaGhr ...@@ -11,5 +11,6 @@ module VenturaGhr
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers # Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded. # -- all .rb files in that directory are automatically loaded.
config.active_job.queue_adapter = :sidekiq
end end
end end
...@@ -9,4 +9,5 @@ Rails.application.routes.draw do ...@@ -9,4 +9,5 @@ Rails.application.routes.draw do
resources :issues resources :issues
resources :pulls resources :pulls
resources :repositories resources :repositories
resources :comments
end end
class ChangeTimeline < ActiveRecord::Migration[5.0]
def change
change_column :timelines, :started_time, :datetime
change_column :timelines, :end_time, :datetime
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: 20161228040705) do ActiveRecord::Schema.define(version: 20161230092006) do
create_table "comments", force: :cascade do |t| create_table "comments", force: :cascade do |t|
t.string "html_url" t.string "html_url"
...@@ -112,8 +112,8 @@ ActiveRecord::Schema.define(version: 20161228040705) do ...@@ -112,8 +112,8 @@ ActiveRecord::Schema.define(version: 20161228040705) do
t.integer "duration" t.integer "duration"
t.integer "issue_id" t.integer "issue_id"
t.string "label" t.string "label"
t.date "started_time" t.datetime "started_time"
t.date "end_time" t.datetime "end_time"
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.index ["issue_id"], name: "index_timelines_on_issue_id" t.index ["issue_id"], name: "index_timelines_on_issue_id"
......
...@@ -130,6 +130,10 @@ class GithubLoader ...@@ -130,6 +130,10 @@ class GithubLoader
db_issue.updated_at = issue.updated_at db_issue.updated_at = issue.updated_at
db_issue.closed_at = issue.closed_at db_issue.closed_at = issue.closed_at
# TODO
col_labels = ["discussion", "todo", "inprogress", "vnreview", "jpreview",
"ready", "done", "releasefailed", "pending"]
old_label = db_issue.labels.find_by(name: col_labels)
db_issue.labels.clear db_issue.labels.clear
issue.labels.each do |label| issue.labels.each do |label|
list_db_label.each do |db_label| list_db_label.each do |db_label|
...@@ -139,6 +143,22 @@ class GithubLoader ...@@ -139,6 +143,22 @@ class GithubLoader
end end
end end
end end
new_label = db_issue.labels.find_by(name: col_labels)
if old_label.nil?
unless new_label.nil?
timeline = Timeline.new
timeline.issue_id = db_issue.id
timeline.label = new_label.name
timeline.started_time = Time.now
timeline.save
$logger.info "Hello"
end
elsif new_label.name != old_label.name
timeline = Timeline.where(issue_id: db_issue.id, label: old_label.name).first
timeline.end_time = Time.now
timeline.save
end
# end TODO
db_issue.users.clear db_issue.users.clear
issue.assignees.each do |assignee| issue.assignees.each do |assignee|
......
require 'test_helper'
class RepositoryJobTest < ActiveJob::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