diff --git a/Gemfile b/Gemfile index 3da6f273d..dd8885df7 100644 --- a/Gemfile +++ b/Gemfile @@ -135,4 +135,4 @@ gem 'doorkeeper' gem 'doorkeeper-jwt' -gem 'gitea-client', '~> 0.10.2' \ No newline at end of file +gem 'gitea-client', '~> 0.10.4' \ No newline at end of file diff --git a/app/controllers/api/v1/projects/pulls/base_controller.rb b/app/controllers/api/v1/projects/pulls/base_controller.rb new file mode 100644 index 000000000..0d5ae08b5 --- /dev/null +++ b/app/controllers/api/v1/projects/pulls/base_controller.rb @@ -0,0 +1,20 @@ +class Api::V1::Projects::Pulls::BaseController < Api::V1::BaseController + before_action :require_public_and_member_above + before_action :load_pull_request + + def load_pull_request + pull_request_id = params[:pull_id] || params[:id] + @pull_request = @project.pull_requests.where(gitea_number: pull_request_id).where.not(id: pull_request_id).take || PullRequest.find_by_id(pull_request_id) + @issue = @pull_request&.issue + if @pull_request + logger.info "###########pull_request founded" + @pull_request + else + logger.info "###########pull_request not found" + @pull_request = nil + render_not_found and return + end + + @pull_request + end +end \ No newline at end of file diff --git a/app/controllers/api/v1/projects/pulls/versions_controller.rb b/app/controllers/api/v1/projects/pulls/versions_controller.rb new file mode 100644 index 000000000..dfd5d9e9d --- /dev/null +++ b/app/controllers/api/v1/projects/pulls/versions_controller.rb @@ -0,0 +1,10 @@ +class Api::V1::Projects::Pulls::VersionsController < Api::V1::Projects::Pulls::BaseController + + def index + @result_object = Api::V1::Projects::Pulls::Versions::ListService.call(@project, @pull_request, {page: page, limit: limit}, current_user&.gitea_token) + end + + def diff + @result_object = Api::V1::Projects::Pulls::Versions::GetDiffService.call(@project, @pull_request, params[:id], {filepath: params[:filepath]}, current_user&.gitea_token) + end +end \ No newline at end of file diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb index eec57113d..e12016904 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::PullRequests::Reviews::CreateService.call(@project, @pull_request, review_params, current_user) + @journal, @review = Api::V1::Projects::Pulls::Reviews::CreateService.call(@project, @pull_request, review_params, current_user) end private diff --git a/app/docs/slate/source/includes/_pulls.md b/app/docs/slate/source/includes/_pulls.md index b9ad3b0ba..e7df64097 100644 --- a/app/docs/slate/source/includes/_pulls.md +++ b/app/docs/slate/source/includes/_pulls.md @@ -499,4 +499,319 @@ await octokit.request('GET /api/Jasder/gitlink/pulls.json') } ] } +``` + +## 获取合并请求版本列表 +获取合并请求版本列表 + +> 示例: + +```shell +curl -X GET http://localhost:3000/api/v1/yystopf/ceshi_commit/pulls/3/versions.json +``` + +```javascript +await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/versions.json') +``` + +### HTTP 请求 +`GET /api/v1/:owner/:repo/pulls/:index/versions.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|owner |是| |string |用户登录名 | +|repo |是| |string |项目标识identifier | +|index |是|| int |合并请求序号| + + +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|total_count |int |合并请求版本总数| +|versions.id |int |版本ID| +|versions.add_line_num |int |该版本新增行数| +|versions.del_line_num |int |该版本删除行数| +|versions.commits_count |int |该版本提交总数| +|versions.files_count |int |该版本提交文件总数| +|versions.base_commit_sha |string |目标commit ID| +|versions.head_commit_sha |string |源commit ID| +|versions.start_commit_sha|string |该版本起始commit ID| +|versions.created_time |int |版本创建时间| +|versions.updated_time |int |版本更新时间| + +> 返回的JSON示例: + +```json +{ + "total_count": 1, + "versions": [ + { + "id": 33, + "add_line_num": 5, + "del_line_num": 2, + "commits_count": 31, + "files_count": 29, + "base_commit_sha": "4a277037093c1248e46d2946ee30b61cccdb9df9", + "head_commit_sha": "fa3b1cdc8e0727d0fb9c96d28c545867c39815b8", + "start_commit_sha": "e49b1fd335e093a440fcf35a21e050afd48ef932", + "created_time": 1658469499, + "updated_time": 1658469499 + } + ] +} +``` + +## 获取合并请求版本Diff +获取合并请求版本Diff(支持获取单文件Diff) + +> 示例: + +```shell +curl -X GET \ +-d "filepath=ceshi_dir_1/new_file_1" \ +http://localhost:3000/api/v1/yystopf/ceshi_commit/pulls/3/versions/33/diff.json +``` + +```javascript +await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/versions/33/diff.json') +``` + +### HTTP 请求 +`GET /api/v1/:owner/:repo/pulls/:index/versions/:version_id/diff.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|owner |是| |string |用户登录名 | +|repo |是| |string |项目标识identifier | +|index |是|| int |合并请求序号| +|version_id|是|| int |版本ID| +|filepath|否||string|文件路径| + +### 列表返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|file_nums|int|文件数量| +|total_addition|int|新增行数| +|total_deletion|int|删除行数| +|files.name|string|文件名称| +|files.oldname|string|文件修改前名称| +|files.addition|int|文件新增行数| +|files.deletion|int|文件删除行数| +|files.type|int|文件类型 1: 新增 2: 更改 3: 删除 4: 重命名 5: 复制| +|files.is_created|bool|是否为新建文件| +|files.is_deleted|bool|是否为删除文件| +|files.is_bin|bool|是否为二进制文件| +|files.is_lfs_file|bool|是否为LFS文件| +|files.is_renamed|bool|是否重命名| +|files.is_ambiguous|bool|| +|files.is_submodule|bool|是否为子模块| +|files.sections.file_name|string|文件名称| +|files.sections.name|string|| +|files.sections.lines.left_index|int|文件变动之前所在行数| +|files.sections.lines.right_index|int|文件变动之后所在行数| +|files.sections.lines.match|int|| +|files.sections.lines.type|int|文件变更类型| +|files.sections.lines.content|string|文件变更内容| +|files.sections.lines.section_path|string|文件路径| +|files.sections.lines.section_last_left_index|int|| +|files.sections.lines.section_last_right_index|int|| +|files.sections.lines.section_left_index|int|文件变更之前所在行数| +|files.sections.lines.section_right_index|int|文件变更之后所在行数(即:页面编辑器开始显示的行数)| +|files.sections.lines.section_left_hunk_size|int|文件变更之前的行数| +|files.sections.lines.section_right_hunk_size|int|文件变更之后的行数(及当前页面编辑器显示的总行数)| +|files.is_incomplete|bool|是否不完整| +|files.is_incomplete_line_too_long|bool|文件是否不完整是因为太长了| +|files.is_protected|bool|文件是否被保护| + +> 列表返回的JSON示例: + +```json +{ + "file_nums": 29, + "total_addition": 5, + "total_deletion": 2, + "files": [ + { + "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" + } + ] + }, + {} + ], + "is_incomplete": false, + "is_incomplete_line_too_long": false, + "is_protected": false + } + ] +} +``` + +### 单个文件返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|name|string|文件名称| +|oldname|string|文件修改前名称| +|addition|int|文件新增行数| +|deletion|int|文件删除行数| +|type|int|文件类型 1: 新增 2: 更改 3: 删除 4: 重命名 5: 复制| +|is_created|bool|是否为新建文件| +|is_deleted|bool|是否为删除文件| +|is_bin|bool|是否为二进制文件| +|is_lfs_file|bool|是否为LFS文件| +|is_renamed|bool|是否重命名| +|is_ambiguous|bool|| +|is_submodule|bool|是否为子模块| +|sections.file_name|string|文件名称| +|sections.name|string|| +|sections.lines.left_index|int|文件变动之前所在行数| +|sections.lines.right_index|int|文件变动之后所在行数| +|sections.lines.match|int|| +|sections.lines.type|int|文件变更类型| +|sections.lines.content|string|文件变更内容| +|sections.lines.section_path|string|文件路径| +|sections.lines.section_last_left_index|int|| +|sections.lines.section_last_right_index|int|| +|sections.lines.section_left_index|int|文件变更之前所在行数| +|sections.lines.section_right_index|int|文件变更之后所在行数(即:页面编辑器开始显示的行数)| +|sections.lines.section_left_hunk_size|int|文件变更之前的行数| +|sections.lines.section_right_hunk_size|int|文件变更之后的行数(及当前页面编辑器显示的总行数)| +|is_incomplete|bool|是否不完整| +|is_incomplete_line_too_long|bool|文件是否不完整是因为太长了| +|is_protected|bool|文件是否被保护| + +> 单个文件返回的JSON示例: + +```json +{ + "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 +} ``` \ No newline at end of file diff --git a/app/docs/slate/source/includes/_repositories.md b/app/docs/slate/source/includes/_repositories.md index ae74dac7f..a07f23513 100644 --- a/app/docs/slate/source/includes/_repositories.md +++ b/app/docs/slate/source/includes/_repositories.md @@ -1990,25 +1990,27 @@ await octokit.request('GET /api/v1/yystopf/csfjkkj/compare.json') |diff.files.is_created|bool|是否为新建文件| |diff.files.is_deleted|bool|是否为删除文件| |diff.files.is_bin|bool|是否为二进制文件| -|diff.files.is_lfs_file|bool|| +|diff.files.is_lfs_file|bool|是否为LFS文件| |diff.files.is_renamed|bool|是否重命名| |diff.files.is_ambiguous|bool|| |diff.files.is_submodule|bool|是否为子模块| |diff.files.sections.file_name|string|文件名称| |diff.files.sections.name|string|| -|diff.files.sections.lines.left_index|int|| -|diff.files.sections.lines.right_index|int|| +|diff.files.sections.lines.left_index|int|文件变动之前所在行数| +|diff.files.sections.lines.right_index|int|文件变动之后所在行数| |diff.files.sections.lines.match|int|| -|diff.files.sections.lines.type|int|| -|diff.files.sections.lines.content|string|| -|diff.files.sections.lines.section_path|string|| +|diff.files.sections.lines.type|int|文件变更类型| +|diff.files.sections.lines.content|string|文件变更内容| +|diff.files.sections.lines.section_path|string|文件路径| |diff.files.sections.lines.section_last_left_index|int|| |diff.files.sections.lines.section_last_right_index|int|| -|diff.files.sections.lines.section_left_index|int|| -|diff.files.sections.lines.section_right_index|int|| -|diff.files.sections.lines.section_left_hunk_size|int|| -|diff.files.sections.lines.section_right_hunk_size|int|| - +|diff.files.sections.lines.section_left_index|int|文件变更之前所在行数| +|diff.files.sections.lines.section_right_index|int|文件变更之后所在行数(即:页面编辑器开始显示的行数)| +|diff.files.sections.lines.section_left_hunk_size|int|文件变更之前的行数| +|diff.files.sections.lines.section_right_hunk_size|int|文件变更之后的行数(及当前页面编辑器显示的总行数)| +|diff.files.is_incomplete|bool|是否不完整| +|diff.files.is_incomplete_line_too_long|bool|文件是否不完整是因为太长了| +|diff.files.is_protected|bool|文件是否被保护| > 返回的JSON示例: diff --git a/app/services/api/v1/projects/pull_requests/reviews/create_service.rb b/app/services/api/v1/projects/pulls/reviews/create_service.rb similarity index 93% rename from app/services/api/v1/projects/pull_requests/reviews/create_service.rb rename to app/services/api/v1/projects/pulls/reviews/create_service.rb index c003256dc..13ec9f7e7 100644 --- a/app/services/api/v1/projects/pull_requests/reviews/create_service.rb +++ b/app/services/api/v1/projects/pulls/reviews/create_service.rb @@ -1,4 +1,4 @@ -class Api::V1::Projects::PullRequests::Reviews::CreateService < ApplicationService +class Api::V1::Projects::Pulls::Reviews::CreateService < ApplicationService include ActiveModel::Model attr_reader :project, :pull_request, :issue, :status, :commit_id, :content, :current_user diff --git a/app/services/api/v1/projects/pulls/versions/get_diff_service.rb b/app/services/api/v1/projects/pulls/versions/get_diff_service.rb new file mode 100644 index 000000000..1a4f144af --- /dev/null +++ b/app/services/api/v1/projects/pulls/versions/get_diff_service.rb @@ -0,0 +1,35 @@ +class Api::V1::Projects::Pulls::Versions::GetDiffService < ApplicationService + + attr_reader :project, :pull_request, :version_id, :owner, :repo, :index, :filepath, :token + attr_accessor :gitea_data + + def initialize(project, pull_request, version_id, params, token=nil) + @project = project + @pull_request = pull_request + @version_id = version_id + @owner = project&.owner.login + @repo = project&.identifier + @index = pull_request.gitea_number + @filepath = params[:filepath] + @token = token + end + + def call + load_gitea_data + + gitea_data + end + + private + def request_params + params = { + access_token: token + } + params.merge!(filepath: filepath) if filepath.present? + end + + def load_gitea_data + @gitea_data = $gitea_client.get_repos_pulls_versions_diff_by_owner_repo_index_version_id(owner, repo, index, version_id, {query: request_params}) + raise Error, '获取合并请求版本diff失败!' unless @gitea_data.is_a?(Hash) + end +end \ No newline at end of file diff --git a/app/services/api/v1/projects/pulls/versions/list_service.rb b/app/services/api/v1/projects/pulls/versions/list_service.rb new file mode 100644 index 000000000..ca88ff1f6 --- /dev/null +++ b/app/services/api/v1/projects/pulls/versions/list_service.rb @@ -0,0 +1,36 @@ +class Api::V1::Projects::Pulls::Versions::ListService < ApplicationService + + attr_reader :project, :pull_request, :token, :owner, :repo, :index, :page, :limit + attr_accessor :gitea_data + + def initialize(project, pull_request, params, token = nil) + @project = project + @pull_request = pull_request + @owner = project&.owner.login + @repo = project&.identifier + @page = params[:page] || 1 + @limit = params[:limit] || 15 + @index = pull_request.gitea_number + @token = token + end + + def call + load_gitea_data + + gitea_data + end + + private + def request_params + { + access_token: token, + page: page, + limit: limit + } + end + + def load_gitea_data + @gitea_data = $gitea_client.get_repos_pulls_versions_by_owner_repo_index(owner, repo, index, {query: request_params}) + raise Error, '获取合并请求版本失败!' unless @gitea_data.is_a?(Hash) + end +end \ No newline at end of file diff --git a/app/views/api/v1/projects/_simple_gitea_diff_file_detail.json.jbuilder b/app/views/api/v1/projects/_simple_gitea_diff_file_detail.json.jbuilder new file mode 100644 index 000000000..13f833338 --- /dev/null +++ b/app/views/api/v1/projects/_simple_gitea_diff_file_detail.json.jbuilder @@ -0,0 +1,35 @@ +json.name file['Name'] + json.oldname file['OldName'] + json.addition file['Addition'] + json.deletion file['Deletion'] + json.type file['Type'] + json.is_created file['IsCreated'] + json.is_deleted file['IsDeleted'] + json.is_bin file['IsBin'] + json.is_lfs_file file['IsLFSFile'] + json.is_renamed file['IsRenamed'] + json.is_ambiguous file['IsAmbiguous'] + json.is_submodule file['IsSubmodule'] + json.sections file['Sections'] do |section| + json.file_name section['FileName'] + json.name section['Name'] + json.lines section['Lines'] do |line| + json.left_index line['LeftIdx'] + json.right_index line['RightIdx'] + json.match line['Match'] + json.type line['Type'] + json.content line['Content'] + unless line['SectionInfo'].blank? + json.section_path line['SectionInfo']['Path'] + json.section_last_left_index line['SectionInfo']['LastLeftIdx'] + json.section_last_right_index line['SectionInfo']['LastRightIdx'] + json.section_left_index line['SectionInfo']['LeftIdx'] + json.section_right_index line['SectionInfo']['RightIdx'] + json.section_left_hunk_size line['SectionInfo']['LeftHunkSize'] + json.section_right_hunk_size line['SectionInfo']['RightHunkSize'] + end + end + end + json.is_incomplete file['IsIncomplete'] + json.is_incomplete_line_too_long file['IsIncompleteLineTooLong'] + json.is_protected file['IsProtected'] \ No newline at end of file diff --git a/app/views/api/v1/projects/pulls/versions/diff.json.jbuilder b/app/views/api/v1/projects/pulls/versions/diff.json.jbuilder new file mode 100644 index 000000000..9e2c3430d --- /dev/null +++ b/app/views/api/v1/projects/pulls/versions/diff.json.jbuilder @@ -0,0 +1,6 @@ + +if @result_object.has_key?("NumFiles") + json.partial! "api/v1/projects/simple_gitea_diff_detail", diff: @result_object +else + json.partial! "api/v1/projects/simple_gitea_diff_file_detail", file: @result_object +end \ No newline at end of file diff --git a/app/views/api/v1/projects/pulls/versions/index.json.jbuilder b/app/views/api/v1/projects/pulls/versions/index.json.jbuilder new file mode 100644 index 000000000..4888c4f08 --- /dev/null +++ b/app/views/api/v1/projects/pulls/versions/index.json.jbuilder @@ -0,0 +1,13 @@ +json.total_count @result_object[:total_data].to_i +json.versions @result_object[:data].each do |version| + json.id version['id'] + json.add_line_num version['add_line_num'] + json.del_line_num version['del_line_num'] + json.commits_count version['commits_count'] + json.files_count version['files_count'] + json.base_commit_sha version['base_commit_sha'] + json.head_commit_sha version['head_commit_sha'] + json.start_commit_sha version['start_commit_sha'] + json.created_time render_unix_time(version['created_at']) + json.updated_time render_unix_time(version['updated_at']) +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 81668804e..8340097ee 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -19,7 +19,14 @@ defaults format: :json do # projects文件夹下的 scope module: :projects do resources :issues - resources :pull_requests + resources :pulls, module: 'pulls' do + resources :versions, only: [:index] do + member do + get :diff + end + end + end + resources :versions resources :release_versions resources :webhooks do diff --git a/public/docs/api.html b/public/docs/api.html index 80b1ebdcb..a6653b3f1 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -629,6 +629,12 @@
  • List pull requests
  • +
  • + 获取合并请求版本列表 +
  • +
  • + 获取合并请求版本Diff +
  • @@ -10806,7 +10812,7 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/compare.json diff.files.is_lfs_file bool - +是否为LFS文件 diff.files.is_renamed @@ -10836,12 +10842,12 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/compare.json diff.files.sections.lines.left_index int - +文件变动之前所在行数 diff.files.sections.lines.right_index int - +文件变动之后所在行数 diff.files.sections.lines.match @@ -10851,17 +10857,17 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/compare.json diff.files.sections.lines.type int - +文件变更类型 diff.files.sections.lines.content string - +文件变更内容 diff.files.sections.lines.section_path string - +文件路径 diff.files.sections.lines.section_last_left_index @@ -10876,22 +10882,37 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/compare.json diff.files.sections.lines.section_left_index int - +文件变更之前所在行数 diff.files.sections.lines.section_right_index int - +文件变更之后所在行数(即:页面编辑器开始显示的行数) diff.files.sections.lines.section_left_hunk_size int - +文件变更之前的行数 diff.files.sections.lines.section_right_hunk_size int - +文件变更之后的行数(及当前页面编辑器显示的总行数) + + +diff.files.is_incomplete +bool +是否不完整 + + +diff.files.is_incomplete_line_too_long +bool +文件是否不完整是因为太长了 + + +diff.files.is_protected +bool +文件是否被保护 @@ -13239,6 +13260,670 @@ 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 请求

    +

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

    +

    请求参数:

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

    返回字段说明:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    total_countint合并请求版本总数
    versions.idint版本ID
    versions.add_line_numint该版本新增行数
    versions.del_line_numint该版本删除行数
    versions.commits_countint该版本提交总数
    versions.files_countint该版本提交文件总数
    versions.base_commit_shastring目标commit ID
    versions.head_commit_shastring源commit ID
    versions.start_commit_shastring该版本起始commit ID
    versions.created_timeint版本创建时间
    versions.updated_timeint版本更新时间
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "total_count": 1,
    +    "versions": [
    +        {
    +            "id": 33,
    +            "add_line_num": 5,
    +            "del_line_num": 2,
    +            "commits_count": 31,
    +            "files_count": 29,
    +            "base_commit_sha": "4a277037093c1248e46d2946ee30b61cccdb9df9",
    +            "head_commit_sha": "fa3b1cdc8e0727d0fb9c96d28c545867c39815b8",
    +            "start_commit_sha": "e49b1fd335e093a440fcf35a21e050afd48ef932",
    +            "created_time": 1658469499,
    +            "updated_time": 1658469499
    +        }
    +    ]
    +}
    +

    获取合并请求版本Diff

    +

    获取合并请求版本Diff(支持获取单文件Diff)

    + +
    +

    示例:

    +
    +
    curl -X GET \
    +-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 请求

    +

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

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    indexint合并请求序号
    version_idint版本ID
    filepathstring文件路径
    +

    列表返回字段说明:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    file_numsint文件数量
    total_additionint新增行数
    total_deletionint删除行数
    files.namestring文件名称
    files.oldnamestring文件修改前名称
    files.additionint文件新增行数
    files.deletionint文件删除行数
    files.typeint文件类型 1: 新增 2: 更改 3: 删除 4: 重命名 5: 复制
    files.is_createdbool是否为新建文件
    files.is_deletedbool是否为删除文件
    files.is_binbool是否为二进制文件
    files.is_lfs_filebool是否为LFS文件
    files.is_renamedbool是否重命名
    files.is_ambiguousbool
    files.is_submodulebool是否为子模块
    files.sections.file_namestring文件名称
    files.sections.namestring
    files.sections.lines.left_indexint文件变动之前所在行数
    files.sections.lines.right_indexint文件变动之后所在行数
    files.sections.lines.matchint
    files.sections.lines.typeint文件变更类型
    files.sections.lines.contentstring文件变更内容
    files.sections.lines.section_pathstring文件路径
    files.sections.lines.section_last_left_indexint
    files.sections.lines.section_last_right_indexint
    files.sections.lines.section_left_indexint文件变更之前所在行数
    files.sections.lines.section_right_indexint文件变更之后所在行数(即:页面编辑器开始显示的行数)
    files.sections.lines.section_left_hunk_sizeint文件变更之前的行数
    files.sections.lines.section_right_hunk_sizeint文件变更之后的行数(及当前页面编辑器显示的总行数)
    files.is_incompletebool是否不完整
    files.is_incomplete_line_too_longbool文件是否不完整是因为太长了
    files.is_protectedbool文件是否被保护
    + +
    +

    列表返回的JSON示例:

    +
    +
    {
    +    "file_nums": 29,
    +    "total_addition": 5,
    +    "total_deletion": 2,
    +    "files": [
    +        {
    +            "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"
    +                        }
    +                    ]
    +                },
    +                {}
    +            ],
    +            "is_incomplete": false,
    +            "is_incomplete_line_too_long": false,
    +            "is_protected": false
    +        }
    +    ]
    +}
    +

    单个文件返回字段说明:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    namestring文件名称
    oldnamestring文件修改前名称
    additionint文件新增行数
    deletionint文件删除行数
    typeint文件类型 1: 新增 2: 更改 3: 删除 4: 重命名 5: 复制
    is_createdbool是否为新建文件
    is_deletedbool是否为删除文件
    is_binbool是否为二进制文件
    is_lfs_filebool是否为LFS文件
    is_renamedbool是否重命名
    is_ambiguousbool
    is_submodulebool是否为子模块
    sections.file_namestring文件名称
    sections.namestring
    sections.lines.left_indexint文件变动之前所在行数
    sections.lines.right_indexint文件变动之后所在行数
    sections.lines.matchint
    sections.lines.typeint文件变更类型
    sections.lines.contentstring文件变更内容
    sections.lines.section_pathstring文件路径
    sections.lines.section_last_left_indexint
    sections.lines.section_last_right_indexint
    sections.lines.section_left_indexint文件变更之前所在行数
    sections.lines.section_right_indexint文件变更之后所在行数(即:页面编辑器开始显示的行数)
    sections.lines.section_left_hunk_sizeint文件变更之前的行数
    sections.lines.section_right_hunk_sizeint文件变更之后的行数(及当前页面编辑器显示的总行数)
    is_incompletebool是否不完整
    is_incomplete_line_too_longbool文件是否不完整是因为太长了
    is_protectedbool文件是否被保护
    + +
    +

    单个文件返回的JSON示例:

    +
    +
    {
    +    "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
    +}
     

    Issues

    Organizations

    Teams

    Errors