修改bug

This commit is contained in:
sylor_huang@126.com 2020-06-18 15:46:00 +08:00
parent 16a5887d66
commit 4c7fa23404
10 changed files with 40 additions and 92 deletions

View File

@ -13,14 +13,15 @@ class IssuesController < ApplicationController
def index
@user_admin_or_member = current_user.present? && current_user.logged? && (current_user.admin || @project.member?(current_user))
issues = @project.issues.issue_issue
issues = @project.issues.issue_issue.issue_index_includes
issues = issues.where(is_private: false) unless @user_admin_or_member
@all_issues_size = issues.size
@open_issues_size = issues.where.not(status_id: 5).size
@close_issues_size = issues.where(status_id: 5).size
@assign_to_me_size = issues.where(assigned_to_id: current_user&.id).size
@my_published_size = issues.where(author_id: current_user&.id).size
scopes = Issues::ListQueryService.call(issues,params.delete_if{|k,v| v.blank?})
scopes = Issues::ListQueryService.call(issues,params.delete_if{|k,v| v.blank?}, "Issue")
@issues_size = scopes.size
@issues = paginate(scopes)

View File

@ -10,15 +10,15 @@ class PullRequestsController < ApplicationController
def index
# @issues = Gitea::PullRequest::ListService.new(@user,@repository.try(:identifier)).call #通过gitea获取
issues = @project.issues.issue_pull_request
issues = @project.issues.issue_pull_request.issue_index_includes.includes(:pull_request)
issues = issues.where(is_private: false) unless current_user.present? && (current_user.admin? || @project.member?(current_user))
@all_issues_size = issues.size
@open_issues_size = issues.where.not(status_id: 5).size
@close_issues_size = issues.where(status_id: 5).size
@open_issues_size = issues.joins(:pull_request).where(pull_requests: {status: 0}).size
@close_issues_size = issues.joins(:pull_request).where(pull_requests: {status: 2}).size
@merged_issues_size = issues.joins(:pull_request).where(pull_requests: {status: 1}).size
@user_admin_or_member = current_user.present? && (current_user.admin || @project.member?(current_user))
scopes = Issues::ListQueryService.call(issues,params.delete_if{|k,v| v.blank?})
scopes = Issues::ListQueryService.call(issues,params.delete_if{|k,v| v.blank?}, "PullRequest")
@issues_size = scopes.size
@issues = paginate(scopes)
end
@ -130,19 +130,6 @@ class PullRequestsController < ApplicationController
end
def simple_update
# ActiveRecord::Base.transaction do
# begin
# @pull_request.update(status: 2)
# @pull_request.issue.update(status_id: 5)
# normal_status(1, "已拒绝")
# rescue => e
# normal_status(-1, e.message)
# raise ActiveRecord::Rollback
# end
# end
end
def refuse_merge
ActiveRecord::Base.transaction do
begin
@ -176,9 +163,7 @@ class PullRequestsController < ApplicationController
}
merge_pr = Gitea::PullRequest::MergeService.new(current_user, @repository.try(:identifier), @pull_request.try(:gpid), requests_params).call
if @pull_request.update_attribute(:status, 1) && merge_pr[:status].to_i == 200
# @pull_request.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "merge")
@pull_request&.project_trends&.update_all(action_type: "close")
@issue&.custom_journal_detail("merge", "", "该合并请求已被合并", current_user&.id)
normal_status(1, "合并成功")
else
@ -192,57 +177,6 @@ class PullRequestsController < ApplicationController
end
end
#评审
def check_merge
# notes = params[:content]
# pull_request_status = params[:status]
# if notes.blank?
# normal_status(-1, "评论内容不能为空")
# else
# if @pull_request.status > 0
# normal_status(-1, "已合并,不能评审")
# else
# if pull_request_status.to_i == 1
# message = "评审通过:"
# elsif pull_request_status.to_i == 2
# message = "评审请求变更:"
# else
# message = ""
# end
# journal_params = {
# journalized_id: @issue.id ,
# journalized_type: "Issue",
# user_id: current_user.id ,
# notes: message + notes.to_s.strip
# }
# journal = Journal.new journal_params
# if journal.save
# if pull_request_status.present?
# @pull_request.update_attribute(:status, pull_request_status.to_i)
# end
# if pull_request_status.to_i == 1
# requests_params = {
# do: "merge",
# MergeMessageField: notes,
# MergeTitleField: "Merge PullRequest ##{@pull_request.gpid}"
# }
# merge_pr = Gitea::PullRequest::MergeService.new(current_user, @repository.try(:identifier), @pull_request.try(:gpid), requests_params).call
# if merge_pr
# @pull_request&.project_trends&.update_all(action_type: "close")
# # @pull_request.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "merge")
# @issue.custom_journal_detail("merge", "", "该合并请求已被合并", current_user&.id)
# normal_status(1, "评审成功")
# else
# normal_status(-1, "评审失败")
# end
# end
# normal_status(0, "评审成功")
# else
# normal_status(-1, "评审失败")
# end
# end
# end
end
def check_can_merge
target_head = params[:head] #源分支
@ -268,10 +202,8 @@ class PullRequestsController < ApplicationController
private
def set_repository
# @project = Project.find_by_identifier! params[:id]
@repository = @project.repository
@user = @project.owner
# normal_status(-1, "项目不存在") unless @project.present?
normal_status(-1, "仓库不存在") unless @repository.present?
normal_status(-1, "用户不存在") unless @user.present?
end

