Merge remote-tracking branch 'origin/standalone_develop' into standalone_develop

This commit is contained in:
“xxq250” 2022-08-04 10:03:34 +08:00
commit 7332e4a58b
13 changed files with 45 additions and 13 deletions

View File

@ -2,7 +2,8 @@ class Api::V1::Projects::Pulls::ReviewsController < Api::V1::Projects::Pulls::Ba
def index def index
@reviews = @pull_request.reviews @reviews = @pull_request.reviews
@reviews = kaminari_paginate(@reviews) @reviews = @reviews.where(status: params[:status]) if params[:status].present?
# @reviews = kaminari_paginate(@reviews)
end end
before_action :require_reviewer, only: [:create] before_action :require_reviewer, only: [:create]
@ -13,7 +14,7 @@ class Api::V1::Projects::Pulls::ReviewsController < Api::V1::Projects::Pulls::Ba
private private
def require_reviewer 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 end
def review_params def review_params

View File

@ -5,11 +5,12 @@ class Api::V1::Projects::WebhooksController < Api::V1::BaseController
def index def index
# @result_object = Api::V1::Projects::Webhooks::ListService.call(@project, current_user&.gitea_token) # @result_object = Api::V1::Projects::Webhooks::ListService.call(@project, current_user&.gitea_token)
@webhooks = @project.webhooks @webhooks = @project.webhooks
@webhooks = @webhooks.where(type: params[:type]) if params[:type].present?
@webhooks = kaminari_paginate(@webhooks) @webhooks = kaminari_paginate(@webhooks)
end end
def create 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 end
def show def show
@ -44,6 +45,10 @@ class Api::V1::Projects::WebhooksController < Api::V1::BaseController
end end
private private
def create_webhook_params
params.require(:webhook).permit(:active, :branch_filter, :http_method, :url, :content_type, :secret, :type, events: [])
end
def webhook_params def webhook_params
params.require(:webhook).permit(:active, :branch_filter, :http_method, :url, :content_type, :secret, events: []) params.require(:webhook).permit(:active, :branch_filter, :http_method, :url, :content_type, :secret, events: [])
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_renamed|bool|是否重命名|
|is_ambiguous|bool|| |is_ambiguous|bool||
|is_submodule|bool|是否为子模块| |is_submodule|bool|是否为子模块|
|diff|string|git diff内容|
|sections.file_name|string|文件名称| |sections.file_name|string|文件名称|
|sections.name|string|| |sections.name|string||
|sections.lines.left_index|int|文件变动之前所在行数| |sections.lines.left_index|int|文件变动之前所在行数|
@ -1028,6 +1029,7 @@ await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/reviews.json')
|owner |是| |string |用户登录名 | |owner |是| |string |用户登录名 |
|repo |是| |string |项目标识identifier | |repo |是| |string |项目标识identifier |
|index |是| | int |合并请求序号| |index |是| | int |合并请求序号|
|status |否| |string |审查类型, common: 评论类型, approved: 已通过, rejected: 已拒绝|
### 返回字段说明: ### 返回字段说明:
参数 | 类型 | 字段说明 参数 | 类型 | 字段说明
@ -1372,7 +1374,7 @@ await octokit.request('POST /api/v1/yystopf/ceshi/pulls/1/journals.json')
|index |是| | integer|合并请求序号| |index |是| | integer|合并请求序号|
|type |是| | string |评论类型 comment: 普通, problem: 需要回应的评论| |type |是| | string |评论类型 comment: 普通, problem: 需要回应的评论|
|note |否| | string |评论内容| |note |否| | string |评论内容|
|review_id || | string |审查ID| |review_id || | string |审查ID|
|line_code |否| | string |行号| |line_code |否| | string |行号|
|commit_id |否| | bool |commitID| |commit_id |否| | bool |commitID|
|path |否| | integer|文件路径| |path |否| | integer|文件路径|

View File

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

View File

@ -49,7 +49,7 @@ class Repository < ApplicationRecord
end end
def url 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 end
# with repository is mirror # with repository is mirror

View File

@ -23,7 +23,7 @@ class Api::V1::Projects::Pulls::Journals::CreateService < ApplicationService
def call def call
raise Error, errors.full_messages.join(", ") unless valid? raise Error, errors.full_messages.join(", ") unless valid?
check_review_is_exists check_review_is_exists if review_id.present?
if type == 'problem' if type == 'problem'
create_problem_journal create_problem_journal
else else

View File

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

View File

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

View File

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

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.reviews @reviews.each do |review|
json.partial! 'api/v1/projects/pulls/reviews/simple_detail', review: review json.partial! 'api/v1/projects/pulls/reviews/simple_detail', review: review
end 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.last_status webhook.last_status
json.create_time Time.at(webhook.created_unix).strftime("%Y-%m-%d %H:%M:%S") 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.id webhook["id"]
json.type webhook["type"]
json.content_type webhook['config']['content_type'] json.content_type webhook['config']['content_type']
json.http_method webhook['config']['http_method'] json.http_method webhook['config']['http_method']
json.url webhook['config']['url'] json.url webhook['config']['url']

View File

@ -11384,6 +11384,13 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
<td>array</td> <td>array</td>
<td>触发事件</td> <td>触发事件</td>
</tr> </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> </tbody></table>
<p>触发事件字段说明 </p> <p>触发事件字段说明 </p>
@ -14335,6 +14342,11 @@ http://localhost:3000/api/v1/yystopf/ceshi_commit/pulls/3/versions/33/diff.json
<td>是否为子模块</td> <td>是否为子模块</td>
</tr> </tr>
<tr> <tr>
<td>diff</td>
<td>string</td>
<td>git diff内容</td>
</tr>
<tr>
<td>sections.file_name</td> <td>sections.file_name</td>
<td>string</td> <td>string</td>
<td>文件名称</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>int</td>
<td>合并请求序号</td> <td>合并请求序号</td>
</tr> </tr>
<tr>
<td>status</td>
<td></td>
<td></td>
<td>string</td>
<td>审查类型, common: 评论类型, approved: 已通过, rejected: 已拒绝</td>
</tr>
</tbody></table> </tbody></table>
<h3 id='7447e4874e-7'>返回字段说明:</h3> <h3 id='7447e4874e-7'>返回字段说明:</h3>
<table><thead> <table><thead>
@ -15291,7 +15310,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/journals.json
</tr> </tr>
<tr> <tr>
<td>review_id</td> <td>review_id</td>
<td></td> <td></td>
<td></td> <td></td>
<td>string</td> <td>string</td>
<td>审查ID</td> <td>审查ID</td>