From a35db9fe80711bfa4ddfad9af6c1530ab8314b8e Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 26 Jul 2022 16:45:53 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Areviewers?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_requests_controller.rb | 5 + app/docs/slate/source/includes/_pulls.md | 98 +++++++++++++++++++ .../api/v1/projects/pulls/list_service.rb | 4 +- app/services/issues/list_query_service.rb | 1 + .../pulls/_simple_detail.json.jbuilder | 1 + app/views/pull_requests/_detail.json.jbuilder | 2 +- app/views/pull_requests/edit.json.jbuilder | 1 + app/views/pull_requests/index.json.jbuilder | 3 +- app/views/pull_requests/show.json.jbuilder | 1 + 9 files changed, 113 insertions(+), 3 deletions(-) diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 8bbfdc23..c1643146 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -62,6 +62,8 @@ class PullRequestsController < ApplicationController @pull_request, @gitea_pull_request = PullRequests::CreateService.call(current_user, @owner, @project, params) if @gitea_pull_request[:status] == :success @pull_request.bind_gitea_pull_request!(@gitea_pull_request[:body]["number"], @gitea_pull_request[:body]["id"]) + reviewers = User.where(id: params[:reviewer_ids]) + @pull_request.reviewers = reviewers SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @pull_request&.id) if Site.has_notice_menu? SendTemplateMessageJob.perform_later('ProjectPullRequest', current_user.id, @pull_request&.id) if Site.has_notice_menu? Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}" @@ -107,6 +109,9 @@ class PullRequestsController < ApplicationController end end + reviewers = User.where(id: params[:reviewer_ids]) + @pull_request.reviewers = reviewers + if @issue.update_attributes(@issue_params) if @pull_request.update_attributes(@local_params.compact) gitea_pull = Gitea::PullRequest::UpdateService.call(@owner.login, @repository.identifier, diff --git a/app/docs/slate/source/includes/_pulls.md b/app/docs/slate/source/includes/_pulls.md index dda761ca..ccc6e091 100644 --- a/app/docs/slate/source/includes/_pulls.md +++ b/app/docs/slate/source/includes/_pulls.md @@ -60,6 +60,7 @@ await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/1.json') |last_review.status |string|最后一个审查的状态,common: 一般审查, approved: 通过, rejected: 拒绝通过| |last_review.created_at|string|审查创建的时间| |last_review.reviewer |object|审查创建人| +|reviewers |array|指定审查用户标识数组| |conflict_files |array|有冲突的文件| > 返回的JSON示例: @@ -118,6 +119,9 @@ await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/1.json') "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" } }, + "reviewers": [ + "yystopf" + ], "conflict_files": [] } ``` @@ -586,6 +590,100 @@ await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls.json') } ``` +## 创建一个合并请求 +为仓库创建一个合并请求 + +> 示例: + +```shell +curl -X POST \ +http://localhost:3000/api/yystopf/ceshi/pulls.json +``` + +```javascript +await octokit.request('POST /api/yystopf/ceshi/pulls.json') +``` + +### HTTP 请求 +`POST /api/:owner/:repo/pulls.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|owner |是| | string |用户登录名 | +|repo |是| | string |项目标识identifier | +|title |是| | string |合并请求标题| +|body |否| | string |合并请求内容| +|base |是| | string |目标分支| +|head |是| | string |源分支| +|is_original |是| | bool |是否为fork仓库发来的合并请求| +|fork_project_id |否| | integer|fork仓库ID| +|reviewer_ids |否| | array |审查人员id数组| +|assigned_to_id |否| | integer|指派人员ID| +|fixed_version_id |否| | integer|里程碑ID| +|issue_tag_ids |否| | array |标记ID数组| +|priority_id |否| | integer|优先级ID| +|receivers_login |否| | array |@人员的login| + +> 请求的JSON示例: + +```json +{ + "title": "324", + "assigned_to_id": "2", + "fixed_version_id": "", + "issue_tag_ids": [], + "priority_id": "2", + "body": "312", + "head": "new_branch_1", + "base": "master", + "is_original": false, + "fork_project_id": "", + "files_count": 1, + "commits_count": 1, + "reviewer_ids": [], + "receivers_login": [] +} +``` + +> 返回的JSON示例: + +```json +{ + "status": 0, + "message": "响应成功", + "pull_request_id": 169, + "pull_request_number": 6, + "pull_request_status": 0, + "pull_request_head": "new_branch_1", + "pull_request_base": "master", + "pull_request_staus": "open", + "is_original": false, + "fork_project_id": null, + "fork_project_identifier": null, + "fork_project_user": null, + "reviewers": [ + "yystopf" + ], + "id": 266, + "name": "324", + "pr_time": "1分钟前", + "assign_user_name": "heh", + "assign_user_login": "yystopf", + "author_name": "heh", + "author_login": "yystopf", + "avatar_url": "system/lets/letter_avatars/2/H/188_239_142/120.png", + "priority": "正常", + "version": null, + "journals_count": 0, + "issue_tags": null +} +``` + + + ## 获取合并请求版本列表 获取合并请求版本列表 diff --git a/app/services/api/v1/projects/pulls/list_service.rb b/app/services/api/v1/projects/pulls/list_service.rb index 4a1d6a2f..def8a86b 100644 --- a/app/services/api/v1/projects/pulls/list_service.rb +++ b/app/services/api/v1/projects/pulls/list_service.rb @@ -1,7 +1,7 @@ class Api::V1::Projects::Pulls::ListService < ApplicationService include ActiveModel::Model - attr_reader :project, :keyword, :status, :priority_id, :issue_tag_id, :version_id, :reviewer_id, :sort_by, :sort_direction + attr_reader :project, :keyword, :status, :priority_id, :issue_tag_id, :version_id, :reviewer_id, :assign_user_id, :sort_by, :sort_direction attr_accessor :queried_pull_requests validates :status, inclusion: {in: [0, 1, 2], message: "请输入正确的Status"}, allow_nil: true @@ -16,6 +16,7 @@ class Api::V1::Projects::Pulls::ListService < ApplicationService @issue_tag_id = params[:issue_tag_id] @version_id = params[:version_id] @reviewer_id = params[:reviewer_id] + @assign_user_id = params[:assign_user_id] @sort_by = params[:sort_by] || 'created_at' @sort_direction = params[:sort_direction] || 'desc' end @@ -36,6 +37,7 @@ class Api::V1::Projects::Pulls::ListService < ApplicationService pull_requests = pull_requests.where(issue_tags: {id: issue_tag_id}) if issue_tag_id.present? pull_requests = pull_requests.where(issues: {fixed_version_id: version_id}) if version_id.present? pull_requests = pull_requests.where(users: {id: reviewer_id}) if reviewer_id.present? + pull_requests = pull_requests.where(issues: {assigned_to_id: assign_user_id}) if assign_user_id.present? q = pull_requests.ransack(title_or_body_cont: keyword) scope = q.result.includes(:fork_project, :journals, :reviews, :reviewers, issue: [:journals, :priority, :version, :issue_tags]) diff --git a/app/services/issues/list_query_service.rb b/app/services/issues/list_query_service.rb index 73f0b438..bed8c483 100644 --- a/app/services/issues/list_query_service.rb +++ b/app/services/issues/list_query_service.rb @@ -15,6 +15,7 @@ class Issues::ListQueryService < ApplicationService end_time = params[:due_date] issues = all_issues.issue_index_includes + issues = issues.includes(pull_request: :reviewers) if status_type.to_s == "2" #表示关闭中的 issues = issues.where(status_id: 5) elsif status_type.to_s == "1" diff --git a/app/views/api/v1/projects/pulls/_simple_detail.json.jbuilder b/app/views/api/v1/projects/pulls/_simple_detail.json.jbuilder index d0718085..a4c3c03b 100644 --- a/app/views/api/v1/projects/pulls/_simple_detail.json.jbuilder +++ b/app/views/api/v1/projects/pulls/_simple_detail.json.jbuilder @@ -22,4 +22,5 @@ json.issue do json.issue_tags issue.get_issue_tags end +json.reviewers pull.reviewers.pluck(:login) json.journals_count pull.journals.count \ No newline at end of file diff --git a/app/views/pull_requests/_detail.json.jbuilder b/app/views/pull_requests/_detail.json.jbuilder index 5c934742..814c078e 100644 --- a/app/views/pull_requests/_detail.json.jbuilder +++ b/app/views/pull_requests/_detail.json.jbuilder @@ -9,7 +9,7 @@ json.is_original pr.is_original json.fork_project_id pr&.fork_project_id json.fork_project_identifier pr&.fork_project&.identifier json.fork_project_user pr&.fork_project&.owner.try(:login) - +json.reviewers pr&.reviewers.pluck(:login) json.id issue.id json.name issue.subject diff --git a/app/views/pull_requests/edit.json.jbuilder b/app/views/pull_requests/edit.json.jbuilder index c6f41559..683b1961 100644 --- a/app/views/pull_requests/edit.json.jbuilder +++ b/app/views/pull_requests/edit.json.jbuilder @@ -12,3 +12,4 @@ json.issue_tag_ids @issue&.issue_tags_value&.split(",") json.commits_count @pull_request.commits_count json.files_count @pull_request.files_count json.comments_count @pull_request.comments_count +json.reviewers @pull_request.reviewers.pluck(:login) \ No newline at end of file diff --git a/app/views/pull_requests/index.json.jbuilder b/app/views/pull_requests/index.json.jbuilder index d37901ef..ace52945 100644 --- a/app/views/pull_requests/index.json.jbuilder +++ b/app/views/pull_requests/index.json.jbuilder @@ -24,7 +24,8 @@ json.issues do json.fork_project_identifier pr&.fork_project&.identifier json.fork_project_user pr&.fork_project&.owner.try(:login) json.fork_project_user_name pr&.fork_project&.owner.try(:show_real_name) - + json.reviewers pr.reviewers.pluck(:login) + json.id issue.id json.name issue.subject json.pr_time time_from_now(pr.status == 1 ? pr.updated_at : issue.updated_on) diff --git a/app/views/pull_requests/show.json.jbuilder b/app/views/pull_requests/show.json.jbuilder index 684a60e9..27c393de 100644 --- a/app/views/pull_requests/show.json.jbuilder +++ b/app/views/pull_requests/show.json.jbuilder @@ -30,6 +30,7 @@ json.pull_request do json.create_user @pull_request&.user&.login json.mergeable @gitea_pull["mergeable"] json.state @gitea_pull["state"] + json.reviewers @pull_request.reviewers.pluck(:login) end json.issue do From df5efa0dc64836ca01f1975e26d3de6f05052fc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Tue, 26 Jul 2022 17:08:05 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fixed=20=E9=82=AE=E7=AE=B1=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E6=AD=A3=E5=88=99=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/ob_repository_syncs_controller.rb | 3 ++- app/libs/custom_regexp.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/ob_repository_syncs_controller.rb b/app/controllers/ob_repository_syncs_controller.rb index 013e6fe5..0f1c64b1 100644 --- a/app/controllers/ob_repository_syncs_controller.rb +++ b/app/controllers/ob_repository_syncs_controller.rb @@ -13,7 +13,7 @@ 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) - params.merge({ "gitlink_address": @project.repository.url }) + params = params.merge({ "gitlink_address": @project.repository.url }) res = service.create_projects(params) tip_exception "保存失败: #{res["msg"]}" if res["code"].to_s != "200" sync_id = res["data"]["id"] @@ -23,6 +23,7 @@ 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 diff --git a/app/libs/custom_regexp.rb b/app/libs/custom_regexp.rb index e778c549..889da4df 100644 --- a/app/libs/custom_regexp.rb +++ b/app/libs/custom_regexp.rb @@ -1,6 +1,6 @@ module CustomRegexp PHONE = /1\d{10}/ - EMAIL = /\A[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+\z/ + EMAIL = /\A[a-zA-Z0-9]+([._\-\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+\z/ LOGIN = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]{4,15}\z/ #只含有数字、字母、下划线不能以下划线开头和结尾 LASTNAME = /\A[a-zA-Z0-9\u4e00-\u9fa5]+\z/ NICKNAME = /\A[\u4e00-\u9fa5_a-zA-Z0-9]+\z/ From d6b5dc326af7b35a3f2d9e729dc97d0e4f40b911 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 27 Jul 2022 14:52:49 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=20=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E7=9B=B8=E5=85=B3api=E6=A0=B9=E6=8D=AE=E9=9C=80=E6=B1=82?= =?UTF-8?q?=E9=87=8D=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1/projects/pulls/comments_controller.rb | 2 - .../v1/projects/pulls/journals_controller.rb | 39 ++++ .../v1/projects/pulls/reviews_controller.rb | 2 +- app/controllers/reviews_controller.rb | 2 +- app/models/journal.rb | 13 ++ .../projects/pulls/journals/create_service.rb | 48 +++++ .../projects/pulls/journals/list_service.rb | 45 ++++ .../projects/pulls/journals/update_service.rb | 38 ++++ .../projects/pulls/reviews/create_service.rb | 7 +- .../api/v1/users/projects/list_service.rb | 2 +- .../journals/_simple_detail.json.jbuilder | 21 ++ .../pulls/journals/create.json.jbuilder | 1 + .../pulls/journals/index.json.jbuilder | 4 + .../pulls/journals/update.json.jbuilder | 1 + .../reviews/_simple_detail.json.jbuilder | 8 + config/routes/api.rb | 1 + ...0220726090342_add_line_code_to_journals.rb | 13 ++ public/docs/api.html | 202 +++++++++++++++++- 18 files changed, 432 insertions(+), 17 deletions(-) delete mode 100644 app/controllers/api/v1/projects/pulls/comments_controller.rb create mode 100644 app/controllers/api/v1/projects/pulls/journals_controller.rb create mode 100644 app/services/api/v1/projects/pulls/journals/create_service.rb create mode 100644 app/services/api/v1/projects/pulls/journals/list_service.rb create mode 100644 app/services/api/v1/projects/pulls/journals/update_service.rb create mode 100644 app/views/api/v1/projects/pulls/journals/_simple_detail.json.jbuilder create mode 100644 app/views/api/v1/projects/pulls/journals/create.json.jbuilder create mode 100644 app/views/api/v1/projects/pulls/journals/index.json.jbuilder create mode 100644 app/views/api/v1/projects/pulls/journals/update.json.jbuilder create mode 100644 app/views/api/v1/projects/pulls/reviews/_simple_detail.json.jbuilder create mode 100644 db/migrate/20220726090342_add_line_code_to_journals.rb diff --git a/app/controllers/api/v1/projects/pulls/comments_controller.rb b/app/controllers/api/v1/projects/pulls/comments_controller.rb deleted file mode 100644 index 8622c319..00000000 --- a/app/controllers/api/v1/projects/pulls/comments_controller.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Api::V1::Projects::Pulls::CommentsController < Api::V1::Projects::Pulls::BaseController -end \ No newline at end of file diff --git a/app/controllers/api/v1/projects/pulls/journals_controller.rb b/app/controllers/api/v1/projects/pulls/journals_controller.rb new file mode 100644 index 00000000..76fa30c9 --- /dev/null +++ b/app/controllers/api/v1/projects/pulls/journals_controller.rb @@ -0,0 +1,39 @@ +class Api::V1::Projects::Pulls::JournalsController < Api::V1::Projects::Pulls::BaseController + + def index + @journals = Api::V1::Projects::Pulls::Journals::ListService.call(@project, @pull_request, params, current_user) + @journals = kaminari_paginate(@journals) + end + + def create + @journal = Api::V1::Projects::Pulls::Journals::CreateService.call(@project, @pull_request, create_params, current_user) + end + + before_action :find_journal, only: [:update, :destroy] + + def update + @journal = Api::V1::Projects::Pulls::Journals::UpdateService.call(@project, @pull_request, @journal, update_params, current_user) + end + + def destroy + if @journal.destroy + render_ok + else + render_error("删除评论失败!") + end + end + + private + def create_params + params.permit(:parent_id, :line_code, :note, :commit_id, :path, :type, :review_id, :diff => {}) + end + + def update_params + params.permit(:note, :commit_id, :state) + end + + def find_journal + @journal = Journal.find_by_id(params[:id]) + end + +end \ No newline at end of file diff --git a/app/controllers/api/v1/projects/pulls/reviews_controller.rb b/app/controllers/api/v1/projects/pulls/reviews_controller.rb index 523137a8..039a6c4d 100644 --- a/app/controllers/api/v1/projects/pulls/reviews_controller.rb +++ b/app/controllers/api/v1/projects/pulls/reviews_controller.rb @@ -8,7 +8,7 @@ class Api::V1::Projects::Pulls::ReviewsController < Api::V1::Projects::Pulls::Ba before_action :require_reviewer, only: [:create] def create - @journal, @review = Api::V1::Projects::Pulls::Reviews::CreateService.call(@project, @pull_request, review_params, current_user) + @review = Api::V1::Projects::Pulls::Reviews::CreateService.call(@project, @pull_request, review_params, current_user) end private diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb index e1201690..b5fedfae 100644 --- a/app/controllers/reviews_controller.rb +++ b/app/controllers/reviews_controller.rb @@ -5,7 +5,7 @@ class ReviewsController < ApplicationController def create return render_forbidden('您不是审查人员,无法进行审查!') if current_user&.id != @pull_request.issue.assigned_to_id - @journal, @review = Api::V1::Projects::Pulls::Reviews::CreateService.call(@project, @pull_request, review_params, current_user) + @review = Api::V1::Projects::Pulls::Reviews::CreateService.call(@project, @pull_request, review_params, current_user) end private diff --git a/app/models/journal.rb b/app/models/journal.rb index 19fdce1c..48721bfd 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -13,6 +13,15 @@ # comments_count :integer default("0") # reply_id :integer # review_id :integer +# commit_id :string(255) +# diff :text(4294967295) +# line_code :string(255) +# path :string(255) +# state :integer default("0") +# resolve_at :datetime +# resolveer_id :integer +# need_respond :boolean default("0") +# updated_on :datetime # # Indexes # @@ -24,9 +33,12 @@ # class Journal < ApplicationRecord + serialize :diff, JSON belongs_to :user belongs_to :issue, foreign_key: :journalized_id, :touch => true, optional: true belongs_to :journalized, polymorphic: true + belongs_to :review, optional: true + 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 @@ -34,6 +46,7 @@ class Journal < ApplicationRecord scope :parent_journals, ->{where(parent_id: nil)} scope :children_journals, lambda{|journal_id| where(parent_id: journal_id)} + enum state: {opened: 0, resolved: 1, disabled: 2} def is_journal_detail? self.notes.blank? && self.journal_details.present? diff --git a/app/services/api/v1/projects/pulls/journals/create_service.rb b/app/services/api/v1/projects/pulls/journals/create_service.rb new file mode 100644 index 00000000..45b5ec03 --- /dev/null +++ b/app/services/api/v1/projects/pulls/journals/create_service.rb @@ -0,0 +1,48 @@ +class Api::V1::Projects::Pulls::Journals::CreateService < ApplicationService + include ActiveModel::Model + + attr_reader :project, :pull_request, :issue, :parent_id, :line_code, :note, :commit_id, :path, :type, :diff, :review_id, :user + attr_accessor :journal + + validates :type, inclusion: {in: %w(comment problem), message: '请输入正确的Type'} + + def initialize(project, pull_request, params, user) + @project = project + @pull_request = pull_request + @issue = pull_request&.issue + @parent_id = params[:parent_id] + @line_code = params[:line_code] + @note = params[:note] + @commit_id = params[:commit_id] + @path = params[:path] + @type = params[:type] + @diff = params[:diff] + @review_id = params[:review_id] + @user = user + end + + def call + raise Error, errors.full_messages.join(", ") unless valid? + check_review_is_exists + if type == 'problem' + create_problem_journal + else + create_comment_journal + end + + journal + end + + private + def create_comment_journal + @journal = pull_request.journals.create!(user_id: user&.id, notes: note, parent_id: parent_id, review_id: review_id, commit_id: commit_id, diff: diff, line_code: line_code, path: path) + end + + def check_review_is_exists + raise Error, '合并请求审查不存在!' unless @pull_request.reviews.exists?(review_id) + end + + def create_problem_journal + @journal = pull_request.journals.create!(user_id: user&.id, notes: note, parent_id: parent_id, review_id: review_id, commit_id: commit_id, diff: diff, line_code: line_code, path: path, need_respond: true) + end +end \ No newline at end of file diff --git a/app/services/api/v1/projects/pulls/journals/list_service.rb b/app/services/api/v1/projects/pulls/journals/list_service.rb new file mode 100644 index 00000000..dd69ead0 --- /dev/null +++ b/app/services/api/v1/projects/pulls/journals/list_service.rb @@ -0,0 +1,45 @@ +class Api::V1::Projects::Pulls::Journals::ListService < ApplicationService + include ActiveModel::Model + + attr_reader :project, :pull_request, :keyword, :review_id, :need_respond, :state, :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 :state, inclusion: {in: %w(opened resolved disabled)}, allow_nil: true + + def initialize(project, pull_request, params, user) + @project = project + @pull_request = pull_request + @keyword = params[:keyword] + @review_id = params[:review_id] + @need_respond = ActiveModel::Type::Boolean.new.cast(params[:need_respond]) + @state = params[:state] + @sort_by = params[:sort_by] || 'created_on' + @sort_direction = params[:sort_direction] || 'asc' + @user = user + end + + def call + raise Error, errors.full_messages.join(",") unless valid? + journal_query_data + + queried_journals + end + + private + def journal_query_data + journals = @pull_request.journals.parent_journals + + 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? + + q = journals.ransack(notes_cont: keyword) + scope = q.result.includes(:review) + scope = scope.order("journals.#{sort_by} #{sort_direction}") + + @queried_journals = scope + end +end \ No newline at end of file diff --git a/app/services/api/v1/projects/pulls/journals/update_service.rb b/app/services/api/v1/projects/pulls/journals/update_service.rb new file mode 100644 index 00000000..fec4c7ff --- /dev/null +++ b/app/services/api/v1/projects/pulls/journals/update_service.rb @@ -0,0 +1,38 @@ +class Api::V1::Projects::Pulls::Journals::UpdateService < ApplicationService + include ActiveModel::Model + + attr_reader :project, :pull_request, :journal, :note, :commit_id, :state, :user + attr_accessor :updated_journal + + validates :state, inclusion: {in: %w(opened resolved disabled)} + + def initialize(project, pull_request, journal, params, user) + @project = project + @pull_request = pull_request + @journal = journal + @note = params[:note] + @commit_id = params[:commit_id] + @state = params[:state] + @user = user + end + + def call + raise Error, errors.full_messages.join(", ") unless valid? + + update_journal + + updated_journal + end + + private + def update_journal + journal.attributes = {notes: note, commit_id: commit_id, state: state} + if state == 'resolved' + journal.resolve_at = Time.now + journal.resolveer_id = user.id + end + return Error, '保存评论失败!' unless journal.save + + @updated_journal = journal.reload + end +end \ No newline at end of file diff --git a/app/services/api/v1/projects/pulls/reviews/create_service.rb b/app/services/api/v1/projects/pulls/reviews/create_service.rb index bef94487..1c45d9cf 100644 --- a/app/services/api/v1/projects/pulls/reviews/create_service.rb +++ b/app/services/api/v1/projects/pulls/reviews/create_service.rb @@ -20,10 +20,10 @@ class Api::V1::Projects::Pulls::Reviews::CreateService < ApplicationService raise Error, errors.full_messages.join(", ") unless valid? ActiveRecord::Base.transaction do create_review - create_journal + # create_journal end - return @journal, @review + @review # rescue # raise Error, '服务器错误,请联系系统管理员!' end @@ -33,8 +33,5 @@ class Api::V1::Projects::Pulls::Reviews::CreateService < ApplicationService @review = pull_request.reviews.create!(status: status, content: content, commit_id: commit_id, reviewer_id: @current_user.id) end - def create_journal - @journal = pull_request.journals.create!(notes: content, user_id: @current_user.id, review_id: @review.id) - end end \ No newline at end of file diff --git a/app/services/api/v1/users/projects/list_service.rb b/app/services/api/v1/users/projects/list_service.rb index 9a095c60..91e25a93 100644 --- a/app/services/api/v1/users/projects/list_service.rb +++ b/app/services/api/v1/users/projects/list_service.rb @@ -13,7 +13,7 @@ class Api::V1::Users::Projects::ListService < ApplicationService def initialize(observe_user, params, current_user=nil) @observe_user = observe_user @category = params[:category] || 'all' - @is_public = params[:is_public] + @is_public = ActiveModel::Type::Boolean.new.cast(params[:is_public]) @project_type = params[:project_type] @sort_by = params[:sort_by] || 'updated_on' @sort_direction = params[:sort_direction] || 'desc' diff --git a/app/views/api/v1/projects/pulls/journals/_simple_detail.json.jbuilder b/app/views/api/v1/projects/pulls/journals/_simple_detail.json.jbuilder new file mode 100644 index 00000000..547db46e --- /dev/null +++ b/app/views/api/v1/projects/pulls/journals/_simple_detail.json.jbuilder @@ -0,0 +1,21 @@ +json.(journal, :id, :notes, :commit_id, :line_code, :path, :diff, :need_respond, :state) +json.user do + json.partial! 'api/v1/users/simple_user', user: journal.user +end +json.review do + if journal.review.present? + json.partial! 'api/v1/projects/pulls/reviews/simple_detail', review: journal.review + else + json.nil! + end +end +json.resolveer do + if journal.resolveer.present? + json.partial! 'api/v1/users/simple_user', user: journal.resolveer + else + json.nil! + end +end +json.resolve_at format_time(journal.resolve_at) +json.created_at format_time(journal.created_on) +json.updated_at format_time(journal.updated_on) \ No newline at end of file diff --git a/app/views/api/v1/projects/pulls/journals/create.json.jbuilder b/app/views/api/v1/projects/pulls/journals/create.json.jbuilder new file mode 100644 index 00000000..32bedbf8 --- /dev/null +++ b/app/views/api/v1/projects/pulls/journals/create.json.jbuilder @@ -0,0 +1 @@ +json.partial! 'api/v1/projects/pulls/journals/simple_detail', journal: @journal \ No newline at end of file diff --git a/app/views/api/v1/projects/pulls/journals/index.json.jbuilder b/app/views/api/v1/projects/pulls/journals/index.json.jbuilder new file mode 100644 index 00000000..e71eb5f7 --- /dev/null +++ b/app/views/api/v1/projects/pulls/journals/index.json.jbuilder @@ -0,0 +1,4 @@ +json.total_count @journals.total_count +json.journals @journals.each do |journal| + json.partial! 'api/v1/projects/pulls/journals/simple_detail', journal: journal +end \ No newline at end of file diff --git a/app/views/api/v1/projects/pulls/journals/update.json.jbuilder b/app/views/api/v1/projects/pulls/journals/update.json.jbuilder new file mode 100644 index 00000000..32bedbf8 --- /dev/null +++ b/app/views/api/v1/projects/pulls/journals/update.json.jbuilder @@ -0,0 +1 @@ +json.partial! 'api/v1/projects/pulls/journals/simple_detail', journal: @journal \ No newline at end of file diff --git a/app/views/api/v1/projects/pulls/reviews/_simple_detail.json.jbuilder b/app/views/api/v1/projects/pulls/reviews/_simple_detail.json.jbuilder new file mode 100644 index 00000000..1ded19d6 --- /dev/null +++ b/app/views/api/v1/projects/pulls/reviews/_simple_detail.json.jbuilder @@ -0,0 +1,8 @@ +json.reviewer do + json.partial! "api/v1/users/simple_user", user: review.reviewer +end +json.pull_request do + json.partial! "api/v1/projects/pulls/simple_detail", pull: review.pull_request +end +json.(review, :id, :commit_id, :content, :status) +json.created_at format_time(review.created_at) \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 0dfe6112..d5f82ff7 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -25,6 +25,7 @@ defaults format: :json do get :diff end end + resources :journals, except: [:show, :edit] resources :reviews, only: [:index, :create] end diff --git a/db/migrate/20220726090342_add_line_code_to_journals.rb b/db/migrate/20220726090342_add_line_code_to_journals.rb new file mode 100644 index 00000000..9eb2e45e --- /dev/null +++ b/db/migrate/20220726090342_add_line_code_to_journals.rb @@ -0,0 +1,13 @@ +class AddLineCodeToJournals < ActiveRecord::Migration[5.2] + def change + add_column :journals, :commit_id, :string + add_column :journals, :diff, :text, :limit => 4294967295 + add_column :journals, :line_code, :string + add_column :journals, :path, :string + add_column :journals, :state, :integer, default: 0 + add_column :journals, :resolve_at, :datetime + add_column :journals, :resolveer_id, :integer, index: true + add_column :journals, :need_respond, :bool, default: false + add_column :journals, :updated_on, :datetime, index: true + end +end diff --git a/public/docs/api.html b/public/docs/api.html index ce1fea11..0a684743 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -609,6 +609,9 @@
  • 获取合并请求列表
  • +
  • + 创建一个合并请求 +
  • 获取合并请求版本列表
  • @@ -12229,6 +12232,11 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/tests.json 审查创建人 +reviewers +array +指定审查用户标识数组 + + conflict_files array 有冲突的文件 @@ -12291,6 +12299,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/tests.json "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" } }, + "reviewers": [ + "yystopf" + ], "conflict_files": [] }

    获取合并请求文件列表

    @@ -13271,7 +13282,184 @@ http://localhost:3000/api/Jason/test-txt/compare/master...Jason/test-txt:develop } ] } -

    获取合并请求版本列表

    +

    创建一个合并请求

    +

    为仓库创建一个合并请求

    + +
    +

    示例:

    +
    +
    curl -X POST \
    +http://localhost:3000/api/yystopf/ceshi/pulls.json
    +
    await octokit.request('POST /api/yystopf/ceshi/pulls.json')
    +

    HTTP 请求

    +

    POST /api/:owner/:repo/pulls.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    titlestring合并请求标题
    bodystring合并请求内容
    basestring目标分支
    headstring源分支
    is_originalbool是否为fork仓库发来的合并请求
    fork_project_idintegerfork仓库ID
    reviewer_idsarray审查人员id数组
    assigned_to_idinteger指派人员ID
    fixed_version_idinteger里程碑ID
    issue_tag_idsarray标记ID数组
    priority_idinteger优先级ID
    receivers_loginarray@人员的login
    + +
    +

    请求的JSON示例:

    +
    +
    {
    +    "title": "324",
    +    "assigned_to_id": "2",
    +    "fixed_version_id": "",
    +    "issue_tag_ids": [],
    +    "priority_id": "2",
    +    "body": "312",
    +    "head": "new_branch_1",
    +    "base": "master",
    +    "is_original": false,
    +    "fork_project_id": "",
    +    "files_count": 1,
    +    "commits_count": 1,
    +    "reviewer_ids": [],
    +    "receivers_login": []
    +}
    +
    +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "响应成功",
    +    "pull_request_id": 169,
    +    "pull_request_number": 6,
    +    "pull_request_status": 0,
    +    "pull_request_head": "new_branch_1",
    +    "pull_request_base": "master",
    +    "pull_request_staus": "open",
    +    "is_original": false,
    +    "fork_project_id": null,
    +    "fork_project_identifier": null,
    +    "fork_project_user": null,
    +    "reviewers": [
    +        "yystopf"
    +    ],
    +    "id": 266,
    +    "name": "324",
    +    "pr_time": "1分钟前",
    +    "assign_user_name": "heh",
    +    "assign_user_login": "yystopf",
    +    "author_name": "heh",
    +    "author_login": "yystopf",
    +    "avatar_url": "system/lets/letter_avatars/2/H/188_239_142/120.png",
    +    "priority": "正常",
    +    "version": null,
    +    "journals_count": 0,
    +    "issue_tags": null
    +}
    +
    + +

    获取合并请求版本列表

    获取合并请求版本列表

    @@ -13279,9 +13467,9 @@ http://localhost:3000/api/Jason/test-txt/compare/master...Jason/test-txt:develop
    curl -X GET http://localhost:3000/api/v1/yystopf/ceshi_commit/pulls/3/versions.json
     
    await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/versions.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/pulls/:index/versions.json

    -

    请求参数:

    +

    请求参数:

    @@ -13408,9 +13596,9 @@ http://localhost:3000/api/Jason/test-txt/compare/master...Jason/test-txt:develop -d"filepath=ceshi_dir_1/new_file_1"\ http://localhost:3000/api/v1/yystopf/ceshi_commit/pulls/3/versions/33/diff.json
    await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/versions/33/diff.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/pulls/:index/versions/:version_id/diff.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -13944,9 +14132,9 @@ http://localhost:3000/api/v1/yystopf/ceshi_commit/pulls/3/versions/33/diff.json
    curl -X POST \
     http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/reviews.json
     
    await octokit.request('POST /api/v1/yystopf/ceshi/pulls/1/reviews.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST /api/v1/:owner/:repo/pulls/:index/reviews.json

    -

    请求参数:

    +

    请求参数:

    参数
    From a2549f7ff1181edd9aa523a17816826c4b6fcdac Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 27 Jul 2022 16:07:15 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=20=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E5=8F=8A=E5=AE=A1=E6=9F=A5=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1/projects/pulls/journals_controller.rb | 3 +- app/docs/slate/source/includes/_pulls.md | 598 +++++++++- app/models/journal.rb | 1 + .../projects/pulls/journals/list_service.rb | 12 +- .../journals/_simple_detail.json.jbuilder | 2 +- .../pulls/reviews/index.json.jbuilder | 4 + public/docs/api.html | 1049 ++++++++++++++++- 7 files changed, 1657 insertions(+), 12 deletions(-) create mode 100644 app/views/api/v1/projects/pulls/reviews/index.json.jbuilder diff --git a/app/controllers/api/v1/projects/pulls/journals_controller.rb b/app/controllers/api/v1/projects/pulls/journals_controller.rb index 76fa30c9..d3247497 100644 --- a/app/controllers/api/v1/projects/pulls/journals_controller.rb +++ b/app/controllers/api/v1/projects/pulls/journals_controller.rb @@ -33,7 +33,8 @@ class Api::V1::Projects::Pulls::JournalsController < Api::V1::Projects::Pulls::B end def find_journal - @journal = Journal.find_by_id(params[:id]) + @journal = @pull_request.journals.find_by_id(params[:id]) + return render_not_found unless @journal.present? end end \ No newline at end of file diff --git a/app/docs/slate/source/includes/_pulls.md b/app/docs/slate/source/includes/_pulls.md index ccc6e091..adc6e3cc 100644 --- a/app/docs/slate/source/includes/_pulls.md +++ b/app/docs/slate/source/includes/_pulls.md @@ -501,10 +501,17 @@ await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls.json') ### 请求参数: 参数 | 必选 | 默认 | 类型 | 字段说明 --------- | ------- | ------- | -------- | ---------- -|owner |是| |string |用户登录名 | -|repo |是| |string |项目标识identifier | - - +|owner |是| |string |用户登录名 | +|repo |是| |string |项目标识identifier | +|keyword |否| |string |搜索关键词| +|status |否| | int | 合并请求类型 0: 开启的, 1: 合并的 2: 关闭的,不传则为全部的 | +|priority_id |否| | int | 优先级ID | +|issue_tag_id |否| |int|标记ID| +|version_id |否| |int|里程碑ID| +|reviewer_id |否| |int| 审查人员ID| +|assign_user_id |否| |int| 指派人员ID| +|sort_by |否| created_at |string| 排序字段,created_at: 创建时间, updated_at: 更新时间| +|sort_direction |否| desc |string| 排序类型 desc: 倒序 asc: 正序| ### 返回字段说明: 参数 | 类型 | 字段说明 --------- | ----------- | ----------- @@ -999,6 +1006,108 @@ await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/versions/33/diff } ``` +## 获取合并请求审查列表 +获取合并请求版本审查列表 + +> 示例: + +```shell +curl -X GET http://localhost:3000/api/v1/yystopf/ceshi_commit/pulls/3/reviews.json +``` + +```javascript +await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/reviews.json') +``` + +### HTTP 请求 +`GET /api/v1/:owner/:repo/pulls/:index/reviews.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|owner |是| |string |用户登录名 | +|repo |是| |string |项目标识identifier | +|index |是| | int |合并请求序号| + +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|total_count |int |审查总数| +|reviews.reviewer |object |审查者 | +|reviews.pull_request.id |integer|合并请求ID| +|reviews.pull_request.title |string|合并请求标题| +|reviews.pull_request.body |string|合并请求内容| +|reviews.pull_request.head |string|合并请求源分支| +|reviews.pull_request.base |string|合并请求目标分支| +|reviews.pull_request.is_original |string|合并请求是否从fork仓库所来| +|reviews.pull_request.fork_project.id |int|fork仓库的id| +|reviews.pull_request.fork_project.identifier|string|fork仓库的标识| +|reviews.pull_request.fork_project.login |string|fork仓库拥有者的标识| +|reviews.pull_request.index |string|合并请求的序号| +|reviews.pull_request.status |string|合并请求的状态,open: 打开的, merged: 合并的, closed: 关闭的| +|reviews.pull_request.issue.id |integer|合并请求下疑修的ID| +|reviews.pull_request.issue.author |object|合并请求以及疑修的创建着| +|reviews.pull_request.issue.priority |string|疑修的优先级| +|reviews.pull_request.issue.version |string|疑修的里程碑| +|reviews.pull_request.issue.journals_count|integer|普通评论数量| +|reviews.pull_request.issue.issue_tags |array|所属标记| +|reviews.pull_request.journals_count |integer|审查评论数量| +|reviews.id |integer|审查ID| +|reviews.commit_id |string|审查的commit ID| +|reviews.content |string|审查的内容| +|reviews.status |string|审查类型,common: 普通, approved: 通过,rejected: 拒绝通过| +|reviews.created_at |string|审查创建时间| + +> 返回的JSON示例: + +```json +{ + "total_count": 1, + "reviews": [ + { + "reviewer": { + "id": 2, + "type": "User", + "name": "heh", + "login": "yystopf", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "pull_request": { + "id": 163, + "title": "新合并请求1", + "body": null, + "head": "master_1", + "base": "master", + "is_original": false, + "index": 1, + "status": "closed", + "issue": { + "id": 260, + "author": { + "id": 2, + "type": "User", + "name": "heh", + "login": "yystopf", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "priority": null, + "version": null, + "journals_count": 0, + "issue_tags": null + }, + "reviewers": [], + "journals_count": 8 + }, + "id": 5, + "commit_id": null, + "content": "新建一个审查", + "status": "common", + "created_at": "2022-07-25 17:08" + } + ] +} +``` + ## 为合并请求创建一个审查 合并请求创建一个审查 @@ -1108,3 +1217,484 @@ await octokit.request('POST /api/v1/yystopf/ceshi/pulls/1/reviews.json') + + +## 获取合并请求评论列表 +获取合并请求版本评论列表 + +> 示例: + +```shell +curl -X GET http://localhost:3000/api/v1/yystopf/ceshi_commit/pulls/3/journals.json +``` + +```javascript +await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/journals.json') +``` + +### HTTP 请求 +`GET /api/v1/:owner/:repo/pulls/:index/journals.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|owner |是| |string |用户登录名 | +|repo |是| |string |项目标识identifier | +|index |是| | int |合并请求序号| +|keyword |否| |string |搜索关键词| +|review_id |否| |integer|审查ID| +|need_respond |否| |bool |是否需要回应| +|state |否| |string |状态, opened: 开启的, resolved: 已解决的, disabled: 无效的| +|parent_id |否| |integer|父评论ID| +|sort_by |否|created_on|string |排序字段 created_on: 创建时间, updated_on: 更新时间| +|sort_direction |否|asc |string |排序类型 desc: 倒序, asc: 正序| + +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|total_count |int |评论总数| +|journals.id |int |评论ID| +|journals.notes |string |评论内容| +|journals.commit_id |string |CommitID| +|journals.line_code |string |评论行数| +|journals.path |string |评论文件路径| +|journals.diff |object |评论文件diff内容| +|journals.need_respond |bool |评论是否要回应| +|journals.state |string |评论状态,opened: 开启的, resolved: 已解决的, disabled: 无效的 | +|journals.parent_id |int |父评论ID| +|journals.user |object |评论创建者| +|journals.review |object |评论所属评审| +|journals.resolveer |object |评论解决者| +|journals.resolve_at |int |评论解决时间| +|journals.created_at |int |评论创建时间| +|journals.updated_at |int |评论更新时间| + +> 返回的JSON示例: + +```json +{ + "total_count": 1, + "journals": [ + { + "id": 200, + "note": "测试评论修改", + "commit_id": null, + "line_code": "70eede447ccc01c1902260fd377af5d90be28e0d_0_29", + "path": "Gemfile.lock", + "diff": {}, + "need_respond": true, + "state": "resolved", + "parent_id": nil, + "user": { + "id": 2, + "type": "User", + "name": "heh", + "login": "yystopf", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "review": { + "reviewer": { + "id": 2, + "type": "User", + "name": "heh", + "login": "yystopf", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "pull_request": { + "id": 163, + "title": "新合并请求1", + "body": null, + "head": "master_1", + "base": "master", + "is_original": false, + "index": 1, + "status": "closed", + "issue": { + "id": 260, + "author": { + "id": 2, + "type": "User", + "name": "heh", + "login": "yystopf", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "priority": null, + "version": null, + "journals_count": 0, + "issue_tags": null + }, + "reviewers": [], + "journals_count": 9 + }, + "id": 10, + "commit_id": "1", + "content": "新建一个审查", + "status": "common", + "created_at": "2022-07-26 11:45" + }, + "resolveer": { + "id": 2, + "type": "User", + "name": "heh", + "login": "yystopf", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "resolve_at": "2022-07-27 14:50", + "created_at": "2022-07-27 14:31", + "updated_at": "2022-07-27 14:50" + } + ] +} +``` + +## 创建一个合并请求评论 +为仓库创建一个合并请求的评论 + +> 示例: + +```shell +curl -X POST \ +http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/journals.json +``` + +```javascript +await octokit.request('POST /api/v1/yystopf/ceshi/pulls/1/journals.json') +``` + +### HTTP 请求 +`POST /api/v1/:owner/:repo/pulls/:index/journals.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|owner |是| | string |用户登录名 | +|repo |是| | string |项目标识identifier | +|index |是| | integer|合并请求序号| +|type |是| | string |评论类型 comment: 普通, problem: 需要回应的评论| +|note |否| | string |评论内容| +|review_id |是| | string |审查ID| +|line_code |否| | string |行号| +|commit_id |否| | bool |commitID| +|path |否| | integer|文件路径| +|parent_id |否| | integer|父评论ID| +|diff |否| | array |文件diff内容| + +> 请求的JSON示例: + +```json +{ + "type": "problem", + "note": "测试评论", + "review_id": "10", + "line_code": "70eede447ccc01c1902260fd377af5d90be28e0d_0_29", + "commit_id": "70eede447ccc01c1902260fd377af5d90be28e0d", + "path": "Gemfile.lock", + "diff": { + "name": "README.md", + "oldname": "README.md", + "addition": 1, + "deletion": 2, + "type": 2, + "is_created": false, + "is_deleted": false, + "is_bin": false, + "is_lfs_file": false, + "is_renamed": false, + "is_ambiguous": false, + "is_submodule": false, + "sections": [ + { + "file_name": "README.md", + "name": "", + "lines": [ + { + "left_index": 0, + "right_index": 0, + "match": 0, + "type": 4, + "content": "@@ -1,2 +1 @@", + "section_path": "README.md", + "section_last_left_index": 0, + "section_last_right_index": 0, + "section_left_index": 1, + "section_right_index": 1, + "section_left_hunk_size": 2, + "section_right_hunk_size": 0 + }, + { + "left_index": 1, + "right_index": 0, + "match": 3, + "type": 3, + "content": "-# ceshi_commit" + }, + { + "left_index": 2, + "right_index": 0, + "match": -1, + "type": 3, + "content": "-" + }, + { + "left_index": 0, + "right_index": 1, + "match": 1, + "type": 2, + "content": "+adsa" + } + ] + }, + { + "file_name": "README.md", + "name": "", + "lines": [ + { + "left_index": 0, + "right_index": 0, + "match": 0, + "type": 4, + "content": " ", + "section_path": "README.md", + "section_last_left_index": 0, + "section_last_right_index": 1, + "section_left_index": 3, + "section_right_index": 2, + "section_left_hunk_size": 0, + "section_right_hunk_size": 0 + } + ] + } + ], + "is_incomplete": false, + "is_incomplete_line_too_long": false, + "is_protected": false + } +} +``` + +> 返回的JSON示例: + +```json +{ + "id": 200, + "note": "测试评论修改", + "commit_id": null, + "line_code": "70eede447ccc01c1902260fd377af5d90be28e0d_0_29", + "path": "Gemfile.lock", + "diff": {}, + "need_respond": true, + "state": "resolved", + "user": { + "id": 2, + "type": "User", + "name": "heh", + "login": "yystopf", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "review": { + "reviewer": { + "id": 2, + "type": "User", + "name": "heh", + "login": "yystopf", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "pull_request": { + "id": 163, + "title": "新合并请求1", + "body": null, + "head": "master_1", + "base": "master", + "is_original": false, + "index": 1, + "status": "closed", + "issue": { + "id": 260, + "author": { + "id": 2, + "type": "User", + "name": "heh", + "login": "yystopf", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "priority": null, + "version": null, + "journals_count": 0, + "issue_tags": null + }, + "reviewers": [], + "journals_count": 9 + }, + "id": 10, + "commit_id": "1", + "content": "新建一个审查", + "status": "common", + "created_at": "2022-07-26 11:45" + }, + "resolveer": { + "id": 2, + "type": "User", + "name": "heh", + "login": "yystopf", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "resolve_at": "2022-07-27 14:50", + "created_at": "2022-07-27 14:31", + "updated_at": "2022-07-27 14:50" +} +``` + + +## 修改一个合并请求评论 +修改一个仓库合并请求的评论 + +> 示例: + +```shell +curl -X PATCH \ +http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/journals/200.json +``` + +```javascript +await octokit.request('PATCH /api/v1/yystopf/ceshi/pulls/1/journals/200.json') +``` + +### HTTP 请求 +`PATCH /api/v1/:owner/:repo/pulls/:index/journals/:id.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|owner |是| | string |用户登录名 | +|repo |是| | string |项目标识identifier | +|index |是| | integer|合并请求序号| +|id |是| | integer|评论ID| +|note |是| | string |评论内容| +|commit_id |是| | string |commitID| +|state |是| | string |评论状态, opened: 开启的, resolved: 已解决的, disabled: 无效的| + +> 请求的JSON示例: + +```json +{ + "note": "测试评论", + "commit_id": "70eede447ccc01c1902260fd377af5d90be28e0d", + "state": "resolved" +} +``` + +> 返回的JSON示例: + +```json +{ + "id": 200, + "note": "测试评论修改", + "commit_id": null, + "line_code": "70eede447ccc01c1902260fd377af5d90be28e0d_0_29", + "path": "Gemfile.lock", + "diff": {}, + "need_respond": true, + "state": "resolved", + "user": { + "id": 2, + "type": "User", + "name": "heh", + "login": "yystopf", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "review": { + "reviewer": { + "id": 2, + "type": "User", + "name": "heh", + "login": "yystopf", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "pull_request": { + "id": 163, + "title": "新合并请求1", + "body": null, + "head": "master_1", + "base": "master", + "is_original": false, + "index": 1, + "status": "closed", + "issue": { + "id": 260, + "author": { + "id": 2, + "type": "User", + "name": "heh", + "login": "yystopf", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "priority": null, + "version": null, + "journals_count": 0, + "issue_tags": null + }, + "reviewers": [], + "journals_count": 9 + }, + "id": 10, + "commit_id": "1", + "content": "新建一个审查", + "status": "common", + "created_at": "2022-07-26 11:45" + }, + "resolveer": { + "id": 2, + "type": "User", + "name": "heh", + "login": "yystopf", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "resolve_at": "2022-07-27 14:50", + "created_at": "2022-07-27 14:31", + "updated_at": "2022-07-27 14:50" +} +``` + + +## 删除合并请求的一个评论 +删除合并请求的一个评论 + +> 示例: + +```shell +curl -X DELETE \ +http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/journals/200.json +``` + +```javascript +await octokit.request('DELETE /api/v1/yystopf/ceshi/pulls/1/journals/200.json') +``` + +### HTTP 请求 +`DELETE /api/v1/:owner/:repo/pulls/:index/journals/:id.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|owner |是| | string |用户登录名 | +|repo |是| | string |项目标识identifier | +|index |是| | integer|合并请求序号| +|id |是| | integer|评论ID | + +### 返回字段说明: + +> 返回的JSON示例: + +```json +{ + "status": 0, + "message": "success" +} +``` + diff --git a/app/models/journal.rb b/app/models/journal.rb index 48721bfd..e0dbf36d 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -34,6 +34,7 @@ class Journal < ApplicationRecord serialize :diff, JSON + alias_attribute :note, :notes belongs_to :user belongs_to :issue, foreign_key: :journalized_id, :touch => true, optional: true belongs_to :journalized, polymorphic: true diff --git a/app/services/api/v1/projects/pulls/journals/list_service.rb b/app/services/api/v1/projects/pulls/journals/list_service.rb index dd69ead0..30b650f0 100644 --- a/app/services/api/v1/projects/pulls/journals/list_service.rb +++ b/app/services/api/v1/projects/pulls/journals/list_service.rb @@ -1,7 +1,7 @@ class Api::V1::Projects::Pulls::Journals::ListService < ApplicationService include ActiveModel::Model - attr_reader :project, :pull_request, :keyword, :review_id, :need_respond, :state, :sort_by, :sort_direction, :user + attr_reader :project, :pull_request, :keyword, :review_id, :need_respond, :state, :parent_id, :sort_by, :sort_direction, :user attr_accessor :queried_journals validates :sort_by, inclusion: {in: Journal.column_names, message: '请输入正确的SortBy'} @@ -16,6 +16,7 @@ class Api::V1::Projects::Pulls::Journals::ListService < ApplicationService @review_id = params[:review_id] @need_respond = ActiveModel::Type::Boolean.new.cast(params[:need_respond]) @state = params[:state] + @parent_id = params[:parent_id] @sort_by = params[:sort_by] || 'created_on' @sort_direction = params[:sort_direction] || 'asc' @user = user @@ -30,14 +31,19 @@ class Api::V1::Projects::Pulls::Journals::ListService < ApplicationService private def journal_query_data - journals = @pull_request.journals.parent_journals + journals = @pull_request.journals + if parent_id.present? + journals = journals.where(parent_id: parent_id) + else + journals = journals.parent_journals + 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? q = journals.ransack(notes_cont: keyword) - scope = q.result.includes(:review) + scope = q.result.includes(:user, :resolveer, review: [:reviewer, pull_request: :issue]) scope = scope.order("journals.#{sort_by} #{sort_direction}") @queried_journals = scope diff --git a/app/views/api/v1/projects/pulls/journals/_simple_detail.json.jbuilder b/app/views/api/v1/projects/pulls/journals/_simple_detail.json.jbuilder index 547db46e..d418ffdc 100644 --- a/app/views/api/v1/projects/pulls/journals/_simple_detail.json.jbuilder +++ b/app/views/api/v1/projects/pulls/journals/_simple_detail.json.jbuilder @@ -1,4 +1,4 @@ -json.(journal, :id, :notes, :commit_id, :line_code, :path, :diff, :need_respond, :state) +json.(journal, :id, :note, :commit_id, :line_code, :path, :diff, :need_respond, :state, :parent_id) json.user do json.partial! 'api/v1/users/simple_user', user: journal.user end diff --git a/app/views/api/v1/projects/pulls/reviews/index.json.jbuilder b/app/views/api/v1/projects/pulls/reviews/index.json.jbuilder new file mode 100644 index 00000000..04792d5c --- /dev/null +++ b/app/views/api/v1/projects/pulls/reviews/index.json.jbuilder @@ -0,0 +1,4 @@ +json.total_count @reviews.total_count +json.reviews @reviews.each do |review| + json.partial! 'api/v1/projects/pulls/reviews/simple_detail', review: review +end \ No newline at end of file diff --git a/public/docs/api.html b/public/docs/api.html index 0a684743..50b1c12a 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -618,9 +618,24 @@
  • 获取合并请求版本Diff
  • +
  • + 获取合并请求审查列表 +
  • 为合并请求创建一个审查
  • +
  • + 获取合并请求评论列表 +
  • +
  • + 创建一个合并请求评论 +
  • +
  • + 修改一个合并请求评论 +
  • +
  • + 删除合并请求的一个评论 +
  • @@ -13112,6 +13127,69 @@ http://localhost:3000/api/Jason/test-txt/compare/master...Jason/test-txt:develop
  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数string 项目标识identifier
    keywordstring搜索关键词
    statusint合并请求类型 0: 开启的, 1: 合并的 2: 关闭的,不传则为全部的
    priority_idint优先级ID
    issue_tag_idint标记ID
    version_idint里程碑ID
    reviewer_idint审查人员ID
    assign_user_idint指派人员ID
    sort_bycreated_atstring排序字段,created_at: 创建时间, updated_at: 更新时间
    sort_directiondescstring排序类型 desc: 倒序 asc: 正序

    返回字段说明:

    @@ -14123,6 +14201,231 @@ http://localhost:3000/api/v1/yystopf/ceshi_commit/pulls/3/versions/33/diff.json "is_incomplete_line_too_long": false, "is_protected": false } +

    获取合并请求审查列表

    +

    获取合并请求版本审查列表

    + +
    +

    示例:

    +
    +
    curl -X GET http://localhost:3000/api/v1/yystopf/ceshi_commit/pulls/3/reviews.json
    +
    await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/reviews.json')
    +

    HTTP 请求

    +

    GET /api/v1/:owner/:repo/pulls/:index/reviews.json

    +

    请求参数:

    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    indexint合并请求序号
    +

    返回字段说明:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    total_countint审查总数
    reviews.reviewerobject审查者
    reviews.pull_request.idinteger合并请求ID
    reviews.pull_request.titlestring合并请求标题
    reviews.pull_request.bodystring合并请求内容
    reviews.pull_request.headstring合并请求源分支
    reviews.pull_request.basestring合并请求目标分支
    reviews.pull_request.is_originalstring合并请求是否从fork仓库所来
    reviews.pull_request.fork_project.idintfork仓库的id
    reviews.pull_request.fork_project.identifierstringfork仓库的标识
    reviews.pull_request.fork_project.loginstringfork仓库拥有者的标识
    reviews.pull_request.indexstring合并请求的序号
    reviews.pull_request.statusstring合并请求的状态,open: 打开的, merged: 合并的, closed: 关闭的
    reviews.pull_request.issue.idinteger合并请求下疑修的ID
    reviews.pull_request.issue.authorobject合并请求以及疑修的创建着
    reviews.pull_request.issue.prioritystring疑修的优先级
    reviews.pull_request.issue.versionstring疑修的里程碑
    reviews.pull_request.issue.journals_countinteger普通评论数量
    reviews.pull_request.issue.issue_tagsarray所属标记
    reviews.pull_request.journals_countinteger审查评论数量
    reviews.idinteger审查ID
    reviews.commit_idstring审查的commit ID
    reviews.contentstring审查的内容
    reviews.statusstring审查类型,common: 普通, approved: 通过,rejected: 拒绝通过
    reviews.created_atstring审查创建时间
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "total_count": 1,
    +    "reviews": [
    +        {
    +            "reviewer": {
    +                "id": 2,
    +                "type": "User",
    +                "name": "heh",
    +                "login": "yystopf",
    +                "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +            },
    +            "pull_request": {
    +                "id": 163,
    +                "title": "新合并请求1",
    +                "body": null,
    +                "head": "master_1",
    +                "base": "master",
    +                "is_original": false,
    +                "index": 1,
    +                "status": "closed",
    +                "issue": {
    +                    "id": 260,
    +                    "author": {
    +                        "id": 2,
    +                        "type": "User",
    +                        "name": "heh",
    +                        "login": "yystopf",
    +                        "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +                    },
    +                    "priority": null,
    +                    "version": null,
    +                    "journals_count": 0,
    +                    "issue_tags": null
    +                },
    +                "reviewers": [],
    +                "journals_count": 8
    +            },
    +            "id": 5,
    +            "commit_id": null,
    +            "content": "新建一个审查",
    +            "status": "common",
    +            "created_at": "2022-07-25 17:08"
    +        }
    +    ]
    +}
     

    为合并请求创建一个审查

    合并请求创建一个审查

    @@ -14132,9 +14435,9 @@ http://localhost:3000/api/v1/yystopf/ceshi_commit/pulls/3/versions/33/diff.json
    curl -X POST \
     http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/reviews.json
     
    await octokit.request('POST /api/v1/yystopf/ceshi/pulls/1/reviews.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST /api/v1/:owner/:repo/pulls/:index/reviews.json

    -

    请求参数:

    +

    请求参数:

    @@ -14196,7 +14499,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/reviews.json "commit_id": "e506844b2467ce25a35dd46dad8236a1595a02da", "status": "common" } -

    返回字段说明:

    +

    返回字段说明:

    参数
    @@ -14370,6 +14673,746 @@ http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/reviews.json +

    获取合并请求评论列表

    +

    获取合并请求版本评论列表

    + +
    +

    示例:

    +
    +
    curl -X GET http://localhost:3000/api/v1/yystopf/ceshi_commit/pulls/3/journals.json
    +
    await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/journals.json')
    +

    HTTP 请求

    +

    GET /api/v1/:owner/:repo/pulls/:index/journals.json

    +

    请求参数:

    +
    参数
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    indexint合并请求序号
    keywordstring搜索关键词
    review_idinteger审查ID
    need_respondbool是否需要回应
    statestring状态, opened: 开启的, resolved: 已解决的, disabled: 无效的
    parent_idinteger父评论ID
    sort_bycreated_onstring排序字段 created_on: 创建时间, updated_on: 更新时间
    sort_directionascstring排序类型 desc: 倒序, asc: 正序
    +

    返回字段说明:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    total_countint评论总数
    journals.idint评论ID
    journals.notesstring评论内容
    journals.commit_idstringCommitID
    journals.line_codestring评论行数
    journals.pathstring评论文件路径
    journals.diffobject评论文件diff内容
    journals.need_respondbool评论是否要回应
    journals.statestring评论状态,opened: 开启的, resolved: 已解决的, disabled: 无效的
    journals.parent_idint父评论ID
    journals.userobject评论创建者
    journals.reviewobject评论所属评审
    journals.resolveerobject评论解决者
    journals.resolve_atint评论解决时间
    journals.created_atint评论创建时间
    journals.updated_atint评论更新时间
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "total_count": 1,
    +    "journals": [
    +        {
    +            "id": 200,
    +            "note": "测试评论修改",
    +            "commit_id": null,
    +            "line_code": "70eede447ccc01c1902260fd377af5d90be28e0d_0_29",
    +            "path": "Gemfile.lock",
    +            "diff": {},
    +            "need_respond": true,
    +            "state": "resolved",
    +            "parent_id": nil,
    +            "user": {
    +                "id": 2,
    +                "type": "User",
    +                "name": "heh",
    +                "login": "yystopf",
    +                "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +            },
    +            "review": {
    +                "reviewer": {
    +                    "id": 2,
    +                    "type": "User",
    +                    "name": "heh",
    +                    "login": "yystopf",
    +                    "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +                },
    +                "pull_request": {
    +                    "id": 163,
    +                    "title": "新合并请求1",
    +                    "body": null,
    +                    "head": "master_1",
    +                    "base": "master",
    +                    "is_original": false,
    +                    "index": 1,
    +                    "status": "closed",
    +                    "issue": {
    +                        "id": 260,
    +                        "author": {
    +                            "id": 2,
    +                            "type": "User",
    +                            "name": "heh",
    +                            "login": "yystopf",
    +                            "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +                        },
    +                        "priority": null,
    +                        "version": null,
    +                        "journals_count": 0,
    +                        "issue_tags": null
    +                    },
    +                    "reviewers": [],
    +                    "journals_count": 9
    +                },
    +                "id": 10,
    +                "commit_id": "1",
    +                "content": "新建一个审查",
    +                "status": "common",
    +                "created_at": "2022-07-26 11:45"
    +            },
    +            "resolveer": {
    +                "id": 2,
    +                "type": "User",
    +                "name": "heh",
    +                "login": "yystopf",
    +                "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +            },
    +            "resolve_at": "2022-07-27 14:50",
    +            "created_at": "2022-07-27 14:31",
    +            "updated_at": "2022-07-27 14:50"
    +        }
    +    ]
    +}
    +

    创建一个合并请求评论

    +

    为仓库创建一个合并请求的评论

    + +
    +

    示例:

    +
    +
    curl -X POST \
    +http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/journals.json
    +
    await octokit.request('POST /api/v1/yystopf/ceshi/pulls/1/journals.json')
    +

    HTTP 请求

    +

    POST /api/v1/:owner/:repo/pulls/:index/journals.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    indexinteger合并请求序号
    typestring评论类型 comment: 普通, problem: 需要回应的评论
    notestring评论内容
    review_idstring审查ID
    line_codestring行号
    commit_idboolcommitID
    pathinteger文件路径
    parent_idinteger父评论ID
    diffarray文件diff内容
    + +
    +

    请求的JSON示例:

    +
    +
    {
    +    "type": "problem",
    +    "note": "测试评论",
    +    "review_id": "10",
    +    "line_code": "70eede447ccc01c1902260fd377af5d90be28e0d_0_29",
    +    "commit_id": "70eede447ccc01c1902260fd377af5d90be28e0d",
    +    "path": "Gemfile.lock",
    +    "diff": {
    +        "name": "README.md",
    +        "oldname": "README.md",
    +        "addition": 1,
    +        "deletion": 2,
    +        "type": 2,
    +        "is_created": false,
    +        "is_deleted": false,
    +        "is_bin": false,
    +        "is_lfs_file": false,
    +        "is_renamed": false,
    +        "is_ambiguous": false,
    +        "is_submodule": false,
    +        "sections": [
    +            {
    +                "file_name": "README.md",
    +                "name": "",
    +                "lines": [
    +                    {
    +                        "left_index": 0,
    +                        "right_index": 0,
    +                        "match": 0,
    +                        "type": 4,
    +                        "content": "@@ -1,2 +1 @@",
    +                        "section_path": "README.md",
    +                        "section_last_left_index": 0,
    +                        "section_last_right_index": 0,
    +                        "section_left_index": 1,
    +                        "section_right_index": 1,
    +                        "section_left_hunk_size": 2,
    +                        "section_right_hunk_size": 0
    +                    },
    +                    {
    +                        "left_index": 1,
    +                        "right_index": 0,
    +                        "match": 3,
    +                        "type": 3,
    +                        "content": "-# ceshi_commit"
    +                    },
    +                    {
    +                        "left_index": 2,
    +                        "right_index": 0,
    +                        "match": -1,
    +                        "type": 3,
    +                        "content": "-"
    +                    },
    +                    {
    +                        "left_index": 0,
    +                        "right_index": 1,
    +                        "match": 1,
    +                        "type": 2,
    +                        "content": "+adsa"
    +                    }
    +                ]
    +            },
    +            {
    +                "file_name": "README.md",
    +                "name": "",
    +                "lines": [
    +                    {
    +                        "left_index": 0,
    +                        "right_index": 0,
    +                        "match": 0,
    +                        "type": 4,
    +                        "content": " ",
    +                        "section_path": "README.md",
    +                        "section_last_left_index": 0,
    +                        "section_last_right_index": 1,
    +                        "section_left_index": 3,
    +                        "section_right_index": 2,
    +                        "section_left_hunk_size": 0,
    +                        "section_right_hunk_size": 0
    +                    }
    +                ]
    +            }
    +        ],
    +        "is_incomplete": false,
    +        "is_incomplete_line_too_long": false,
    +        "is_protected": false
    +    }
    +}
    +
    +
    +

    返回的JSON示例:

    +
    +
    {
    +    "id": 200,
    +    "note": "测试评论修改",
    +    "commit_id": null,
    +    "line_code": "70eede447ccc01c1902260fd377af5d90be28e0d_0_29",
    +    "path": "Gemfile.lock",
    +    "diff": {},
    +    "need_respond": true,
    +    "state": "resolved",
    +    "user": {
    +        "id": 2,
    +        "type": "User",
    +        "name": "heh",
    +        "login": "yystopf",
    +        "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +    },
    +    "review": {
    +        "reviewer": {
    +            "id": 2,
    +            "type": "User",
    +            "name": "heh",
    +            "login": "yystopf",
    +            "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +        },
    +        "pull_request": {
    +            "id": 163,
    +            "title": "新合并请求1",
    +            "body": null,
    +            "head": "master_1",
    +            "base": "master",
    +            "is_original": false,
    +            "index": 1,
    +            "status": "closed",
    +            "issue": {
    +                "id": 260,
    +                "author": {
    +                    "id": 2,
    +                    "type": "User",
    +                    "name": "heh",
    +                    "login": "yystopf",
    +                    "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +                },
    +                "priority": null,
    +                "version": null,
    +                "journals_count": 0,
    +                "issue_tags": null
    +            },
    +            "reviewers": [],
    +            "journals_count": 9
    +        },
    +        "id": 10,
    +        "commit_id": "1",
    +        "content": "新建一个审查",
    +        "status": "common",
    +        "created_at": "2022-07-26 11:45"
    +    },
    +    "resolveer": {
    +        "id": 2,
    +        "type": "User",
    +        "name": "heh",
    +        "login": "yystopf",
    +        "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +    },
    +    "resolve_at": "2022-07-27 14:50",
    +    "created_at": "2022-07-27 14:31",
    +    "updated_at": "2022-07-27 14:50"
    +}
    +
    + +

    修改一个合并请求评论

    +

    修改一个仓库合并请求的评论

    + +
    +

    示例:

    +
    +
    curl -X PATCH \
    +http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/journals/200.json
    +
    await octokit.request('PATCH /api/v1/yystopf/ceshi/pulls/1/journals/200.json')
    +

    HTTP 请求

    +

    PATCH /api/v1/:owner/:repo/pulls/:index/journals/:id.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    indexinteger合并请求序号
    idinteger评论ID
    notestring评论内容
    commit_idstringcommitID
    statestring评论状态, opened: 开启的, resolved: 已解决的, disabled: 无效的
    + +
    +

    请求的JSON示例:

    +
    +
    {
    +    "note": "测试评论",
    +    "commit_id": "70eede447ccc01c1902260fd377af5d90be28e0d",
    +    "state": "resolved"
    +}
    +
    +
    +

    返回的JSON示例:

    +
    +
    {
    +    "id": 200,
    +    "note": "测试评论修改",
    +    "commit_id": null,
    +    "line_code": "70eede447ccc01c1902260fd377af5d90be28e0d_0_29",
    +    "path": "Gemfile.lock",
    +    "diff": {},
    +    "need_respond": true,
    +    "state": "resolved",
    +    "user": {
    +        "id": 2,
    +        "type": "User",
    +        "name": "heh",
    +        "login": "yystopf",
    +        "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +    },
    +    "review": {
    +        "reviewer": {
    +            "id": 2,
    +            "type": "User",
    +            "name": "heh",
    +            "login": "yystopf",
    +            "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +        },
    +        "pull_request": {
    +            "id": 163,
    +            "title": "新合并请求1",
    +            "body": null,
    +            "head": "master_1",
    +            "base": "master",
    +            "is_original": false,
    +            "index": 1,
    +            "status": "closed",
    +            "issue": {
    +                "id": 260,
    +                "author": {
    +                    "id": 2,
    +                    "type": "User",
    +                    "name": "heh",
    +                    "login": "yystopf",
    +                    "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +                },
    +                "priority": null,
    +                "version": null,
    +                "journals_count": 0,
    +                "issue_tags": null
    +            },
    +            "reviewers": [],
    +            "journals_count": 9
    +        },
    +        "id": 10,
    +        "commit_id": "1",
    +        "content": "新建一个审查",
    +        "status": "common",
    +        "created_at": "2022-07-26 11:45"
    +    },
    +    "resolveer": {
    +        "id": 2,
    +        "type": "User",
    +        "name": "heh",
    +        "login": "yystopf",
    +        "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +    },
    +    "resolve_at": "2022-07-27 14:50",
    +    "created_at": "2022-07-27 14:31",
    +    "updated_at": "2022-07-27 14:50"
    +}
    +
    + +

    删除合并请求的一个评论

    +

    删除合并请求的一个评论

    + +
    +

    示例:

    +
    +
    curl -X DELETE \
    +http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/journals/200.json
    +
    await octokit.request('DELETE /api/v1/yystopf/ceshi/pulls/1/journals/200.json')
    +

    HTTP 请求

    +

    DELETE /api/v1/:owner/:repo/pulls/:index/journals/:id.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    indexinteger合并请求序号
    idinteger评论ID
    +

    返回字段说明:

    +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "success"
    +}
    +
    +

    Issues

    Organizations

    Teams

    Errors