From 6e54203ebb5d2e81edd9a308726dbe9e14899ca3 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 28 Jul 2022 13:56:31 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E6=8F=90=E4=BA=A4=E6=96=87=E4=BB=B6=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=BC=BA=E5=A4=B1=E4=BB=A5=E5=8F=8A=E6=95=B0=E6=8D=AE=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../projects/contents/batch_create_service.rb | 3 ++- .../v1/projects/contents/batch.json.jbuilder | 20 +++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/services/api/v1/projects/contents/batch_create_service.rb b/app/services/api/v1/projects/contents/batch_create_service.rb index d987f931..ec4aec8d 100644 --- a/app/services/api/v1/projects/contents/batch_create_service.rb +++ b/app/services/api/v1/projects/contents/batch_create_service.rb @@ -13,7 +13,6 @@ class Api::V1::Projects::Contents::BatchCreateService < ApplicationService def initialize(project, params, token=nil) - puts params @project = project @owner = project&.owner.login @repo = project&.identifier @@ -63,6 +62,7 @@ class Api::V1::Projects::Contents::BatchCreateService < ApplicationService committer: Time.at(committer_timeunix.to_i) }, message: message, + branch: branch, new_branch: new_branch, signoff: false } @@ -77,6 +77,7 @@ class Api::V1::Projects::Contents::BatchCreateService < ApplicationService end def excute_data_to_gitea + puts request_body.to_json @gitea_data = $gitea_client.post_repos_contents_batch_by_owner_repo(owner, repo, {body: request_body.to_json, query: request_params}) rescue nil raise Error, '创建文件失败!' unless @gitea_data.is_a?(Hash) end diff --git a/app/views/api/v1/projects/contents/batch.json.jbuilder b/app/views/api/v1/projects/contents/batch.json.jbuilder index a9ef08fa..fa41bfb9 100644 --- a/app/views/api/v1/projects/contents/batch.json.jbuilder +++ b/app/views/api/v1/projects/contents/batch.json.jbuilder @@ -3,12 +3,16 @@ json.commit do json.authored_time render_unix_time(@result_object['commit']['author']['date']) json.commited_time render_unix_time(@result_object['commit']['committer']['date']) end -json.contents @result_object['contents'].each do |content| - json.name content['name'] - json.path content['path'] - json.sha content['sha'] - json.type content['type'] - json.size content['size'] - json.encoding content['encoding'] - json.content content['content'] +if @result_object['contents'].is_a?(Array) + json.contents @result_object['contents'].each do |content| + json.name content['name'] + json.path content['path'] + json.sha content['sha'] + json.type content['type'] + json.size content['size'] + json.encoding content['encoding'] + json.content content['content'] + end +else + json.contents [] end \ No newline at end of file From f417e4286477dfc6d749961f4e4dc4e62c3c1116 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 28 Jul 2022 14:02:37 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/projects/contents/batch_create_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/projects/contents/batch_create_service.rb b/app/services/api/v1/projects/contents/batch_create_service.rb index ec4aec8d..5fa88011 100644 --- a/app/services/api/v1/projects/contents/batch_create_service.rb +++ b/app/services/api/v1/projects/contents/batch_create_service.rb @@ -79,7 +79,7 @@ class Api::V1::Projects::Contents::BatchCreateService < ApplicationService def excute_data_to_gitea puts request_body.to_json @gitea_data = $gitea_client.post_repos_contents_batch_by_owner_repo(owner, repo, {body: request_body.to_json, query: request_params}) rescue nil - raise Error, '创建文件失败!' unless @gitea_data.is_a?(Hash) + raise Error, '提交文件失败!' unless @gitea_data.is_a?(Hash) end def check_branch_exist From 35c6cb98db6ba0532cfeabed4d1f76168e14675b Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 28 Jul 2022 14:25:33 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E6=8F=90=E4=BA=A4=E6=96=87=E4=BB=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E9=80=89=E5=A1=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/contents_controller.rb | 6 +++- .../slate/source/includes/_repositories.md | 30 ++++++++--------- .../projects/contents/batch_create_service.rb | 4 +-- public/docs/api.html | 32 +++++++++---------- 4 files changed, 38 insertions(+), 34 deletions(-) diff --git a/app/controllers/api/v1/projects/contents_controller.rb b/app/controllers/api/v1/projects/contents_controller.rb index a4e65051..44ab8c54 100644 --- a/app/controllers/api/v1/projects/contents_controller.rb +++ b/app/controllers/api/v1/projects/contents_controller.rb @@ -2,7 +2,11 @@ class Api::V1::Projects::ContentsController < Api::V1::BaseController before_action :require_operate_above, only: [:batch] def batch - @result_object = Api::V1::Projects::Contents::BatchCreateService.call(@project, batch_content_params, current_user&.gitea_token) + @batch_content_params = batch_content_params + # 处理下author和committer信息,如果没传则默认为当前用户信息 + @batch_content_params.merge!(author_email: current_user.mail, author_name: current_user.login) if batch_content_params[:author_email].blank? && batch_content_params[:author_name].blank? + @batch_content_params.merge!(committer_email: current_user.mail, committer_name: current_user.login) if batch_content_params[:committer_email].blank? && batch_content_params[:committer_name].blank? + @result_object = Api::V1::Projects::Contents::BatchCreateService.call(@project, @batch_content_params, current_user&.gitea_token) puts @result_object end diff --git a/app/docs/slate/source/includes/_repositories.md b/app/docs/slate/source/includes/_repositories.md index a07f2351..a9fa42e2 100644 --- a/app/docs/slate/source/includes/_repositories.md +++ b/app/docs/slate/source/includes/_repositories.md @@ -1126,21 +1126,21 @@ await octokit.request('POST /api/v1/yystopf/ceshi/contents/batch.json') ### 请求参数: 参数 | 必选 | 默认 | 类型 | 字段说明 --------- | ------- | ------- | -------- | ---------- -|owner |是| |string |用户登录名 | -|repo |是| |string |项目标识identifier | -|files.action_type |是| |string|操作类型 create: 创建 update: 更新 delete: 删除| -|files.content |是| |string|文件内容| -|files.encoding |是| |string|文件编码方式 text 文本 base64 加密| -|files.file_path |是| |string|文件路径| -|author_email |是| |string|作者邮箱| -|author_name |是| |string|作者名称| -|author_timeunix |是| |int|编码时间,精确到秒| -|committer_email |是| |string|提交者邮箱| -|committer_name |是| |string|提交者名称| -|committer_timeunix|是| |int|提交时间戳,精确到秒| -|branch |是| |string|提交分支| -|new_branch |否| |string|如果需要创建新分支,这个需要填| -|message |是| |string|提交信息| +|owner |是| |string |用户登录名 | +|repo |是| |string |项目标识identifier | +|files.action_type |是| |string|操作类型 create: 创建 update: 更新 delete: 删除| +|files.content |是| |string|文件内容| +|files.encoding |是| |string|文件编码方式 text 文本 base64 加密| +|files.file_path |是| |string|文件路径| +|author_email |否| 当前用户邮箱 |string|作者邮箱,不填时需要与作者名称同时为空| +|author_name |否| 当前用户标识 |string|作者名称,不填时需要与作者邮箱同时为空| +|author_timeunix |否| 当前时间戳 |int|编码时间,精确到秒| +|committer_email |否| 当前用户邮箱 |string|提交者邮箱,不填时需要与提交者名称同时为空| +|committer_name |否| 当前用户标识 |string|提交者名称,不填时需要与提交者邮箱同时为空| +|committer_timeunix|否| 当前时间戳 |int|提交时间戳,精确到秒| +|branch |是| |string|提交分支| +|new_branch |否| |string|如果需要创建新分支,这个需要填| +|message |是| |string|提交信息| > 请求的JSON示例: diff --git a/app/services/api/v1/projects/contents/batch_create_service.rb b/app/services/api/v1/projects/contents/batch_create_service.rb index 5fa88011..464f8eec 100644 --- a/app/services/api/v1/projects/contents/batch_create_service.rb +++ b/app/services/api/v1/projects/contents/batch_create_service.rb @@ -20,11 +20,11 @@ class Api::V1::Projects::Contents::BatchCreateService < ApplicationService @files = params[:files] @author_email = params[:author_email] @author_name = params[:author_name] - @author_timeunix = params[:author_timeunix] + @author_timeunix = params[:author_timeunix] || Time.now.to_i @branch = params[:branch] @committer_email = params[:committer_email] @committer_name = params[:committer_name] - @committer_timeunix = params[:committer_timeunix] + @committer_timeunix = params[:committer_timeunix] || Time.now.to_i @message = params[:message] @new_branch = params[:new_branch] end diff --git a/public/docs/api.html b/public/docs/api.html index 50b1c12a..bcc4da5c 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -9164,43 +9164,43 @@ http://localhost:3000/api/v1/yystopf/ceshi/contents/batch.json author_email -是 - +否 +当前用户邮箱 string -作者邮箱 +作者邮箱,不填时需要与作者名称同时为空 author_name -是 - +否 +当前用户标识 string -作者名称 +作者名称,不填时需要与作者邮箱同时为空 author_timeunix -是 - +否 +当前时间戳 int 编码时间,精确到秒 committer_email -是 - +否 +当前用户邮箱 string -提交者邮箱 +提交者邮箱,不填时需要与提交者名称同时为空 committer_name -是 - +否 +当前用户标识 string -提交者名称 +提交者名称,不填时需要与提交者邮箱同时为空 committer_timeunix -是 - +否 +当前时间戳 int 提交时间戳,精确到秒 From d5c141f89207a8b22c3eebfa43be9d3b5ec18703 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 28 Jul 2022 15:19:31 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Apulls=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9load?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/{ => pulls}/pulls_controller.rb | 2 +- app/services/api/v1/projects/contents/batch_create_service.rb | 2 +- app/views/api/v1/projects/pulls/{ => pulls}/index.json.jbuilder | 0 app/views/api/v1/projects/pulls/{ => pulls}/show.json.jbuilder | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename app/controllers/api/v1/projects/{ => pulls}/pulls_controller.rb (89%) rename app/views/api/v1/projects/pulls/{ => pulls}/index.json.jbuilder (100%) rename app/views/api/v1/projects/pulls/{ => pulls}/show.json.jbuilder (100%) diff --git a/app/controllers/api/v1/projects/pulls_controller.rb b/app/controllers/api/v1/projects/pulls/pulls_controller.rb similarity index 89% rename from app/controllers/api/v1/projects/pulls_controller.rb rename to app/controllers/api/v1/projects/pulls/pulls_controller.rb index c93cd8bd..1a7c574d 100644 --- a/app/controllers/api/v1/projects/pulls_controller.rb +++ b/app/controllers/api/v1/projects/pulls/pulls_controller.rb @@ -1,4 +1,4 @@ -class Api::V1::Projects::PullsController < Api::V1::BaseController +class Api::V1::Projects::Pulls::PullsController < Api::V1::BaseController before_action :require_public_and_member_above def index diff --git a/app/services/api/v1/projects/contents/batch_create_service.rb b/app/services/api/v1/projects/contents/batch_create_service.rb index 464f8eec..92bd30a9 100644 --- a/app/services/api/v1/projects/contents/batch_create_service.rb +++ b/app/services/api/v1/projects/contents/batch_create_service.rb @@ -86,7 +86,7 @@ class Api::V1::Projects::Contents::BatchCreateService < ApplicationService result = $gitea_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params} ) rescue nil raise Error, '查询分支名称失败!' unless result.is_a?(Hash) raise Error, '分支不存在!' unless result['branch_name'].include?(branch) - raise Error, '分支已存在!' if result['branch_name'].include?(new_branch) && new_branch.nil? + raise Error, '分支已存在!' if result['branch_name'].include?(new_branch) && !new_branch.nil? end end \ No newline at end of file diff --git a/app/views/api/v1/projects/pulls/index.json.jbuilder b/app/views/api/v1/projects/pulls/pulls/index.json.jbuilder similarity index 100% rename from app/views/api/v1/projects/pulls/index.json.jbuilder rename to app/views/api/v1/projects/pulls/pulls/index.json.jbuilder diff --git a/app/views/api/v1/projects/pulls/show.json.jbuilder b/app/views/api/v1/projects/pulls/pulls/show.json.jbuilder similarity index 100% rename from app/views/api/v1/projects/pulls/show.json.jbuilder rename to app/views/api/v1/projects/pulls/pulls/show.json.jbuilder