Merge remote-tracking branch 'origin_trustie/dev_trustie' into dev_trustie

This commit is contained in:
qyzh 2020-07-15 10:55:16 +08:00
commit 38193dff54
62 changed files with 1139 additions and 375 deletions

1
.gitignore vendored
View File

@ -80,3 +80,4 @@ docker/
educoder.sql
redis_data/
Dockerfile
dump.rdb

View File

@ -40,7 +40,7 @@ gem 'oauth2'
#导出为pdf
gem 'pdfkit'
gem 'wkhtmltopdf-binary'
gem 'request_store'
# gem 'request_store'
#gem 'iconv'
# markdown 转html
gem 'redcarpet', '~> 3.4'
@ -66,6 +66,7 @@ group :development, :test do
end
group :development do
gem 'prettier'
gem 'rubocop', '~> 0.52.0'
gem 'solargraph', '~> 0.38.0'
gem 'awesome_print'

View File

@ -218,6 +218,7 @@ GEM
activerecord (>= 5.2.1)
popper_js (1.16.0)
powerpack (0.1.2)
prettier (0.18.2)
public_suffix (4.0.3)
puma (3.12.2)
rack (2.0.9)
@ -466,6 +467,7 @@ DEPENDENCIES
omniauth-oauth2 (~> 1.6.0)
parallel (~> 1.19, >= 1.19.1)
pdfkit
prettier
puma (~> 3.11)
rack-cors
rack-mini-profiler

View File

@ -0,0 +1,13 @@
// Action Cable provides the framework to deal with WebSockets in Rails.
// You can generate new channels where WebSocket features live using the `rails generate channel` command.
//
//= require action_cable
//= require_self
//= require_tree ./channels
(function() {
this.App || (this.App = {});
App.cable = ActionCable.createConsumer();
}).call(this);

View File

@ -0,0 +1,13 @@
App.mirror_project = App.cable.subscriptions.create("MirrorProjectChannel", {
connected: function() {
// Called when the subscription is ready for use on the server
},
disconnected: function() {
// Called when the subscription has been terminated by the server
},
received: function(data) {
// Called when there's incoming data on the websocket for this channel
}
});

View File

@ -1,4 +1,20 @@
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
logger.add_tags 'ActionCable', current_user.id
end
private
def find_verified_user
puts "############### cookies.signed[:signed_user_id]: #{cookies.signed[:user_id]}"
if current_user = User.find_by(id: cookies.signed[:user_id])
current_user
else
reject_unauthorized_connection
end
end
end
end

View File

@ -0,0 +1,12 @@
class MirrorProjectChannel < ApplicationCable::Channel
def subscribed
Rails.logger.info "################### channel params: #{params}"
# @project = Project.find_by_identifier params[:id]
stream_from "channel_room_#{params[:id]}"
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
Rails.logger.info "################### unsubscribed ################### "
end
end

View File

@ -1,8 +1,13 @@
class AdminConstraint
def matches?(request)
laboratory = Laboratory.first
return false unless request.session[:"#{laboratory.try(:identifier).split('.').first}_user_id"]
user = User.find request.session[:"#{laboratory.try(:identifier).split('.').first}_user_id"]
user && user.admin?
if Rails.env.development?
true
else
laboratory = Laboratory.first
return false unless request.session[:"#{laboratory.try(:identifier).split('.').first}_user_id"]
user = User.find request.session[:"#{laboratory.try(:identifier).split('.').first}_user_id"]
user && user.admin?
end
end
end

View File

@ -269,7 +269,9 @@ class AccountsController < ApplicationController
cookie_options = cookie_options.merge(domain: edu_setting('cookie_domain'))
end
cookies[autologin_cookie_name] = cookie_options
logger.info("cookies is #{cookies}")
cookies.signed[:user_id] ||= user.id
logger.info("cookies is #{cookies} ======> #{cookies.signed[:user_id]} =====> #{cookies[autologin_cookie_name]}")
end
def logout

View File

@ -24,8 +24,10 @@ module LoginHelper
unless cookies[autologin_cookie_name].present?
cookies[autologin_cookie_name] = cookie_options
end
# for action cable
cookies.signed[:user_id] ||= user.id
Rails.logger.info("cookies is #{cookies}")
Rails.logger.info("cookies is #{cookies} ======> #{cookies.signed[:user_id]}")
end
def successful_authentication(user)

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

