merge from develop
This commit is contained in:
commit
af7a779af6
|
@ -1,392 +1,397 @@
|
||||||
class RepositoriesController < ApplicationController
|
class RepositoriesController < ApplicationController
|
||||||
include RepositoriesHelper
|
include RepositoriesHelper
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
include OperateProjectAbilityAble
|
include OperateProjectAbilityAble
|
||||||
include Repository::LanguagesPercentagable
|
include Repository::LanguagesPercentagable
|
||||||
|
|
||||||
before_action :require_login, only: %i[edit update create_file update_file delete_file sync_mirror]
|
before_action :require_login, only: %i[edit update create_file update_file delete_file sync_mirror]
|
||||||
before_action :require_profile_completed, only: [:create_file]
|
before_action :require_profile_completed, only: [:create_file]
|
||||||
before_action :load_repository
|
before_action :load_repository
|
||||||
before_action :authorizate!, except: [:sync_mirror, :tags, :commit, :archive]
|
before_action :authorizate!, except: [:sync_mirror, :tags, :commit, :archive]
|
||||||
before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror]
|
before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror]
|
||||||
before_action :get_ref, only: %i[entries sub_entries top_counts files archive]
|
before_action :get_ref, only: %i[entries sub_entries top_counts files archive]
|
||||||
before_action :get_latest_commit, 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]
|
before_action :get_statistics, only: %i[top_counts]
|
||||||
|
|
||||||
def files
|
def files
|
||||||
result = @project.educoder? ? nil : Gitea::Repository::Files::GetService.call(@owner, @project.identifier, @ref, params[:search], @owner.gitea_token)
|
result = @project.educoder? ? nil : Gitea::Repository::Files::GetService.call(@owner, @project.identifier, @ref, params[:search], @owner.gitea_token)
|
||||||
render json: result
|
render json: result
|
||||||
end
|
end
|
||||||
|
|
||||||
# 新版项目详情
|
# 新版项目详情
|
||||||
def detail
|
def detail
|
||||||
@user = current_user
|
@user = current_user
|
||||||
@result = Repositories::DetailService.call(@owner, @repository, @user)
|
@result = Repositories::DetailService.call(@owner, @repository, @user)
|
||||||
@project_fork_id = @project.try(:forked_from_project_id)
|
@project_fork_id = @project.try(:forked_from_project_id)
|
||||||
if @project_fork_id.present?
|
if @project_fork_id.present?
|
||||||
@fork_project = Project.find_by(id: @project_fork_id)
|
@fork_project = Project.find_by(id: @project_fork_id)
|
||||||
@fork_project_user = @fork_project.owner
|
@fork_project_user = @fork_project.owner
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
tip_exception(e.message)
|
tip_exception(e.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@user = current_user
|
@user = current_user
|
||||||
@repo = @project.repository
|
@repo = @project.repository
|
||||||
@result = @project.forge? ? Gitea::Repository::GetService.new(@owner, @project.identifier).call : nil
|
@result = @project.forge? ? Gitea::Repository::GetService.new(@owner, @project.identifier).call : nil
|
||||||
@project_fork_id = @project.try(:forked_from_project_id)
|
@project_fork_id = @project.try(:forked_from_project_id)
|
||||||
if @project_fork_id.present?
|
if @project_fork_id.present?
|
||||||
@fork_project = Project.find_by(id: @project_fork_id)
|
@fork_project = Project.find_by(id: @project_fork_id)
|
||||||
@fork_project_user = @fork_project.owner
|
@fork_project_user = @fork_project.owner
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
tip_exception(e.message)
|
tip_exception(e.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def entries
|
def entries
|
||||||
@project.increment!(:visits)
|
@week_project_visit_record, @month_project_visit_record = TimeableVisitRecord.build(@project.id)
|
||||||
CacheAsyncSetJob.perform_later("project_common_service", {visits: 1}, @project.id)
|
if @week_project_visit_record.visits < 300 && @month_project_visit_record.visits < 1000
|
||||||
if @project.educoder?
|
@week_project_visit_record.increment!(:visits)
|
||||||
@entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder.repo_name)
|
@month_project_visit_record.increment!(:visits)
|
||||||
else
|
@project.increment!(:visits)
|
||||||
@entries = Gitea::Repository::Entries::ListService.new(@owner, @project.identifier, ref: @ref).call
|
CacheAsyncSetJob.perform_later("project_common_service", {visits: 1}, @project.id)
|
||||||
@entries = @entries.present? ? @entries.sort_by{ |hash| hash['type'] } : []
|
end
|
||||||
@path = GiteaService.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/"
|
if @project.educoder?
|
||||||
end
|
@entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder.repo_name)
|
||||||
end
|
else
|
||||||
|
@entries = Gitea::Repository::Entries::ListService.new(@owner, @project.identifier, ref: @ref).call
|
||||||
def top_counts
|
@entries = @entries.present? ? @entries.sort_by{ |hash| hash['type'] } : []
|
||||||
@result = @project.educoder? ? nil : Gitea::Repository::GetService.new(@project.owner, @project.identifier).call
|
@path = GiteaService.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
def sub_entries
|
|
||||||
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
|
def top_counts
|
||||||
|
@result = @project.educoder? ? nil : Gitea::Repository::GetService.new(@project.owner, @project.identifier).call
|
||||||
if @project.educoder?
|
end
|
||||||
if params[:type] === 'file'
|
|
||||||
@sub_entries = Educoder::Repository::Entries::GetService.call(@project&.project_educoder&.repo_name, file_path_uri)
|
def sub_entries
|
||||||
logger.info "######### sub_entries: #{@sub_entries}"
|
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
|
||||||
return render_error('该文件暂未开放,敬请期待.') if @sub_entries['status'].to_i === -1
|
|
||||||
|
if @project.educoder?
|
||||||
tmp_entries = {
|
if params[:type] === 'file'
|
||||||
"content" => @sub_entries['data']['content'],
|
@sub_entries = Educoder::Repository::Entries::GetService.call(@project&.project_educoder&.repo_name, file_path_uri)
|
||||||
"type" => "blob"
|
logger.info "######### sub_entries: #{@sub_entries}"
|
||||||
}
|
return render_error('该文件暂未开放,敬请期待.') if @sub_entries['status'].to_i === -1
|
||||||
@sub_entries = {
|
|
||||||
"trees"=>tmp_entries,
|
tmp_entries = {
|
||||||
"commits" => [{}]
|
"content" => @sub_entries['data']['content'],
|
||||||
}
|
"type" => "blob"
|
||||||
else
|
}
|
||||||
begin
|
@sub_entries = {
|
||||||
@sub_entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder&.repo_name, {path: file_path_uri})
|
"trees"=>tmp_entries,
|
||||||
if @sub_entries.blank? || @sub_entries['status'].to_i === -1
|
"commits" => [{}]
|
||||||
@sub_entries = Educoder::Repository::Entries::GetService.call(@project&.project_educoder&.repo_name, file_path_uri)
|
}
|
||||||
return render_error('该文件暂未开放,敬请期待.') if @sub_entries['status'].to_i === -1
|
else
|
||||||
tmp_entries = {
|
begin
|
||||||
"content" => @sub_entries['data']['content'],
|
@sub_entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder&.repo_name, {path: file_path_uri})
|
||||||
"type" => "blob"
|
if @sub_entries.blank? || @sub_entries['status'].to_i === -1
|
||||||
}
|
@sub_entries = Educoder::Repository::Entries::GetService.call(@project&.project_educoder&.repo_name, file_path_uri)
|
||||||
@sub_entries = {
|
return render_error('该文件暂未开放,敬请期待.') if @sub_entries['status'].to_i === -1
|
||||||
"trees"=>tmp_entries,
|
tmp_entries = {
|
||||||
"commits" => [{}]
|
"content" => @sub_entries['data']['content'],
|
||||||
}
|
"type" => "blob"
|
||||||
end
|
}
|
||||||
rescue
|
@sub_entries = {
|
||||||
return render_error('该文件暂未开放,敬请期待.')
|
"trees"=>tmp_entries,
|
||||||
end
|
"commits" => [{}]
|
||||||
end
|
}
|
||||||
else
|
end
|
||||||
@path = GiteaService.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/"
|
rescue
|
||||||
interactor = Repositories::EntriesInteractor.call(@owner, @project.identifier, file_path_uri, ref: @ref)
|
return render_error('该文件暂未开放,敬请期待.')
|
||||||
if interactor.success?
|
end
|
||||||
result = interactor.result
|
end
|
||||||
@sub_entries = result.is_a?(Array) ? result.sort_by{ |hash| hash['type'] } : result
|
else
|
||||||
else
|
@path = GiteaService.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/"
|
||||||
render_error(interactor.error)
|
interactor = Repositories::EntriesInteractor.call(@owner, @project.identifier, file_path_uri, ref: @ref)
|
||||||
end
|
if interactor.success?
|
||||||
end
|
result = interactor.result
|
||||||
end
|
@sub_entries = result.is_a?(Array) ? result.sort_by{ |hash| hash['type'] } : result
|
||||||
|
else
|
||||||
def commits
|
render_error(interactor.error)
|
||||||
if @project.educoder?
|
end
|
||||||
@commits = Educoder::Repository::Commits::ListService.call(@project&.project_educoder&.repo_name)
|
end
|
||||||
else
|
end
|
||||||
if params[:filepath].present?
|
|
||||||
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
|
def commits
|
||||||
@hash_commit = Gitea::Repository::Commits::FileListService.new(@owner.login, @project.identifier, file_path_uri,
|
if @project.educoder?
|
||||||
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
|
@commits = Educoder::Repository::Commits::ListService.call(@project&.project_educoder&.repo_name)
|
||||||
else
|
else
|
||||||
@hash_commit = Gitea::Repository::Commits::ListService.new(@owner.login, @project.identifier,
|
if params[:filepath].present?
|
||||||
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
|
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
|
||||||
end
|
@hash_commit = Gitea::Repository::Commits::FileListService.new(@owner.login, @project.identifier, file_path_uri,
|
||||||
end
|
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
|
||||||
end
|
else
|
||||||
|
@hash_commit = Gitea::Repository::Commits::ListService.new(@owner.login, @project.identifier,
|
||||||
def commits_slice
|
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
|
||||||
@hash_commit = Gitea::Repository::Commits::ListSliceService.call(@owner.login, @project.identifier,
|
end
|
||||||
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token)
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def commit
|
def commits_slice
|
||||||
@sha = params[:sha]
|
@hash_commit = Gitea::Repository::Commits::ListSliceService.call(@owner.login, @project.identifier,
|
||||||
if @project.educoder?
|
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token)
|
||||||
return render_error('暂未开放,敬请期待.')
|
end
|
||||||
else
|
|
||||||
@commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token)
|
def commit
|
||||||
@commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token, {diff: true})
|
@sha = params[:sha]
|
||||||
render_error(@commit[:message], @commit[:status]) if @commit.has_key?(:status) || @commit_diff.has_key?(:status)
|
if @project.educoder?
|
||||||
end
|
return render_error('暂未开放,敬请期待.')
|
||||||
end
|
else
|
||||||
|
@commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token)
|
||||||
def tags
|
@commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token, {diff: true})
|
||||||
result = Gitea::Repository::Tags::ListService.call(current_user&.gitea_token, @owner.login, @project.identifier, {page: params[:page], limit: params[:limit]})
|
render_error(@commit[:message], @commit[:status]) if @commit.has_key?(:status) || @commit_diff.has_key?(:status)
|
||||||
|
end
|
||||||
@tags = result.is_a?(Hash) && result.key?(:status) ? [] : result
|
end
|
||||||
end
|
|
||||||
|
def tags
|
||||||
def contributors
|
result = Gitea::Repository::Tags::ListService.call(current_user&.gitea_token, @owner.login, @project.identifier, {page: params[:page], limit: params[:limit]})
|
||||||
if params[:filepath].present? || @project.educoder?
|
|
||||||
@contributors = []
|
@tags = result.is_a?(Hash) && result.key?(:status) ? [] : result
|
||||||
else
|
end
|
||||||
result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier)
|
|
||||||
@contributors = result.is_a?(Hash) && result.key?(:status) ? [] : result
|
def contributors
|
||||||
end
|
if params[:filepath].present? || @project.educoder?
|
||||||
rescue
|
@contributors = []
|
||||||
@contributors = []
|
else
|
||||||
end
|
result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier)
|
||||||
|
@contributors = result.is_a?(Hash) && result.key?(:status) ? [] : result
|
||||||
def edit
|
end
|
||||||
return render_forbidden if !@project.manager?(current_user) && !current_user.admin?
|
rescue
|
||||||
end
|
@contributors = []
|
||||||
|
end
|
||||||
def create_file
|
|
||||||
interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params)
|
def edit
|
||||||
if interactor.success?
|
return render_forbidden if !@project.manager?(current_user) && !current_user.admin?
|
||||||
@file = interactor.result
|
end
|
||||||
# create_new_pr(params)
|
|
||||||
#如果是更新流水线文件
|
def create_file
|
||||||
if params[:pipeline_id]
|
interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params)
|
||||||
update_pipeline(params[:pipeline_id])
|
if interactor.success?
|
||||||
end
|
@file = interactor.result
|
||||||
else
|
# create_new_pr(params)
|
||||||
render_error(interactor.error)
|
#如果是更新流水线文件
|
||||||
end
|
if params[:pipeline_id]
|
||||||
end
|
update_pipeline(params[:pipeline_id])
|
||||||
|
end
|
||||||
def update_pipeline(pipeline_id)
|
else
|
||||||
pipeline = Ci::Pipeline.find(pipeline_id)
|
render_error(interactor.error)
|
||||||
if pipeline
|
end
|
||||||
pipeline.update!(sync: 1)
|
end
|
||||||
end
|
|
||||||
end
|
def update_pipeline(pipeline_id)
|
||||||
|
pipeline = Ci::Pipeline.find(pipeline_id)
|
||||||
def update_file
|
if pipeline
|
||||||
interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, params.merge(identifier: @project.identifier))
|
pipeline.update!(sync: 1)
|
||||||
if interactor.success?
|
end
|
||||||
@file = interactor.result
|
end
|
||||||
# TODO: 是否创建pr
|
|
||||||
# create_new_pr(params)
|
def update_file
|
||||||
render_result(1, "更新成功")
|
interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, params.merge(identifier: @project.identifier))
|
||||||
else
|
if interactor.success?
|
||||||
render_error(interactor.error)
|
@file = interactor.result
|
||||||
end
|
# TODO: 是否创建pr
|
||||||
end
|
# create_new_pr(params)
|
||||||
|
render_result(1, "更新成功")
|
||||||
def delete_file
|
else
|
||||||
interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, params.merge(identifier: @project.identifier))
|
render_error(interactor.error)
|
||||||
if interactor.success?
|
end
|
||||||
@file = interactor.result
|
end
|
||||||
render_result(1, "文件删除成功")
|
|
||||||
else
|
def delete_file
|
||||||
render_error(interactor.error)
|
interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, params.merge(identifier: @project.identifier))
|
||||||
end
|
if interactor.success?
|
||||||
end
|
@file = interactor.result
|
||||||
|
render_result(1, "文件删除成功")
|
||||||
def repo_hook
|
else
|
||||||
|
render_error(interactor.error)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
def sync_mirror
|
|
||||||
return render_error("正在镜像中..") if @repository.mirror.waiting?
|
def repo_hook
|
||||||
|
|
||||||
@repository.sync_mirror!
|
end
|
||||||
SyncMirroredRepositoryJob.perform_later(@repository.id, current_user.id)
|
|
||||||
render_ok
|
def sync_mirror
|
||||||
end
|
return render_error("正在镜像中..") if @repository.mirror.waiting?
|
||||||
|
|
||||||
def readme
|
@repository.sync_mirror!
|
||||||
if params[:filepath].present?
|
SyncMirroredRepositoryJob.perform_later(@repository.id, current_user.id)
|
||||||
result = Gitea::Repository::Readme::DirService.call(@owner.login, @repository.identifier, params[:filepath], params[:ref], current_user&.gitea_token)
|
render_ok
|
||||||
else
|
end
|
||||||
result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], current_user&.gitea_token)
|
|
||||||
end
|
def readme
|
||||||
@path = GiteaService.gitea_config[:domain]+"/#{@owner.login}/#{@repository.identifier}/raw/branch/#{params[:ref]}/"
|
if params[:filepath].present?
|
||||||
@readme = result[:status] === :success ? result[:body] : nil
|
result = Gitea::Repository::Readme::DirService.call(@owner.login, @repository.identifier, params[:filepath], params[:ref], current_user&.gitea_token)
|
||||||
@readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref], @path)
|
else
|
||||||
@readme['replace_content'] = readme_decode64_content(@readme, @owner, @repository, params[:ref], @path)
|
result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], current_user&.gitea_token)
|
||||||
render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha", "replace_content")
|
end
|
||||||
rescue
|
@path = GiteaService.gitea_config[:domain]+"/#{@owner.login}/#{@repository.identifier}/raw/branch/#{params[:ref]}/"
|
||||||
render json: nil
|
@readme = result[:status] === :success ? result[:body] : nil
|
||||||
end
|
@readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref], @path)
|
||||||
|
@readme['replace_content'] = readme_decode64_content(@readme, @owner, @repository, params[:ref], @path)
|
||||||
def languages
|
render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha", "replace_content")
|
||||||
if @project.educoder?
|
rescue
|
||||||
render json: {}
|
render json: nil
|
||||||
else
|
end
|
||||||
render json: languages_precentagable
|
|
||||||
end
|
def languages
|
||||||
end
|
if @project.educoder?
|
||||||
|
render json: {}
|
||||||
def archive
|
else
|
||||||
domain = GiteaService.gitea_config[:domain]
|
render json: languages_precentagable
|
||||||
api_url = GiteaService.gitea_config[:base_url]
|
end
|
||||||
archive_url = "/repos/#{@owner.login}/#{@repository.identifier}/archive/#{Addressable::URI.escape(params[:archive])}"
|
end
|
||||||
|
|
||||||
file_path = [domain, api_url, archive_url].join
|
def archive
|
||||||
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("?") if @repository.hidden?
|
domain = GiteaService.gitea_config[:domain]
|
||||||
|
api_url = GiteaService.gitea_config[:base_url]
|
||||||
return render_not_found if !request.format.zip? && !request.format.gzip?
|
archive_url = "/repos/#{@owner.login}/#{@repository.identifier}/archive/#{Addressable::URI.escape(params[:archive])}"
|
||||||
|
|
||||||
redirect_to file_path
|
file_path = [domain, api_url, archive_url].join
|
||||||
end
|
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("?") if @repository.hidden?
|
||||||
|
|
||||||
def raw
|
return render_not_found if !request.format.zip? && !request.format.gzip?
|
||||||
domain = GiteaService.gitea_config[:domain]
|
|
||||||
api_url = GiteaService.gitea_config[:base_url]
|
redirect_to file_path
|
||||||
|
end
|
||||||
url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{Addressable::URI.escape(params[:filepath])}?ref=#{Addressable::URI.escape(params[:ref])}"
|
|
||||||
file_path = [domain, api_url, url].join
|
def raw
|
||||||
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("&")
|
domain = GiteaService.gitea_config[:domain]
|
||||||
|
api_url = GiteaService.gitea_config[:base_url]
|
||||||
redirect_to file_path
|
|
||||||
end
|
url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{Addressable::URI.escape(params[:filepath])}?ref=#{Addressable::URI.escape(params[:ref])}"
|
||||||
|
file_path = [domain, api_url, url].join
|
||||||
private
|
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("&")
|
||||||
|
|
||||||
def find_project
|
redirect_to file_path
|
||||||
@project = Project.find params[:id]
|
end
|
||||||
render_not_found("未找到相关的仓库") unless @project
|
|
||||||
end
|
private
|
||||||
|
|
||||||
def find_project_with_includes
|
def find_project
|
||||||
@project = Project.includes(:repository, :owner, :watchers, :praise_treads).find params[:id]
|
@project = Project.find params[:id]
|
||||||
end
|
render_not_found("未找到相关的仓库") unless @project
|
||||||
|
end
|
||||||
def authorizate!
|
|
||||||
return if current_user && current_user.admin?
|
def find_project_with_includes
|
||||||
if @project.repository.hidden? && !@project.member?(current_user)
|
@project = Project.includes(:repository, :owner, :watchers, :praise_treads).find params[:id]
|
||||||
render_forbidden
|
end
|
||||||
end
|
|
||||||
end
|
def authorizate!
|
||||||
|
return if current_user && current_user.admin?
|
||||||
# TODO 获取最新commit信息
|
if @project.repository.hidden? && !@project.member?(current_user)
|
||||||
def project_commits
|
render_forbidden
|
||||||
if params[:filepath].present?
|
end
|
||||||
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
|
end
|
||||||
Gitea::Repository::Commits::FileListService.new(@project.owner.login, @project.identifier, file_path_uri,
|
|
||||||
sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call
|
# TODO 获取最新commit信息
|
||||||
else
|
def project_commits
|
||||||
Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier,
|
if params[:filepath].present?
|
||||||
sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call
|
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
|
||||||
end
|
Gitea::Repository::Commits::FileListService.new(@project.owner.login, @project.identifier, file_path_uri,
|
||||||
end
|
sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call
|
||||||
|
else
|
||||||
def get_statistics
|
Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier,
|
||||||
@branches_count = @project.educoder? ? 0 : Gitea::Repository::Branches::ListService.new(@project.owner, @project.identifier).call&.size
|
sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call
|
||||||
@tags_count = @project.educoder? ? 0 : Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @project.owner.login, @project.identifier).call&.size
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_ref
|
def get_statistics
|
||||||
@ref = params[:ref] || @project&.default_branch
|
@branches_count = @project.educoder? ? 0 : Gitea::Repository::Branches::ListService.new(@project.owner, @project.identifier).call&.size
|
||||||
end
|
@tags_count = @project.educoder? ? 0 : Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @project.owner.login, @project.identifier).call&.size
|
||||||
|
end
|
||||||
def get_latest_commit
|
|
||||||
latest_commit = @project.educoder? ? nil : project_commits
|
def get_ref
|
||||||
@latest_commit = latest_commit.present? ? latest_commit[:body][0] : nil
|
@ref = params[:ref] || @project&.default_branch
|
||||||
@commits_count = latest_commit.present? ? latest_commit[:total_count] : 0
|
end
|
||||||
end
|
|
||||||
|
def get_latest_commit
|
||||||
def content_params
|
latest_commit = @project.educoder? ? nil : project_commits
|
||||||
{
|
@latest_commit = latest_commit.present? ? latest_commit[:body][0] : nil
|
||||||
filepath: params[:filepath],
|
@commits_count = latest_commit.present? ? latest_commit[:total_count] : 0
|
||||||
branch: params[:branch],
|
end
|
||||||
new_branch: params[:new_branch],
|
|
||||||
content: params[:content],
|
def content_params
|
||||||
message: params[:message],
|
{
|
||||||
committer: {
|
filepath: params[:filepath],
|
||||||
email: current_user.mail,
|
branch: params[:branch],
|
||||||
name: current_user.login
|
new_branch: params[:new_branch],
|
||||||
},
|
content: params[:content],
|
||||||
identifier: @project.identifier
|
message: params[:message],
|
||||||
}
|
committer: {
|
||||||
end
|
email: current_user.mail,
|
||||||
|
name: current_user.login
|
||||||
def hook_params(hook_type, params)
|
},
|
||||||
# if hook_type == "push"
|
identifier: @project.identifier
|
||||||
# # TODO hook返回的记录中,暂时没有文件代码数量的增减,暂时根据 commits数量来计算
|
}
|
||||||
# uploadPushInfo = {
|
end
|
||||||
# "sha": params["commits"].present? ? params["commits"].last : "",
|
|
||||||
# "branch": params["ref"].to_s.split("/").last,
|
def hook_params(hook_type, params)
|
||||||
# "modification_lines": params["commits"].length
|
# if hook_type == "push"
|
||||||
# }
|
# # TODO hook返回的记录中,暂时没有文件代码数量的增减,暂时根据 commits数量来计算
|
||||||
# elsif hook_type == "pull_request" && params["action"].to_s == "closed" #合并请求合并后才会有上链操作
|
# uploadPushInfo = {
|
||||||
# uploadPushInfo = {
|
# "sha": params["commits"].present? ? params["commits"].last : "",
|
||||||
# "branch": params["base"]["ref"].to_s.split("/").last,
|
# "branch": params["ref"].to_s.split("/").last,
|
||||||
# "sha": params["pull_request"]["merge_base"],
|
# "modification_lines": params["commits"].length
|
||||||
# "modification_lines": 1 #pull_request中没有commits数量
|
# }
|
||||||
# }
|
# elsif hook_type == "pull_request" && params["action"].to_s == "closed" #合并请求合并后才会有上链操作
|
||||||
# else
|
# uploadPushInfo = {
|
||||||
# uploadPushInfo = {}
|
# "branch": params["base"]["ref"].to_s.split("/").last,
|
||||||
# end
|
# "sha": params["pull_request"]["merge_base"],
|
||||||
|
# "modification_lines": 1 #pull_request中没有commits数量
|
||||||
# uploadPushInfo
|
# }
|
||||||
end
|
# else
|
||||||
|
# uploadPushInfo = {}
|
||||||
def create_new_pr(params)
|
# end
|
||||||
if params[:new_branch].present? && params[:new_branch] != params[:branch]
|
|
||||||
local_params = {
|
# uploadPushInfo
|
||||||
title: params[:message], #标题
|
end
|
||||||
body: params[:content], #内容
|
|
||||||
head: params[:new_branch], #源分支
|
def create_new_pr(params)
|
||||||
base: params[:branch], #目标分支
|
if params[:new_branch].present? && params[:new_branch] != params[:branch]
|
||||||
milestone: 0 #里程碑,未与本地的里程碑关联
|
local_params = {
|
||||||
|
title: params[:message], #标题
|
||||||
}
|
body: params[:content], #内容
|
||||||
requests_params = local_params.merge({
|
head: params[:new_branch], #源分支
|
||||||
assignee: current_user.try(:login),
|
base: params[:branch], #目标分支
|
||||||
assignees: [],
|
milestone: 0 #里程碑,未与本地的里程碑关联
|
||||||
labels: [],
|
|
||||||
due_date: Time.now
|
}
|
||||||
})
|
requests_params = local_params.merge({
|
||||||
|
assignee: current_user.try(:login),
|
||||||
issue_params = {
|
assignees: [],
|
||||||
author_id: current_user.id,
|
labels: [],
|
||||||
project_id: @project.id,
|
due_date: Time.now
|
||||||
subject: params[:message],
|
})
|
||||||
description: params[:content],
|
|
||||||
assigned_to_id: nil,
|
issue_params = {
|
||||||
fixed_version_id: nil,
|
author_id: current_user.id,
|
||||||
issue_tags_value: nil,
|
project_id: @project.id,
|
||||||
issue_classify: "pull_request",
|
subject: params[:message],
|
||||||
issue_type: "1",
|
description: params[:content],
|
||||||
tracker_id: 2,
|
assigned_to_id: nil,
|
||||||
status_id: 1,
|
fixed_version_id: nil,
|
||||||
priority_id: params[:priority_id] || "2"
|
issue_tags_value: nil,
|
||||||
}
|
issue_classify: "pull_request",
|
||||||
@pull_issue = Issue.new(issue_params)
|
issue_type: "1",
|
||||||
if @pull_issue.save!
|
tracker_id: 2,
|
||||||
local_requests = PullRequest.new(local_params.merge(user_id: current_user.try(:id), project_id: @project.id, issue_id: @pull_issue.id))
|
status_id: 1,
|
||||||
if local_requests.save
|
priority_id: params[:priority_id] || "2"
|
||||||
gitea_request = Gitea::PullRequest::CreateService.new(current_user.try(:gitea_token), @owner.login, @project.try(:identifier), requests_params).call
|
}
|
||||||
if gitea_request[:status] == :success && local_requests.update_attributes(gpid: gitea_request["body"]["number"])
|
@pull_issue = Issue.new(issue_params)
|
||||||
local_requests.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
if @pull_issue.save!
|
||||||
end
|
local_requests = PullRequest.new(local_params.merge(user_id: current_user.try(:id), project_id: @project.id, issue_id: @pull_issue.id))
|
||||||
end
|
if local_requests.save
|
||||||
end
|
gitea_request = Gitea::PullRequest::CreateService.new(current_user.try(:gitea_token), @owner.login, @project.try(:identifier), requests_params).call
|
||||||
end
|
if gitea_request[:status] == :success && local_requests.update_attributes(gpid: gitea_request["body"]["number"])
|
||||||
end
|
local_requests.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: timeable_visit_records
|
||||||
|
#
|
||||||
|
# id :integer not null, primary key
|
||||||
|
# time :string(255)
|
||||||
|
# project_id :integer
|
||||||
|
# visits :integer
|
||||||
|
# created_at :datetime not null
|
||||||
|
# updated_at :datetime not null
|
||||||
|
#
|
||||||
|
# Indexes
|
||||||
|
#
|
||||||
|
# index_timeable_visit_records_on_project_id (project_id)
|
||||||
|
# index_timeable_visit_records_on_time (time)
|
||||||
|
#
|
||||||
|
|
||||||
|
class TimeableVisitRecord < ApplicationRecord
|
||||||
|
|
||||||
|
belongs_to :project
|
||||||
|
|
||||||
|
def self.build(project_id)
|
||||||
|
week = TimeableVisitRecord.find_or_create_by!(time: Date.today.cweek, project_id: project_id)
|
||||||
|
month = TimeableVisitRecord.find_or_create_by!(time: Date.today.strftime("%Y%m"), project_id: project_id)
|
||||||
|
|
||||||
|
return week, month
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,13 @@
|
||||||
|
class CreateTimeableVisitRecords < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :timeable_visit_records do |t|
|
||||||
|
t.string :time
|
||||||
|
t.references :project
|
||||||
|
t.integer :visits, default: 0
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index :timeable_visit_records, :time
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue