Commit 821d7250 by Bui Minh Duc

add pullrequest controller

parent 4f7c94b1
# 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 pulls controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class PullsController < ApplicationController
def show
@pull = Issue.find_by(id: params[:id])
@issue = @pull.issue
@repo = @issue.repository
@comments = @pull.comments
@rv_comments = @pull.review_comments
@options = [
{id: 0, type: "None"},
{id: 1, type: "Small"},
{id: 2, type: "Medium"},
{id: 3, type: "Large"}]
end
def update
@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
class RepositoriesController < ApplicationController
require 'ostruct'
def index
@repos = Repository.all
......@@ -11,7 +12,9 @@ class RepositoriesController < ApplicationController
1 => "Closed",
2 => "Both"
}
@current_type = params["issue"]["type"]
@current_type = params["type"]
@repo = Repository.find_by(id: params[:id])
@issues = nil
if @current_type.nil? || @current_type == "0"
......
module PullsHelper
end
......@@ -9,30 +9,9 @@ class RepositoryJob < ApplicationJob
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
# byebug
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"
loader.insert_issues($client, list_db_repo)
loader.insert_comments($client, list_db_repo)
loader.insert_review_comments($client, list_db_repo)
logger.info "Finished task update in #{Time.now - start_time}s"
end
end
<div class="container">
<h2><%= @repo_name %></h2>
<ol class="breadcrumb">
<li><h3><%= @repo_name %></h3></li>
</ol>
<div>
<table data-toolbar="#toolbar"
data-toggle="table"
......
<div class="container">
<h2><%= @issue.repository.name + "/" + @issue.title %></h2>
<ol class="breadcrumb">
<li><%= link_to @issue.repository.name, @issue.repository %></li>
<li><%= @issue.title %></li>
</ol>
<div class="row">
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-body">
<%= $markdown.render(@issue.body).html_safe %>
</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 %>
<table class="table table-bordered">
<thead>
<tr>
......@@ -73,28 +35,58 @@
<% end %>
</tbody>
</table>
<div class="panel panel-default">
<div class="panel-body">
<%= $markdown.render(@issue.body).html_safe %>
</div>
<div class="col-md-4">
</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">
<div class="panel-heading">
<h4>Assignee</h4>
<%= f.hidden_field "id", value: comment.id %>
<div class="panel-heading"><h4><%= link_to comment.user.login, comment.user.html_url %></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>
<ul class="list-group">
<% @issue.users.each do |user| %>
<li class="list-group-item"><%= user.login %></li>
<% end %>
</ul>
</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">
<div class="panel-heading">
<h4>Label</h4>
<%= 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">
<div class="panel panel-default">
<div class="panel-body">
<p><%= simple_format(rv_comment.diff_hunk) %></p>
</div>
</div>
<div class="col-md-8">
<%= $markdown.render(rv_comment.body).html_safe %>
</div>
<div class="col-md-4">
<div class="form-group" style="float: right;">
<% @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>
</div>
<ul class="list-group">
<% @issue.labels.each do |label| %>
<li class="list-group-item"><%= label.name %></li>
<% end %>
</ul>
<% end %>
</div>
<div class="col-md-4">
<table class="table table-bordered">
<tbody>
<tr>
......@@ -128,11 +120,31 @@
<ul class="list-group">
<% unless @pulls.nil? %>
<% @pulls.each do |pull| %>
<li class="list-group-item"><%= link_to pull.title, issue_path(pull) %></li>
<li class="list-group-item"><%= link_to pull.title, pull_path(pull.id) %></li>
<% end %>
<% end %>
</ul>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4>Assignee</h4>
</div>
<ul class="list-group">
<% @issue.users.each do |user| %>
<li class="list-group-item"><%= user.login %></li>
<% end %>
</ul>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4>Label</h4>
</div>
<ul class="list-group">
<% @issue.labels.each do |label| %>
<li class="list-group-item"><%= label.name %></li>
<% end %>
</ul>
</div>
</div>
</div>
</div>
......
<div class="container">
<ol class="breadcrumb">
<li><%= link_to @repo.name, @repo %></li>
<li><%= link_to @issue.title, @issue %></li>
<li><%= @pull.title %></li>
</ol>
<div class="row">
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-body">
<%= $markdown.render(@pull.body).html_safe %>
</div>
</div>
<% @comments.each do |comment| %>
<div class="panel panel-default">
<div class="panel-heading"><h4><%= link_to comment.user.login, comment.user.html_url %></h4></div>
<div class="panel-body"><%= $markdown.render(comment.body).html_safe %></div>
</div>
<% end %>
<% @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">
<div class="panel panel-default">
<div class="panel-body">
<p><%= simple_format(rv_comment.diff_hunk) %></p>
</div>
</div>
<div class="col-md-8">
<%= $markdown.render(rv_comment.body).html_safe %>
</div>
<div class="col-md-4">
<div class="form-group" style="float: right;">
<% @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>
</div>
<% end %>
<% end %>
</div>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<h4>Assignee</h4>
</div>
<ul class="list-group">
<% @pull.users.each do |user| %>
<li class="list-group-item"><%= user.login %></li>
<% end %>
</ul>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4>Label</h4>
</div>
<ul class="list-group">
<% @pull.labels.each do |label| %>
<li class="list-group-item"><%= label.name %></li>
<% end %>
</ul>
</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>
</div>
<div class="container">
<h2><%= @repo.name %></h2>
<ol class="breadcrumb">
<li><%= @repo.name %></li>
</ol>
<div id="toolbar">
<form class="form-inline">
<div class="form-group">
<label>Type</label>
<div class="form-group">
<%= select("issue", "type", @type.collect{ |x| [x[1], x[0]] }, {}, { class: "form-control" }) %>
<%= select_tag "type", options_from_collection_for_select(@type, "first", "second", @current_type), { class: "form-control" } %>
<input type="submit" class="btn btn-default">
</div>
</div>
......@@ -16,6 +18,7 @@
<div style="margin-top: 20px">
<table data-toolbar="#toolbar"
id="main_table"
data-toggle="table"
data-search="true"
data-show-export="true"
......@@ -28,17 +31,24 @@
data-page-list="[10, 25, 50, 100, ALL]">
<thead>
<tr>
<th>List of issues</th>
<th class="col-md-9">List of issues</th>
<th class="col-md-3">Created at</th>
</tr>
</thead>
<tbody>
<% @issues.each do |issue| %>
<tr>
<td><%= link_to issue.title, issue %></td>
<td><%= issue.created_at %></td>
</tr>
<% issue.pull_requests.each do |pull| %>
<tr>
<td>______<%= link_to pull.title, pull_path(pull.id) %></td>
<td><%= pull.created_at %></td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</div>
</div>
......@@ -27,7 +27,6 @@ class GithubLoader
db_repo.html_url = repo.html_url
db_repo.created_at = repo.created_at
db_repo.updated_at = repo.updated_at
end
db_repo.save
# list_db_repo.append(db_repo)
......@@ -90,7 +89,6 @@ class GithubLoader
db_user.login = user.login
db_user.url = user.url
db_user.html_url = user.html_url
end
db_user.save
# list_db_user.append(db_user)
......@@ -99,11 +97,11 @@ class GithubLoader
# list_db_user
end
def insert_issues(client)
def insert_issues(client, db_repos)
$logger.info "Insert issues"
list_db_user = User.all
list_db_label = Label.all
db_repos = Repository.all
# db_repos = Repository.all
# list_db_issue = []
db_repos.each do |repo|
......@@ -167,7 +165,7 @@ class GithubLoader
timeline.end_time = Time.now
timeline.save
rescue
byebug
# byebug
end
new_timeline(db_issue.id, new_label.name)
......@@ -198,10 +196,10 @@ class GithubLoader
# list_db_issue
end
def insert_comments(client)
def insert_comments(client, list_db_repo)
$logger.info "Insert comments"
# list_db_comment = []
list_db_repo = Repository.all
# list_db_repo = Repository.all
list_db_repo.each do |db_repo|
comments = client.issues_comments($org + "/" + db_repo.name)
......@@ -236,10 +234,8 @@ class GithubLoader
# list_db_comment
end
def insert_review_comments(client)
def insert_review_comments(client, list_db_repo)
$logger.info "Insert review comments"
# list_db_rv_comment = []
list_db_repo = Repository.all
list_db_repo.each do |db_repo|
rv_comments = client.pull_requests_comments($org + "/" + db_repo.name)
last_page = 1
......@@ -249,12 +245,14 @@ class GithubLoader
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)
$logger.info rv_comment.body
db_rv_comment = ReviewComment.where(commit_id: rv_comment.commit_id, rv_comment_id: rv_comment.id).first
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.rv_comment_id = rv_comment.id
db_rv_comment.url = rv_comment.url
db_rv_comment.diff_hunk = rv_comment.diff_hunk
db_rv_comment.path = rv_comment.path
......@@ -277,12 +275,11 @@ class GithubLoader
db_rv_comment.updated_at = rv_comment.updated_at
db_rv_comment.body = rv_comment.body
db_rv_comment.save
# list_db_rv_comment.append(db_rv_comment)
end
end
end
# list_db_rv_comment
end
def update_issue_pull_association
......
......@@ -4,12 +4,6 @@ namespace :github do
$org = "ZIGExN"
$logger = Logger.new("github.log")
desc "Task description"
task task_test: :environment do
# logger = Logger.new("test.log")
# logger.info "a message"
end
desc "Insert Zigexn Github data"
task insert_github_data: :environment do
loader = GithubLoader.new
......@@ -19,7 +13,7 @@ namespace :github do
loader.insert_repos($client)
loader.insert_users($client)
loader.insert_labels($client)
loader.insert_issues($client)
loader.insert_issues($client, Repository.all)
loader.update_issue_pull_association
......@@ -66,32 +60,13 @@ namespace :github do
task insert_github_data_for_specific_repos: :environment do
loader = GithubLoader.new
start_time = Time.now
repos_to_update = Other.where(data_type: 2).map{ |x|x.data }
repos_to_update = Other.where(data_type: 2).map{ |x| x.data }
$logger.info "Begin task update " + repos_to_update.to_s
list_db_repo = Repository.where(name: repos_to_update)
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
loader.insert_issues($client, list_db_repo)
loader.insert_comments($client, list_db_repo)
loader.insert_review_comments($client, list_db_repo)
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
......
require 'test_helper'
class PullsControllerTest < 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