Merge branch 'standalone_develop' into pre_trustie_server

This commit is contained in:
“xxq250” 2022-08-12 15:44:45 +08:00
commit 092e3e2546
32 changed files with 209 additions and 74 deletions

View File

@ -7,12 +7,12 @@ class Admins::MessageTemplatesController < Admins::BaseController
end
def new
@message_template = MessageTemplate::CustomTip.new
@message_template = MessageTemplate.new
end
def create
@message_template = MessageTemplate::CustomTip.new(ignore_params)
def create
@message_template = MessageTemplate::CustomTip.new(message_template_params)
@message_template.type = "MessageTemplate::CustomTip"
if @message_template.save!
redirect_to admins_message_templates_path
flash[:success] = "创建消息模板成功"
@ -47,7 +47,9 @@ class Admins::MessageTemplatesController < Admins::BaseController
private
def message_template_params
params.require(@message_template.type.split("::").join("_").underscore.to_sym).permit!
# type = @message_template.present? ? @message_template.type : "MessageTemplate::CustomTip"
# params.require(type.split("::").join("_").underscore.to_sym).permit!
params.require(:message_template).permit!
end
def get_template

View File

@ -1,8 +1,9 @@
class Admins::Topic::BannersController < Admins::Topic::BaseController
before_action :find_banner, only: [:edit, :update, :destroy]
def index
def index
@banners = paginate(::Topic::Banner)
@banners = paginate(::Topic::Banner.where("title like ?", "%#{params[:search]}%")) if params[:search].present?
end
def new

View File

@ -40,6 +40,13 @@ class Api::V1::BaseController < ApplicationController
return render_forbidden if !current_user.admin? && !@project.operator?(current_user)
end
# 具有仓库的操作权限或者fork仓库的操作权限
def require_operate_above_or_fork_project
@project = load_project
puts !current_user.admin? && !@project.operator?(current_user) && !(@project.fork_project.present? && @project.fork_project.operator?(current_user))
return render_forbidden if !current_user.admin? && !@project.operator?(current_user) && !(@project.fork_project.present? && @project.fork_project.operator?(current_user))
end
# 具有对仓库的访问权限
def require_public_and_member_above
@project = load_project

View File

@ -1,13 +1,13 @@
class Api::V1::Projects::ContentsController < Api::V1::BaseController
before_action :require_operate_above, only: [:batch]
before_action :require_operate_above_or_fork_project, only: [:batch]
def batch
@batch_content_params = batch_content_params
# 处理下author和committer信息如果没传则默认为当前用户信息
@batch_content_params.merge!(author_email: current_user.mail, author_name: current_user.login) if batch_content_params[:author_email].blank? && batch_content_params[:author_name].blank?
@batch_content_params.merge!(committer_email: current_user.mail, committer_name: current_user.login) if batch_content_params[:committer_email].blank? && batch_content_params[:committer_name].blank?
@result_object = Api::V1::Projects::Contents::BatchCreateService.call(@project, @batch_content_params, current_user&.gitea_token)
puts @result_object
@result_object = Api::V1::Projects::Contents::BatchCreateService.call(@project, @batch_content_params, @project.owner.gitea_token)
end
private

View File

@ -2,7 +2,7 @@ class Api::V1::Projects::Pulls::JournalsController < Api::V1::Projects::Pulls::B
def index
@journals = Api::V1::Projects::Pulls::Journals::ListService.call(@project, @pull_request, params, current_user)
@journals = kaminari_paginate(@journals)
@journals = @journals.limit(200)
end
def create

View File