@ -1,7 +1,8 @@
class ProjectsController < ApplicationController
include ApplicationHelper
include OperateProjectAbilityAble
before_action :require_login, except: %i[index branches group_type_list]
include ProjectsHelper
before_action :require_login, except: %i[index branches group_type_list simple]
before_action :find_project_with_id, only: %i[show branches update destroy fork_users praise_users watch_users]
before_action :authorizate_user_can_edit_project!, only: %i[update]
before_action :project_public?, only: %i[fork_users praise_users watch_user]
@ -25,10 +26,8 @@ class ProjectsController < ApplicationController
end
def migrate
ActiveRecord::Base.transaction do
Projects::MigrateForm.new(mirror_params).validate!
@project = Projects::MigrateService.new(current_user, mirror_params).call
end
Projects::MigrateForm.new(mirror_params).validate!
@project = Projects::MigrateService.new(current_user, mirror_params).call
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
@ -100,6 +99,11 @@ class ProjectsController < ApplicationController
@fork_users = paginate(fork_users)
end
def simple
project = Project.includes(:owner, :repository).select(:id, :name, :identifier, :user_id, :project_type).find params[:id]
json_response(project)
end
private
def project_params
params.permit(:user_id, :name, :description, :repository_name,

View File

@ -2,42 +2,53 @@ class PullRequestsController < ApplicationController
before_action :require_login, except: [:index, :show]
before_action :find_project_with_id
before_action :set_repository
before_action :find_pull_request, except: [:index, :new, :create, :check_can_merge]
before_action :find_pull_request, except: [:index, :new, :create, :check_can_merge,:get_branches,:create_merge_infos]
# before_action :get_relatived, only: [:edit]
include TagChosenHelper
include ApplicationHelper
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: :user)
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
@assign_to_me_size = issues.where(assigned_to_id: current_user&.id).size
@my_published_size = issues.where(author_id: current_user&.id).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
def new
@all_branches = []
get_all_branches = Gitea::Repository::Branches::ListService.new(@user, @repository.try(:identifier)).call
if get_all_branches && get_all_branches.size > 0
get_all_branches.each do |b|
@all_branches.push(b["name"])
end
@all_branches = PullRequests::BranchesService.new(@user, @project).call
@is_fork = @project.forked_from_project_id.present?
@projects_names = [{
project_user_login: @user.try(:login),
project_name: "#{@user.try(:show_real_name)}/#{@repository.try(:identifier)}",
project_id: @project.id
}]
@merge_projects = @projects_names
fork_project = @project.fork_project if @is_fork
if fork_project.present?
@merge_projects.push({
project_user_login: fork_project.owner.try(:login),
project_name: "#{fork_project.owner.try(:show_real_name)}/#{fork_project.repository.try(:identifier)}",
project_id: fork_project.id
})
end
@project_tags = @project.issue_tags&.select(:id,:name, :color).as_json
@project_versions = @project.versions&.select(:id,:name, :status).as_json
@project_members = @project.members_user_infos
end
def get_branches
branch_result = PullRequests::BranchesService.new(@user, @project).call
render json: branch_result
# return json: branch_result
end
def create
if params[:title].nil?
normal_status(-1, "名称不能为空")
elsif params[:issue_tag_ids].nil?
@ -45,55 +56,27 @@ class PullRequestsController < ApplicationController
else
ActiveRecord::Base.transaction do
begin
local_params = {
title: params[:title], #标题
body: params[:body], #内容
head: params[:head], #源分支
base: params[:base], #目标分支
milestone: 0, #里程碑,未与本地的里程碑关联
}
requests_params = local_params.merge({
assignee: current_user.try(:login),
assignees: ["#{params[:assigned_login].to_s}"],
labels: params[:issue_tag_ids],
due_date: Time.now
})
issue_params = {
author_id: current_user.id,
project_id: @project.id,
subject: params[:title],
description: params[:body],
assigned_to_id: params[:assigned_to_id],
fixed_version_id: params[:fixed_version_id],
issue_tags_value: params[:issue_tag_ids].present? ? params[:issue_tag_ids].join(",") : "",
issue_classify: "pull_request",
issue_type: params[:issue_type] || "1",
tracker_id: 2,
status_id: 1,
priority_id: 1
}
pull_issue = Issue.new(issue_params)
merge_params
pull_issue = Issue.new(@issue_params)
if pull_issue.save!
local_requests = PullRequest.new(local_params.merge(user_id: current_user.try(:id), project_id: @project.id, issue_id: pull_issue.id))
pr_params = {
user_id: current_user.try(:id),
project_id: @project.id,
issue_id: pull_issue.id,
fork_project_id: params[:fork_project_id],
is_original: params[:is_original]
}
local_requests = PullRequest.new(@local_params.merge(pr_params))
if local_requests.save
gitea_request = Gitea::PullRequest::CreateService.new(current_user.try(:gitea_token), @project.owner, @repository.try(:identifier), requests_params).call
remote_pr_params = @local_params
remote_pr_params = remote_pr_params.merge(head: "#{params[:merge_user_login]}:#{params[:head]}").compact if local_requests.is_original && params[:merge_user_login]
gitea_request = Gitea::PullRequest::CreateService.call(current_user.try(:gitea_token), @project.owner, @repository.try(:identifier), remote_pr_params.except(:milestone))
if gitea_request && local_requests.update_attributes(gpid: gitea_request["number"])
if params[:issue_tag_ids].present?
params[:issue_tag_ids].each do |tag|
IssueTagsRelate.create!(issue_id: pull_issue.id, issue_tag_id: tag)
end
end
if params[:attachment_ids].present?
params[:attachment_ids].each do |id|
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
unless attachment.blank?
attachment.container = pull_issue
attachment.author_id = current_user.id
attachment.description = ""
attachment.save
end
end
end
if params[:assigned_to_id].present?
Tiding.create!(user_id: params[:assigned_to_id], trigger_user_id: current_user.id,
@ -122,8 +105,9 @@ class PullRequestsController < ApplicationController
end
def edit
@issue_chosen = issue_left_chosen(@project, @issue.id)
@issue_attachments = @issue.attachments
@fork_project_user_name = @project&.fork_project&.owner.try(:show_real_name)
@fork_project_user = @project&.fork_project&.owner.try(:login)
@fork_project_identifier = @project&.fork_project&.repository.try(:identifier)
end
def update
@ -134,25 +118,7 @@ class PullRequestsController < ApplicationController
else
ActiveRecord::Base.transaction do
begin
local_params = {
title: params[:title], #标题
body: params[:body], #内容
head: params[:head], #源分支
base: params[:base], #目标分支
milestone: 0, #里程碑,未与本地的里程碑关联
}
requests_params = local_params.merge({
assignee: current_user.try(:login),
assignees: ["#{params[:assigned_login].to_s}"],
labels: params[:issue_tag_ids]
})
issue_params = {
subject: params[:title],
description: params[:body],
assigned_to_id: params[:assigned_to_id].to_s,
fixed_version_id: params[:fixed_version_id],
issue_tags_value: params[:issue_tag_ids].present? ? params[:issue_tag_ids].join(",") : "",
}
merge_params
if params[:issue_tag_ids].present? && !@issue&.issue_tags_relates.where(issue_tag_id: params[:issue_tag_ids]).exists?
@issue&.issue_tags_relates&.destroy_all
@ -161,26 +127,10 @@ class PullRequestsController < ApplicationController
end
end
if @issue.update_attributes(issue_params)
if @pull_request.update_attributes(local_params)
gitea_request = Gitea::PullRequest::UpdateService.new(current_user, @repository.try(:identifier), requests_params, @pull_request.try(:gpid)).call
if @issue.update_attributes(@issue_params)
if @pull_request.update_attributes(@local_params.compact)
gitea_request = Gitea::PullRequest::UpdateService.new(@project.owner, @repository.try(:identifier), @requests_params, @pull_request.try(:gpid)).call
if gitea_request
issue_files = params[:attachment_ids]
change_files = false
issue_file_ids = []
if issue_files.present?
change_files = true
issue_files.each do |id|
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
unless attachment.blank?
attachment.container = @issue
attachment.author_id = current_user.id
attachment.description = ""
attachment.save
end
end
end
if params[:issue_tag_ids].present?
params[:issue_tag_ids].each do |tag|
IssueTagsRelate.create(issue_id: @issue.id, issue_tag_id: tag)
@ -189,7 +139,6 @@ class PullRequestsController < ApplicationController
if params[:status_id].to_i == 5
@issue.issue_times.update_all(end_time: Time.now)
end
@issue.create_journal_detail(change_files, issue_files, issue_file_ids, current_user&.id)
normal_status(0, "PullRequest更新成功")
else
normal_status(-1, "PullRequest更新失败")
@ -207,70 +156,46 @@ class PullRequestsController < ApplicationController
end
def simple_update
def refuse_merge
ActiveRecord::Base.transaction do
begin
issue_params = {
assigned_to_id: params[:assigned_to_id].to_s,
fixed_version_id: params[:fixed_version_id],
issue_tags_value: params[:issue_tag_ids].present? ? params[:issue_tag_ids].join(",") : "",
}
if params[:issue_tag_ids].blank?
@issue&.issue_tags_relates&.destroy_all
end
if params[:issue_tag_ids].present? && !@issue&.issue_tags_relates.where(issue_tag_id: params[:issue_tag_ids]).exists?
@issue&.issue_tags_relates&.destroy_all
params[:issue_tag_ids].each do |tag|
IssueTagsRelate.create(issue_id: @issue.id, issue_tag_id: tag)
end
end
if @issue.update_attributes(issue_params)
normal_status(0, "PullRequest更新成功")
else
normal_status(-1, "PullRequest更新成功")
end
@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 create_merge_infos
get_relatived
end
def show
@user_permission = current_user.present? && current_user.logged? && (!@issue.is_lock || @project.member?(current_user) || current_user.admin? || @issue.user == current_user)
@issue_attachments = @issue.attachments
@issue_user = @issue.user
@issue_assign_to = @issue.get_assign_user
@join_users = join_users(@issue)
#总耗时
# cost_time(@issue)
# #被依赖
# @be_depended_issues_array = be_depended_issues(@issue)
# #依赖于
# depended_issues(@issue)
end
def pr_merge
return render_forbidden("你没有权限操作.") if @project.reporter?(current_user)
if params[:do].blank?
normal_status(-1, "请选择合并方式")
else
ActiveRecord::Base.transaction do
begin
requests_params = {
do: params[:do],
Do: params[:do],
MergeMessageField: params[:body],
MergeTitleField: params[:title]
}
merge_pr = Gitea::PullRequest::MergeService.new(current_user, @repository.try(:identifier), @pull_request.try(:gpid), requests_params).call
merge_pr = Gitea::PullRequest::MergeService.call(current_user.gitea_token, @project.owner.login,
@repository.try(:identifier), @pull_request.try(:gpid), requests_params)
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
@ -284,73 +209,21 @@ 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] #源分支
target_base = params[:base] #目标分支
is_original = params[:is_original]
if target_head.blank? || target_base.blank?
normal_status(-1, "请选择分支")
elsif target_head === target_base
normal_status(-1, "分支内容相同,无需创建合并请求")
normal_status(-2, "请选择分支")
elsif target_head === target_base && !is_original
normal_status(-2, "分支内容相同,无需创建合并请求")
else
can_merge = @project&.pull_requests.where(user_id: current_user&.id, head: target_head, base: target_base, status: 0)
can_merge = @project&.pull_requests.where(user_id: current_user&.id, head: target_head, base: target_base, status: 0, is_original: is_original, fork_project_id: params[:fork_project_id])
if can_merge.present?
render json: {
status: -2,
message: "在这些分支之间的合并请求已存在",
pull_request_id: can_merge.first.id,
pull_request_name: can_merge.first.try(:title)
message: "在这些分支之间的合并请求已存在:<a href='/projects/#{@project.id}/merge/#{can_merge.first.id}/Messagecount''>#{can_merge.first.try(:title)}</a>",
}
else
normal_status(0, "可以合并")
@ -362,10 +235,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
@ -379,4 +250,41 @@ class PullRequestsController < ApplicationController
normal_status(-1, "您没有权限")
end
end
end
def get_relatived
@project_tags = @project.issue_tags&.select(:id,:name, :color).as_json
@project_versions = @project.versions&.select(:id,:name, :status).as_json
@project_members = @project.members_user_infos
@project_priories = IssuePriority&.select(:id,:name, :position).as_json
end
def merge_params
@local_params = {
title: params[:title], #标题
body: params[:body], #内容
head: params[:head], #源分支
base: params[:base], #目标分支
milestone: 0, #里程碑,未与本地的里程碑关联
}
@requests_params = @local_params.merge({
assignee: current_user.try(:login),
assignees: ["#{params[:assigned_login].to_s}"],
labels: params[:issue_tag_ids],
due_date: Time.now
})
@issue_params = {
author_id: current_user.id,
project_id: @project.id,
subject: params[:title],
description: params[:body],
assigned_to_id: params[:assigned_to_id],
fixed_version_id: params[:fixed_version_id],
issue_tags_value: params[:issue_tag_ids].present? ? params[:issue_tag_ids].join(",") : "",
priority_id: params[:priority_id] || "2",
issue_classify: "pull_request",
issue_type: params[:issue_type] || "1",
tracker_id: 2,
status_id: 1,
}
end
end

