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

This commit is contained in:
“xxq250” 2022-07-28 16:46:27 +08:00
commit 321f367e3e
14 changed files with 119 additions and 47 deletions

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,29 @@
class MarkFilesController < ApplicationController
before_action :require_login
before_action :load_project
before_action :load_pull_request
def index
@files_result = Gitea::PullRequest::FilesService.call(@owner.login, @project.identifier, @pull_request.gitea_number, current_user&.gitea_token)
MarkFile.bulk_insert(*%i[pull_request_id, file_path_sha file_path created_at updated_at]) do |worker|
@files_result['Files'].echo do |file|
worker.add(pull_request_id: @pull_request.id, file_path_sha: SecureRandom.uuid.gsub("-", ""), file_path: file['Name'])
end
end
@mark_files = MarkFile.where(pull_request_id: @pull_request.id)
end
def create
end
private
def review_params
params.require(:review).permit(:content, :commit_id, :status)
end
def load_pull_request
@pull_request = @project.pull_requests.where(gitea_number: params[:id]).where.not(id: params[:id]).take || PullRequest.find_by_id(params[:id])
end
end

View File

@ -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示例:

5
app/models/mark_file.rb Normal file
View File

@ -0,0 +1,5 @@
class MarkFile < ApplicationRecord
belongs_to :pull_request
end

View File

@ -43,6 +43,7 @@ class PullRequest < ApplicationRecord
has_many :reviews, dependent: :destroy
has_many :pull_requests_reviewers, dependent: :destroy
has_many :reviewers, through: :pull_requests_reviewers
has_many :mark_files, dependent: :destroy
scope :merged_and_closed, ->{where.not(status: 0)}
scope :opening, -> {where(status: 0)}

View File

@ -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
@ -21,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
@ -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,15 +77,16 @@ 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)
raise Error, '提交文件失败!' unless @gitea_data.is_a?(Hash)
end
def check_branch_exist
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

View File

@ -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

View File

@ -0,0 +1,12 @@
json.status 0
json.message 'success'
json.count @mark_files.count
json.files do
json.array! @mark_files do |file|
json.sha file.file_path_sha
json.name file.file_path
json.mark_as_read file.mark_as_read
json.updated_after_read file.updated_after_read
end
end

View File

@ -556,7 +556,8 @@ Rails.application.routes.draw do
post :refuse_merge
get :files
get :commits
resources :reviews, only: [:create]
resources :reviews, only: [:create]
resources :mark_files, only: [:index, :create]
end
collection do
post :check_can_merge

View File

@ -0,0 +1,15 @@
class CreateMarkFiles < ActiveRecord::Migration[5.2]
def change
create_table :mark_files do |t|
t.references :pull_request
t.integer :user_id
t.string :file_path_sha
t.string :file_path
t.boolean :mark_as_read, default: false
t.boolean :updated_after_read, default: false
t.timestamps
end
add_index :mark_files, :file_path_sha
end
end

View File

@ -9184,43 +9184,43 @@ http://localhost:3000/api/v1/yystopf/ceshi/contents/batch.json
</tr>
<tr>
<td>author_email</td>
<td></td>
<td></td>
<td></td>
<td>当前用户邮箱</td>
<td>string</td>
<td>作者邮箱</td>
<td>作者邮箱,不填时需要与作者名称同时为空</td>
</tr>
<tr>
<td>author_name</td>
<td></td>
<td></td>
<td></td>
<td>当前用户标识</td>
<td>string</td>
<td>作者名称</td>
<td>作者名称,不填时需要与作者邮箱同时为空</td>
</tr>
<tr>
<td>author_timeunix</td>
<td></td>
<td></td>
<td></td>
<td>当前时间戳</td>
<td>int</td>
<td>编码时间,精确到秒</td>
</tr>
<tr>
<td>committer_email</td>
<td></td>
<td></td>
<td></td>
<td>当前用户邮箱</td>
<td>string</td>
<td>提交者邮箱</td>
<td>提交者邮箱,不填时需要与提交者名称同时为空</td>
</tr>
<tr>
<td>committer_name</td>
<td></td>
<td></td>
<td></td>
<td>当前用户标识</td>
<td>string</td>
<td>提交者名称</td>
<td>提交者名称,不填时需要与提交者邮箱同时为空</td>
</tr>
<tr>
<td>committer_timeunix</td>
<td></td>
<td></td>
<td></td>
<td>当前时间戳</td>
<td>int</td>
<td>提交时间戳,精确到秒</td>
</tr>