@ -2,7 +2,8 @@ class Api::V1::Projects::Pulls::ReviewsController < Api::V1::Projects::Pulls::Ba
def index
@reviews = @pull_request.reviews
@reviews = kaminari_paginate(@reviews)
@reviews = @reviews.where(status: params[:status]) if params[:status].present?
# @reviews = kaminari_paginate(@reviews)
end
before_action :require_reviewer, only: [:create]
@ -13,7 +14,7 @@ class Api::V1::Projects::Pulls::ReviewsController < Api::V1::Projects::Pulls::Ba
private
def require_reviewer
return render_forbidden('您没有审查权限,请联系项目管理员') if !current_user.admin? && !@pull_request.reviewers.exists?(current_user.id)
return render_forbidden('您没有审查权限,请联系项目管理员') if !current_user.admin? && !@pull_request.reviewers.exists?(current_user.id) && !@project.manager?(current_user)
end
def review_params

View File

@ -5,11 +5,12 @@ class Api::V1::Projects::WebhooksController < Api::V1::BaseController
def index
# @result_object = Api::V1::Projects::Webhooks::ListService.call(@project, current_user&.gitea_token)
@webhooks = @project.webhooks
@webhooks = @webhooks.where(type: params[:type]) if params[:type].present?
@webhooks = kaminari_paginate(@webhooks)
end
def create
@result_object = Api::V1::Projects::Webhooks::CreateService.call(@project, webhook_params, current_user&.gitea_token)
@result_object = Api::V1::Projects::Webhooks::CreateService.call(@project, create_webhook_params, current_user&.gitea_token)
end
def show
@ -44,6 +45,10 @@ class Api::V1::Projects::WebhooksController < Api::V1::BaseController
end
private
def create_webhook_params
params.require(:webhook).permit(:active, :branch_filter, :http_method, :url, :content_type, :secret, :type, events: [])
end
def webhook_params
params.require(:webhook).permit(:active, :branch_filter, :http_method, :url, :content_type, :secret, events: [])
end

View File

@ -3,7 +3,7 @@ module RenderHelper
render json: { status: 0, message: 'success' }.merge(data)
end
def render_error(message = '')
def render_error(message = '', status = -1)
render json: { status: status, message: message }
end

View File

@ -4,26 +4,44 @@ class MarkFilesController < ApplicationController
before_action :load_pull_request
def index
@files_result = Gitea::PullRequest::FilesService.call(@owner.login, @project.identifier, @pull_request.gitea_number, current_user&.gitea_token)
@files_result = Gitea::PullRequest::FilesService.call(@owner.login, @project.identifier, @pull_request.gitea_number, current_user&.gitea_token, { "only-file-name": true })
@mark_files = MarkFile.where(pull_request_id: @pull_request.id)
end
def create
unless @pull_request.mark_files.present?
MarkFile.bulk_insert(*%i[pull_request_id, file_path_sha file_path created_at updated_at]) do |worker|
@files_result['Files'].each do |file|
worker.add(pull_request_id: @pull_request.id, file_path_sha: SecureRandom.uuid.gsub("-", ""), file_path: file['Name'])
end
end
end
# unless @pull_request.mark_files.present?
# MarkFile.bulk_insert(*%i[pull_request_id, file_path_sha file_path created_at updated_at]) do |worker|
# @files_result['Files'].each do |file|
# worker.add(pull_request_id: @pull_request.id, file_path_sha: SecureRandom.uuid.gsub("-", ""), file_path: file['Name'])
# end
# end
# end
end
def mark_file_as_unread
tip_exception "参数错误" if params[:file_path_sha].blank?
file_path = Base64.strict_decode64(params[:file_path_sha].to_s)
mark_file = @pull_request.mark_files.find_or_initialize_by(file_path_sha: params[:file_path_sha])
mark_file.file_path = file_path
mark_file.user_id = current_user.id
mark_file.mark_as_read = false
mark_file.save
render_ok
rescue Exception => e
tip_exception "参数解析错误"
end
def mark_file_as_read
tip_exception "参数错误" if params[:file_path_sha].blank?
file_path = Base64.strict_decode64(params[:file_path_sha].to_s)
mark_file = @pull_request.mark_files.find_or_initialize_by(file_path_sha: params[:file_path_sha])
mark_file.file_path = file_path
mark_file.user_id = current_user.id
mark_file.mark_as_read = true
mark_file.save
render_ok
rescue Exception => e
tip_exception "参数解析错误"
end
private