View File

@ -7,15 +7,13 @@ class RepositoriesController < ApplicationController
before_action :authorizate!, except: [:sync_mirror, :tags, :commit]
before_action :find_repository_by_id, only: %i[commit sync_mirror tags]
before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror]
before_action :get_ref, only: %i[entries sub_entries]
before_action :get_latest_commit, :get_ref, only: %i[entries sub_entries]
before_action :get_ref, only: %i[entries sub_entries top_counts]
before_action :get_latest_commit, only: %i[entries sub_entries top_counts]
before_action :get_statistics, only: %i[top_counts]
def show
@user = current_user
@branches_count = Gitea::Repository::Branches::ListService.new(@project.owner, @project.identifier).call&.size
@commits_count = Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier,
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call[:total_count]
@tags_count = Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @project.owner.login, @project.identifier).call&.size
@repo = @project.repository
@result = Gitea::Repository::GetService.new(@project.owner, @project.identifier).call
@project_fork_id = @project.try(:forked_from_project_id)
if @project_fork_id.present?
@ -31,7 +29,12 @@ class RepositoriesController < ApplicationController
@project.increment!(:visits)
@project_owner = @project.owner
@entries = Gitea::Repository::Entries::ListService.new(@project_owner, @project.identifier, ref: @ref).call
@entries = @entries.sort_by{ |hash| hash['type'] }
@entries = @entries.present? ? @entries.sort_by{ |hash| hash['type'] } : []
@path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/"
end
def top_counts
@result = Gitea::Repository::GetService.new(@project.owner, @project.identifier).call
end
def sub_entries
@ -50,6 +53,8 @@ class RepositoriesController < ApplicationController
@project_owner = @project.owner
@hash_commit = Gitea::Repository::Commits::ListService.new(@project_owner.login, @project.identifier,
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
Rails.logger.info("#####################_______hash_commit______############{@hash_commit}")
Rails.logger.info("#####################_______hash_commit_size______############{@hash_commit.size}")
end
def commit
@ -95,11 +100,13 @@ class RepositoriesController < ApplicationController
end
def repo_hook
end
def sync_mirror
@repo&.mirror.set_status!(Mirror.statuses[:waiting])
return render_error("正在镜像中..") if @repo.mirror.waiting?
@repo.sync_mirror!
SyncMirroredRepositoryJob.perform_later(@repo.id, current_user.id)
render_ok
end
@ -122,16 +129,26 @@ class RepositoriesController < ApplicationController
end
# TODO 获取最新commit信息
def get_latest_commit
@latest_commit = Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier,
def project_commits
Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier,
sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call
@latest_commit = @latest_commit.blank? ? nil : @latest_commit[:body][0]
end
def get_statistics
@branches_count = Gitea::Repository::Branches::ListService.new(@project.owner, @project.identifier).call&.size
@tags_count = Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @project.owner.login, @project.identifier).call&.size
end
def get_ref
@ref = params[:ref] || "master"
end
def get_latest_commit
latest_commit = project_commits
@latest_commit = latest_commit[:body][0] if latest_commit.present?
@commits_count = latest_commit[:total_count] if latest_commit.present?
end
def content_params
{
filepath: params[:filepath],

View File

@ -0,0 +1,288 @@
class SyncForgeController < ApplicationController
# before_action :check_token
def create
ActiveRecord::Base.transaction do
params.permit!
sync_params = params[:sync_params]
#以前已同步的项目,那么肯定存在仓库
if Project.exists?(identifier: sync_params[:identifier])
SyncLog.sync_log("=================begin_to_update_project========")
project = Project.find_by(identifier: sync_params[:identifier])
check_sync_project(project, sync_params)
else #新建项目
SyncLog.sync_log("=================begin_to_create_new_project========")
project_user = User.where(login: sync_params[:owner_login]).first
project_params = {
repository_name: sync_params[:identifier],
user_id: project_user.id,
private: !sync_params[:is_public],
name: sync_params[:name]
}
project = Projects::CreateService.new(project_user, project_params).call
if project.present?
if sync_params[:project_score].present?
sync_params.permit!
score_params = sync_params[:project_score].merge(project_id: project.id)
new_project_score = ProjectScore.create(score_params)
SyncLog.sync_log("=================new_project_score:#{new_project_score.try(:id)}========")
end
SyncRepositoryJob.perform_later(sync_params[:owner_login], sync_params[:identifier], sync_params[:repository], get_sudomain) if sync_params[:repository].present?
check_new_project(project, sync_params)
end
end
end
rescue Exception => e
SyncLog.sync_project_log("=============sync_has_errors:==#{e.message}, project_id==:#{params[:sync_params][:id]}")
end
def sync_users
params.permit!
sync_params = params[:sync_params]
users_params = sync_params[:users]
users_params.each do |u|
if User.exists?(login: u[:user_params][:login])
SyncLog.sync_log("=================sync_to_user_been_exists====#{u[:user_params][:login]}")
else
# new_user = User.new(u[:user_params])
if u[:user_params][:mail].blank?
u_mail = "#{u[:user_params][:login]}@example.com"
else
u_mail = u[:user_params][:mail]
end
new_user = User.new(u[:user_params].merge(mail: u_mail))
username = new_user.login
password = "12345678"
if new_user.save!
SyncLog.sync_log("=================sync_to_user_success==#{new_user.login}")
else
SyncLog.sync_log("=================sync_to_user_failed,user_login==#{new_user.login}")
end
# ActiveRecord::Base.transaction do
# interactor = Gitea::RegisterInteractor.call({username: username, email: new_user.mail, password: password})
# if interactor.success?
# gitea_user = interactor.result
# result = Gitea::User::GenerateTokenService.new(username, password).call
# new_user.gitea_token = result['sha1']
# new_user.gitea_uid = gitea_user['id']
# if new_user.save!
# UserExtension.create!(u[:user_extensions][:user_extensions].merge(user_id: new_user.id)) if u[:user_extensions].present? && u[:user_extensions][:user_extensions].present?
# else
# SyncLog.sync_log("=================sync_to_user_failed,user_login==#{new_user.login}")
# end
# else
# SyncLog.sync_project_log("=============sync_to_user_failed,user_login====#{new_user.login}")
# SyncLog.sync_log("=================sync_to_user_failed,user_login====#{new_user.login}")
# end
# end
end
end
# normal_status(1, "completed_sync")
rescue Exception => e
SyncLog.sync_log("=================sync_user_failed====#{e}")
end
private
def check_sync_project(project,sync_params)
begin
gitea_main = "https://www.trustie.net/"
if request.subdomain === 'testforgeplus'
gitea_main = "https://ucloudtest.trustie.net/"
end
SyncLog.sync_log("----begin_to_check_sync_project----project_id:#{project.id}---------------")
change_project_score(project, sync_params[:project_score], sync_params[:repository]) if sync_params[:repository].present? #更新project_score
change_project_issues(project, sync_params[:issues],project.id, gitea_main)
change_project_members(project, sync_params[:members],gitea_main)
change_project_versions(project, sync_params[:project_versions],gitea_main)
change_project_watchers(project, sync_params[:project_watchers],gitea_main)
change_project_praises(project, sync_params[:praise_trends],gitea_main)
rescue => e
SyncLog.sync_log("=========check_sync_project_errors:#{e}===================")
end
end
def check_new_project(project,sync_params)
SyncLog.sync_log("***8. begin_to_sync_new_project---------------")
sync_projects_params = {
type: "Project",
ids: sync_params[:id],
token: get_token,
sync_params: sync_params,
new_project_id: project.id
}
gitea_main = "https://www.trustie.net/"
if request.subdomain === 'testforgeplus'
gitea_main = "https://ucloudtest.trustie.net/"
end
SyncProjectsJob.perform_later(sync_projects_params, gitea_main)
SyncLog.sync_log("***8. end_to_sync_new_project---------------")
end
def change_project_praises(project, praises,gitea_main)
SyncLog.sync_log("***6. begin_to_sync_parises---------------")
forge_praises_ids = project&.praise_treads&.select(:id)&.pluck(:id)
diff_target_ids = praises[:ids] - forge_praises_ids
if diff_target_ids.size > 0
sync_projects_params = {
type: "PraiseTread",
ids: diff_target_ids,
token: get_token,
parent_id: project.id
}
SyncProjectsJob.perform_later(sync_projects_params,gitea_main)
SyncLog.sync_log("***6. end_to_sync_parises---------------")
end
end
#检查repository和project_score
def change_project_score(project, project_scores, repository_params)
SyncLog.sync_log("***1. begin_to_sync_project_score---------------")
begin
pre_project_score = project.project_score
if pre_project_score.present?
change_num = 0
project_scores.each do |k,v|
unless pre_project_score.send("#{k}") == v
change_num += 1
pre_project_score[:"#{k}"] = v
end
if k == "changeset_num" && v.to_i > pre_project_score.changeset_num.to_i && repository_params[:url].present?
SyncRepositoryJob.perform_later(project.owner.try(:login), project.identifier, repository_params, get_sudomain)
end
end
pre_project_score.save! if change_num > 0 #如果 project_score有变化则更新
else
ProjectScore.create!(project_scores.merge(project_id: project.id))
end
SyncLog.sync_log("***1. end_to_sync_project_score---------------")
rescue Exception => e
SyncLog.sync_log("=========change_project_score_errors:#{e}===================")
end
end
def change_project_issues(project, old_issues_params,project_id, gitea_main)
SyncLog.sync_log("***2. begin_to_syncissues---------------")
begin
forge_issue_ids = project&.issues&.select(:id)&.pluck(:id)
sync_projects_params = {}
unless forge_issue_ids.size.to_i < old_issues_params[:count].to_i
forge_journal_ids = Journal.select([:id, :journalized_id, :journalized_type]).where(journalized_id: forge_issue_ids).pluck(:id)
diff_issue_ids = old_issues_params[:ids] - forge_issue_ids
if diff_issue_ids.size == 0 #issue数量一样判断评论是否有增减
diff_journal_ids = old_issues_params[:journals][:ids] - forge_journal_ids
unless diff_journal_ids.size == 0
sync_projects_params = {
type: "Journal",
ids: diff_journal_ids,
token: get_token,
parent_id: project_id
}
end
else
sync_projects_params = {
type: "Issue",
ids: diff_issue_ids,
token: get_token,
parent_id: project_id
}
end
end
SyncProjectsJob.perform_later(sync_projects_params, gitea_main) if sync_projects_params.present?
SyncLog.sync_log("***2. end_to_syncissues---------------")
rescue Exception => e
SyncLog.sync_log("=========change_project_issues_errors:#{e}===================")
end
end
def change_project_watchers(project, watchers,gitea_main)
SyncLog.sync_log("***5. begin_to_sync_watchers---------------")
forge_watchers_ids = project&.watchers&.select(:id)&.pluck(:id)
unless forge_watchers_ids.size.to_i < watchers[:count].to_i
diff_target_ids = watchers[:ids] - forge_watchers_ids
if diff_target_ids.size > 0
sync_projects_params = {
type: "Watcher",
ids: diff_target_ids,
token: get_token,
parent_id: project.id
}
SyncProjectsJob.perform_later(sync_projects_params,gitea_main)
end
end
SyncLog.sync_log("***5. begin_to_sync_watchers---------------")
end
def change_project_versions(project, versions,gitea_main)
SyncLog.sync_log("***4. begin_to_sync_versions---------------")
forge_version_ids = project&.versions&.select(:id)&.pluck(:id)
unless forge_version_ids.size < versions[:count].to_i
diff_version_ids = versions[:ids] - forge_version_ids
if diff_version_ids.size > 0
sync_projects_params = {
type: "Version",
ids: diff_version_ids,
token: get_token,
parent_id: project.id
}
SyncProjectsJob.perform_later(sync_projects_params,gitea_main)
end
SyncLog.sync_log("***4. end_to_sync_versions---------------")
end
end
def change_project_members(project, members,gitea_main)
SyncLog.sync_log("***3. begin_to_sync_members---------------")
forge_member_ids = project&.members&.select(:id)&.pluck(:id)
unless forge_member_ids.size < members[:count]
diff_member_ids = members[:ids] - forge_member_ids
if diff_member_ids.size > 0
sync_projects_params = {
type: "Member",
ids: diff_member_ids,
token: get_token,
parent_id: project.id
}
SyncProjectsJob.perform_later(sync_projects_params,gitea_main)
end
SyncLog.sync_log("***3. end_to_sync_members---------------")
end
end
# def check_token
# sync_params = params[:sync_params]
# unless sync_params[:token] && sync_params[:token] == get_token
# render json: {message: "token_errors"}
# end
# end
def get_token
"34c82f51e0b699d9d16d70fd6497c9b1e4821d6ea3e872558a6537a091076b8e"
end
def get_sudomain
SyncLog.sync_log("=================request.subdomain:#{request.subdomain}========")
gitea_main = "gitea.trustie.net"
if request.subdomain === 'testforgeplus'
gitea_main = "testgitea2.trustie.net"
# elsif request.subdomain === 'forgeplus'
# gitea_main = "gitea.trustie.net"
end
return gitea_main
end
end

View File

@ -2,7 +2,7 @@ class UsersController < ApplicationController
before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users]
before_action :check_user_exist, only: [:show, :homepage_info,:projects, :watch_users, :fan_users]
before_action :require_login, only: %i[me list projects]
before_action :require_login, only: %i[me list]
skip_before_action :check_sign, only: [:attachment_show]
def list
@ -20,6 +20,7 @@ class UsersController < ApplicationController
user_projects = User.current.logged? && (User.current.admin? || User.current.login == @user.login) ? @user.projects : @user.projects.visible
@projects_common_count = user_projects.common.size
@projects_mirrior_count = user_projects.mirror.size
@projects_sync_mirrior_count = user_projects.sync_mirror.size
end
def watch_users
@ -145,6 +146,44 @@ class UsersController < ApplicationController
render_ok
end
def trustie_related_projects
projects = Project.includes(:owner, :members, :project_score).where(id: params[:ids]).order("updated_on desc")
projects_json = []
if projects.present?
projects.each do |p|
pj = {
id: p.id,
name: p.name,
is_public: p.is_public,
updated_on: p.updated_on.strftime("%Y-%m-%d"),
owner: {
name: p.owner.try(:show_real_name),
login: p.owner.login
},
members_count: p&.members.size,
issues_count: p.issues_count - p.pull_requests_count,
commits_count: p&.project_score&.changeset_num.to_i
}
projects_json.push(pj)
end
end
Rails.logger.info("==========projects_json========+########{projects_json}")
render json: { projects: projects_json }
end
def trustie_projects
user_id = User.select(:id, :login).where(login: params[:login])&.first&.id
projects = Project.visible
projects = projects.joins(:members).where(members: { user_id: user_id })
search = params[:search].to_s.strip
projects = projects.where('projects.name LIKE ?', "%#{search}%") if search.present?
projects = projects.select(:id, :name).limit(10).as_json
render json: { projects: projects }
end
def projects
is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == @user.id)
scope = Projects::ListMyQuery.call(params, @user,is_current_admin_user)

