新增: 合并请求评论查询is_full

This commit is contained in:
yystopf 2022-08-11 15:21:11 +08:00
parent bdddd655bf
commit 13472b2311
4 changed files with 19 additions and 6 deletions

View File

@ -1249,6 +1249,7 @@ await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/journals.json')
|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: 正序|

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

@ -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, :path, :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,7 @@ 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
@ -33,11 +35,13 @@ class Api::V1::Projects::Pulls::Journals::ListService < ApplicationService
private
def journal_query_data
journals = @pull_request.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?
@ -45,7 +49,7 @@ class Api::V1::Projects::Pulls::Journals::ListService < ApplicationService
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

@ -14776,6 +14776,13 @@ http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/reviews.json
<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>