View File

@ -26,6 +26,9 @@ class MembersController < ApplicationController
@total_count = scope.size
@members = paginate(scope)
if @project.owner.is_a?(Organization) && (params[:page].to_i == 1 || params[:page].blank?) && !@project.members.exists?(user_id: current_user.id)
@current_user_header_team = Team.joins(:team_users, :team_projects).where(team_projects: {project_id: @project.id}, team_users: {user_id: current_user.id}).order(authorize: :desc).take
end
end
def remove
@ -61,10 +64,13 @@ class MembersController < ApplicationController
end
def check_member_exists!
return render_error("user_id为#{params[:user_id]}的用户已经是项目成员") if member_exists?
@current_user_header_team = Team.joins(:team_users, :team_projects).where(team_projects: {project_id: @project.id}, team_users: {user_id: current_user.id}).order(authorize: :desc).take
return render_error("user_id为#{params[:user_id]}的用户已经是项目成员") if member_exists? || (params[:user_id].to_i == current_user.id && @current_user_header_team.present?)
end
def check_member_not_exists!
@current_user_header_team = Team.joins(:team_users, :team_projects).where(team_projects: {project_id: @project.id}, team_users: {user_id: current_user.id}).order(authorize: :desc).take
return render_error("用户为组织成员,请到组织下操作!") if (params[:user_id].to_i == current_user.id && @current_user_header_team.present?) && !member_exists?
return render_error("user_id为#{params[:user_id]}的用户还不是项目成员") unless member_exists?
end

View File