View File

@ -3,7 +3,8 @@ module ProjectsHelper
def render_zh_project_type(project_type)
case project_type
when 'common' then "开源托管项目"
when 'mirror', 'sync_mirror' then "开源镜像项目"
when 'sync_mirror' then "镜像托管项目"
when 'mirror' then "开源镜像项目"
end
end
@ -26,4 +27,30 @@ module ProjectsHelper
def find_user_by_login_or_mail(identifier)
(User.find_by_login identifier) || (User.find_by_mail identifier)
end
def json_response(project)
repo = project.repository
tmp_json = {}
unless project.common?
tmp_json = tmp_json.merge({
mirror_status: repo.mirror_status,
mirror_num: repo.mirror_num,
mirror_url: repo.mirror_url,
first_sync: repo.first_sync?
})
end
tmp_json = tmp_json.merge({
identifier: project.identifier,
name: project.name,
id: project.id,
type: project.numerical_for_project_type,
author: {
login: project.owner.login,
name: project.owner.real_name,
image_url: url_to_avatar(project.owner)
}
}).compact
render json: tmp_json
end
end

View File

@ -5,7 +5,7 @@ module RepositoriesHelper
end
def download_type(str)
default_type = %w(xlsx xls ppt pptx pdf zip 7z rar exe pdb obj idb png jpg gif tif psd svg)
default_type = %w(xlsx xls ppt pptx pdf zip 7z rar exe pdb obj idb png jpg gif tif psd svg RData rdata)
default_type.include?(str&.downcase)
end
@ -14,8 +14,46 @@ module RepositoriesHelper
default_type.include?(str&.downcase)
end
def is_readme_type?(str)
return false if str.blank?
readme_types = ["readme.md", "readme", "readme_en.md", "readme_zh.md", "readme_en", "readme_zh"]
readme_types.include?(str.to_s.downcase)
end
def render_commit_author(author_json)
return nil if author_json.blank?
find_user_by_login author_json['login']
end
def readme_render_decode64_content(str, path)
return nil if str.blank?
content = Base64.decode64(str).force_encoding('UTF-8')
c_regex = /\!\[.*?\]\((.*?)\)/
src_regex = /src=\"(.*?)\"/
ss = content.to_s.scan(c_regex)
ss_src = content.to_s.scan(src_regex)
total_images = ss + ss_src
if total_images.length > 0
total_images.each do |s|
image_title = /\"(.*?)\"/
r_content = s[0]
remove_title = r_content.to_s.scan(image_title)
if remove_title.length > 0
r_content = r_content.gsub(/#{remove_title[0]}/, "").strip
end
if r_content.include?("?")
new_r_content = r_content + "&raw=true"
else
new_r_content = r_content + "?raw=true"
end
unless r_content.include?("http://") || r_content.include?("https://") || r_content.include?("mailto:")
new_r_content = "#{path}" + new_r_content
end
content = content.gsub(/#{r_content}/, new_r_content)
end
end
return content
end
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

@ -2,14 +2,32 @@ class MigrateRemoteRepositoryJob < ApplicationJob
queue_as :default
def perform(repo_id, token, params)
puts "############ perform: repo_id: #{repo_id}, token: #{token}, params: #{params}}"
repo = Repository.find_by(id: repo_id)
return if repo.blank?
puts "############ MigrateRemoteRepositoryJob starting ... ############"
gitea_repository = Gitea::Repository::MigrateService.new(token, params).call
if gitea_repository
repo&.project&.update_columns(gpid: gitea_repository["id"], identifier: gitea_repository["name"])
repo&.project&.update_columns(gpid: gitea_repository["id"])
repo&.mirror&.update_columns(status: Mirror.statuses[:succeeded])
project = repo.project
json_data = {
mirror_status: repo.mirror_status,
mirror_num: repo.mirror_num,
mirror_url: repo.mirror_url,
first_sync: repo.first_sync?,
identifier: repo.identifier,
name: project.name,
id: project.id,
type: project.numerical_for_project_type
}
puts "############ broadcast start.......... ############"
cable_result = ActionCable.server.broadcast "channel_room_#{repo.identifier}", project: json_data
puts "############ room_channel_#{repo.identifier} result : #{cable_result}"
end
end
end

View File

@ -0,0 +1,136 @@
require 'uri'
require 'net/http'
class SyncProjectsJob < ApplicationJob
queue_as :default
def perform(sync_params, gitea_main)
SyncLog.sync_log("==========begin to sync #{sync_params[:type]} to forge============")
SyncLog.sync_log("==========sync_params:#{sync_params}============")
begin
url = "#{gitea_main}/sync_forges" #trustie上的相关路由
uri = URI.parse(url)
http = Net::HTTP.new(uri.hostname, uri.port)
http.use_ssl = true
response = http.send_request('GET', uri.path, sync_params.to_json, {'Content-Type' => 'application/json'})
SyncLog.sync_log("==========response_status::#{response.code}============")
if response.code == '200'
target_jsons = eval(response.body)
if sync_params[:type] == "Project"
SyncLog.sync_project_log("==========target_jsons: #{target_jsons}============")
update_new_project(target_jsons[:targets_params][0], sync_params[:new_project_id])
else
SyncLog.sync_project_log("========== #{sync_params[:type]}============")
create_target(target_jsons[:targets_params], sync_params[:type].to_s)
end
else
SyncLog.sync_project_log("==========sync_project_to_forge_failed #{sync_params[:type]}============")
end
rescue => e
SyncLog.sync_project_log("==========sync_project_to_forge_failed #{sync_params[:type]}============errors:#{e}")
end
end
private
def update_new_project(re, project_id)
SyncLog.sync_log("=========begin_to_update_project=project_id: #{project_id}============")
project = Project.find_by(id: project_id)
project.update(re[:target_params]) if re[:target_params].present?
create_target(re[:issues_params], "Issue") if re[:issues_params].present?
create_target(re[:member_params], "Member") if re[:member_params].present?
create_target(re[:watcher_params], "Watcher") if re[:watcher_params].present?
create_target(re[:praise_treads], "PraiseTread") if re[:praise_treads].present?
create_versions(project, re[:versions_params]) if re[:versions_params].present?
end
def create_target(target_jsons, target_type)
begin
SyncLog.sync_project_log("***【#{target_type}】. begin_to_create_target---------------")
return SyncLog.sync_log("*** no target_jsons") if target_jsons.blank?
target_jsons.each_with_index do |re,index|
SyncLog.sync_project_log("***user_login:#{re[:user_login]}----target_type:#{target_type}-----#{index+1}")
if re[:target_params].present?
SyncLog.sync_log("***user_login:#{re[:user_login]}----target_type:#{target_type}")
u_id = User.select(:id, :login).where(login: re[:user_login]).pluck(:id).first
re[:target_params].delete(:id)
if target_type == "Issue"
new_target = target_type.constantize.new(re[:target_params].merge(author_id: u_id))
else
new_target = target_type.constantize.new(re[:target_params].merge(user_id: u_id))
end
if target_type == "Issue"
assing_u_id = User.select(:id, :login).where(login: re[:assign_login]).pluck(:id).first
new_target.assigned_to_id = assing_u_id
end
if new_target.save!
SyncLog.sync_project_log("***【#{target_type}】. create_success---------------")
if re[:journals].present?
create_journals(re[:journals], "Journal", new_target.id)
end
if re[:journal_details].present?
re[:journal_details].each do |j|
JournalDetail.create!(j.merge(journal_id: new_target.id)) if j.present?
end
end
if re[:member_roles].present?
re[:member_roles].each do |m|
MemberRole.create!(m.merge(member_id: new_target.id)) if m.present?
end
end
else
SyncLog.sync_project_log("***【#{target_type}】. create_failed---------------")
end
end
end
SyncLog.sync_project_log("***111222. end_to_create_target---------------")
rescue => e
SyncLog.sync_project_log("=========***【#{target_type}】creat_had_erros:#{e}===================")
end
end
def create_journals(target_jsons, target_type,issue_id)
SyncLog.sync_log("***【#{target_type}】. begin_to_create_target---------------")
return SyncLog.sync_log("*** no target_jsons") if target_jsons.blank?
target_jsons.each_with_index do |re,index|
SyncLog.sync_log("***user_login:#{re[:user_login]}----target_type:#{target_type}-----#{index+1}")
if re[:target_params].present?
u_id = User.select(:id, :login).where(login: re[:user_login]).pluck(:id).first
re[:target_params].delete(:id)
new_target = Journal.new(re[:target_params].merge(user_id: u_id))
new_target.journalized_id = issue_id
if new_target.save!
if re[:journal_details].present?
re[:journal_details].each do |j|
JournalDetail.create!(j.merge(journal_id: new_target.id))
end
end
end
end
end
SyncLog.sync_log("***111222. end_to_create_journal---------------")
end
def create_versions(project, target_jsons)
SyncLog.sync_log("***【Versions】. begin_to_create_verison---------------")
return SyncLog.sync_log("*** no target_jsons") if target_jsons.blank?
all_issues = project.issues.select(:id, :project_id, :fixed_version_id)
target_jsons.each do |re|
old_id = re[:target_params][:id]
if re[:target_params].present?
u_id = User.select(:id, :login).where(login: re[:user_login]).pluck(:id).first
re[:target_params].delete(:id)
new_target = Version.new(re[:target_params].merge(user_id: u_id))
if new_target.save!
all_issues&.where(fixed_version_id: old_id)&.update_all(fixed_version_id: new_target.id)
end
end
end
SyncLog.sync_log("***111222. end_to_create_target---------------")
end
end

View File

@ -0,0 +1,40 @@
class SyncRepositoryJob < ApplicationJob
queue_as :default
#同步 trustie的仓库
def perform(user_login, identifier, repository_params, gitea_main)
#创建临时文件夹 clone 并强推代码
SyncLog.sync_log("=================begin to sync request trustie repository=====================")
path = "#{Rails.root}/public/cache_repository"
image_url = repository_params[:git_url]
gitlab_branches = repository_params[:gitlab_branches]
image_repo_name = image_url.to_s.split('/')&.last&.chomp('.git')
unless File.directory?(path)
FileUtils.mkdir_p(path)
end
if Dir.exist?("#{path}/#{image_repo_name}")
system("rm -rf #{path}/#{image_repo_name}")
end
check_clone = system("cd #{path} && git clone #{image_url}")
if check_clone
new_gitlab_url = "http://root:_Trustie_10010@#{gitea_main}/#{user_login}/#{identifier}.git"
shell_remote_1 = system("cd #{path}/#{image_repo_name} && git remote set-url origin #{new_gitlab_url}")
gitlab_branches.each do |branch|
shell5 = system("cd #{path}/#{image_repo_name} && git checkout #{branch} && git push --force --set-upstream origin #{branch}")
if !shell5
SyncLog.sync_project_log("=============force_push_erros==#{path}/#{image_repo_name}++branch:#{branch}")
else
SyncLog.sync_project_log("=============force_push_success==#{path}/#{image_repo_name}++branch+++#{branch}")
end
end
else
SyncLog.sync_project_log("=============check_clone_erros==#{path}/#{image_repo_name}")
SyncLog.sync_log("++++++++++++++++++check_clone_erros++++++++++++++++++#{image_repo_name}")
end
SyncLog.sync_log("=================end to sync repository=====================#{image_repo_name}")
end
end

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

@ -1,10 +1,10 @@
class Mirror < ApplicationRecord
# 0 - succeeded, 1 - waiting, 2 - failed
# 0: 同步镜像成功1: 正在同步镜像2: 同步失败默认值为0
# 0: 同步镜像成功1: 正在同步镜像2: 同步失败; 默认值为0
enum status: { succeeded: 0, waiting: 1, failed: 2 }
belongs_to :repository
belongs_to :repository, foreign_key: :repo_id
def set_status!(status=Mirror.statuses[:succeeded])

View File

@ -18,7 +18,6 @@ class Project < ApplicationRecord
has_many :project_trends, dependent: :destroy
has_many :watchers, as: :watchable, dependent: :destroy
has_many :fork_users, dependent: :destroy
# has_many :commits, dependent: :destroy
has_one :project_score, dependent: :destroy
@ -38,13 +37,16 @@ class Project < ApplicationRecord
scope :no_anomory_projects, -> {where("projects.user_id is not null and projects.user_id != ?", 2)}
def self.search_project(search)
ransack(name_or_identifier_cont: search)
end
# 创建者
def creator
User.find(user_id).full_name
end
def members_user_infos
members.joins("left join users on members.user_id = users.id").includes(:user).where("users.type = ?", "User")
members.joins(:roles).where("roles.name in ('Manager', 'Developer')").joins("left join users on members.user_id = users.id ").includes(:user).where("users.type = ?", "User")
# members.joins("left join users on members.user_id = users.id").select("users.id", "users.login","users.firstname","users.lastname")
# .pluck("users.id", "users.login","users.lastname", "users.firstname")
end
@ -158,4 +160,12 @@ class Project < ApplicationRecord
member&.roles&.last&.name || permission
end
def fork_project
Project.find_by(id: self.forked_from_project_id)
end
def self.members_projects(member_user_id)
joins(:members).where(members: { user_id: member_user_id})
end
end

View File

@ -3,8 +3,13 @@ class PullRequest < ApplicationRecord
belongs_to :issue
belongs_to :user
belongs_to :project, :counter_cache => true
# belongs_to :fork_project, foreign_key: :fork_project_id
has_many :pull_request_assigns, foreign_key: :pull_request_id
has_many :pull_request_tags, foreign_key: :pull_request_id
has_many :project_trends, as: :trend, dependent: :destroy
has_many :attachments, as: :container, dependent: :destroy
def fork_project
Project.find_by(id: self.fork_project_id)
end
end

View File

@ -15,4 +15,22 @@ class Repository < ApplicationRecord
def set_mirror!
self.build_mirror(status: Mirror.statuses[:waiting]).save
end
def mirror_status
self&.mirror&.numerical_for_status
end
def mirror_num
self&.mirror&.sync_num
end
def first_sync?
self&.mirror&.sync_num === 1
end
def sync_mirror!
repo_mirror = self.mirror
repo_mirror.set_status!(Mirror.statuses[:waiting])
repo_mirror.increment!(:sync_num)
end
end

11
app/models/sync_log.rb Normal file
View File

@ -0,0 +1,11 @@
class SyncLog
def self.sync_log(message=nil)
@my_log ||= Logger.new("#{Rails.root}/log/sync.log")
@my_log.debug(message) unless message.nil?
end
def self.sync_project_log(message=nil)
@my_log ||= Logger.new("#{Rails.root}/log/sync_error_project.log")
@my_log.debug(message) unless message.nil?
end
end

View File

@ -17,10 +17,15 @@ class Projects::ListMyQuery < ApplicationQuery
projects = Project.visible
end
if params[:is_public].present?
projects = projects.is_private.members_projects(user.id) if params[:is_public].to_s == "private"
projects = projects.visible.members_projects(user.id) if params[:is_public].to_s == "public"
end
if params[:category].blank?
projects = projects.joins(:members).where(members: { user_id: user.id })
projects = projects.members_projects(user.id)
elsif params[:category].to_s == "join"
projects = projects.where.not(user_id: user.id).joins(:members).where(members: { user_id: user.id })
projects = projects.where.not(user_id: user.id).members_projects(user.id)
elsif params[:category].to_s == "manage"
projects = projects.where(user_id: user.id)
elsif params[:category].to_s == "watched" #我关注的
@ -28,16 +33,18 @@ 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"
projects = projects.common
elsif params[:project_type].to_s === "mirror"
projects = projects.mirror
elsif params[:project_type].to_s === "sync_mirror"
projects = projects.sync_mirror
end
q = projects.ransack(name_or_identifier_cont: params[:search])

View File

@ -10,7 +10,7 @@ class Projects::ListQuery < ApplicationQuery
end
def call
q = Project.visible.ransack(name_or_identifier_cont: params[:search])
q = Project.visible.search_project(params[:search])
scope = q.result(distinct: true)
.includes(:project_category, :project_language, :repository, owner: :user_extension)

View File

@ -1,16 +1,33 @@
class Gitea::PullRequest::CreateService < Gitea::ClientService
attr_reader :token, :user, :repo, :params
# params ex:
# {
# title: 'pull request title',
# body: 'pull request content',
# head: 'develop', // from branch 源分支
# base: 'master' // to branch 目标分支
# }
# 以上列子说明从develop分支合并到master分支
# repo: 仓库名称
# 同一个项目下发送pr例子如下
# 参数说明:
# user: 项目拥有者
# repo 项目名称
# params:
# {
# title: 'pull request title',
# body: 'pull request content',
# head: 'develop', // from branch 源分支, 格式branch
# base: 'master' // to branch 目标分支
# }
# 以上列子说明从develop分支合并到master分支
# Gitea::PullRequest::CreateService.call('token', '项目拥有者', '项目名称', params)
# fork的项目向源项目发送pr例子如下
# 参数说明:
# user源项目拥有者
# repo源项目仓库名称
# params:
# {
# "base": "develop", // to branch 目标分支
# "head": "jasder:master", // from branch 源分支格式username:branch
# "body": "像源项目发送pr",
# "title": "jasder用户向源项目发送pr"
# }
# 以上例子说明jasder用户fork的项目master分支向源项目的develop分支发送pr
# Gitea::PullRequest::CreateService.call('token', '源项目拥有者', '源项目名称', params)
def initialize(token, user, repo, params={})
@token = token
@user = user
@ -19,13 +36,11 @@ class Gitea::PullRequest::CreateService < Gitea::ClientService
end
def call
Rails.logger.info("######_____pr_url______#########{url}")
post(url, request_params)
end
private
def url
"/repos/#{@user.login}/#{@repo}/pulls".freeze
end

View File

@ -1,6 +1,6 @@
# Merge a pull request
class Gitea::PullRequest::MergeService < Gitea::ClientService
attr_reader :user, :repo, :pull_request_id, :params
attr_reader :token, :owner, :repo, :pull_request_id, :params
# parameters:
# repo: name of the repo
@ -8,8 +8,10 @@ class Gitea::PullRequest::MergeService < Gitea::ClientService
# params:
# title: merge标题
# message: merge说明
def initialize(user, repo, pull_request_id, params={})
@user = user
# eq: Gitea::PullRequest::MergeService.call(current_user.gitea_token, @repo.owner.lgoin, @repo.identifier, params)
def initialize(token, owner, repo, pull_request_id, params={})
@token = token
@owner = owner
@repo = repo
@params = params
@pull_request_id = pull_request_id
@ -21,11 +23,11 @@ class Gitea::PullRequest::MergeService < Gitea::ClientService
private
def url
"/repos/#{user.login}/#{repo}/pulls/#{pull_request_id}/merge"
"/repos/#{owner}/#{repo}/pulls/#{pull_request_id}/merge"
end
def request_params
Hash.new.merge(token: user.gitea_token, data: params)
Hash.new.merge(token: token, data: params)
end
end

View File

@ -29,7 +29,7 @@ class Gitea::Repository::Entries::ListService < Gitea::ClientService
when 200
body
else
{status: -1, message: "#{body['message']}"}
[]
end
end
end

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,13 @@ 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
if search_name.present?

View File

@ -7,12 +7,14 @@ 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!
Repositories::CreateService.new(user, @project, repository_params).call
else
#
Rails.logger.info("#############___________create_project_erros______###########{@project.errors.messages}")
end
end
@project
@ -39,17 +41,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] || true
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

@ -21,6 +21,7 @@ class Projects::ForkService < ApplicationService
new_repository = clone_project.repository
new_repository.user = @target_owner
new_repository.identifier = @project.identifier
new_repository.save!
result = Gitea::Repository::ForkService.new(@project.owner, @target_owner, @project.identifier, @organization).call

View File

@ -8,12 +8,10 @@ class Projects::MigrateService < ApplicationService
def call
@project = Project.new(project_params)
ActiveRecord::Base.transaction do
if @project.save!
Repositories::MigrateService.new(user, @project, repository_params).call
else
#
end
if @project.save!
Repositories::MigrateService.new(user, @project, repository_params).call
else
#
end
@project
rescue => e
@ -27,11 +25,12 @@ class Projects::MigrateService < ApplicationService
{
name: params[:name],
user_id: params[:user_id],
project_type: set_project_type,
description: params[:description],
identifier: params[:repository_name],
is_public: project_secretion[:public],
project_category_id: params[:project_category_id],
project_language_id: params[:project_language_id],
is_public: project_secretion[:public],
project_type: set_project_type
}
end

View File

@ -0,0 +1,34 @@
class PullRequests::BranchesService < ApplicationService
attr_reader :user, :project
def initialize(user, project)
@user = user
@project = project
end
def call
all_branches = []
user_name = user.try(:show_real_name)
identifier = project.repository.try(:identifier)
get_all_branches = Gitea::Repository::Branches::ListService.new(user, identifier).call
all_branches = branch_lists(user_name,user.try(:login), identifier, get_all_branches) if get_all_branches && get_all_branches.size > 0
return all_branches
end
def branch_lists(user_name,user_login, identifier, branches)
branches_array = []
branches.each do |b|
branch_params = {
user_name: user_name,
user_login: user_login,
identifier: identifier,
name: b["name"],
can_merge: b["user_can_merge"],
}
branches_array.push(branch_params)
end
return branches_array
end
end

View File

@ -14,6 +14,8 @@ class Repositories::CreateService < ApplicationService
gitea_repository = Gitea::Repository::CreateService.new(user.gitea_token, gitea_repository_params).call
sync_project(@repository, gitea_repository)
sync_repository(@repository, gitea_repository)
else
Rails.logger.info("#############___________create_repository_erros______###########{@repository.errors.messages}")
end
@repository
end
@ -24,7 +26,7 @@ class Repositories::CreateService < ApplicationService
private
def sync_project(repository, gitea_repository)
def sync_project(repository, gitea_repository)
if gitea_repository
project.update_columns(
gpid: gitea_repository["id"],

View File

@ -9,13 +9,11 @@ class Repositories::MigrateService < ApplicationService
def call
@repository = Repository.new(repository_params)
ActiveRecord::Base.transaction do
if @repository.save!
@repository.set_mirror! if wrapper_mirror
MigrateRemoteRepositoryJob.perform_later(@repository.id, user.gitea_token, gitea_repository_params)
end
@repository
if @repository.save!
@repository.set_mirror!
MigrateRemoteRepositoryJob.perform_later(@repository.id, user.gitea_token, gitea_repository_params)
end
@repository
rescue => e
puts "create mirror repository service error: #{e.message}"
raise Error, e.message
@ -23,7 +21,7 @@ class Repositories::MigrateService < ApplicationService
private
def repository_params
params.merge(project_id: project.id)
params.merge(project_id: project.id, identifier: params[:identifier])
end
def gitea_repository_params

View File

@ -1 +1,16 @@
json.partial! 'users/user', user: @user
# json.partial! 'users/user', user: @user
json.username @user.full_name
json.real_name @user.real_name
json.login @user.login
json.user_id @user.id
json.image_url url_to_avatar(@user)
json.admin @user.admin?
json.user_identity @user.identity
json.is_watch current_user&.watched?(@user)
# json.watched_count @user.fan_count #粉丝
# json.watching_count @user.follow_count #关注数
# json.undo_events @undo_events
# json.user_composes_count @user_composes_count
# json.common_projects_count @projects_common_count
# json.mirror_projects_count @projects_mirrior_count

View File

@ -0,0 +1,14 @@
json.issue_tags @project_tags
json.issue_versions @project_versions
json.issue_priories @project_priories
json.project_author @project.owner.try(:show_real_name)
json.project_name @project.try(:name)
json.members do
json.array! @project_members.to_a.each do |member|
json.id member.user_id
json.login member.user.try(:login)
json.name member.user.try(:show_real_name)
json.avatar_url url_to_avatar(member.user)
end
end

View File

@ -0,0 +1,2 @@
json.partial! "commons/success"
json.partial! "pull_requests/merge_item"

View File

@ -1,18 +1,11 @@
json.partial! "commons/success"
json.pull_request do
json.extract! @pull_request, :id,:base, :head, :status
end
json.issue do
json.extract! @issue, :id,:subject,:description,:is_private,:assigned_to_id,:tracker_id,:status_id,:priority_id,:fixed_version_id,
:start_date,:due_date,:estimated_hours, :issue_type, :token,:issue_classify, :branch_name
json.done_ratio @issue.done_ratio.to_s + "%"
json.issue_tags @issue.get_issue_tags
json.issue_chosen @issue_chosen
end
json.attachments do
json.array! @issue_attachments do |attachment|
json.partial! "attachments/attachment_simple", locals: {attachment: attachment}
end
end
# json.partial! "pull_requests/merge_item"
json.fork_project_user_name @fork_project_user_name
json.fork_project_user @fork_project_user
json.fork_project_identifier @fork_project_identifier
json.project_author @project.owner.try(:show_real_name)
json.project_name @project.repository.try(:identifier)
json.project_login @project.owner.try(:login)
json.extract! @pull_request, :id, :title, :body, :milestone,:head,:base,:is_original
json.extract! @issue, :assigned_to_id, :fixed_version_id, :priority_id
json.issue_tag_ids @issue&.issue_tags_value&.split(",")

View File

@ -2,39 +2,38 @@ json.partial! "commons/success"
json.all_count @all_issues_size
json.open_count @open_issues_size
json.close_count @close_issues_size
json.assign_me_count @assign_to_me_size
json.my_published_count @my_published_size
json.merged_issues_size @merged_issues_size
json.search_count @issues_size
json.limit @limit
json.user_admin_or_member @user_admin_or_member
json.project_name @project.name
json.project_author_name @project.owner.try(:login)
json.issues do
json.array! @issues.to_a do |issue|
# cost_time(issue)
json.pull_request_id issue.pull_request.id
json.pull_request_status issue.pull_request.status
pr = issue.pull_request
json.pull_request_id pr.id
json.pull_request_status pr.status
json.pull_request_head pr.head
json.pull_request_base pr.base
json.pull_request_staus pr.status == 1 ? "merged" : (pr.status == 2 ? "closed" : "open")
json.is_original pr.is_original
json.fork_project_id pr&.fork_project_id
json.fork_project_user pr&.fork_project&.owner.try(:login)
json.id issue.id
json.name issue.subject
json.format_time format_time(issue.created_on)
json.created_at time_from_now(issue.created_on)
json.updated_at format_time(issue.updated_on)
json.pr_time time_from_now(pr.status == 1 ? pr.updated_at : issue.updated_on)
json.assign_user_name issue.get_assign_user.try(:show_real_name)
json.assign_user_login issue.get_assign_user.try(:login)
json.author_name issue.user.try(:show_real_name)
json.author_login issue.user.try(:login)
json.tracker issue.tracker.try(:name)
json.issue_status issue.issue_status.try(:name)
json.avatar_url url_to_avatar(issue.user)
json.priority issue.priority.try(:name)
json.version issue.version.try(:name)
json.done_ratio issue.done_ratio.to_s + "%"
json.journals_count issue.get_journals_size
json.issue_tags issue.get_issue_tags
json.issue_type issue.issue_type == "1" ? "普通" : "悬赏"
json.token issue.issue_type == "2" ? issue.token : ""
json.issue_classify issue.issue_classify
json.branch_name issue.branch_name
# json.cost_time @all_cost_time
end
end
# json.issues @issues

View File

@ -1,13 +1,7 @@
json.partial! "commons/success"
json.project_id @project.id
json.branches @all_branches
json.issue_tags @project_tags
json.issue_versions @project_versions
json.members do
json.array! @project_members.to_a.each do |member|
json.id member.user_id
json.login member.user.try(:login)
json.name member.user.try(:show_real_name)
json.avatar_url url_to_avatar(member.user)
end
end
json.is_fork @is_fork
json.projects_names @projects_names
json.merge_projects @merge_projects
# json.merge_branches @merge_branches

View File

@ -1,12 +1,17 @@
json.partial! "commons/success"
json.project_name @project.name
json.pr_time time_from_now(@pull_request.updated_at)
json.pull_request do
json.extract! @pull_request, :id,:base, :head, :status, :gpid
json.extract! @pull_request, :id,:base, :head, :status,:fork_project_id, :is_original
json.pull_request_staus @pull_request.status == 1 ? "merged" : (@pull_request.status == 2 ? "closed" : "open")
json.fork_project_user @pull_request&.fork_project&.owner.try(:login)
end
json.issue do
json.extract! @issue, :id,:subject,:is_lock,:description,:is_private, :start_date,:due_date,:estimated_hours,:issue_classify, :branch_name
json.user_permission @user_permission
json.extract! @issue, :id,:subject,:description,:is_private, :branch_name
json.project_author_name @project.owner.try(:login)
#json.user_permission @user_permission
json.closed_on @issue.closed_on.present? ? format_time(@issue.closed_on) : ""
json.created_at format_time(@issue.created_on)
json.assign_user_name @issue_assign_to.try(:show_real_name)
@ -14,27 +19,13 @@ json.issue do
json.author_name @issue_user.try(:show_real_name)
json.author_login @issue_user.try(:login)
json.author_picture url_to_avatar(@issue_user)
json.tracker @issue.tracker.try(:name)
json.issue_status @issue.issue_status.try(:name)
json.priority @issue.priority.try(:name)
json.version @issue.version.try(:name)
json.issue_tags @issue.get_issue_tags
json.done_ratio @issue.done_ratio.to_s + "%"
json.issue_type @issue.issue_type == "1" ? "普通" : "悬赏"
json.token @issue.issue_type == "2" ? @issue.token : ""
json.join_users @join_users
# json.cost_time @cost_time_array
# json.total_cost_time Time.at(@all_cost_time).utc.strftime('%H h %M min %S s')
# json.be_depended_issues @be_depended_issues_array
# json.depended_issues @depended_issues_array
end
json.attachments do
json.array! @issue_attachments do |attachment|
json.partial! "attachments/attachment_simple", locals: {attachment: attachment}
end
end

View File

@ -12,7 +12,7 @@ json.target entry['target']
json.download_url entry['download_url']
json.direct_download direct_download
json.image_type image_type
json.is_readme_file is_readme_type?(file_name)
if entry['latest_commit']
json.partial! 'last_commit', entry: entry
end

View File

@ -5,6 +5,9 @@ json.last_commit do
json.nil!
end
end
#json.tags_count @tags_count
#json.branches_count @branches_count
#json.commits_count @commits_count
json.zip_url render_zip_url(@project, @ref)
json.tar_url render_tar_url(@project, @ref)
json.entries do
@ -15,12 +18,15 @@ json.entries do
json.type entry['type']
json.size entry['size']
content =
if entry['name'] === 'README.md'
if is_readme_type?(entry['name'])
is_readme_file = true
content = Gitea::Repository::Entries::GetService.call(@project_owner, @project.identifier, entry['name'], ref: @ref)['content']
render_decode64_content content
readme_render_decode64_content(content, @path)
else
is_readme_file = false
entry['content']
end
json.is_readme_file is_readme_file
json.content content
json.target entry['target']
if entry['latest_commit']

View File

@ -1,8 +1,8 @@
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.repo_id @repo.id
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
@ -12,14 +12,17 @@ json.versions_count @project.versions_count #里程碑数量
json.version_releases_count @project.releases_size(@user.try(:id), "all")
json.version_releasesed_count @project.releases_size(@user.try(:id), "released") #已发行的版本
json.contributor_users_count @project.contributor_users
json.issue_tags_count @tags_count
json.branches_count @branches_count
json.commits_count @commits_count
json.permission @project.get_premission(@user)
json.mirror_url @project&.repository.mirror_url
json.mirror @project&.repository.mirror_url.present?
json.type @project.numerical_for_project_type
json.mirror_status @project.repository&.mirror&.numerical_for_status if @project.sync_mirror?
unless @project.common?
json.mirror_status @repo.mirror_status
json.mirror_num @repo.mirror_num
json.first_sync @repo.first_sync?
end
json.watched @project.watched_by? @user
json.praised @project.praised_by? @user
json.status @project.status
@ -32,12 +35,14 @@ json.fork_info do
end
end
json.size replace_bytes_to_b(number_to_human_size(@result['size'].to_i*1024))
json.ssh_url @result['ssh_url']
json.clone_url @result['clone_url']
json.default_branch @result['default_branch']
json.empty @result['empty']
json.full_name @result['full_name']
if @result
json.size replace_bytes_to_b(number_to_human_size(@result['size'].to_i*1024))
json.ssh_url @result['ssh_url']
json.clone_url @result['clone_url']
json.default_branch @result['default_branch']
json.empty @result['empty']
json.full_name @result['full_name']
json.private @result['private']
end
json.private @result['private']
json.partial! 'author', locals: { user: @project.owner }

View File

@ -6,6 +6,9 @@ json.last_commit do
json.nil!
end
end
#json.tags_count @tags_count
#json.branches_count @branches_count
#json.commits_count @commits_count
json.entries do
json.array! @sub_entries do |entry|
json.partial! 'repositories/simple_entry', locals: { entry: entry }

View File

@ -0,0 +1,7 @@
json.tags_count @tags_count
json.branches_count @branches_count
json.commits_count @commits_count
json.version_releasesed_count @project.releases_size(current_user.try(:id), "released") #已发行的版本
if @result
json.size replace_bytes_to_b(number_to_human_size(@result['size'].to_i*1024))
end

View File

@ -13,4 +13,5 @@ json.watching_count @user.follow_count #关注数
json.undo_events @undo_events
json.user_composes_count @user_composes_count
json.common_projects_count @projects_common_count
json.mirror_projects_count @projects_mirrior_count
json.mirror_projects_count @projects_mirrior_count
json.sync_mirror_projects_count @projects_sync_mirrior_count

2
bin/cable Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
bundle exec puma -p 28080 cable/config.ru

4
cable/config.ru Normal file
View File

@ -0,0 +1,4 @@
require_relative '../config/environment'
Rails.application.eager_load!
run ActionCable.server

View File

@ -29,6 +29,9 @@ module Educoderplus
# job
config.active_job.queue_adapter = :sidekiq
# disable actioncable development nend true
# config.action_cable.disable_request_forgery_protection = true
config.middleware.use OmniAuth::Builder do
provider :cas, url: 'https://urp.tfswufe.edu.cn/cas'
end

View File

@ -1,10 +1,12 @@
development:
adapter: async
adapter: redis
url: redis://localhost:6379
test:
adapter: async
adapter: redis
url: redis://localhost:6379
production:
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: educoderplus_production
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379" } %>
channel_prefix: forgeplus_production

View File

@ -2,10 +2,12 @@ Rails.application.routes.draw do
require 'sidekiq/web'
require 'admin_constraint'
# mount Sidekiq::Web => '/sidekiq'
mount Sidekiq::Web => '/sidekiq', :constraints => AdminConstraint.new
# Serve websocket cable requests in-process
mount ActionCable.server => '/cable'
get 'attachments/download/:id', to: 'attachments#show'
get 'attachments/download/:id/:filename', to: 'attachments#show'
get 'auth/qq/callback', to: 'oauth/qq#create'
@ -14,6 +16,11 @@ Rails.application.routes.draw do
resources :edu_settings
scope '/api' do
resources :sync_forge, only: [:create] do
collection do
post :sync_users
end
end
resources :composes do
resources :compose_projects, only: [:create, :destroy]
end
@ -32,8 +39,8 @@ Rails.application.routes.draw do
delete 'commons/delete', to: 'commons#delete'
resources :issues, except: [:index, :new,:create, :update, :edit, :destroy] do
resources :journals, only: [:index, :create, :destroy, :edit, :update] do
member do
resources :journals, only: [:index, :create, :destroy, :edit, :update] do
member do
get :get_children_journals
end
end
@ -64,11 +71,13 @@ 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
post :check_can_merge
get :create_merge_infos
get :get_branches
end
end
resources :version_releases, only: [:index,:new, :create, :edit, :update, :destroy]
@ -118,6 +127,7 @@ Rails.application.routes.draw do
get :watch_users
get :praise_users
get :fork_users
get :simple
end
end
@ -160,6 +170,8 @@ Rails.application.routes.draw do
post :sync_token
post :sync_gitea_pwd
post :sync_salt
get :trustie_projects
get :trustie_related_projects
end
scope module: :users do
@ -209,6 +221,7 @@ Rails.application.routes.draw do
delete :delete_file
post :repo_hook
post :sync_mirror
get :top_counts
get 'commits/:sha', to: 'repositories#commit', as: 'commit'
end
end

View File

@ -0,0 +1,5 @@
class RemoveIssuesLockVersionColumn < ActiveRecord::Migration[5.2]
def change
remove_column :issues, :lock_version
end
end

View File

@ -0,0 +1,5 @@
class AddSyncNumToMirrors < ActiveRecord::Migration[5.2]
def change
add_column :mirrors, :sync_num, :integer, default: 1
end
end

View File

@ -0,0 +1,6 @@
class AddOriginProjectIdToPullRequest < ActiveRecord::Migration[5.2]
def change
add_column :pull_requests, :fork_project_id, :integer
add_column :pull_requests, :is_original, :boolean, default: false
end
end

BIN
dump.rdb

Binary file not shown.