View File

@ -34,7 +34,7 @@ module TagChosenHelper
end
project_members = project.members_user_infos
project_members_info = [] #指派给
project_members.each do |member|
project_members.includes(user: :user_extension).each do |member|
user = member&.user
if user
real_name = user.try(:show_real_name)

View File

@ -22,14 +22,14 @@ class Issue < ApplicationRecord
scope :issue_many_includes, ->{includes(journals: :user)}
scope :issue_issue, ->{where(issue_classify: [nil,"issue"])}
scope :issue_pull_request, ->{where(issue_classify: "pull_request")}
scope :issue_index_includes, ->{includes(:user,:tracker, :priority, :version, :issue_status, :journals, :issue_times)}
scope :issue_index_includes, ->{includes(:tracker, :priority, :version, :issue_status, :journals,:issue_tags,user: :user_extension)}
after_update :change_versions_count
after_destroy :update_closed_issues_count_in_project!
def get_assign_user
User.select(:login, :lastname,:firstname, :nickname)&.find_by_id(self.assigned_to_id)
User&.find_by_id(self.assigned_to_id) if self.assigned_to_id.present?
end
def create_journal_detail(change_files, issue_files, issue_file_ids, user_id)

View File

@ -17,6 +17,12 @@ class Projects::ListMyQuery < ApplicationQuery
projects = Project.visible
end
if params[:is_public].present? && !params[:is_public]
projects = projects.is_private.joins(:members).where(members: { user_id: user.id })
else
projects = projects.visible.joins(:members).where(members: { user_id: user.id })
end
if params[:category].blank?
projects = projects.joins(:members).where(members: { user_id: user.id })
elsif params[:category].to_s == "join"
@ -28,10 +34,10 @@ class Projects::ListMyQuery < ApplicationQuery
elsif params[:category].to_s == "forked" #我fork的
fork_ids = user.fork_users.select(:id, :fork_project_id).pluck(:fork_project_id)
projects = projects.where(id: fork_ids)
elsif params[:category].to_s == "public"
projects = projects.visible.joins(:members).where(members: { user_id: user.id })
elsif params[:category].to_s == "private"
projects = projects.is_private.joins(:members).where(members: { user_id: user.id })
# elsif params[:category].to_s == "public"
# projects = projects.visible.joins(:members).where(members: { user_id: user.id })
# elsif params[:category].to_s == "private"
# projects = projects.is_private.joins(:members).where(members: { user_id: user.id })
end
if params[:project_type].to_s === "common"

View File

@ -1,10 +1,11 @@
class Issues::ListQueryService < ApplicationService
attr_reader :all_issues, :params
attr_reader :all_issues, :params,:select_type
def initialize(all_issues, params)
def initialize(all_issues, params, select_type)
@all_issues = all_issues
@params = params
@select_type = select_type
end
def call
@ -17,7 +18,11 @@ class Issues::ListQueryService < ApplicationService
if status_type.to_s == "2" #表示关闭中的
issues = issues.where(status_id: 5)
elsif status_type.to_s == "1"
issues = issues.where.not(status_id: 5) #默认显示开启中的
if(select_type == "Issue")
issues = issues.where.not(status_id: 5) #默认显示开启中的
else
issues = issues.joins(:pull_request).where(pull_requests: {status: 0}) #默认显示开启中的
end
elsif status_type.to_s == "11" #表示pr的已关闭
issues = issues.joins(:pull_request).where(pull_requests: {status: 1})
end

View File

@ -7,9 +7,12 @@ class Projects::CreateService < ApplicationService
end
def call
Rails.logger.info("#############__________project_params______###########{project_params}")
@project = Project.new(project_params)
ActiveRecord::Base.transaction do
if @project.save!
Rails.logger.info("#############___________repository_params______###########{repository_params}")
Repositories::CreateService.new(user, @project, repository_params).call
else
#
@ -39,17 +42,17 @@ class Projects::CreateService < ApplicationService
def repository_params
{
hidden: get_is_public,
hidden: !repo_is_public,
user_id: params[:user_id],
identifier: params[:repository_name]
}
end
def get_is_public
params[:private] || false
end
# def get_is_public
# params[:private] || false
# end
def repo_is_public
params[:private].blank? ? true : !get_is_public
params[:private].blank? ? true : !params[:private]
end
end

View File

@ -11,6 +11,8 @@ class Repositories::CreateService < ApplicationService
@repository = Repository.new(repository_params)
ActiveRecord::Base.transaction do
if @repository.save!
Rails.logger.info("#############__________gitea_repository_params______###########{gitea_repository_params}")
gitea_repository = Gitea::Repository::CreateService.new(user.gitea_token, gitea_repository_params).call
sync_project(@repository, gitea_repository)
sync_repository(@repository, gitea_repository)

View File

@ -2,7 +2,7 @@ json.identifier @project.identifier
json.name @project.name
json.project_id @project.id
json.repo_id @project.repository.id
json.issues_count @project.issues_count
json.issues_count @project.issues_count.to_i - @project.pull_requests_count.to_i
json.pull_requests_count @project.pull_requests_count
json.project_identifier @project.identifier
json.praises_count @project.praises_count.to_i

View File

@ -64,8 +64,7 @@ Rails.application.routes.draw do
resources :pull_requests, except: [:destroy] do
member do
post :pr_merge
post :check_merge
post :simple_update
# post :check_merge
post :refuse_merge
end
collection do