@ -13,7 +13,8 @@ class ObRepositorySyncsController < ApplicationController
tip_exception "参数错误" if params[:github_address].blank? && params[:gitee_address].blank?
project_name ="#{@project.owner.name}:#{@project.identifier}"
service = ObRepositorySync::ApiService.new(project_name)
project_params = params.merge({ "gitlink_address": @project.repository.url })
domain = GiteaService.gitea_config[:domain]
project_params = params.merge({ "gitlink_address": "#{domain}/#{@project.owner&.login}/#{@project.identifier}.git" })
res = service.create_projects(project_params)
tip_exception "保存失败: #{res["msg"]}" if res["code"].to_s != "200"
sync_id = res["data"]["id"]
@ -23,7 +24,6 @@ class ObRepositorySyncsController < ApplicationController
ob_repository_sync.name = project_name
ob_repository_sync.github_address = "#{params[:github_address]}"
ob_repository_sync.gitee_address = "#{params[:gitee_address]}"
ob_repository_sync.gitlink_address = @project.repository.url
ob_repository_sync.github_token = "#{params[:github_token]}"
ob_repository_sync.gitee_token = "#{params[:gitee_token]}"
ob_repository_sync.sync_id = sync_id
@ -38,16 +38,30 @@ class ObRepositorySyncsController < ApplicationController
if res["code"].to_s == "200"
@ob_repository_sync.destroy!
end
render_ok
end
def jobs
tip_exception "该项目未创建同步任务" if @ob_repository_sync.blank?
service = ObRepositorySync::ApiService.new(@ob_repository_sync.name)
res = service.get_projects_jobs
render_ok(count: res["data"]["total"], data: res["data"]["list"])
data = res["data"]["list"]
if params[:type] && params[:type].to_s.downcase == "github"
data = data.select { |row| row["github_branch"].present? }
elsif params[:type] && params[:type].to_s.downcase == "gitee"
data = data.select { |row| row["gitee_branch"].present? }
end
render_ok(count: res["data"]["total"], data: data)
end
def create_jobs
tip_exception "必须配置一个分支" if params[:github_branch].blank? && params[:gitee_branch].blank? && params[:gitlink_branch].blank?
ob_jobs = ObRepositorySyncJob.where(ob_repository_sync_id: @ob_repository_sync.id)
ob_jobs = ob_jobs.where(job_type: params[:job_type]) if params[:job_type].present?
ob_jobs = ob_jobs.where(github_branch: params[:github_branch]) if params[:github_branch].present?
ob_jobs = ob_jobs.where(gitee_branch: params[:gitee_branch]) if params[:gitee_branch].present?
ob_jobs = ob_jobs.where(gitlink_branch: params[:gitlink_branch]) if params[:gitlink_branch].present?
tip_exception "该分支组合已配置,不能重复!" if ob_jobs.count > 0
service = ObRepositorySync::ApiService.new(@ob_repository_sync.name)
res = service.create_projects_jobs(params)
tip_exception "保存失败: #{res["msg"]}" if res["code"].to_s != "200"
@ -57,7 +71,7 @@ class ObRepositorySyncsController < ApplicationController
job.github_branch = "#{params[:github_branch]}"
job.gitee_branch = "#{params[:gitee_branch]}"
job.gitlink_branch = "#{params[:gitlink_branch]}"
job.job_type = "#{params[:type]}"
job.job_type = "#{params[:job_type]}"
job.base = "#{params[:base]}"
job.job_id = job_id
job.save
@ -70,7 +84,8 @@ class ObRepositorySyncsController < ApplicationController
service = ObRepositorySync::ApiService.new(@ob_repository_sync.name)
res = service.delete_job params[:job_id]
tip_exception "保存失败: #{res["msg"]}" if res["code"].to_s != "200"
@ob_repository_sync.destroy!
job = ObRepositorySyncJob.find_by(ob_repository_sync_id: @ob_repository_sync.id, job_id: params[:job_id])
job.destroy! if job.present?
render_ok
end
@ -94,7 +109,7 @@ class ObRepositorySyncsController < ApplicationController
tip_exception "该项目未创建同步任务" if @ob_repository_sync.blank?
tip_exception "缺少参数job_id" if params[:job_id].blank?
service = ObRepositorySync::ApiService.new(@ob_repository_sync.name)
@data = service.job_logs params[:job_id]
res = service.job_logs params[:job_id]
tip_exception "请求错误: #{res["msg"]}" if res["code"].to_s != "200"
render_ok(count: res["data"]["total"], data: res["data"]["list"])
end

View File

@ -137,6 +137,7 @@ class RepositoriesController < ApplicationController
else
@commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token)
@commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token, {diff: true})
render_error(@commit[:message], @commit[:status]) if @commit.has_key?(:status) || @commit_diff.has_key?(:status)
end
end
@ -388,4 +389,4 @@ class RepositoriesController < ApplicationController
end
end
end
end

View File

@ -3,6 +3,7 @@ class Traces::ProjectsController < Traces::BaseController
before_action :require_login
before_action :load_project
before_action :require_project_not_be_forked_project
before_action :set_trace_token_to_cookie
before_action :authorizate_user_can_edit_project!, except: [:task_results]
@ -95,4 +96,8 @@ class Traces::ProjectsController < Traces::BaseController
:domain => Trace.trace_config[:cookie_domain]
}
end
def require_project_not_be_forked_project
return render_error('fork仓库暂不支持代码溯源服务敬请谅解。') if @project.forked_from_project_id.present?
end
end

View File

