mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-16 17:55:56 +08:00
Merge branch 'dev_trustie' of http://gitea.trustie.net/jasder/forgeplus into dev_trustie
This commit is contained in:
@@ -5,7 +5,7 @@ module OperateProjectAbilityAble
|
||||
end
|
||||
|
||||
def authorizate_user_can_edit_project!
|
||||
return if current_user.project_manager? @project || current_user.admin?
|
||||
return if @project.manager?(current_user) || current_user.admin?
|
||||
render_forbidden('你没有权限操作.')
|
||||
end
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class ProjectsController < ApplicationController
|
||||
ActiveRecord::Base.transaction do
|
||||
Projects::CreateForm.new(project_params).validate!
|
||||
@project = Projects::CreateService.new(current_user, project_params).call
|
||||
|
||||
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
@@ -107,8 +107,8 @@ class ProjectsController < ApplicationController
|
||||
end
|
||||
|
||||
def mirror_params
|
||||
params.permit(:user_id, :name, :description, :repository_name,
|
||||
:project_category_id, :project_language_id, :clone_addr, :private)
|
||||
params.permit(:user_id, :name, :description, :repository_name, :is_mirror, :auth_username,
|
||||
:auth_password, :project_category_id, :project_language_id, :clone_addr, :private)
|
||||
end
|
||||
|
||||
def project_public?
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
class RepositoriesController < ApplicationController
|
||||
include ApplicationHelper
|
||||
before_action :require_login, only: %i[edit update create_file update_file delete_file]
|
||||
include OperateProjectAbilityAble
|
||||
before_action :require_login, only: %i[edit update create_file update_file delete_file sync_mirror]
|
||||
before_action :find_project, :authorizate!
|
||||
before_action :find_repository, only: %i[sync_mirror]
|
||||
before_action :authorizate_user_can_edit_project!, only: %i[sync_mirror]
|
||||
|
||||
def show
|
||||
@branches_count = Gitea::Repository::BranchesService.new(@project.owner, @project.identifier).call&.size
|
||||
@@ -125,8 +128,8 @@ class RepositoriesController < ApplicationController
|
||||
|
||||
def repo_hook
|
||||
hook_type = request.headers["X-Gitea-Event"].to_s # 获取推送的方式
|
||||
ownername = @project.owner.try(:login)
|
||||
reponame = @project.identifier
|
||||
ownername = @project.owner.try(:login)
|
||||
reponame = @project.identifier
|
||||
username = current_user.try(:login)
|
||||
user_params = {
|
||||
"ownername": ownername,
|
||||
@@ -142,6 +145,12 @@ class RepositoriesController < ApplicationController
|
||||
@project.update_attribute(:token, @project.token + uploadPushInfo[:modificationLines].to_i)
|
||||
end
|
||||
|
||||
def sync_mirror
|
||||
@repo&.mirror.set_status!(Mirror.statuses[:waiting])
|
||||
SyncMirroredRepositoryJob(@repo, current_user)
|
||||
render_ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_project
|
||||
@@ -149,6 +158,10 @@ class RepositoriesController < ApplicationController
|
||||
render_not_found("未找到相关的仓库") unless @project
|
||||
end
|
||||
|
||||
def find_repository
|
||||
@repo = Repository.find params[:id]
|
||||
end
|
||||
|
||||
def authorizate!
|
||||
if @project.repository.hidden? && !@project.member?(current_user)
|
||||
render_forbidden
|
||||
@@ -166,13 +179,13 @@ class RepositoriesController < ApplicationController
|
||||
}
|
||||
end
|
||||
|
||||
def hook_params(hook_type, params)
|
||||
def hook_params(hook_type, params)
|
||||
if hook_type == "push"
|
||||
# TODO hook返回的记录中,暂时没有文件代码数量的增减,暂时根据 commits数量来计算
|
||||
# TODO hook返回的记录中,暂时没有文件代码数量的增减,暂时根据 commits数量来计算
|
||||
uploadPushInfo = {
|
||||
"shas": params["commits"].present? ? params["commits"].map{|c| c["id"]} : "",
|
||||
"shas": params["commits"].present? ? params["commits"].map{|c| c["id"]} : "",
|
||||
"branch": params["ref"].to_s.split("/").last,
|
||||
"modificationLines": params["commits"].length
|
||||
"modificationLines": params["commits"].length
|
||||
}
|
||||
elsif hook_type == "pull_request" && params["action"].to_s == "closed" #合并请求合并后才会有上链操作
|
||||
uploadPushInfo = {
|
||||
@@ -183,7 +196,7 @@ class RepositoriesController < ApplicationController
|
||||
"shas": [params["pull_request"]["merge_commit_sha"], params["pull_request"]["merge_base"]],
|
||||
"modificationLines": 1 #pull_request中没有commits数量
|
||||
}
|
||||
else
|
||||
else
|
||||
uploadPushInfo = {}
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user