@ -903,6 +903,7 @@ await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/versions/33/diff
|is_renamed|bool|是否重命名|
|is_ambiguous|bool||
|is_submodule|bool|是否为子模块|
|diff|string|git diff内容|
|sections.file_name|string|文件名称|
|sections.name|string||
|sections.lines.left_index|int|文件变动之前所在行数|
@ -1028,6 +1029,7 @@ await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/reviews.json')
|owner |是| |string |用户登录名 |
|repo |是| |string |项目标识identifier |
|index |是| | int |合并请求序号|
|status |否| |string |审查类型, common: 评论类型, approved: 已通过, rejected: 已拒绝|
### 返回字段说明:
参数 | 类型 | 字段说明
@ -1246,6 +1248,8 @@ await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/journals.json')
|need_respond |否| |bool |是否需要回应|
|state |否| |string |状态, opened: 开启的, resolved: 已解决的, disabled: 无效的|
|parent_id |否| |integer|父评论ID|
|path |否| |string |评论文件路径|
|is_full |否| |bool |是否展示全部评论(包括回复)|
|sort_by |否|created_on|string |排序字段 created_on: 创建时间, updated_on: 更新时间|
|sort_direction |否|asc |string |排序类型 desc: 倒序, asc: 正序|
@ -1370,9 +1374,9 @@ await octokit.request('POST /api/v1/yystopf/ceshi/pulls/1/journals.json')
|owner |是| | string |用户登录名 |
|repo |是| | string |项目标识identifier |
|index |是| | integer|合并请求序号|
|type |是| | string |评论类型 comment: 普通, problem: 需要回应的评论|
|type |否|comment| string |评论类型 comment: 普通, problem: 需要回应的评论|
|note |否| | string |评论内容|
|review_id || | string |审查ID|
|review_id || | string |审查ID|
|line_code |否| | string |行号|
|commit_id |否| | bool |commitID|
|path |否| | integer|文件路径|

View File

@ -2283,7 +2283,7 @@ await octokit.request('POST /api/v1/yystopf/ceshi/webhooks.json')
|webhook.active |是| | bool | 是否激活|
|webhook.branch_filter|否| |string|分支过滤|
|webhook.events |否| |array|触发事件|
|webhook.type |否| gitea |string| hook类型gitea slack discord dingtalk telegram msteams feishu matrix jianmu|
触发事件字段说明
参数| 含义|

View File

@ -42,6 +42,7 @@ class Journal < ApplicationRecord
belongs_to :resolveer, class_name: 'User', foreign_key: :resolveer_id, optional: true
has_many :journal_details, :dependent => :delete_all
has_many :attachments, as: :container, dependent: :destroy
has_many :children_journals, class_name: 'Journal', foreign_key: :parent_id
scope :journal_includes, ->{includes(:user, :journal_details, :attachments)}
scope :parent_journals, ->{where(parent_id: nil)}

View File

@ -13,6 +13,7 @@
#
class MessageTemplate < ApplicationRecord
self.inheritance_column = nil
PLATFORM = 'GitLink'
def self.build_init_data
@ -113,6 +114,6 @@ class MessageTemplate < ApplicationRecord
end
def simple_type
self.type.split("::")[-1]
self.type.to_s.split("::")[-1]
end
end

View File

@ -49,7 +49,7 @@ class Repository < ApplicationRecord
end
def url
self['url'].blank? ? "#{Gitea.gitea_config[:domain]}/#{self.owner&.login}/#{self.identifier}.git" : self['url']
self['url'].blank? ? "#{GiteaService.gitea_config[:domain]}/#{self.owner&.login}/#{self.identifier}.git" : self['url']
end
# with repository is mirror

View File

@ -15,7 +15,7 @@ class Api::V1::Projects::Pulls::Journals::CreateService < ApplicationService
@note = params[:note]
@commit_id = params[:commit_id]
@path = params[:path]
@type = params[:type]
@type = params[:type] || "comment"
@diff = params[:diff]
@review_id = params[:review_id]
@user = user
@ -23,7 +23,7 @@ class Api::V1::Projects::Pulls::Journals::CreateService < ApplicationService
def call
raise Error, errors.full_messages.join(", ") unless valid?
check_review_is_exists
check_review_is_exists if review_id.present?
if type == 'problem'
create_problem_journal
else

View File

@ -1,12 +1,13 @@
class Api::V1::Projects::Pulls::Journals::ListService < ApplicationService
include ActiveModel::Model
attr_reader :project, :pull_request, :keyword, :review_id, :need_respond, :state, :parent_id, :sort_by, :sort_direction, :user
attr_reader :project, :pull_request, :keyword, :review_id, :need_respond, :state, :parent_id, :path, :is_full, :sort_by, :sort_direction, :user
attr_accessor :queried_journals
validates :sort_by, inclusion: {in: Journal.column_names, message: '请输入正确的SortBy'}
validates :sort_direction, inclusion: {in: %w(asc desc), message: '请输入正确的SortDirection'}
validates :need_respond, inclusion: {in: [true, false], message: '请输入正确的NeedRespond'}, allow_nil: true
validates :is_full, inclusion: {in: [true, false], message: '请输入正确的IsFull'}
validates :state, inclusion: {in: %w(opened resolved disabled)}, allow_nil: true
def initialize(project, pull_request, params, user)
@ -19,6 +20,8 @@ class Api::V1::Projects::Pulls::Journals::ListService < ApplicationService
@parent_id = params[:parent_id]
@sort_by = params[:sort_by] || 'created_on'
@sort_direction = params[:sort_direction] || 'asc'
@is_full = ActiveModel::Type::Boolean.new.cast(params[:is_full]) || false
@path = params[:path]
@user = user
end
@ -32,18 +35,21 @@ class Api::V1::Projects::Pulls::Journals::ListService < ApplicationService
private
def journal_query_data
journals = @pull_request.journals
if parent_id.present?
journals = journals.where(parent_id: parent_id)
else
journals = journals.parent_journals
if !is_full
if parent_id.present?
journals = journals.where(parent_id: parent_id)
else
journals = journals.parent_journals
end
end
journals = journals.where(review_id: review_id) if review_id.present?
journals = journals.where(need_respond: need_respond) if need_respond.present?
journals = journals.where(state: state) if state.present?
journals = journals.where(path: path) if path.present?
q = journals.ransack(notes_cont: keyword)
scope = q.result.includes(:user, :resolveer, review: [:reviewer, pull_request: :issue])
scope = q.result.includes(:user, :resolveer, :children_journals, review: [:reviewer, pull_request: :issue])
scope = scope.order("journals.#{sort_by} #{sort_direction}")
@queried_journals = scope

View File

@ -1,14 +1,14 @@
class Api::V1::Projects::Webhooks::CreateService < ApplicationService
include ActiveModel::Model
attr_reader :project, :token, :owner, :repo, :active, :branch_filter, :content_type, :url, :http_method, :secret, :events
attr_reader :project, :token, :owner, :repo, :active, :branch_filter, :content_type, :url, :http_method, :secret, :events, :type
attr_accessor :gitea_data
validates :url, format: { with: URI::regexp(%w[http https]), message: "请输入正确的地址" }
validates :active, inclusion: {in: [true, false]}
validates :http_method, inclusion: { in: %w(POST GET), message: "请输入正确的请求方式"}
validates :content_type, inclusion: { in: %w(json form), message: "请输入正确的Content Type"}
validates :type, inclusion: {in: %w(gitea slack discord dingtalk telegram msteams feishu matrix jianmu), message: "请输入正确的Webhook Type"}
def initialize(project, params, token=nil)
@project = project
@owner = project&.owner.login
@ -20,6 +20,7 @@ class Api::V1::Projects::Webhooks::CreateService < ApplicationService
@http_method = params[:http_method]
@secret = params[:secret]
@events = params[:events]
@type = params[:type] || "gitea"
@token = token
end
@ -52,7 +53,7 @@ class Api::V1::Projects::Webhooks::CreateService < ApplicationService
secret: secret
},
events: events || [],
type: 'gitea',
type: type,
}
end

View File

@ -1,6 +1,6 @@
# List pull requests files
class Gitea::PullRequest::FilesService < Gitea::ClientService
attr_reader :owner, :repo, :pull_number, :token
attr_reader :owner, :repo, :pull_number, :token, :params
# GET /repos/{owner}/{repo}/pulls/{pull_number}/files
# owner: 用户
@ -8,22 +8,23 @@ class Gitea::PullRequest::FilesService < Gitea::ClientService
# pull_number: pull request主键id
# eg:
# Gitea::PullRequest::FilesService.call('jasder', 'repo_identifier', 1)
def initialize(owner, repo, pull_number, token=nil)
def initialize(owner, repo, pull_number, token=nil, params={})
@owner = owner
@repo = repo
@token = token
@pull_number = pull_number
@params = params
end
def call
response = get(url, params)
response = get(url, params.merge(token: token))
render_result(response)
end
private
def params
Hash.new.merge(token: token)
end
# def params
# Hash.new.merge(token: token)
# end
def url
"/repos/#{owner}/#{repo}/pulls/#{pull_number}/files".freeze

View File

@ -43,7 +43,7 @@ class ObRepositorySync::ApiService < ApplicationService
end
def get_projects_jobs
url = URI("#{domain}/cerobot/projects/#{@project_name}/jobs")
url = URI("#{domain}/cerobot/projects/#{@project_name}/jobs?pageSize=100&pageNum=1")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Get.new(url)
request["Content-Type"] = "application/json"
@ -58,7 +58,7 @@ class ObRepositorySync::ApiService < ApplicationService
"github_branch": "#{params[:github_branch]}",
"gitee_branch": "#{params[:gitee_branch]}",
"gitlink_branch": "#{params[:gitlink_branch]}",
"type": "#{params[:type]}",
"type": "#{params[:job_type]}",
"base": "#{params[:base]}"
}
url = URI("#{domain}/cerobot/projects/#{@project_name}/jobs")
@ -124,11 +124,7 @@ class ObRepositorySync::ApiService < ApplicationService
response = http.request(request)
Rails.logger.info "set_commit job response.read_body======#{response.read_body}"
res = JSON.parse(response.body)
if res["code"].to_s == "200"
res["data"]
else
[]
end
res
end
def pull_requests

View File

@ -14,6 +14,7 @@ json.files diff['Files'].each do |file|
json.is_renamed file['IsRenamed']
json.is_ambiguous file['IsAmbiguous']
json.is_submodule file['IsSubmodule']
json.diff file['Diff']
json.sections file['Sections'] do |section|
json.file_name section['FileName']
json.name section['Name']

View File

@ -10,6 +10,7 @@ json.name file['Name']
json.is_renamed file['IsRenamed']
json.is_ambiguous file['IsAmbiguous']
json.is_submodule file['IsSubmodule']
json.diff file['Diff']
json.sections file['Sections'] do |section|
json.file_name section['FileName']
json.name section['Name']

View File

@ -1,4 +1,4 @@
json.total_count @journals.total_count
json.total_count @journals.count
json.journals @journals.each do |journal|
json.partial! 'api/v1/projects/pulls/journals/simple_detail', journal: journal
end

View File

@ -1,4 +1,5 @@
json.total_count @reviews.total_count
# json.total_count @reviews.total_count
json.total_count @reviews.count
json.reviews @reviews.each do |review|
json.partial! 'api/v1/projects/pulls/reviews/simple_detail', review: review
end

View File

@ -1,3 +1,3 @@
json.(webhook, :id, :url, :http_method, :is_active)
json.(webhook, :id, :url, :http_method, :is_active, :type)
json.last_status webhook.last_status
json.create_time Time.at(webhook.created_unix).strftime("%Y-%m-%d %H:%M:%S")

View File

@ -1,4 +1,5 @@
json.id webhook["id"]
json.type webhook["type"]
json.content_type webhook['config']['content_type']
json.http_method webhook['config']['http_method']
json.url webhook['config']['url']

View File

@ -1,9 +1,31 @@
json.total_count @total_count
json.members @members do |member|
if member.user.present?
json.partial! 'member', user: member.user
json.is_owner @project.owner?(member.user)
json.role member.roles.last.name
json.role_name t("roles.#{member.roles.last.name}")
json.members do
if @current_user_header_team.present?
json.child! do
json.partial! 'member', user: current_user
json.is_owner @project.owner?(current_user)
case @current_user_header_team.authorize
when 'read'
json.role 'Reporter'
json.role_name t("roles.Reporter")
when 'write'
json.role 'Developer'
json.role_name t("roles.Developer")
when 'admin'
json.role 'Manager'
json.role_name t("roles.Manager")
when 'owner'
json.role 'Manager'
json.role_name t("roles.Manager")
end
end
end
@members.each do |member|
json.child! do
json.partial! 'member', user: member.user
json.is_owner @project.owner?(member.user)
json.role member.roles.last.name
json.role_name t("roles.#{member.roles.last.name}")
end
end
end

View File

@ -557,7 +557,11 @@ Rails.application.routes.draw do
get :files
get :commits
resources :reviews, only: [:create]
resources :mark_files, only: [:index, :create]
scope '/diffs' do
resources :mark_files, only: [:index]
put :mark_file_as_unread, to: 'mark_files#mark_file_as_unread', as: 'mark_file_as_unread'
put :mark_file_as_read, to: 'mark_files#mark_file_as_read', as: 'mark_file_as_read'
end
end
collection do
post :check_can_merge
@ -588,6 +592,7 @@ Rails.application.routes.draw do
collection do
delete :delete
get :jobs
get :job_logs
post :create_jobs
delete :delete_job
post :start_job

View File

@ -11384,6 +11384,13 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
<td>array</td>
<td>触发事件</td>
</tr>
<tr>
<td>webhook.type</td>
<td></td>
<td>gitea</td>
<td>string</td>
<td>hook类型gitea slack discord dingtalk telegram msteams feishu matrix jianmu</td>
</tr>
</tbody></table>
<p>触发事件字段说明 </p>
@ -14335,6 +14342,11 @@ http://localhost:3000/api/v1/yystopf/ceshi_commit/pulls/3/versions/33/diff.json
<td>是否为子模块</td>
</tr>
<tr>
<td>diff</td>
<td>string</td>
<td>git diff内容</td>
</tr>
<tr>
<td>sections.file_name</td>
<td>string</td>
<td>文件名称</td>
@ -14545,6 +14557,13 @@ http://localhost:3000/api/v1/yystopf/ceshi_commit/pulls/3/versions/33/diff.json
<td>int</td>
<td>合并请求序号</td>
</tr>
<tr>
<td>status</td>
<td></td>
<td></td>
<td>string</td>
<td>审查类型, common: 评论类型, approved: 已通过, rejected: 已拒绝</td>
</tr>
</tbody></table>
<h3 id='7447e4874e-7'>返回字段说明:</h3>
<table><thead>
@ -15053,6 +15072,20 @@ http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/reviews.json
<td>父评论ID</td>
</tr>
<tr>
<td>path</td>
<td></td>
<td></td>
<td>string</td>
<td>评论文件路径</td>
</tr>
<tr>
<td>is_full</td>
<td></td>
<td></td>
<td>bool</td>
<td>是否展示全部评论(包括回复)</td>
</tr>
<tr>
<td>sort_by</td>
<td></td>
<td>created_on</td>
@ -15277,8 +15310,8 @@ http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/journals.json
</tr>
<tr>
<td>type</td>
<td></td>
<td></td>
<td></td>
<td>comment</td>
<td>string</td>
<td>评论类型 comment: 普通, problem: 需要回应的评论</td>
</tr>
@ -15291,7 +15324,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/journals.json
</tr>
<tr>
<td>review_id</td>
<td></td>
<td></td>
<td></td>
<td>string</td>
<td>审查ID</td>