From fbbacfa9836fe12d34177fc3cdce7671bf8102d6 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 14 Jul 2022 09:36:52 +0800 Subject: [PATCH 01/29] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20apk=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=BA=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 998629c9d..27ed6d12b 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -10,7 +10,7 @@ module RepositoriesHelper end def download_type(str) - default_type = %w(xlsx xls ppt pptx pdf zip 7z rar exe pdb obj idb RData rdata doc docx mpp vsdx dot otf eot ttf woff woff2 mp4 mov wmv flv mpeg avi avchd webm mkv) + default_type = %w(xlsx xls ppt pptx pdf zip 7z rar exe pdb obj idb RData rdata doc docx mpp vsdx dot otf eot ttf woff woff2 mp4 mov wmv flv mpeg avi avchd webm mkv apk) default_type.include?(str&.downcase) || str.blank? end From a5d1058ea9f2061ad05af53b8d42d6e55e0a10c1 Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Thu, 14 Jul 2022 15:21:42 +0800 Subject: [PATCH 02/29] =?UTF-8?q?fixed=20=E6=8F=90=E4=BA=A4=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=AE=B0=E5=BD=95=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= =?UTF-8?q?,=E4=BB=93=E5=BA=93=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/commit_logs_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/commit_logs_controller.rb b/app/controllers/commit_logs_controller.rb index 0064d2f07..c02d199b0 100644 --- a/app/controllers/commit_logs_controller.rb +++ b/app/controllers/commit_logs_controller.rb @@ -13,7 +13,9 @@ class CommitLogsController < ApplicationController repository_id = params[:repository][:id] repository_name = params[:repository][:name] repository_full_name = params[:repository][:full_name] - project = Project.where(identifier: repository_name).where(user_id: user.id)&.first + owner_name = repository_full_name.split("/")[0] + owner = User.find_by(login: owner_name) + project = Project.where(identifier: repository_name).where(user_id: owner&.id)&.first project = Project.where(identifier: repository_name).where(gpid: repository_id)&.first if project.blank? CommitLog.create(user: user, project: project, repository_id: repository_id, name: repository_name, full_name: repository_full_name, From 4ed3a9d478f9c805eba1cb0438617cc7c10f1774 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 11 Jul 2022 18:50:13 +0800 Subject: [PATCH 03/29] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:cherry=20pick=20doorke?= =?UTF-8?q?eper=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/base_controller.rb | 19 ++++++++++++++----- config/initializers/doorkeeper.rb | 5 +++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/v1/base_controller.rb b/app/controllers/api/v1/base_controller.rb index 9170975b5..d97123f45 100644 --- a/app/controllers/api/v1/base_controller.rb +++ b/app/controllers/api/v1/base_controller.rb @@ -3,13 +3,22 @@ class Api::V1::BaseController < ApplicationController include Api::ProjectHelper include Api::UserHelper - before_action :doorkeeper_authorize! - skip_before_action :user_setup + # before_action :doorkeeper_authorize! + # skip_before_action :user_setup protected - def current_user - User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token - end + # def current_user + # #client方法对接,需要一直带着用户标识uid + # Rails.logger.info doorkeeper_token + # if doorkeeper_token && doorkeeper_token.resource_owner_id.blank? + # # return User.anonymous if params[:uid].nil? + # # tip_exception("2222") + # # return render_error('缺少用户标识!') if params[:uid].nil? + # User.current = User.find(params[:uid]) + # else + # User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token + # end + # end def require_manager_above @project = load_project diff --git a/config/initializers/doorkeeper.rb b/config/initializers/doorkeeper.rb index d80dcac68..512cb36ac 100644 --- a/config/initializers/doorkeeper.rb +++ b/config/initializers/doorkeeper.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true Doorkeeper.configure do + base_controller 'ApplicationController' # Change the ORM that doorkeeper will use (requires ORM extensions installed). # Check the list of supported ORMs here: https://github.com/doorkeeper-gem/doorkeeper#orms orm :active_record @@ -20,8 +21,8 @@ Doorkeeper.configure do access_token_generator '::Doorkeeper::JWT' admin_authenticator do - user = User.find_by_id(session[:www_user_id]) - unless user #&& user.admin_or_business? + user = current_user + unless user && user.admin_or_business? redirect_to root_url end end From 24d83133e7a3e562acdcd6556d89fa45d5529474 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 15 Jul 2022 14:02:48 +0800 Subject: [PATCH 04/29] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=20=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=88=86=E6=94=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- app/controllers/api/v1/base_controller.rb | 13 +++ .../api/v1/projects/branches_controller.rb | 19 +++++ app/controllers/application_controller.rb | 83 +++++++++++-------- .../concerns/api/project_helper.rb | 2 +- .../v1/projects/branches/all_list_service.rb | 27 ++++++ .../v1/projects/branches/create_service.rb | 47 +++++++++++ .../branches/_simple_detail.json.jbuilder | 4 + .../_simple_gitea_detail.json.jbuilder | 23 +++++ .../v1/projects/branches/all.json.jbuilder | 3 + .../v1/projects/branches/create.json.jbuilder | 1 + .../api/v1/users/_commit_user.json.jbuilder | 21 +++++ config/routes/api.rb | 5 ++ 13 files changed, 213 insertions(+), 37 deletions(-) create mode 100644 app/controllers/api/v1/projects/branches_controller.rb create mode 100644 app/services/api/v1/projects/branches/all_list_service.rb create mode 100644 app/services/api/v1/projects/branches/create_service.rb create mode 100644 app/views/api/v1/projects/branches/_simple_detail.json.jbuilder create mode 100644 app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder create mode 100644 app/views/api/v1/projects/branches/all.json.jbuilder create mode 100644 app/views/api/v1/projects/branches/create.json.jbuilder create mode 100644 app/views/api/v1/users/_commit_user.json.jbuilder diff --git a/Gemfile b/Gemfile index 175ca330c..091716e52 100644 --- a/Gemfile +++ b/Gemfile @@ -135,4 +135,4 @@ gem 'doorkeeper' gem 'doorkeeper-jwt' -gem 'gitea-client', '~> 0.8.2' \ No newline at end of file +gem 'gitea-client', '~> 0.9.1' \ No newline at end of file diff --git a/app/controllers/api/v1/base_controller.rb b/app/controllers/api/v1/base_controller.rb index d97123f45..9832ee112 100644 --- a/app/controllers/api/v1/base_controller.rb +++ b/app/controllers/api/v1/base_controller.rb @@ -20,8 +20,21 @@ class Api::V1::BaseController < ApplicationController # end # end + # 具有对仓库的管理权限 def require_manager_above @project = load_project return render_forbidden unless current_user.admin? && @project.manager?(current_user) end + + # 具有对仓库的操作权限 + def require_operate_above + @project = load_project + return render_forbidden unless current_user.admin? && @project.operator?(current_user) + end + + # 具有对仓库的访问权限 + def require_public_and_member_above + @project = load_project + return render_forbidden unless @project.is_public || (current_user.admin? && @project.member?(current_user)) + end end \ No newline at end of file diff --git a/app/controllers/api/v1/projects/branches_controller.rb b/app/controllers/api/v1/projects/branches_controller.rb new file mode 100644 index 000000000..d7f66d749 --- /dev/null +++ b/app/controllers/api/v1/projects/branches_controller.rb @@ -0,0 +1,19 @@ +class Api::V1::Projects::BranchesController < Api::V1::BaseController + before_action :require_public_and_member_above, only: [:index] + + def all + @result_object = Api::V1::Projects::Branches::AllListService.call(@project, current_user&.gitea_token) + end + + before_action :require_operate_above, only: [:create] + + def create + @result_object = Api::V1::Projects::Branches::CreateService.call(@project, branch_params, current_user&.gitea_token) + puts @result_object + end + + private + def branch_params + params.require(:branch).permit(:new_branch_name, :old_branch_name) + end +end \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f71a7501b..45a814a22 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -248,44 +248,57 @@ class ApplicationController < ActionController::Base #return if params[:controller] == "main" # Find the current user #Rails.logger.info("current_laboratory is #{current_laboratory} domain is #{request.subdomain}") - User.current = find_current_user - uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous")) - - # 开放课程通过链接访问的用户 - if !User.current.logged? && !params[:chinaoocTimestamp].blank? && !params[:websiteName].blank? && !params[:chinaoocKey].blank? - content = "#{OPENKEY}#{params[:websiteName]}#{params[:chinaoocTimestamp]}" - - if Digest::MD5.hexdigest(content) == params[:chinaoocKey] - user = open_class_user - if user - start_user_session(user) - set_autologin_cookie(user) + if request.headers["Authorization"].present? && request.headers["Authorization"].start_with?('Bearer') + tip_exception(401, "请登录后再操作!") unless valid_doorkeeper_token? + if @doorkeeper_token.present? + # client方法对接,需要一直带着用户标识uid + if @doorkeeper_token.resource_owner_id.blank? + tip_exception(-1, "缺少用户标识!") if params[:uid].nil? + User.current = User.find(params[:uid]) + else + User.current = User.find_by(id: @doorkeeper_token.resource_owner_id) end - User.current = user end + else + User.current = find_current_user + uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous")) + + # 开放课程通过链接访问的用户 + if !User.current.logged? && !params[:chinaoocTimestamp].blank? && !params[:websiteName].blank? && !params[:chinaoocKey].blank? + content = "#{OPENKEY}#{params[:websiteName]}#{params[:chinaoocTimestamp]}" + + if Digest::MD5.hexdigest(content) == params[:chinaoocKey] + user = open_class_user + if user + start_user_session(user) + set_autologin_cookie(user) + end + User.current = user + end + end + + # if !User.current.logged? && Rails.env.development? + # user = User.find 1 + # User.current = user + # start_user_session(user) + # end + + + # 测试版前端需求 + # logger.info("subdomain:#{request.subdomain}") + # if request.subdomain != "www" + # if params[:debug] == 'teacher' #todo 为了测试,记得讲debug删除 + # User.current = User.find 81403 + # elsif params[:debug] == 'student' + # User.current = User.find 8686 + # elsif params[:debug] == 'admin' + # logger.info "@@@@@@@@@@@@@@@@@@@@@@ debug mode....." + # user = User.find 36480 + # User.current = user + # cookies.signed[:user_id] = user.id + # end + # end end - - if !User.current.logged? && Rails.env.development? - user = User.find 1 - User.current = user - start_user_session(user) - end - - - # 测试版前端需求 - logger.info("subdomain:#{request.subdomain}") - # if request.subdomain != "www" - # if params[:debug] == 'teacher' #todo 为了测试,记得讲debug删除 - # User.current = User.find 81403 - # elsif params[:debug] == 'student' - # User.current = User.find 8686 - # elsif params[:debug] == 'admin' - # logger.info "@@@@@@@@@@@@@@@@@@@@@@ debug mode....." - # user = User.find 36480 - # User.current = user - # cookies.signed[:user_id] = user.id - # end - # end # User.current = User.find 81403 end diff --git a/app/controllers/concerns/api/project_helper.rb b/app/controllers/concerns/api/project_helper.rb index 0b444c488..52967e784 100644 --- a/app/controllers/concerns/api/project_helper.rb +++ b/app/controllers/concerns/api/project_helper.rb @@ -8,7 +8,7 @@ module Api::ProjectHelper @project, @owner = Project.find_with_namespace(namespace, repo) if @project - logger.info "###########:project not founded" + logger.info "###########:project founded" @project else logger.info "###########:project not found" diff --git a/app/services/api/v1/projects/branches/all_list_service.rb b/app/services/api/v1/projects/branches/all_list_service.rb new file mode 100644 index 000000000..fd942288f --- /dev/null +++ b/app/services/api/v1/projects/branches/all_list_service.rb @@ -0,0 +1,27 @@ +class Api::V1::Projects::Branches::AllListService < ApplicationService + + attr_accessor :project, :token, :owner, :repo + attr_accessor :gitea_data + + def initialize(project, token=nil) + @project = project + @owner = project&.owner.login + @repo = project&.identifier + @token = token + end + + def call + $gitea_client.token = token unless token.blank? + load_gitea_data + + $gitea_client.token = nil unless token.blank? + gitea_data + rescue + raise Error, "服务器错误,请联系系统管理员!" + end + + private + def load_gitea_data + @gitea_data = $gitea_client.get_repos_branch_name_set_by_owner_repo(owner, repo) + end +end \ No newline at end of file diff --git a/app/services/api/v1/projects/branches/create_service.rb b/app/services/api/v1/projects/branches/create_service.rb new file mode 100644 index 000000000..a4d9f854b --- /dev/null +++ b/app/services/api/v1/projects/branches/create_service.rb @@ -0,0 +1,47 @@ +class Api::V1::Projects::Branches::CreateService < ApplicationService + include ActiveModel::Model + + attr_accessor :project, :token, :owner, :repo, :old_branch_name, :new_branch_name + attr_accessor :gitea_data + + validates :new_branch_name, :old_branch_name, presence: :true + + def initialize(project, params, token=nil) + @project = project + @owner = project&.owner.login + @repo = project&.identifier + @new_branch_name = params[:new_branch_name] + @old_branch_name = params[:old_branch_name] + @token = token + end + + def call + raise Error, errors.full_messages.join(",") unless valid? + $gitea_client.token = token unless token.blank? + + check_new_branch_exist + excute_data_to_gitea + + $gitea_client.token = nil unless token.blank? + gitea_data + end + + private + def request_body + { + new_branch_name: new_branch_name, + old_branch_name: old_branch_name, + } + end + + def excute_data_to_gitea + @gitea_data = $gitea_client.post_repos_branches_by_owner_repo(owner, repo, {body: request_body.to_json}) + raise Error, '创建分支失败!' unless @gitea_data.is_a?(Hash) + end + + def check_new_branch_exist + result = $gitea_client.get_repos_branch_name_set_by_owner_repo(owner, repo) + raise Error, '查询分支名称失败!' unless result.is_a?(Hash) + raise Error, '分支已存在!' if result['branch_name'].include?(@new_branch_name) + end +end \ No newline at end of file diff --git a/app/views/api/v1/projects/branches/_simple_detail.json.jbuilder b/app/views/api/v1/projects/branches/_simple_detail.json.jbuilder new file mode 100644 index 000000000..b1e407a9b --- /dev/null +++ b/app/views/api/v1/projects/branches/_simple_detail.json.jbuilder @@ -0,0 +1,4 @@ +json.name branch +json.http_url render_http_url(@project) +json.zip_url render_zip_url(@owner, @project.repository, branch) +json.tar_url render_tar_url(@owner, @project.repository, branch) \ No newline at end of file diff --git a/app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder b/app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder new file mode 100644 index 000000000..9fee552d4 --- /dev/null +++ b/app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder @@ -0,0 +1,23 @@ +json.name branch['name'] +json.commit do + json.id branch['commit']['id'] + json.message branch['commit']['message'] + json.author do + + json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(branch['commit']['author']), name: branch['commit']['author']['name'] } + end + + json.committer do + json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(branch['commit']['committer']), name: branch['commit']['committer']['name'] } + end + json.time_ago time_from_now(branch['commit']['timestamp'].to_time) + json.timestamp branch['commit']['timestamp'] +end + +json.protected branch['protected'] +json.user_can_push branch['user_can_push'] +json.user_can_merge branch['user_can_merge'] +json.commit_id branch['commit_id'] +json.commit_time_from_now branch['commit_time'] +json.commit_time branch['commit_time'] +json.default_branch branch['default_branch'] \ No newline at end of file diff --git a/app/views/api/v1/projects/branches/all.json.jbuilder b/app/views/api/v1/projects/branches/all.json.jbuilder new file mode 100644 index 000000000..d89b1ee16 --- /dev/null +++ b/app/views/api/v1/projects/branches/all.json.jbuilder @@ -0,0 +1,3 @@ +json.array! @result_object["branch_name"] do |branch| + json.partial! "api/v1/projects/branches/simple_detail", branch: branch +end \ No newline at end of file diff --git a/app/views/api/v1/projects/branches/create.json.jbuilder b/app/views/api/v1/projects/branches/create.json.jbuilder new file mode 100644 index 000000000..eed860b81 --- /dev/null +++ b/app/views/api/v1/projects/branches/create.json.jbuilder @@ -0,0 +1 @@ +json.partial! "api/v1/projects/branches/simple_gitea_detail", branch: @result_object diff --git a/app/views/api/v1/users/_commit_user.json.jbuilder b/app/views/api/v1/users/_commit_user.json.jbuilder new file mode 100644 index 000000000..83935709a --- /dev/null +++ b/app/views/api/v1/users/_commit_user.json.jbuilder @@ -0,0 +1,21 @@ +if user.present? + if user.is_a?(Hash) + json.id user["id"] + json.login user["login"] + json.name user["name"] + json.type user["type"] + json.image_url user["avatar_url"] + else + json.id user.id + json.login user.login + json.name user.real_name + json.type user&.type + json.image_url url_to_avatar(user) + end +else + json.id nil + json.login name + json.name name + json.type nil + json.image_url User::Avatar.get_letter_avatar_url(name) +end diff --git a/config/routes/api.rb b/config/routes/api.rb index 32acdabd4..c969302ba 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -23,6 +23,11 @@ defaults format: :json do get :hooktasks end end + resources :branches, only:[:index, :create] do + collection do + get :all + end + end end end From b8d4b15b40b98688715ab287c798017e6967c6fb Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 15 Jul 2022 14:40:35 +0800 Subject: [PATCH 05/29] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=20=E5=88=86=E6=94=AF?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/branches_controller.rb | 3 +- .../slate/source/includes/_repositories.md | 99 ++++++++++++++++++- .../v1/projects/branches/all_list_service.rb | 3 +- .../_simple_gitea_detail.json.jbuilder | 7 +- 4 files changed, 101 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/v1/projects/branches_controller.rb b/app/controllers/api/v1/projects/branches_controller.rb index d7f66d749..bc4919616 100644 --- a/app/controllers/api/v1/projects/branches_controller.rb +++ b/app/controllers/api/v1/projects/branches_controller.rb @@ -1,5 +1,5 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController - before_action :require_public_and_member_above, only: [:index] + before_action :require_public_and_member_above, only: [:all] def all @result_object = Api::V1::Projects::Branches::AllListService.call(@project, current_user&.gitea_token) @@ -9,7 +9,6 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController def create @result_object = Api::V1::Projects::Branches::CreateService.call(@project, branch_params, current_user&.gitea_token) - puts @result_object end private diff --git a/app/docs/slate/source/includes/_repositories.md b/app/docs/slate/source/includes/_repositories.md index f0a64a60d..624afd5b1 100644 --- a/app/docs/slate/source/includes/_repositories.md +++ b/app/docs/slate/source/includes/_repositories.md @@ -409,21 +409,21 @@ await octokit.request('GET /api/yystopf/csfjkkj/tags.json') ``` -## 仓库分支列表 -仓库分支列表 +## 仓库所有分支列表 +仓库所有分支列表 > 示例: ```shell -curl -X GET http://localhost:3000/api/yystopf/csfjkkj/branches.json +curl -X GET http://localhost:3000/api/v1/yystopf/csfjkkj/branches/all.json ``` ```javascript -await octokit.request('GET /api/yystopf/csfjkkj/branches.json') +await octokit.request('GET /api/v1/yystopf/csfjkkj/branches/all.json') ``` ### HTTP 请求 -`GET /api/:owner/:repo/branches.json` +`GET /api/v1/:owner/:repo/branches/all.json` ### 请求参数: 参数 | 必选 | 默认 | 类型 | 字段说明 @@ -466,6 +466,95 @@ await octokit.request('GET /api/yystopf/csfjkkj/branches.json') ] ``` +## 仓库创建分支 +为仓库创建一个新的分支 + +> 示例: + +```shell +curl -X POST http://localhost:3000/api/v1/yystopf/csfjkkj/branches.json +``` + +```javascript +await octokit.request('POST /api/v1/yystopf/csfjkkj/branches.json') +``` + +### HTTP 请求 +`POST /api/v1/:owner/:repo/branches.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|owner |是| |string |用户登录名 | +|repo |是| |string |项目标识identifier | +|new_branch_name|是||string| 新分支名称| +|old_branch_name|否||string| 来源分支名称| + +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|name |string|分支名称| +|commit.id |string|提交ID| +|commit.message |string|提交信息| +|commit.author.id |string|提交作者ID| +|commit.author.login |string|提交作者标识| +|commit.author.name |string|提交作者名称| +|commit.author.type |string|提交作者类型| +|commit.committer.id |string|提交者ID| +|commit.committer.login |string|提交者标识| +|commit.committer.name |string|提交者名称| +|commit.committer.type |string|提交者类型| +|commit.committer.image_url|string|提交者头像| +|commit.time_ago |string|分支最新提交时间距现在时间差| +|commit.timestamp |string|分支最新提交时间| +|protected |bool |是否为保护分支| +|user_can_push |bool |当前用户是否能提交| +|user_can_merge |bool |当前用户是否能合并| +|commit_id |string|提交ID| +|commit_time_from_now |string|分支最新提交时间距现在时间差| +|commit_time |string|分支最新提交时间| +|http_url |string|分支http地址| +|zip_url |string|分支zip包下载地址| +|tar_url |string|分支tar包下载地址| + +> 返回的JSON示例: + +```json +{ + "name": "new_branch_8", + "commit": { + "id": "80dd40214a58622312393b2ae693756a4781fab2", + "message": "x拟增\n\nSigned-off-by: yystopf ", + "author": { + "id": "2", + "login": "yystopf", + "name": "heh", + "type": "User", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "committer": { + "id": "2", + "login": "yystopf", + "name": "heh", + "type": "User", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "time_ago": "1天前", + "timestamp": "2022-07-13T09:54:15Z" + }, + "protected": false, + "user_can_push": true, + "user_can_merge": true, + "commit_id": "80dd40214a58622312393b2ae693756a4781fab2", + "commit_time_from_now": "1天前", + "commit_time": "2022-07-13T09:54:15Z", + "default_branch": "master", + "http_url": "http://127.0.0.1:10081/yystopf/ceshi_hook.git", + "zip_url": "http://localhost:3000/api/yystopf/ceshi_hook/archive/new_branch_8.zip", + "tar_url": "http://localhost:3000/api/yystopf/ceshi_hook/archive/new_branch_8.tar.gz" +} +``` + ## 仓库贡献者列表 仓库贡献者列表 diff --git a/app/services/api/v1/projects/branches/all_list_service.rb b/app/services/api/v1/projects/branches/all_list_service.rb index fd942288f..9e97b6dd2 100644 --- a/app/services/api/v1/projects/branches/all_list_service.rb +++ b/app/services/api/v1/projects/branches/all_list_service.rb @@ -16,12 +16,11 @@ class Api::V1::Projects::Branches::AllListService < ApplicationService $gitea_client.token = nil unless token.blank? gitea_data - rescue - raise Error, "服务器错误,请联系系统管理员!" end private def load_gitea_data @gitea_data = $gitea_client.get_repos_branch_name_set_by_owner_repo(owner, repo) + raise Error, '获取所有分支失败!' unless @gitea_data.is_a?(Hash) end end \ No newline at end of file diff --git a/app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder b/app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder index 9fee552d4..70fac8238 100644 --- a/app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder +++ b/app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder @@ -18,6 +18,9 @@ json.protected branch['protected'] json.user_can_push branch['user_can_push'] json.user_can_merge branch['user_can_merge'] json.commit_id branch['commit_id'] -json.commit_time_from_now branch['commit_time'] +json.commit_time_from_now time_from_now(branch['commit_time'].to_time) json.commit_time branch['commit_time'] -json.default_branch branch['default_branch'] \ No newline at end of file +json.default_branch branch['default_branch'] +json.http_url render_http_url(@project) +json.zip_url render_zip_url(@owner, @project.repository, branch['name']) +json.tar_url render_tar_url(@owner, @project.repository, branch['name']) \ No newline at end of file From bd3cbf33fd76713ff46d78de1243273368e9233a Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 15 Jul 2022 14:41:00 +0800 Subject: [PATCH 06/29] fix --- public/docs/api.html | 911 ++++++++++++++++++++++++++----------------- 1 file changed, 562 insertions(+), 349 deletions(-) diff --git a/public/docs/api.html b/public/docs/api.html index 86560740d..e9091591e 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -503,7 +503,10 @@ 仓库标签列表
  • - 仓库分支列表 + 仓库所有分支列表 +
  • +
  • + 仓库创建分支
  • 仓库贡献者列表 @@ -7798,16 +7801,16 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat } } ] -

    仓库分支列表

    -

    仓库分支列表

    +

    仓库所有分支列表

    +

    仓库所有分支列表

    示例:

    -
    curl -X GET http://localhost:3000/api/yystopf/csfjkkj/branches.json
    -
    await octokit.request('GET /api/yystopf/csfjkkj/branches.json')
    +
    curl -X GET http://localhost:3000/api/v1/yystopf/csfjkkj/branches/all.json
    +
    await octokit.request('GET /api/v1/yystopf/csfjkkj/branches/all.json')
     

    HTTP 请求

    -

    GET /api/:owner/:repo/branches.json

    +

    GET /api/v1/:owner/:repo/branches/all.json

    请求参数:

    @@ -7886,16 +7889,16 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat "tar_url": "http://localhost:3000/api/yystopf/hahahah/archive/touch-100.tar.gz" } ] -

    仓库贡献者列表

    -

    仓库贡献者列表

    +

    仓库创建分支

    +

    为仓库创建一个新的分支

    示例:

    -
    curl -X GET http://localhost:3000/api/yystopf/csfjkkj/contributors.json
    -
    await octokit.request('GET /api/yystopf/csfjkkj/contributors.json')
    +
    curl -X POST http://localhost:3000/api/v1/yystopf/csfjkkj/branches.json
    +
    await octokit.request('POST /api/v1/yystopf/csfjkkj/branches.json')
     

    HTTP 请求

    -

    GET /api/:owner/:repo/contributors.json

    +

    POST /api/v1/:owner/:repo/branches.json

    请求参数:

    @@ -7920,6 +7923,20 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat + + + + + + + + + + + + + +
    string 项目标识identifier
    new_branch_name是||string新分支名称
    old_branch_name否|string来源分支名称

    返回字段说明:

    @@ -7930,6 +7947,202 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    namestring分支名称
    commit.idstring提交ID
    commit.messagestring提交信息
    commit.author.idstring提交作者ID
    commit.author.loginstring提交作者标识
    commit.author.namestring提交作者名称
    commit.author.typestring提交作者类型
    commit.committer.idstring提交者ID
    commit.committer.loginstring提交者标识
    commit.committer.namestring提交者名称
    commit.committer.typestring提交者类型
    commit.committer.image_urlstring提交者头像
    commit.time_agostring分支最新提交时间距现在时间差
    commit.timestampstring分支最新提交时间
    protectedbool是否为保护分支
    user_can_pushbool当前用户是否能提交
    user_can_mergebool当前用户是否能合并
    commit_idstring提交ID
    commit_time_from_nowstring分支最新提交时间距现在时间差
    commit_timestring分支最新提交时间
    http_urlstring分支http地址
    zip_urlstring分支zip包下载地址
    tar_urlstring分支tar包下载地址
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "name": "new_branch_8",
    +    "commit": {
    +        "id": "80dd40214a58622312393b2ae693756a4781fab2",
    +        "message": "x拟增\n\nSigned-off-by: yystopf <yystopf@163.com>",
    +        "author": {
    +            "id": "2",
    +            "login": "yystopf",
    +            "name": "heh",
    +            "type": "User",
    +            "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +        },
    +        "committer": {
    +            "id": "2",
    +            "login": "yystopf",
    +            "name": "heh",
    +            "type": "User",
    +            "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +        },
    +        "time_ago": "1天前",
    +        "timestamp": "2022-07-13T09:54:15Z"
    +    },
    +    "protected": false,
    +    "user_can_push": true,
    +    "user_can_merge": true,
    +    "commit_id": "80dd40214a58622312393b2ae693756a4781fab2",
    +    "commit_time_from_now": "1天前",
    +    "commit_time": "2022-07-13T09:54:15Z",
    +    "default_branch": "master",
    +    "http_url": "http://127.0.0.1:10081/yystopf/ceshi_hook.git",
    +    "zip_url": "http://localhost:3000/api/yystopf/ceshi_hook/archive/new_branch_8.zip",
    +    "tar_url": "http://localhost:3000/api/yystopf/ceshi_hook/archive/new_branch_8.tar.gz"
    +}
    +

    仓库贡献者列表

    +

    仓库贡献者列表

    + +
    +

    示例:

    +
    +
    curl -X GET http://localhost:3000/api/yystopf/csfjkkj/contributors.json
    +
    await octokit.request('GET /api/yystopf/csfjkkj/contributors.json')
    +

    HTTP 请求

    +

    GET /api/:owner/:repo/contributors.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    +

    返回字段说明:

    + + + + + + + + @@ -7986,9 +8199,9 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat
    curl -X GET http://localhost:3000/api/yystopf/csfjkkj/languages.json
     
    await octokit.request('GET /api/yystopf/csfjkkj/languages.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/languages.json

    -

    请求参数:

    +

    请求参数:

    参数类型字段说明
    list.contributions int 贡献者commit数量
    @@ -8013,7 +8226,7 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat
    参数项目标识identifier
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -8050,9 +8263,9 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat
    curl -X GET http://localhost:3000/api/jasder/jasder_test/edit.json
     
    await octokit.request('GET /api/jasder/jasder_test/edit.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/edit.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -8077,7 +8290,7 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat
    参数项目标识identifier
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -8154,9 +8367,9 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat -d"private=true"\ http://localhost:3000/api/jasder/jasder_test.json
    await octokit.request('PATCH /api/jasder/jasder_test.json')
    -

    HTTP 请求

    +

    HTTP 请求

    PATCH /api/:owner/:repo

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -8216,7 +8429,7 @@ http://localhost:3000/api/jasder/jasder_test.json
    参数项目是否私有, true:为私有,false: 公开,默认为公开
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -8281,9 +8494,9 @@ http://localhost:3000/api/jasder/jasder_test.json
    curl -X DELETE http://localhost:3000/api/jasder/jasder_test.json
     
    await octokit.request('DELETE /api/jasder/jasder_test.json')
    -

    HTTP 请求

    +

    HTTP 请求

    PATCH /api/:owner/:repo

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -8308,7 +8521,7 @@ http://localhost:3000/api/jasder/jasder_test.json
    参数项目标识identifier
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -8349,83 +8562,8 @@ http://localhost:3000/api/jasder/jasder_test.json -d"user_id=12"\ http://localhost:3000/api/jasder/jasder_test/collaborators.json
    await octokit.request('POST /api/jasder/jasder_test/collaborators.json')
    -

    HTTP 请求

    -

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

    -

    请求参数:

    -
    参数
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    user_idint用户id
    -

    返回字段说明:

    - - - - - - - - - - - - - - - - - -
    参数类型字段说明
    statusint返回状态, 0: 表示操作成功
    messagestring返回信息说明
    - -
    -

    返回的JSON示例:

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

    删除仓库成员

    -

    仓库中删除成员操作

    - -
    -

    示例:

    -
    -
    curl -X DELETE \
    --d "user_id=12" \
    -http://localhost:3000/api/jasder/jasder_test/collaborators.json
    -
    await octokit.request('DELETE /api/jasder/jasder_test/collaborators.json')
     

    HTTP 请求

    -

    DELETE /api/:owner/:repo/collaborators.json

    +

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

    请求参数:

    @@ -8478,6 +8616,81 @@ http://localhost:3000/api/jasder/jasder_test/collaborators.json
    +
    +

    返回的JSON示例:

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

    删除仓库成员

    +

    仓库中删除成员操作

    + +
    +

    示例:

    +
    +
    curl -X DELETE \
    +-d "user_id=12" \
    +http://localhost:3000/api/jasder/jasder_test/collaborators.json
    +
    await octokit.request('DELETE /api/jasder/jasder_test/collaborators.json')
    +

    HTTP 请求

    +

    DELETE /api/:owner/:repo/collaborators.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    user_idint用户id
    +

    返回字段说明:

    + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    statusint返回状态, 0: 表示操作成功
    messagestring返回信息说明
    +

    返回的JSON示例:

    @@ -8500,9 +8713,9 @@ http://localhost:3000/api/jasder/jasder_test/collaborators.json -d "role=Developer" \ http://localhost:3000/api/jasder/jasder_test/change_role.json
    await octokit.request('PUT /api/jasder/jasder_test/change_role.json')
    -

    HTTP 请求

    +

    HTTP 请求

    PUT /api/:owner/:repo/change_role.json

    -

    请求参数:

    +

    请求参数:

    @@ -8541,7 +8754,7 @@ http://localhost:3000/api/jasder/jasder_test/change_role.json
    参数取值范围:"Manager", "Developer", "Reporter";分别为项目管理人员(拥有所有操作权限)、项目开发人员(只拥有读写权限)、项目报告人员(只拥有读权限)
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -8583,9 +8796,9 @@ http://localhost:3000/api/jasder/jasder_test/change_role.json -d"limit=5"\ http://localhost:3000/api/jasder/jasder_test/collaborators.json
    await octokit.request('GET /api/jasder/jasder_test/collaborators.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/collaborators.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -8624,7 +8837,7 @@ http://localhost:3000/api/jasder/jasder_test/collaborators.json
    参数每页多少条数据,默认15条
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -8712,9 +8925,9 @@ http://localhost:3000/api/jasder/jasder_test/collaborators.json -d"ref=develop"\ http://localhost:3000/api/yystopf/ceshi/files.json
    await octokit.request('GET /api/yystopf/ceshi/files.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/files

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -8753,7 +8966,7 @@ http://localhost:3000/api/yystopf/ceshi/files.json
    参数分支名,默认为仓库默认分支
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -8835,9 +9048,9 @@ http://localhost:3000/api/yystopf/ceshi/files.json -d"ref=develop"\ http://localhost:3000//api/jasder/jasder_test/entries.json
    await octokit.request('GET /api/jasder/jasder_test/entries.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/entries.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -8869,7 +9082,7 @@ http://localhost:3000//api/jasder/jasder_test/entries.json
    参数分支名称、tag名称或是提交记录id,默认为master分支
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -8983,9 +9196,9 @@ http://localhost:3000//api/jasder/jasder_test/entries.json -d"filepath=file"\ http://localhost:3000//api/jasder/jasder_test/sub_entries.json
    await octokit.request('GET /api/jasder/jasder_test/sub_entries.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/sub_entries.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -9024,7 +9237,7 @@ http://localhost:3000//api/jasder/jasder_test/sub_entries.json
    参数分支名称、tag名称或是提交记录id,默认为master分支
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -9121,9 +9334,9 @@ http://localhost:3000//api/jasder/jasder_test/sub_entries.json -d"filepath=lib"\ http://localhost:3000/api/yystopf/csfjkkj/readme.json
    await octokit.request('GET /api/yystopf/csfjkkj/readme.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/readme.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -9162,7 +9375,7 @@ http://localhost:3000/api/yystopf/csfjkkj/readme.json
    参数子目录名称,默认为空
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -9234,9 +9447,9 @@ http://localhost:3000/api/yystopf/csfjkkj/readme.json -d"filepath=lib"\ http://localhost:3000/api/yystopf/csfjkkj/contributors.json
    await octokit.request('GET /api/yystopf/csfjkkj/contributors.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/contributors.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -9275,7 +9488,7 @@ http://localhost:3000/api/yystopf/csfjkkj/contributors.json
    参数子目录名称,默认为空
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -9350,9 +9563,9 @@ http://localhost:3000/api/yystopf/csfjkkj/contributors.json
    curl -X GET \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
     
    await octokit.request('GET /api/v1/yystopf/ceshi/webhooks.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/webhooks.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -9377,7 +9590,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
    参数项目标识identifier
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -9470,9 +9683,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
    curl -X GET \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
     
    await octokit.request('GET /api/v1/yystopf/ceshi/webhooks/3.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/webhooks/:id.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -9504,7 +9717,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -9627,214 +9840,8 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
    curl -X POST \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
     
    await octokit.request('POST /api/v1/yystopf/ceshi/webhooks.json')
    -

    HTTP 请求

    -

    POST /api/v1/:owner/:repo/webhooks.json

    -

    请求参数:

    -
    参数
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    webhook.urlstring目标url
    webhook.http_methodstringhttp方法, POST和GET
    webhook.content_typestringPOST Content Type
    webhook.secretstring密钥文本
    webhook.activebool是否激活
    webhook.branch_filterstring分支过滤
    webhook.eventsarray触发事件
    - -

    触发事件字段说明

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数含义
    create创建分支或标签
    delete分支或标签删除
    pushgit仓库推送
    pull_request合并请求
    pull_request_assign合并请求被指派
    pull_request_review_approved合并请求被批准
    pull_request_review_rejected合并请求被拒绝
    - -
    -

    请求的JSON示例:

    -
    -
    {
    -    "active": true, 
    -    "content_type": "json",
    -    "http_method": "GET",
    -    "secret": "123456",
    -    "url": "http://localhost:10000",
    -    "branch_filter": "*",
    -    "events": ["push"]
    -}
    -

    返回字段说明:

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数类型字段说明
    idintid
    urlstring地址
    content_typestringPOST Content Type
    is_activebool是否激活
    typestring类型
    eventsarray触发事件
    create_timestring创建时间
    - -
    -

    返回的JSON示例:

    -
    -
    {
    -    "id": 68,
    -    "content_type": "json",
    -    "http_method": "GET",
    -    "url": "http://127.0.0.1:3000",
    -    "events": [
    -        "create",
    -        "delete",
    -        "push",
    -        "pull_request",
    -        "pull_request_assign",
    -        "pull_request_review_approved",
    -        "pull_request_review_rejected"
    -    ],
    -    "active": true,
    -    "branch_filter": "*",
    -    "created_at": "2022-06-23 15:52"
    -}
    -
    - -

    更新仓库webhook

    -

    更新仓库webhook

    - -
    -

    示例:

    -
    -
    curl -X PATCH \
    -http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    -
    await octokit.request('PATCH /api/v1/yystopf/ceshi/webhooks/7.json')
     

    HTTP 请求

    -

    PATCH /api/v1/:owner/:repo/webhooks/68.json

    +

    POST /api/v1/:owner/:repo/webhooks.json

    请求参数:

    @@ -9860,13 +9867,6 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json - - - - - - - @@ -9968,6 +9968,219 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json "events": ["push"] }

    返回字段说明:

    +
    项目标识identifier
    idstringwebhook id
    webhook.url
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    idintid
    urlstring地址
    content_typestringPOST Content Type
    is_activebool是否激活
    typestring类型
    eventsarray触发事件
    create_timestring创建时间
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "id": 68,
    +    "content_type": "json",
    +    "http_method": "GET",
    +    "url": "http://127.0.0.1:3000",
    +    "events": [
    +        "create",
    +        "delete",
    +        "push",
    +        "pull_request",
    +        "pull_request_assign",
    +        "pull_request_review_approved",
    +        "pull_request_review_rejected"
    +    ],
    +    "active": true,
    +    "branch_filter": "*",
    +    "created_at": "2022-06-23 15:52"
    +}
    +
    + +

    更新仓库webhook

    +

    更新仓库webhook

    + +
    +

    示例:

    +
    +
    curl -X PATCH \
    +http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    +
    await octokit.request('PATCH /api/v1/yystopf/ceshi/webhooks/7.json')
    +

    HTTP 请求

    +

    PATCH /api/v1/:owner/:repo/webhooks/68.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    idstringwebhook id
    webhook.urlstring目标url
    webhook.http_methodstringhttp方法, POST和GET
    webhook.content_typestringPOST Content Type
    webhook.secretstring密钥文本
    webhook.activebool是否激活
    webhook.branch_filterstring分支过滤
    webhook.eventsarray触发事件
    + +

    触发事件字段说明

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数含义
    create创建分支或标签
    delete分支或标签删除
    pushgit仓库推送
    pull_request合并请求
    pull_request_assign合并请求被指派
    pull_request_review_approved合并请求被批准
    pull_request_review_rejected合并请求被拒绝
    + +
    +

    请求的JSON示例:

    +
    +
    {
    +    "active": true, 
    +    "content_type": "json",
    +    "http_method": "GET",
    +    "secret": "123456",
    +    "url": "http://localhost:10000",
    +    "branch_filter": "*",
    +    "events": ["push"]
    +}
    +

    返回字段说明:

    返回的JSON示例:

    @@ -10002,9 +10215,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    curl -X DELETE \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
     
    await octokit.request('DELETE /api/v1/yystopf/ceshi/webhooks/7.json')
    -

    HTTP 请求

    +

    HTTP 请求

    DELETE /api/v1/:owner/:repo/webhooks/:id.json

    -

    请求参数:

    +

    请求参数:

    @@ -10036,7 +10249,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    参数webhook id
    -

    返回字段说明:

    +

    返回字段说明:

    返回的JSON示例:

    @@ -10057,9 +10270,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    curl -X GET \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
     
    await octokit.request('GET /api/v1/yystopf/ceshi/webhooks/3/hooktasks.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/webhooks/:id/hooktasks.json

    -

    请求参数:

    +

    请求参数:

    @@ -10091,7 +10304,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -10328,9 +10541,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
    curl -X POST \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/tests.json
     
    await octokit.request('POST /api/v1/yystopf/ceshi/webhooks/3/tests.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST /api/v1/:owner/:repo/webhooks/:id/tests.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -10362,7 +10575,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/tests.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    返回的JSON示例:

    From 0dd062ce1c294f34b653bd0ebe971b3aad728481 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 15 Jul 2022 17:03:18 +0800 Subject: [PATCH 07/29] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=20blobs=E5=92=8C?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=A0=91=E6=8E=A5=E5=8F=A3=E5=8F=8A=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/base_controller.rb | 7 + .../api/v1/projects/git_controller.rb | 12 + .../slate/source/includes/_repositories.md | 116 ++++++- .../api/v1/projects/git/blobs_service.rb | 30 ++ .../api/v1/projects/git/trees_service.rb | 50 +++ .../api/v1/projects/git/blobs.json.jbuilder | 4 + .../api/v1/projects/git/trees.json.jbuilder | 9 + config/routes/api.rb | 2 + public/docs/api.html | 286 ++++++++++++++++-- 9 files changed, 483 insertions(+), 33 deletions(-) create mode 100644 app/controllers/api/v1/projects/git_controller.rb create mode 100644 app/services/api/v1/projects/git/blobs_service.rb create mode 100644 app/services/api/v1/projects/git/trees_service.rb create mode 100644 app/views/api/v1/projects/git/blobs.json.jbuilder create mode 100644 app/views/api/v1/projects/git/trees.json.jbuilder diff --git a/app/controllers/api/v1/base_controller.rb b/app/controllers/api/v1/base_controller.rb index 9832ee112..a66bfc528 100644 --- a/app/controllers/api/v1/base_controller.rb +++ b/app/controllers/api/v1/base_controller.rb @@ -19,6 +19,13 @@ class Api::V1::BaseController < ApplicationController # User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token # end # end + + def limit + params.fetch(:limit, 15) + end + def page + params.fetch(:page, 1) + end # 具有对仓库的管理权限 def require_manager_above diff --git a/app/controllers/api/v1/projects/git_controller.rb b/app/controllers/api/v1/projects/git_controller.rb new file mode 100644 index 000000000..f30dce1a9 --- /dev/null +++ b/app/controllers/api/v1/projects/git_controller.rb @@ -0,0 +1,12 @@ +class Api::V1::Projects::GitController < Api::V1::BaseController + before_action :require_public_and_member_above, only: [:trees, :blobs] + + def trees + @result_object = Api::V1::Projects::Git::TreesService.call(@project, params[:sha], {recursive: params[:recursive], page: page, limit: limit}, current_user&.gitea_token) + end + + def blobs + @result_object = Api::V1::Projects::Git::BlobsService.call(@project, params[:sha], current_user&.gitea_token) + end + +end \ 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 624afd5b1..7da740efb 100644 --- a/app/docs/slate/source/includes/_repositories.md +++ b/app/docs/slate/source/includes/_repositories.md @@ -472,7 +472,10 @@ await octokit.request('GET /api/v1/yystopf/csfjkkj/branches/all.json') > 示例: ```shell -curl -X POST http://localhost:3000/api/v1/yystopf/csfjkkj/branches.json +curl -X POST \ +-d "new_branch_name=ceshi_branch_1" \ +-d "old_branch_name=master" \ +http://localhost:3000/api/v1/yystopf/csfjkkj/branches.json ``` ```javascript @@ -487,8 +490,8 @@ await octokit.request('POST /api/v1/yystopf/csfjkkj/branches.json') --------- | ------- | ------- | -------- | ---------- |owner |是| |string |用户登录名 | |repo |是| |string |项目标识identifier | -|new_branch_name|是||string| 新分支名称| -|old_branch_name|否||string| 来源分支名称| +|new_branch_name|是||string| 新分支名称| +|old_branch_name|否||string| 来源分支名称| ### 返回字段说明: 参数 | 类型 | 字段说明 @@ -1303,6 +1306,113 @@ await octokit.request('GET /api/yystopf/csfjkkj/readme.json') Success Data. + +## 获取文件树列表 +根据分支、标签、commit ID获取仓库文件树列表 + +> 示例: + +```shell +curl -X GET \ +-d "recursive=true" \ +-d "page=1" \ +-d "limit=1" \ +http://localhost:3000/api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae693756a4781fab2.json +``` + +```javascript +await octokit.request('GET /api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae693756a4781fab2.json') +``` + +### HTTP 请求 +`GET /api/v1/:owner/:repo/git/trees/:sha.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|owner |是| | string |用户登录名 | +|repo |是| | string |项目标识identifier | +|sha |是| | string |分支名称、tag名称或是提交记录id | +|recursive|否| | bool |是否显示目录| +|page |否|1 | int |页码| +|limit |否|15| int |分页个数| +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|total_count |int |文件树数量| +|sha |string |查询分支、标签、commit_id最后一次提交的ID | +|entries.name |string |文件树名称| +|entries.mode |string |文件树权限| +|entries.type |string |文件树类型, file:文件,dir: 文件夹| +|entries.size |int |文件树大小| +|entries.sha |string |文件树commit_ID| + + +> 返回的JSON示例: + +```json +{ + "total_count": 13, + "sha": "80dd40214a58622312393b2ae693756a4781fab2", + "entries": [ + { + "name": "README.md", + "mode": "100644", + "type": "file", + "size": 14, + "sha": "b2f7b457fd8ca55f2274032cbb2abcb7dd8cd57e" + } + ] +} +``` + + +## 获取仓库blobs内容 +根据commit ID获取仓库blobs内容 + +> 示例: + +```shell +curl -X GET http://localhost:3000/api/v1/yystopf/csfjkkj/git/blobs/80dd40214a58622312393b2ae693756a4781fab2.json +``` + +```javascript +await octokit.request('GET /api/v1/yystopf/csfjkkj/git/blobs/80dd40214a58622312393b2ae693756a4781fab2.json') +``` + +### HTTP 请求 +`GET /api/v1/:owner/:repo/git/blobs/:sha.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|owner|是| | string |用户登录名 | +|repo |是| | string |项目标识identifier | +|sha |是| | string |提交记录id | +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|sha |string |提交ID | +|size |int |blobs大小| +|encoding |string |内容编码模式| +|content |string |blobs内容| + +> 返回的JSON示例: + +```json +{ + "sha": "80dd40214a58622312393b2ae693756a4781fab2", + "size": 247, + "encoding": "base64", + "content": "dHJlZSAyN2JjYjI2ZDQ5YmU1M2RmOGZmYTk5NDc3MjRkYmI3YzIzZWI4MjY4CnBhcmVudCA3ZTRkOGJiM2MyOGUyNGQ0Y2Q2YjIwNWYyZWVkMzI1MTNlOTM3NTI0CmF1dGhvciB5eXN0b3BmIDx5eXN0b3BmQDE2My5jb20+IDE2NTc3MDYwNTUgKzAwMDAKY29tbWl0dGVyIHl5c3RvcGYgPHl5c3RvcGZAMTYzLmNvbT4gMTY1NzcwNjA1NSArMDAwMAoKeOaLn+WingoKU2lnbmVkLW9mZi1ieTogeXlzdG9wZiA8eXlzdG9wZkAxNjMuY29tPg==" +} +``` + + ## 获取仓库贡献者 获取仓库贡献者 diff --git a/app/services/api/v1/projects/git/blobs_service.rb b/app/services/api/v1/projects/git/blobs_service.rb new file mode 100644 index 000000000..0b197c106 --- /dev/null +++ b/app/services/api/v1/projects/git/blobs_service.rb @@ -0,0 +1,30 @@ +class Api::V1::Projects::Git::BlobsService < ApplicationService + include ActiveModel::Model + + attr_accessor :project, :sha, :token, :owner, :repo + attr_accessor :gitea_data + + validates :sha, presence: :true + + + def initialize(project, sha, token=nil) + @project = project + @owner = project&.owner.login + @repo = project&.identifier + @sha = sha + @token = token + end + + def call + $gitea_client.token = token unless token.blank? + load_gitea_data + + $gitea_client.token = nil unless token.blank? + gitea_data + end + + private + def load_gitea_data + @gitea_data = $gitea_client.get_repos_git_blobs_by_owner_repo_sha(owner, repo, sha) + end +end \ No newline at end of file diff --git a/app/services/api/v1/projects/git/trees_service.rb b/app/services/api/v1/projects/git/trees_service.rb new file mode 100644 index 000000000..2a72c11a5 --- /dev/null +++ b/app/services/api/v1/projects/git/trees_service.rb @@ -0,0 +1,50 @@ +class Api::V1::Projects::Git::TreesService < ApplicationService + include ActiveModel::Model + + attr_accessor :project, :token, :sha, :recursive, :page, :limit, :owner, :repo + attr_accessor :gitea_data + + validates :sha, presence: :true + validates :recursive, inclusion: {in: [nil, '', true, false]} + + def initialize(project, sha, params, token=nil) + @project = project + @owner = project&.owner.login + @repo = project&.identifier + @token = token + @sha = sha + @recursive = params[:recursive] + @page = params[:page] || 1 + @limit = params[:limit] || 15 + end + + def call + raise Error, errors.full_messages.join(", ") unless valid? + $gitea_client.token = token unless token.blank? + load_gitea_data + + $gitea_client.token = nil unless token.blank? + gitea_data + end + + private + def request_query + if recursive.present? + { + recursive: recursive, + page: page, + per_page: limit + } + else + { + page: page, + per_page: limit + } + end + end + + def load_gitea_data + @gitea_data = $gitea_client.get_repos_git_trees_by_owner_repo_sha(owner, repo, sha, {query: request_query}) + raise Error, '获取文件树列表失败!' unless @gitea_data.is_a?(Hash) + end +end \ No newline at end of file diff --git a/app/views/api/v1/projects/git/blobs.json.jbuilder b/app/views/api/v1/projects/git/blobs.json.jbuilder new file mode 100644 index 000000000..e5397e925 --- /dev/null +++ b/app/views/api/v1/projects/git/blobs.json.jbuilder @@ -0,0 +1,4 @@ +json.sha @result_object['sha'] +json.size @result_object['size'] +json.encoding @result_object['encoding'] +json.content @result_object['content'] \ No newline at end of file diff --git a/app/views/api/v1/projects/git/trees.json.jbuilder b/app/views/api/v1/projects/git/trees.json.jbuilder new file mode 100644 index 000000000..0eb08f048 --- /dev/null +++ b/app/views/api/v1/projects/git/trees.json.jbuilder @@ -0,0 +1,9 @@ +json.total_count @result_object['total_count'] +json.sha @result_object['sha'] +json.entries @result_object['tree'].each do |entry| + json.name entry['path'] + json.mode entry['mode'] + json.type entry['type'] === 'blob' ? 'file' : 'dir' + json.size entry['size'] + json.sha entry['sha'] +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index c969302ba..99684e6d9 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -28,6 +28,8 @@ defaults format: :json do get :all end end + get '/git/blobs/:sha', to: 'git#blobs' + get '/git/trees/:sha', to: 'git#trees' end end diff --git a/public/docs/api.html b/public/docs/api.html index e9091591e..6fedc946e 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -547,6 +547,12 @@
  • 获取仓库README文件
  • +
  • + 获取文件树列表 +
  • +
  • + 获取仓库blobs内容 +
  • 获取仓库贡献者
  • @@ -7895,7 +7901,10 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat

    示例:

    -
    curl -X POST http://localhost:3000/api/v1/yystopf/csfjkkj/branches.json
    +
    curl -X POST \
    +-d "new_branch_name=ceshi_branch_1" \
    +-d "old_branch_name=master" \
    +http://localhost:3000/api/v1/yystopf/csfjkkj/branches.json
     
    await octokit.request('POST /api/v1/yystopf/csfjkkj/branches.json')
     

    HTTP 请求

    POST /api/v1/:owner/:repo/branches.json

    @@ -7925,17 +7934,17 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat new_branch_name -是||string +是 + +string 新分支名称 - - old_branch_name -否| +否 + string 来源分支名称 -

    返回字段说明:

    @@ -9436,6 +9445,223 @@ http://localhost:3000/api/yystopf/csfjkkj/readme.json +

    获取文件树列表

    +

    根据分支、标签、commit ID获取仓库文件树列表

    + +
    +

    示例:

    +
    +
    curl -X GET \
    +-d "recursive=true" \
    +-d "page=1" \
    +-d "limit=1" \
    +http://localhost:3000/api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae693756a4781fab2.json
    +
    await octokit.request('GET /api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae693756a4781fab2.json')
    +

    HTTP 请求

    +

    GET /api/v1/:owner/:repo/git/trees/:sha.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    shastring分支名称、tag名称或是提交记录id
    recursivebool是否显示目录
    page1int页码
    limit15int分页个数
    +

    返回字段说明:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    total_countint文件树数量
    shastring查询分支、标签、commit_id最后一次提交的ID
    entries.namestring文件树名称
    entries.modestring文件树权限
    entries.typestring文件树类型, file:文件,dir: 文件夹
    entries.sizeint文件树大小
    entries.shastring文件树commit_ID
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "total_count": 13,
    +    "sha": "80dd40214a58622312393b2ae693756a4781fab2",
    +    "entries": [
    +        {
    +            "name": "README.md",
    +            "mode": "100644",
    +            "type": "file",
    +            "size": 14,
    +            "sha": "b2f7b457fd8ca55f2274032cbb2abcb7dd8cd57e"
    +        }
    +    ]
    +}
    +
    + +

    获取仓库blobs内容

    +

    根据commit ID获取仓库blobs内容

    + +
    +

    示例:

    +
    +
    curl -X GET http://localhost:3000/api/v1/yystopf/csfjkkj/git/blobs/80dd40214a58622312393b2ae693756a4781fab2.json
    +
    await octokit.request('GET /api/v1/yystopf/csfjkkj/git/blobs/80dd40214a58622312393b2ae693756a4781fab2.json')
    +

    HTTP 请求

    +

    GET /api/v1/:owner/:repo/git/blobs/:sha.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    shastring提交记录id
    +

    返回字段说明:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    shastring提交ID
    sizeintblobs大小
    encodingstring内容编码模式
    contentstringblobs内容
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "sha": "80dd40214a58622312393b2ae693756a4781fab2",
    +    "size": 247,
    +    "encoding": "base64",
    +    "content": "dHJlZSAyN2JjYjI2ZDQ5YmU1M2RmOGZmYTk5NDc3MjRkYmI3YzIzZWI4MjY4CnBhcmVudCA3ZTRkOGJiM2MyOGUyNGQ0Y2Q2YjIwNWYyZWVkMzI1MTNlOTM3NTI0CmF1dGhvciB5eXN0b3BmIDx5eXN0b3BmQDE2My5jb20+IDE2NTc3MDYwNTUgKzAwMDAKY29tbWl0dGVyIHl5c3RvcGYgPHl5c3RvcGZAMTYzLmNvbT4gMTY1NzcwNjA1NSArMDAwMAoKeOaLn+WingoKU2lnbmVkLW9mZi1ieTogeXlzdG9wZiA8eXlzdG9wZkAxNjMuY29tPg=="
    +}
    +
    +

    获取仓库贡献者

    获取仓库贡献者

    @@ -9447,9 +9673,9 @@ http://localhost:3000/api/yystopf/csfjkkj/readme.json -d "filepath=lib" \ http://localhost:3000/api/yystopf/csfjkkj/contributors.json
    await octokit.request('GET /api/yystopf/csfjkkj/contributors.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/contributors.json

    -

    请求参数:

    +

    请求参数:

    @@ -9488,7 +9714,7 @@ http://localhost:3000/api/yystopf/csfjkkj/contributors.json
    参数子目录名称,默认为空
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -9563,9 +9789,9 @@ http://localhost:3000/api/yystopf/csfjkkj/contributors.json
    curl -X GET \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
     
    await octokit.request('GET /api/v1/yystopf/ceshi/webhooks.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/webhooks.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -9590,7 +9816,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
    参数项目标识identifier
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -9683,9 +9909,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
    curl -X GET \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
     
    await octokit.request('GET /api/v1/yystopf/ceshi/webhooks/3.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/webhooks/:id.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -9717,7 +9943,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -9840,9 +10066,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
    curl -X POST \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
     
    await octokit.request('POST /api/v1/yystopf/ceshi/webhooks.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST /api/v1/:owner/:repo/webhooks.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -9967,7 +10193,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json "branch_filter": "*", "events": ["push"] } -

    返回字段说明:

    +

    返回字段说明:

    参数
    @@ -10046,9 +10272,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
    curl -X PATCH \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
     
    await octokit.request('PATCH /api/v1/yystopf/ceshi/webhooks/7.json')
    -

    HTTP 请求

    +

    HTTP 请求

    PATCH /api/v1/:owner/:repo/webhooks/68.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -10180,7 +10406,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json "branch_filter": "*", "events": ["push"] } -

    返回字段说明:

    +

    返回字段说明:

    返回的JSON示例:

    @@ -10215,9 +10441,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    curl -X DELETE \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
     
    await octokit.request('DELETE /api/v1/yystopf/ceshi/webhooks/7.json')
    -

    HTTP 请求

    +

    HTTP 请求

    DELETE /api/v1/:owner/:repo/webhooks/:id.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -10249,7 +10475,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    参数webhook id
    -

    返回字段说明:

    +

    返回字段说明:

    返回的JSON示例:

    @@ -10270,9 +10496,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    curl -X GET \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
     
    await octokit.request('GET /api/v1/yystopf/ceshi/webhooks/3/hooktasks.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/webhooks/:id/hooktasks.json

    -

    请求参数:

    +

    请求参数:

    @@ -10304,7 +10530,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -10541,9 +10767,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
    curl -X POST \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/tests.json
     
    await octokit.request('POST /api/v1/yystopf/ceshi/webhooks/3/tests.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST /api/v1/:owner/:repo/webhooks/:id/tests.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -10575,7 +10801,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/tests.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    返回的JSON示例:

    From ed0655452c1a00611cd95fd162d732e2e8902f32 Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Mon, 11 Jul 2022 15:52:38 +0800 Subject: [PATCH 08/29] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BB=8Ewebhook?= =?UTF-8?q?=E6=8E=A5=E6=94=B6=E4=BB=93=E5=BA=93=E6=97=A5=E5=BF=97=E8=AE=B0?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/commit_logs_controller.rb | 23 +++++++++++++++++++ app/models/commit_log.rb | 6 +++++ config/routes.rb | 2 ++ .../20220711061848_create_commit_logs.rb | 17 ++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 app/controllers/commit_logs_controller.rb create mode 100644 app/models/commit_log.rb create mode 100644 db/migrate/20220711061848_create_commit_logs.rb diff --git a/app/controllers/commit_logs_controller.rb b/app/controllers/commit_logs_controller.rb new file mode 100644 index 000000000..71eada879 --- /dev/null +++ b/app/controllers/commit_logs_controller.rb @@ -0,0 +1,23 @@ +class CommitLogsController < ApplicationController + + def create + tip_exception "未认证" unless params[:token].to_s == "7917908927b6f1b792f2027a08a8b24a2de42c1692c2fd45da0dee5cf90a5af5" + ref = params[:ref] + commit_id = params[:commits][0][:id] + message = params[:commits][0][:message] + user_name = params[:message][0][:committer][:username] + user_mail = params[:message][0][:committer][:email] + user = User.find_by(mail: user_mail) + user = User.find_by(login: user_name) if user.blank? + + repository_id = params[:repository][:id] + repository_name = params[:repository][:name] + repository_full_name = params[:repository][:full_name] + project = Project.where(identifier: repository_name).where(user_id: user.id)&.first + project = Project.where(identifier: repository_name).where(gpid: repository_id)&.first if project.blank? + CommitLog.create(user: user, project: project, repository_id: repository_id, + name: repository_name, full_name: repository_full_name, + ref: ref, commit_id: commit_id, message: message) + + end +end diff --git a/app/models/commit_log.rb b/app/models/commit_log.rb new file mode 100644 index 000000000..9b51b0631 --- /dev/null +++ b/app/models/commit_log.rb @@ -0,0 +1,6 @@ +class CommitLog < ApplicationRecord + belongs_to :user + belongs_to :project + belongs_to :repository + +end diff --git a/config/routes.rb b/config/routes.rb index 79b937b00..73e06ea53 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -973,6 +973,8 @@ Rails.application.routes.draw do get 'oauth/get_code', to: 'oauth#get_code' get 'oauth/get_token_callback', to: 'oauth#get_token_callback' + resources :commit_logs, :only => [:create] + root 'main#index' diff --git a/db/migrate/20220711061848_create_commit_logs.rb b/db/migrate/20220711061848_create_commit_logs.rb new file mode 100644 index 000000000..e0ef451af --- /dev/null +++ b/db/migrate/20220711061848_create_commit_logs.rb @@ -0,0 +1,17 @@ +class CreateCommitLogs < ActiveRecord::Migration[5.2] + def change + create_table :commit_logs do |t| + t.references :user + t.references :project + t.integer :repository_id + t.string :name + t.string :full_name + t.string :commit_id + t.string :ref + t.string :message + t.timestamps + end + + add_index :commit_logs, :commit_id + end +end From 5fcf789e63c544eabd364f6976e570489cd39d0c Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Thu, 14 Jul 2022 15:21:42 +0800 Subject: [PATCH 09/29] =?UTF-8?q?fixed=20=E6=8F=90=E4=BA=A4=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=AE=B0=E5=BD=95=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= =?UTF-8?q?,=E4=BB=93=E5=BA=93=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/commit_logs_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/commit_logs_controller.rb b/app/controllers/commit_logs_controller.rb index 71eada879..1708b162b 100644 --- a/app/controllers/commit_logs_controller.rb +++ b/app/controllers/commit_logs_controller.rb @@ -13,7 +13,9 @@ class CommitLogsController < ApplicationController repository_id = params[:repository][:id] repository_name = params[:repository][:name] repository_full_name = params[:repository][:full_name] - project = Project.where(identifier: repository_name).where(user_id: user.id)&.first + owner_name = repository_full_name.split("/")[0] + owner = User.find_by(login: owner_name) + project = Project.where(identifier: repository_name).where(user_id: owner&.id)&.first project = Project.where(identifier: repository_name).where(gpid: repository_id)&.first if project.blank? CommitLog.create(user: user, project: project, repository_id: repository_id, name: repository_name, full_name: repository_full_name, From 8dae15225e0cc5263516238d071ec0474aca1b10 Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Mon, 11 Jul 2022 15:52:38 +0800 Subject: [PATCH 10/29] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile.lock | 354 ++++++++++-------- .../admins/dashboards_controller.rb | 35 +- app/views/admins/dashboards/index.html.erb | 266 +++---------- 3 files changed, 272 insertions(+), 383 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index e27c504aa..d675a0723 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,69 +1,69 @@ GEM remote: https://gems.ruby-china.com/ specs: - aasm (5.0.6) + aasm (5.2.0) concurrent-ruby (~> 1.0) - actioncable (5.2.4.1) - actionpack (= 5.2.4.1) + actioncable (5.2.6) + actionpack (= 5.2.6) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.4.1) - actionpack (= 5.2.4.1) - actionview (= 5.2.4.1) - activejob (= 5.2.4.1) + actionmailer (5.2.6) + actionpack (= 5.2.6) + actionview (= 5.2.6) + activejob (= 5.2.6) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.4.1) - actionview (= 5.2.4.1) - activesupport (= 5.2.4.1) + actionpack (5.2.6) + actionview (= 5.2.6) + activesupport (= 5.2.6) rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.4.1) - activesupport (= 5.2.4.1) + actionview (5.2.6) + activesupport (= 5.2.6) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - active_decorator (1.3.2) + active_decorator (1.4.0) activesupport - activejob (5.2.4.1) - activesupport (= 5.2.4.1) + activejob (5.2.6) + activesupport (= 5.2.6) globalid (>= 0.3.6) - activemodel (5.2.4.1) - activesupport (= 5.2.4.1) - activerecord (5.2.4.1) - activemodel (= 5.2.4.1) - activesupport (= 5.2.4.1) + activemodel (5.2.6) + activesupport (= 5.2.6) + activerecord (5.2.6) + activemodel (= 5.2.6) + activesupport (= 5.2.6) arel (>= 9.0) - activestorage (5.2.4.1) - actionpack (= 5.2.4.1) - activerecord (= 5.2.4.1) - marcel (~> 0.3.1) - activesupport (5.2.4.1) + activestorage (5.2.6) + actionpack (= 5.2.6) + activerecord (= 5.2.6) + marcel (~> 1.0.0) + activesupport (5.2.6) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) acts-as-taggable-on (6.5.0) activerecord (>= 5.0, < 6.1) - acts_as_list (0.9.19) - activerecord (>= 3.0) - addressable (2.7.0) + acts_as_list (1.0.4) + activerecord (>= 4.2) + addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) - ancestry (3.0.7) - activerecord (>= 3.2.0) - annotate (2.6.5) + ancestry (4.1.0) + activerecord (>= 5.2.6) + annotate (2.6.7) activerecord (>= 2.3.0) - rake (>= 0.8.7) + rake (~> 10.4.2, >= 10.4.2) archive-zip (0.12.0) io-like (~> 0.3.0) arel (9.0.0) - ast (2.4.0) - autoprefixer-rails (9.7.4) - execjs - awesome_print (1.8.0) + ast (2.4.2) + autoprefixer-rails (10.3.3.0) + execjs (~> 2) + awesome_print (1.9.2) axlsx (3.0.0.pre) htmlentities (~> 4.3, >= 4.3.4) mimemagic (~> 0.3) @@ -72,40 +72,43 @@ GEM axlsx_rails (0.5.2) actionpack (>= 3.1) axlsx (>= 2.0.1) - backport (1.1.2) - benchmark (0.1.0) + backport (1.2.0) + benchmark (0.2.0) bindex (0.8.1) - bootsnap (1.4.6) + bootsnap (1.9.3) msgpack (~> 1.0) bootstrap (4.3.1) autoprefixer-rails (>= 9.1.0) popper_js (>= 1.14.3, < 2) sassc-rails (>= 2.0.0) builder (3.2.4) - bulk_insert (1.7.0) + bulk_insert (1.9.0) activerecord (>= 3.2.0) - capybara (3.15.1) + capybara (3.36.0) addressable + matrix mini_mime (>= 0.1.3) nokogiri (~> 1.8) rack (>= 1.6.0) rack-test (>= 0.6.3) - regexp_parser (~> 1.2) + regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - chartkick (3.3.1) - childprocess (3.0.0) - chinese_pinyin (1.0.2) + chartkick (4.1.2) + childprocess (4.1.0) + chinese_pinyin (1.1.0) chromedriver-helper (2.1.1) archive-zip (~> 0.10) nokogiri (~> 1.8) - chunky_png (1.3.11) - concurrent-ruby (1.1.6) - connection_pool (2.2.2) + chunky_png (1.4.0) + concurrent-ruby (1.1.9) + connection_pool (2.2.5) crass (1.0.6) deep_cloneable (3.0.0) activerecord (>= 3.1.0, < 7) diff-lcs (1.3) diffy (3.3.0) + domain_name (0.5.20190701) + unf (>= 0.0.5, < 1.0.0) doorkeeper (5.5.1) railties (>= 5) doorkeeper-jwt (0.4.1) @@ -119,93 +122,103 @@ GEM elasticsearch-transport (7.5.0) faraday (>= 0.14, < 1) multi_json - enumerize (2.3.1) + enumerize (2.4.0) activesupport (>= 3.2) - erubi (1.9.0) - et-orbi (1.2.4) + erubi (1.10.0) + et-orbi (1.2.6) tzinfo - execjs (2.7.0) + execjs (2.8.1) faraday (0.15.4) multipart-post (>= 1.2, < 3) - ffi (1.12.2) + ffi (1.15.4) font-awesome-sass (4.7.0) sass (>= 3.2) - fugit (1.4.1) + fugit (1.5.2) et-orbi (~> 1.1, >= 1.1.8) raabro (~> 1.4) - globalid (0.4.2) - activesupport (>= 4.2.0) + gitea-client (0.9.2) + rest-client (~> 2.1.0) + globalid (1.0.0) + activesupport (>= 5.0) grape-entity (0.7.1) activesupport (>= 4.0) multi_json (>= 1.3.2) groupdate (4.1.2) activesupport (>= 4.2) harmonious_dictionary (0.0.1) - hashie (3.6.0) + hashie (5.0.0) htmlentities (4.3.4) - i18n (1.8.2) + http-accept (1.7.0) + http-cookie (1.0.5) + domain_name (~> 0.5) + i18n (1.8.11) concurrent-ruby (~> 1.0) io-like (0.3.1) jaro_winkler (1.5.4) - jbuilder (2.10.0) + jbuilder (2.11.3) activesupport (>= 5.0.0) - jquery-rails (4.3.5) + jquery-rails (4.4.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - jwt (2.2.1) - kaminari (1.2.0) + jwt (2.3.0) + kaminari (1.2.1) activesupport (>= 4.1.0) - kaminari-actionview (= 1.2.0) - kaminari-activerecord (= 1.2.0) - kaminari-core (= 1.2.0) - kaminari-actionview (1.2.0) + kaminari-actionview (= 1.2.1) + kaminari-activerecord (= 1.2.1) + kaminari-core (= 1.2.1) + kaminari-actionview (1.2.1) actionview - kaminari-core (= 1.2.0) - kaminari-activerecord (1.2.0) + kaminari-core (= 1.2.1) + kaminari-activerecord (1.2.1) activerecord - kaminari-core (= 1.2.0) - kaminari-core (1.2.0) - letter_avatar (0.3.8) + kaminari-core (= 1.2.1) + kaminari-core (1.2.1) + letter_avatar (0.3.9) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) ruby_dep (~> 1.2) - loofah (2.4.0) + loofah (2.13.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) - marcel (0.3.3) - mimemagic (~> 0.3.2) + marcel (1.0.2) maruku (0.7.3) - method_source (0.9.2) - mimemagic (0.3.10) + matrix (0.4.2) + method_source (1.0.0) + mime-types (3.4.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2022.0105) + mimemagic (0.4.3) nokogiri (~> 1) rake - mini_mime (1.0.2) - mini_portile2 (2.4.0) - minitest (5.14.0) - msgpack (1.3.3) - multi_json (1.14.1) + mini_mime (1.1.2) + mini_portile2 (2.6.1) + minitest (5.14.4) + msgpack (1.4.2) + multi_json (1.15.0) multi_xml (0.6.0) multipart-post (2.1.1) mustermann (1.1.1) ruby2_keywords (~> 0.0.1) mysql2 (0.5.3) + netrc (0.11.0) nio4r (2.5.2) - nokogiri (1.10.8) - mini_portile2 (~> 2.4.0) - oauth2 (1.4.4) + nokogiri (1.12.5) + mini_portile2 (~> 2.6.1) + racc (~> 1.4) + oauth2 (1.4.7) faraday (>= 0.8, < 2.0) jwt (>= 1.0, < 3.0) multi_json (~> 1.3) multi_xml (~> 0.5) rack (>= 1.2, < 3) - omniauth (1.9.0) - hashie (>= 3.4.6, < 3.7.0) + omniauth (1.9.1) + hashie (>= 3.4.6) rack (>= 1.6.2, < 3) - omniauth-cas (1.1.1) + omniauth-cas (2.0.0) addressable (~> 2.3) nokogiri (~> 1.5) omniauth (~> 1.2) @@ -213,108 +226,112 @@ GEM oauth2 (~> 1.1) omniauth (~> 1.9) parallel (1.19.1) - parser (2.7.1.1) - ast (~> 2.4.0) + parser (2.7.2.0) + ast (~> 2.4.1) pdfkit (0.8.4.1) - polyamorous (2.3.2) - activerecord (>= 5.2.1) popper_js (1.16.0) - powerpack (0.1.2) - prettier (0.18.2) - public_suffix (4.0.3) - puma (3.12.2) + powerpack (0.1.3) + prettier (2.0.0) + public_suffix (4.0.6) + puma (3.12.6) raabro (1.4.0) - rack (2.0.9) + racc (1.6.0) + rack (2.2.3) rack-cors (1.1.1) rack (>= 2.0.0) - rack-mini-profiler (2.0.1) + rack-mini-profiler (2.3.3) rack (>= 1.2.0) - rack-protection (2.0.8.1) + rack-protection (2.1.0) rack rack-test (1.1.0) rack (>= 1.0, < 3) - rails (5.2.4.1) - actioncable (= 5.2.4.1) - actionmailer (= 5.2.4.1) - actionpack (= 5.2.4.1) - actionview (= 5.2.4.1) - activejob (= 5.2.4.1) - activemodel (= 5.2.4.1) - activerecord (= 5.2.4.1) - activestorage (= 5.2.4.1) - activesupport (= 5.2.4.1) + rails (5.2.6) + actioncable (= 5.2.6) + actionmailer (= 5.2.6) + actionpack (= 5.2.6) + actionview (= 5.2.6) + activejob (= 5.2.6) + activemodel (= 5.2.6) + activerecord (= 5.2.6) + activestorage (= 5.2.6) + activesupport (= 5.2.6) bundler (>= 1.3.0) - railties (= 5.2.4.1) + railties (= 5.2.6) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.3.0) + rails-html-sanitizer (1.4.2) loofah (~> 2.3) rails-i18n (5.1.3) i18n (>= 0.7, < 2) railties (>= 5.0, < 6) - railties (5.2.4.1) - actionpack (= 5.2.4.1) - activesupport (= 5.2.4.1) + railties (5.2.6) + actionpack (= 5.2.6) + activesupport (= 5.2.6) method_source rake (>= 0.8.7) thor (>= 0.19.0, < 2.0) rainbow (3.0.0) - rake (13.0.1) - ransack (2.3.2) - activerecord (>= 5.2.1) - activesupport (>= 5.2.1) + rake (10.4.2) + ransack (2.4.2) + activerecord (>= 5.2.4) + activesupport (>= 5.2.4) i18n - polyamorous (= 2.3.2) - rb-fsevent (0.10.3) + rb-fsevent (0.11.0) rb-inotify (0.10.1) ffi (~> 1.0) rchardet (1.8.0) - redcarpet (3.5.0) - redis (4.1.3) + redcarpet (3.5.1) + redis (4.5.1) redis-actionpack (5.2.0) actionpack (>= 5, < 7) redis-rack (>= 2.1.0, < 3) redis-store (>= 1.1.0, < 2) - redis-activesupport (5.2.0) + redis-activesupport (5.2.1) activesupport (>= 3, < 7) redis-store (>= 1.3, < 2) - redis-rack (2.1.2) + redis-rack (2.1.3) rack (>= 2.0.8, < 3) redis-store (>= 1.2, < 2) redis-rails (5.0.2) redis-actionpack (>= 5.0, < 6) redis-activesupport (>= 5.0, < 6) redis-store (>= 1.2, < 2) - redis-store (1.8.2) + redis-store (1.9.0) redis (>= 4, < 5) - regexp_parser (1.7.0) + regexp_parser (2.2.0) request_store (1.5.0) rack (>= 1.4) + rest-client (2.1.0) + http-accept (>= 1.7.0, < 2.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 4.0) + netrc (~> 0.8) reverse_markdown (1.4.0) nokogiri + rexml (3.2.5) roo (2.8.3) nokogiri (~> 1) rubyzip (>= 1.3.0, < 3.0.0) roo-xls (1.2.0) nokogiri - roo (>= 2.0.0, < 3) + roo (= 2.8.3) spreadsheet (> 0.9.0) rqrcode (0.10.1) chunky_png (~> 1.0) rqrcode_png (0.1.5) chunky_png rqrcode - rspec-core (3.9.1) - rspec-support (~> 3.9.1) - rspec-expectations (3.9.0) + rspec-core (3.9.3) + rspec-support (~> 3.9.3) + rspec-expectations (3.9.4) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) rspec-mocks (3.9.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) - rspec-rails (3.9.0) + rspec-rails (3.9.1) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) @@ -322,7 +339,7 @@ GEM rspec-expectations (~> 3.9.0) rspec-mocks (~> 3.9.0) rspec-support (~> 3.9.0) - rspec-support (3.9.2) + rspec-support (3.9.4) rubocop (0.52.1) parallel (~> 1.10) parser (>= 2.4.0.2, < 3.0) @@ -331,8 +348,8 @@ GEM ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) ruby-ole (1.2.12.2) - ruby-progressbar (1.10.1) - ruby2_keywords (0.0.2) + ruby-progressbar (1.11.0) + ruby2_keywords (0.0.5) ruby_dep (1.5.0) rubyzip (1.3.0) sass (3.7.4) @@ -340,13 +357,13 @@ GEM sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - sass-rails (5.0.7) - railties (>= 4.0.0, < 6) + sass-rails (5.1.0) + railties (>= 5.2.0) sass (~> 3.1) sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - sassc (2.2.1) + sassc (2.4.0) ffi (~> 1.9) sassc-rails (2.1.2) railties (>= 4.0.0) @@ -354,31 +371,31 @@ GEM sprockets (> 3.0) sprockets-rails tilt - searchkick (3.1.3) - activemodel (>= 4.2) - elasticsearch (>= 5) + searchkick (4.6.3) + activemodel (>= 5) + elasticsearch (>= 6, < 7.14) hashie - selenium-webdriver (3.142.7) - childprocess (>= 0.5, < 4.0) + selenium-webdriver (4.1.0) + childprocess (>= 0.5, < 5.0) + rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2) - sidekiq (5.2.8) - connection_pool (~> 2.2, >= 2.2.2) - rack (< 2.1.0) - rack-protection (>= 1.5.0) - redis (>= 3.3.5, < 5) + sidekiq (6.3.1) + connection_pool (>= 2.2.2) + rack (~> 2.0) + redis (>= 4.2.0) sidekiq-cron (1.2.0) fugit (~> 1.1) sidekiq (>= 4.2.1) - simple_form (5.0.2) - actionpack (>= 5.0) - activemodel (>= 5.0) + simple_form (5.1.0) + actionpack (>= 5.2) + activemodel (>= 5.2) simple_xlsx_reader (1.0.4) nokogiri rubyzip - sinatra (2.0.8.1) + sinatra (2.1.0) mustermann (~> 1.0) - rack (~> 2.0) - rack-protection (= 2.0.8.1) + rack (~> 2.2) + rack-protection (= 2.1.0) tilt (~> 2.0) solargraph (0.38.6) backport (~> 1.1) @@ -394,43 +411,47 @@ GEM thor (~> 1.0) tilt (~> 2.0) yard (~> 0.9) - spreadsheet (1.2.6) - ruby-ole (>= 1.0) - spring (2.0.2) - activesupport (>= 4.2) + spreadsheet (1.3.0) + ruby-ole + spring (2.1.1) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.1) - actionpack (>= 4.0) - activesupport (>= 4.0) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) sprockets (>= 3.0.0) - thor (1.0.1) + thor (1.1.0) thread_safe (0.3.6) tilt (2.0.10) turbolinks (5.2.1) turbolinks-source (~> 5.2) turbolinks-source (5.2.0) - tzinfo (1.2.6) + tzinfo (1.2.9) thread_safe (~> 0.1) uglifier (4.2.0) execjs (>= 0.3.0, < 3) - unicode-display_width (1.6.1) + unf (0.1.4) + unf_ext + unf_ext (0.0.8.2) + unicode-display_width (1.8.0) web-console (3.7.0) actionview (>= 5.0) activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) - websocket-driver (0.7.1) + webrick (1.7.0) + websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.4) - wkhtmltopdf-binary (0.12.5.4) + websocket-extensions (0.1.5) + wkhtmltopdf-binary (0.12.6.5) xpath (3.2.0) nokogiri (~> 1.8) - yard (0.9.24) + yard (0.9.27) + webrick (~> 1.7.0) PLATFORMS ruby @@ -459,6 +480,7 @@ DEPENDENCIES enumerize faraday (~> 0.15.4) font-awesome-sass (= 4.7.0) + gitea-client (~> 0.9.1) grape-entity (~> 0.7.1) groupdate (~> 4.1.0) harmonious_dictionary (~> 0.0.1) diff --git a/app/controllers/admins/dashboards_controller.rb b/app/controllers/admins/dashboards_controller.rb index 3971971ff..0d88d0440 100644 --- a/app/controllers/admins/dashboards_controller.rb +++ b/app/controllers/admins/dashboards_controller.rb @@ -1,10 +1,33 @@ class Admins::DashboardsController < Admins::BaseController def index - @active_user_count = User.where(last_login_on: today).count - @weekly_active_user_count = User.where(last_login_on: current_week).count - @month_active_user_count = User.where(last_login_on: current_month).count + # 用户活跃数 + day_user_ids = CommitLog.where(created_at: today).pluck(:project_id).uniq + weekly_user_ids = CommitLog.where(created_at: current_week).pluck(:project_id).uniq + month_user_ids = CommitLog.where(created_at: current_month).pluck(:project_id).uniq + @active_user_count = User.where(last_login_on: today).or(User.where(id: day_user_ids)).count + @weekly_active_user_count = User.where(last_login_on: current_week).or(User.where(id: weekly_user_ids)).count + @month_active_user_count = User.where(last_login_on: current_month).or(User.where(id: month_user_ids)).count + user_ids = User.where(created_on: pre_week).pluck(:id).uniq + weekly_keep_user_count = User.where(id: user_ids).where(last_login_on: current_week).count + @weekly_keep_rate = format("%.2f", weekly_keep_user_count > 0 ? weekly_keep_user_count / weekly_keep_user_count : 0) - @new_user_count = User.where(created_on: current_month).count + # 新用户注册数 + @day_new_user_count = User.where(created_on: today).count + @weekly_new_user_count = User.where(created_on: current_week).count + @month_new_user_count = User.where(created_on: current_month).count + + # 活跃项目数 + day_project_ids = CommitLog.where(created_at: today).pluck(:project_id).uniq + weekly_project_ids = CommitLog.where(created_at: current_week).pluck(:project_id).uniq + month_project_ids = CommitLog.where(created_at: current_month).pluck(:project_id).uniq + @day_active_project_count = Project.where(updated_on: today).or(Project.where(id: day_project_ids)).count + @weekly_active_project_count = Project.where(updated_on: current_week).or(Project.where(id: weekly_project_ids)).count + @month_active_project_count = Project.where(updated_on: current_month).or(Project.where(id: month_project_ids)).count + + # 新增项目数 + @day_new_project_count = User.where(created_on: today).count + @weekly_new_project_count = User.where(created_on: current_week).count + @month_new_project_count = User.where(created_on: current_month).count end def month_active_user @@ -48,4 +71,8 @@ class Admins::DashboardsController < Admins::BaseController def current_month 30.days.ago.beginning_of_day..Time.now.end_of_day end + + def pre_week + 14.days.ago.beginning_of_day..7.days.ago.beginning_of_day + end end \ No newline at end of file diff --git a/app/views/admins/dashboards/index.html.erb b/app/views/admins/dashboards/index.html.erb index e02c307a5..649c00904 100644 --- a/app/views/admins/dashboards/index.html.erb +++ b/app/views/admins/dashboards/index.html.erb @@ -2,217 +2,57 @@ <% add_admin_breadcrumb('概览', admins_path) %> <% end %> -
    -
    -
    - -
    -
    -
    -
    -
    -
    -
    当日活跃用户
    - <%= @active_user_count %> -
    -
    -
    - -
    -
    -
    - - - - -
    -
    -
    -
    -
    -
    -
    -
    -
    7天内活跃用户数
    - <%= @weekly_active_user_count %> -
    -
    -
    - -
    -
    -
    - - - - -
    -
    -
    -
    -
    -
    -
    -
    -
    30天内活跃用户数
    - <%= @month_active_user_count %> -
    -
    -
    - -
    -
    -
    - - - - -
    -
    -
    -
    -
    -
    -
    -
    -
    30天内新增用户数
    - <%= @new_user_count %> -
    -
    -
    - -
    -
    -
    - - - - -
    -
    -
    -
    -
    -
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    指标名称当日数七日内30日内周用户留存率
    + + <%=@active_user_count %><%=@weekly_active_user_count %><%=@month_active_user_count %><%="#{@weekly_keep_rate.to_f * 100 }%" %>
    + + <%=@day_new_user_count %><%=@weekly_new_user_count %><%=@month_new_user_count %><%="--" %>
    + + <%=@day_active_project_count %><%=@weekly_new_project_count %><%=@month_new_project_count %><%="--" %>
    + + <%=@day_new_project_count %><%=@weekly_new_user_count %><%=@month_new_user_count %><%="--" %>
    - -
    -
    -
    -
    - - - - - - - - -
    -
    - -
    -
    -
    -
    -
    30天内新增用户
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - <%# 5.times do %> - - - - - - - - - <%# end %> - - - - - - - - - - - - - - - - - - - - - - - - - - - - <%# 5.times do %> - - - - - - - - - - - - - - - - - - - <%# end %> - - - - - - - \ No newline at end of file +
    +
    \ No newline at end of file From df7b91a8ba19fb09f7c0b2dc0871ad7acfe110b8 Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Mon, 18 Jul 2022 10:38:45 +0800 Subject: [PATCH 11/29] gemfile.lock reset --- Gemfile.lock | 354 ++++++++++++++++++++++++--------------------------- 1 file changed, 166 insertions(+), 188 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d675a0723..e27c504aa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,69 +1,69 @@ GEM remote: https://gems.ruby-china.com/ specs: - aasm (5.2.0) + aasm (5.0.6) concurrent-ruby (~> 1.0) - actioncable (5.2.6) - actionpack (= 5.2.6) + actioncable (5.2.4.1) + actionpack (= 5.2.4.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.6) - actionpack (= 5.2.6) - actionview (= 5.2.6) - activejob (= 5.2.6) + actionmailer (5.2.4.1) + actionpack (= 5.2.4.1) + actionview (= 5.2.4.1) + activejob (= 5.2.4.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.6) - actionview (= 5.2.6) - activesupport (= 5.2.6) + actionpack (5.2.4.1) + actionview (= 5.2.4.1) + activesupport (= 5.2.4.1) rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.6) - activesupport (= 5.2.6) + actionview (5.2.4.1) + activesupport (= 5.2.4.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - active_decorator (1.4.0) + active_decorator (1.3.2) activesupport - activejob (5.2.6) - activesupport (= 5.2.6) + activejob (5.2.4.1) + activesupport (= 5.2.4.1) globalid (>= 0.3.6) - activemodel (5.2.6) - activesupport (= 5.2.6) - activerecord (5.2.6) - activemodel (= 5.2.6) - activesupport (= 5.2.6) + activemodel (5.2.4.1) + activesupport (= 5.2.4.1) + activerecord (5.2.4.1) + activemodel (= 5.2.4.1) + activesupport (= 5.2.4.1) arel (>= 9.0) - activestorage (5.2.6) - actionpack (= 5.2.6) - activerecord (= 5.2.6) - marcel (~> 1.0.0) - activesupport (5.2.6) + activestorage (5.2.4.1) + actionpack (= 5.2.4.1) + activerecord (= 5.2.4.1) + marcel (~> 0.3.1) + activesupport (5.2.4.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) acts-as-taggable-on (6.5.0) activerecord (>= 5.0, < 6.1) - acts_as_list (1.0.4) - activerecord (>= 4.2) - addressable (2.8.0) + acts_as_list (0.9.19) + activerecord (>= 3.0) + addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) - ancestry (4.1.0) - activerecord (>= 5.2.6) - annotate (2.6.7) + ancestry (3.0.7) + activerecord (>= 3.2.0) + annotate (2.6.5) activerecord (>= 2.3.0) - rake (~> 10.4.2, >= 10.4.2) + rake (>= 0.8.7) archive-zip (0.12.0) io-like (~> 0.3.0) arel (9.0.0) - ast (2.4.2) - autoprefixer-rails (10.3.3.0) - execjs (~> 2) - awesome_print (1.9.2) + ast (2.4.0) + autoprefixer-rails (9.7.4) + execjs + awesome_print (1.8.0) axlsx (3.0.0.pre) htmlentities (~> 4.3, >= 4.3.4) mimemagic (~> 0.3) @@ -72,43 +72,40 @@ GEM axlsx_rails (0.5.2) actionpack (>= 3.1) axlsx (>= 2.0.1) - backport (1.2.0) - benchmark (0.2.0) + backport (1.1.2) + benchmark (0.1.0) bindex (0.8.1) - bootsnap (1.9.3) + bootsnap (1.4.6) msgpack (~> 1.0) bootstrap (4.3.1) autoprefixer-rails (>= 9.1.0) popper_js (>= 1.14.3, < 2) sassc-rails (>= 2.0.0) builder (3.2.4) - bulk_insert (1.9.0) + bulk_insert (1.7.0) activerecord (>= 3.2.0) - capybara (3.36.0) + capybara (3.15.1) addressable - matrix mini_mime (>= 0.1.3) nokogiri (~> 1.8) rack (>= 1.6.0) rack-test (>= 0.6.3) - regexp_parser (>= 1.5, < 3.0) + regexp_parser (~> 1.2) xpath (~> 3.2) - chartkick (4.1.2) - childprocess (4.1.0) - chinese_pinyin (1.1.0) + chartkick (3.3.1) + childprocess (3.0.0) + chinese_pinyin (1.0.2) chromedriver-helper (2.1.1) archive-zip (~> 0.10) nokogiri (~> 1.8) - chunky_png (1.4.0) - concurrent-ruby (1.1.9) - connection_pool (2.2.5) + chunky_png (1.3.11) + concurrent-ruby (1.1.6) + connection_pool (2.2.2) crass (1.0.6) deep_cloneable (3.0.0) activerecord (>= 3.1.0, < 7) diff-lcs (1.3) diffy (3.3.0) - domain_name (0.5.20190701) - unf (>= 0.0.5, < 1.0.0) doorkeeper (5.5.1) railties (>= 5) doorkeeper-jwt (0.4.1) @@ -122,103 +119,93 @@ GEM elasticsearch-transport (7.5.0) faraday (>= 0.14, < 1) multi_json - enumerize (2.4.0) + enumerize (2.3.1) activesupport (>= 3.2) - erubi (1.10.0) - et-orbi (1.2.6) + erubi (1.9.0) + et-orbi (1.2.4) tzinfo - execjs (2.8.1) + execjs (2.7.0) faraday (0.15.4) multipart-post (>= 1.2, < 3) - ffi (1.15.4) + ffi (1.12.2) font-awesome-sass (4.7.0) sass (>= 3.2) - fugit (1.5.2) + fugit (1.4.1) et-orbi (~> 1.1, >= 1.1.8) raabro (~> 1.4) - gitea-client (0.9.2) - rest-client (~> 2.1.0) - globalid (1.0.0) - activesupport (>= 5.0) + globalid (0.4.2) + activesupport (>= 4.2.0) grape-entity (0.7.1) activesupport (>= 4.0) multi_json (>= 1.3.2) groupdate (4.1.2) activesupport (>= 4.2) harmonious_dictionary (0.0.1) - hashie (5.0.0) + hashie (3.6.0) htmlentities (4.3.4) - http-accept (1.7.0) - http-cookie (1.0.5) - domain_name (~> 0.5) - i18n (1.8.11) + i18n (1.8.2) concurrent-ruby (~> 1.0) io-like (0.3.1) jaro_winkler (1.5.4) - jbuilder (2.11.3) + jbuilder (2.10.0) activesupport (>= 5.0.0) - jquery-rails (4.4.0) + jquery-rails (4.3.5) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - jwt (2.3.0) - kaminari (1.2.1) + jwt (2.2.1) + kaminari (1.2.0) activesupport (>= 4.1.0) - kaminari-actionview (= 1.2.1) - kaminari-activerecord (= 1.2.1) - kaminari-core (= 1.2.1) - kaminari-actionview (1.2.1) + kaminari-actionview (= 1.2.0) + kaminari-activerecord (= 1.2.0) + kaminari-core (= 1.2.0) + kaminari-actionview (1.2.0) actionview - kaminari-core (= 1.2.1) - kaminari-activerecord (1.2.1) + kaminari-core (= 1.2.0) + kaminari-activerecord (1.2.0) activerecord - kaminari-core (= 1.2.1) - kaminari-core (1.2.1) - letter_avatar (0.3.9) + kaminari-core (= 1.2.0) + kaminari-core (1.2.0) + letter_avatar (0.3.8) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) ruby_dep (~> 1.2) - loofah (2.13.0) + loofah (2.4.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) - marcel (1.0.2) + marcel (0.3.3) + mimemagic (~> 0.3.2) maruku (0.7.3) - matrix (0.4.2) - method_source (1.0.0) - mime-types (3.4.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2022.0105) - mimemagic (0.4.3) + method_source (0.9.2) + mimemagic (0.3.10) nokogiri (~> 1) rake - mini_mime (1.1.2) - mini_portile2 (2.6.1) - minitest (5.14.4) - msgpack (1.4.2) - multi_json (1.15.0) + mini_mime (1.0.2) + mini_portile2 (2.4.0) + minitest (5.14.0) + msgpack (1.3.3) + multi_json (1.14.1) multi_xml (0.6.0) multipart-post (2.1.1) mustermann (1.1.1) ruby2_keywords (~> 0.0.1) mysql2 (0.5.3) - netrc (0.11.0) nio4r (2.5.2) - nokogiri (1.12.5) - mini_portile2 (~> 2.6.1) - racc (~> 1.4) - oauth2 (1.4.7) + nokogiri (1.10.8) + mini_portile2 (~> 2.4.0) + oauth2 (1.4.4) faraday (>= 0.8, < 2.0) jwt (>= 1.0, < 3.0) multi_json (~> 1.3) multi_xml (~> 0.5) rack (>= 1.2, < 3) - omniauth (1.9.1) - hashie (>= 3.4.6) + omniauth (1.9.0) + hashie (>= 3.4.6, < 3.7.0) rack (>= 1.6.2, < 3) - omniauth-cas (2.0.0) + omniauth-cas (1.1.1) addressable (~> 2.3) nokogiri (~> 1.5) omniauth (~> 1.2) @@ -226,112 +213,108 @@ GEM oauth2 (~> 1.1) omniauth (~> 1.9) parallel (1.19.1) - parser (2.7.2.0) - ast (~> 2.4.1) + parser (2.7.1.1) + ast (~> 2.4.0) pdfkit (0.8.4.1) + polyamorous (2.3.2) + activerecord (>= 5.2.1) popper_js (1.16.0) - powerpack (0.1.3) - prettier (2.0.0) - public_suffix (4.0.6) - puma (3.12.6) + powerpack (0.1.2) + prettier (0.18.2) + public_suffix (4.0.3) + puma (3.12.2) raabro (1.4.0) - racc (1.6.0) - rack (2.2.3) + rack (2.0.9) rack-cors (1.1.1) rack (>= 2.0.0) - rack-mini-profiler (2.3.3) + rack-mini-profiler (2.0.1) rack (>= 1.2.0) - rack-protection (2.1.0) + rack-protection (2.0.8.1) rack rack-test (1.1.0) rack (>= 1.0, < 3) - rails (5.2.6) - actioncable (= 5.2.6) - actionmailer (= 5.2.6) - actionpack (= 5.2.6) - actionview (= 5.2.6) - activejob (= 5.2.6) - activemodel (= 5.2.6) - activerecord (= 5.2.6) - activestorage (= 5.2.6) - activesupport (= 5.2.6) + rails (5.2.4.1) + actioncable (= 5.2.4.1) + actionmailer (= 5.2.4.1) + actionpack (= 5.2.4.1) + actionview (= 5.2.4.1) + activejob (= 5.2.4.1) + activemodel (= 5.2.4.1) + activerecord (= 5.2.4.1) + activestorage (= 5.2.4.1) + activesupport (= 5.2.4.1) bundler (>= 1.3.0) - railties (= 5.2.6) + railties (= 5.2.4.1) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.4.2) + rails-html-sanitizer (1.3.0) loofah (~> 2.3) rails-i18n (5.1.3) i18n (>= 0.7, < 2) railties (>= 5.0, < 6) - railties (5.2.6) - actionpack (= 5.2.6) - activesupport (= 5.2.6) + railties (5.2.4.1) + actionpack (= 5.2.4.1) + activesupport (= 5.2.4.1) method_source rake (>= 0.8.7) thor (>= 0.19.0, < 2.0) rainbow (3.0.0) - rake (10.4.2) - ransack (2.4.2) - activerecord (>= 5.2.4) - activesupport (>= 5.2.4) + rake (13.0.1) + ransack (2.3.2) + activerecord (>= 5.2.1) + activesupport (>= 5.2.1) i18n - rb-fsevent (0.11.0) + polyamorous (= 2.3.2) + rb-fsevent (0.10.3) rb-inotify (0.10.1) ffi (~> 1.0) rchardet (1.8.0) - redcarpet (3.5.1) - redis (4.5.1) + redcarpet (3.5.0) + redis (4.1.3) redis-actionpack (5.2.0) actionpack (>= 5, < 7) redis-rack (>= 2.1.0, < 3) redis-store (>= 1.1.0, < 2) - redis-activesupport (5.2.1) + redis-activesupport (5.2.0) activesupport (>= 3, < 7) redis-store (>= 1.3, < 2) - redis-rack (2.1.3) + redis-rack (2.1.2) rack (>= 2.0.8, < 3) redis-store (>= 1.2, < 2) redis-rails (5.0.2) redis-actionpack (>= 5.0, < 6) redis-activesupport (>= 5.0, < 6) redis-store (>= 1.2, < 2) - redis-store (1.9.0) + redis-store (1.8.2) redis (>= 4, < 5) - regexp_parser (2.2.0) + regexp_parser (1.7.0) request_store (1.5.0) rack (>= 1.4) - rest-client (2.1.0) - http-accept (>= 1.7.0, < 2.0) - http-cookie (>= 1.0.2, < 2.0) - mime-types (>= 1.16, < 4.0) - netrc (~> 0.8) reverse_markdown (1.4.0) nokogiri - rexml (3.2.5) roo (2.8.3) nokogiri (~> 1) rubyzip (>= 1.3.0, < 3.0.0) roo-xls (1.2.0) nokogiri - roo (= 2.8.3) + roo (>= 2.0.0, < 3) spreadsheet (> 0.9.0) rqrcode (0.10.1) chunky_png (~> 1.0) rqrcode_png (0.1.5) chunky_png rqrcode - rspec-core (3.9.3) - rspec-support (~> 3.9.3) - rspec-expectations (3.9.4) + rspec-core (3.9.1) + rspec-support (~> 3.9.1) + rspec-expectations (3.9.0) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) rspec-mocks (3.9.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) - rspec-rails (3.9.1) + rspec-rails (3.9.0) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) @@ -339,7 +322,7 @@ GEM rspec-expectations (~> 3.9.0) rspec-mocks (~> 3.9.0) rspec-support (~> 3.9.0) - rspec-support (3.9.4) + rspec-support (3.9.2) rubocop (0.52.1) parallel (~> 1.10) parser (>= 2.4.0.2, < 3.0) @@ -348,8 +331,8 @@ GEM ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) ruby-ole (1.2.12.2) - ruby-progressbar (1.11.0) - ruby2_keywords (0.0.5) + ruby-progressbar (1.10.1) + ruby2_keywords (0.0.2) ruby_dep (1.5.0) rubyzip (1.3.0) sass (3.7.4) @@ -357,13 +340,13 @@ GEM sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - sass-rails (5.1.0) - railties (>= 5.2.0) + sass-rails (5.0.7) + railties (>= 4.0.0, < 6) sass (~> 3.1) sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - sassc (2.4.0) + sassc (2.2.1) ffi (~> 1.9) sassc-rails (2.1.2) railties (>= 4.0.0) @@ -371,31 +354,31 @@ GEM sprockets (> 3.0) sprockets-rails tilt - searchkick (4.6.3) - activemodel (>= 5) - elasticsearch (>= 6, < 7.14) + searchkick (3.1.3) + activemodel (>= 4.2) + elasticsearch (>= 5) hashie - selenium-webdriver (4.1.0) - childprocess (>= 0.5, < 5.0) - rexml (~> 3.2, >= 3.2.5) + selenium-webdriver (3.142.7) + childprocess (>= 0.5, < 4.0) rubyzip (>= 1.2.2) - sidekiq (6.3.1) - connection_pool (>= 2.2.2) - rack (~> 2.0) - redis (>= 4.2.0) + sidekiq (5.2.8) + connection_pool (~> 2.2, >= 2.2.2) + rack (< 2.1.0) + rack-protection (>= 1.5.0) + redis (>= 3.3.5, < 5) sidekiq-cron (1.2.0) fugit (~> 1.1) sidekiq (>= 4.2.1) - simple_form (5.1.0) - actionpack (>= 5.2) - activemodel (>= 5.2) + simple_form (5.0.2) + actionpack (>= 5.0) + activemodel (>= 5.0) simple_xlsx_reader (1.0.4) nokogiri rubyzip - sinatra (2.1.0) + sinatra (2.0.8.1) mustermann (~> 1.0) - rack (~> 2.2) - rack-protection (= 2.1.0) + rack (~> 2.0) + rack-protection (= 2.0.8.1) tilt (~> 2.0) solargraph (0.38.6) backport (~> 1.1) @@ -411,47 +394,43 @@ GEM thor (~> 1.0) tilt (~> 2.0) yard (~> 0.9) - spreadsheet (1.3.0) - ruby-ole - spring (2.1.1) + spreadsheet (1.2.6) + ruby-ole (>= 1.0) + spring (2.0.2) + activesupport (>= 4.2) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) sprockets (>= 3.0.0) - thor (1.1.0) + thor (1.0.1) thread_safe (0.3.6) tilt (2.0.10) turbolinks (5.2.1) turbolinks-source (~> 5.2) turbolinks-source (5.2.0) - tzinfo (1.2.9) + tzinfo (1.2.6) thread_safe (~> 0.1) uglifier (4.2.0) execjs (>= 0.3.0, < 3) - unf (0.1.4) - unf_ext - unf_ext (0.0.8.2) - unicode-display_width (1.8.0) + unicode-display_width (1.6.1) web-console (3.7.0) actionview (>= 5.0) activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) - webrick (1.7.0) - websocket-driver (0.7.5) + websocket-driver (0.7.1) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.5) - wkhtmltopdf-binary (0.12.6.5) + websocket-extensions (0.1.4) + wkhtmltopdf-binary (0.12.5.4) xpath (3.2.0) nokogiri (~> 1.8) - yard (0.9.27) - webrick (~> 1.7.0) + yard (0.9.24) PLATFORMS ruby @@ -480,7 +459,6 @@ DEPENDENCIES enumerize faraday (~> 0.15.4) font-awesome-sass (= 4.7.0) - gitea-client (~> 0.9.1) grape-entity (~> 0.7.1) groupdate (~> 4.1.0) harmonious_dictionary (~> 0.0.1) From b5dfd83527a6113bfea2e134bdd540775cbc5d31 Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Mon, 18 Jul 2022 10:43:57 +0800 Subject: [PATCH 12/29] =?UTF-8?q?fix=20=E6=8F=90=E4=BA=A4=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=8F=90=E4=BA=A4=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=B8=8D=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/commit_logs_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/commit_logs_controller.rb b/app/controllers/commit_logs_controller.rb index 1708b162b..c02d199b0 100644 --- a/app/controllers/commit_logs_controller.rb +++ b/app/controllers/commit_logs_controller.rb @@ -5,8 +5,8 @@ class CommitLogsController < ApplicationController ref = params[:ref] commit_id = params[:commits][0][:id] message = params[:commits][0][:message] - user_name = params[:message][0][:committer][:username] - user_mail = params[:message][0][:committer][:email] + user_name = params[:pusher][:login] + user_mail = params[:pusher][:email] user = User.find_by(mail: user_mail) user = User.find_by(login: user_name) if user.blank? From d9a1d32ec8b63759d0e12d9a9706d514794e4a03 Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Mon, 18 Jul 2022 10:55:41 +0800 Subject: [PATCH 13/29] =?UTF-8?q?fixed=20=E5=90=8E=E5=8F=B0=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E4=BC=98=E5=8C=96,=E5=91=A8=E5=AD=98=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admins/dashboards_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admins/dashboards_controller.rb b/app/controllers/admins/dashboards_controller.rb index 0d88d0440..3d86f161d 100644 --- a/app/controllers/admins/dashboards_controller.rb +++ b/app/controllers/admins/dashboards_controller.rb @@ -9,7 +9,7 @@ class Admins::DashboardsController < Admins::BaseController @month_active_user_count = User.where(last_login_on: current_month).or(User.where(id: month_user_ids)).count user_ids = User.where(created_on: pre_week).pluck(:id).uniq weekly_keep_user_count = User.where(id: user_ids).where(last_login_on: current_week).count - @weekly_keep_rate = format("%.2f", weekly_keep_user_count > 0 ? weekly_keep_user_count / weekly_keep_user_count : 0) + @weekly_keep_rate = format("%.2f", user_ids.size > 0 ? weekly_keep_user_count / user_ids.size : 0) # 新用户注册数 @day_new_user_count = User.where(created_on: today).count From d9653e461eaa556b5f4646ee453fe9754c8e6989 Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Mon, 18 Jul 2022 11:00:47 +0800 Subject: [PATCH 14/29] =?UTF-8?q?fixed=20=E5=90=8E=E5=8F=B0=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E4=BC=98=E5=8C=96,=E5=91=A8=E5=AD=98=E7=8E=87?= =?UTF-8?q?=E5=B0=8F=E6=95=B0=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admins/dashboards_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admins/dashboards_controller.rb b/app/controllers/admins/dashboards_controller.rb index 3d86f161d..d9e25c664 100644 --- a/app/controllers/admins/dashboards_controller.rb +++ b/app/controllers/admins/dashboards_controller.rb @@ -9,7 +9,7 @@ class Admins::DashboardsController < Admins::BaseController @month_active_user_count = User.where(last_login_on: current_month).or(User.where(id: month_user_ids)).count user_ids = User.where(created_on: pre_week).pluck(:id).uniq weekly_keep_user_count = User.where(id: user_ids).where(last_login_on: current_week).count - @weekly_keep_rate = format("%.2f", user_ids.size > 0 ? weekly_keep_user_count / user_ids.size : 0) + @weekly_keep_rate = format("%.2f", user_ids.size > 0 ? weekly_keep_user_count.to_f / user_ids.size : 0) # 新用户注册数 @day_new_user_count = User.where(created_on: today).count From 3580a8653d0b80e56526357aa17b1f2972a1a24f Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Mon, 18 Jul 2022 11:04:57 +0800 Subject: [PATCH 15/29] =?UTF-8?q?fixed=20=E5=90=8E=E5=8F=B0=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E4=BC=98=E5=8C=96,=E6=96=B0=E5=A2=9E=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admins/dashboards_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/admins/dashboards_controller.rb b/app/controllers/admins/dashboards_controller.rb index d9e25c664..5ac1508d1 100644 --- a/app/controllers/admins/dashboards_controller.rb +++ b/app/controllers/admins/dashboards_controller.rb @@ -25,9 +25,9 @@ class Admins::DashboardsController < Admins::BaseController @month_active_project_count = Project.where(updated_on: current_month).or(Project.where(id: month_project_ids)).count # 新增项目数 - @day_new_project_count = User.where(created_on: today).count - @weekly_new_project_count = User.where(created_on: current_week).count - @month_new_project_count = User.where(created_on: current_month).count + @day_new_project_count = Project.where(created_on: today).count + @weekly_new_project_count = Project.where(created_on: current_week).count + @month_new_project_count = Project.where(created_on: current_month).count end def month_active_user From 07518f0d009d0ee9c703715418ba95e1d26e1f3f Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Mon, 18 Jul 2022 11:11:15 +0800 Subject: [PATCH 16/29] =?UTF-8?q?fixed=20=E5=90=8E=E5=8F=B0=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E4=BC=98=E5=8C=96,=E6=96=B0=E5=A2=9E=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/admins/dashboards/index.html.erb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/admins/dashboards/index.html.erb b/app/views/admins/dashboards/index.html.erb index 649c00904..2d86b4b6c 100644 --- a/app/views/admins/dashboards/index.html.erb +++ b/app/views/admins/dashboards/index.html.erb @@ -38,17 +38,17 @@ <%=@day_active_project_count %> - <%=@weekly_new_project_count %> - <%=@month_new_project_count %> + <%=@weekly_active_project_count %> + <%=@month_active_project_count %> <%="--" %> - + <%=@day_new_project_count %> - <%=@weekly_new_user_count %> - <%=@month_new_user_count %> + <%=@weekly_new_project_count %> + <%=@month_new_project_count %> <%="--" %> From 04b9e433826a8e19cb5874ed6fb32a95cf274886 Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Mon, 18 Jul 2022 11:14:45 +0800 Subject: [PATCH 17/29] =?UTF-8?q?fixed=20=E5=90=8E=E5=8F=B0=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E4=BC=98=E5=8C=96,=E6=96=B0=E5=A2=9E=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/admins/dashboards/index.html.erb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/admins/dashboards/index.html.erb b/app/views/admins/dashboards/index.html.erb index 649c00904..2d86b4b6c 100644 --- a/app/views/admins/dashboards/index.html.erb +++ b/app/views/admins/dashboards/index.html.erb @@ -38,17 +38,17 @@ <%=@day_active_project_count %> - <%=@weekly_new_project_count %> - <%=@month_new_project_count %> + <%=@weekly_active_project_count %> + <%=@month_active_project_count %> <%="--" %> - + <%=@day_new_project_count %> - <%=@weekly_new_user_count %> - <%=@month_new_user_count %> + <%=@weekly_new_project_count %> + <%=@month_new_project_count %> <%="--" %> From b248f770f1b870afb6e5380f3f1a753ec9684a63 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 18 Jul 2022 11:18:29 +0800 Subject: [PATCH 18/29] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=8D=95=E4=B8=AA=E6=8F=90=E4=BA=A4=E7=9A=84blame?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=8E=A5=E5=8F=A3=E4=BB=A5=E5=8F=8A=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/commits_controller.rb | 8 + .../slate/source/includes/_repositories.md | 164 +++++++--- .../api/v1/projects/commits/diff_service.rb | 31 ++ .../v1/projects/commits/diff.json.jbuilder | 40 +++ config/routes/api.rb | 2 + public/docs/api.html | 279 +++++++++++++++--- 6 files changed, 444 insertions(+), 80 deletions(-) create mode 100644 app/controllers/api/v1/projects/commits_controller.rb create mode 100644 app/services/api/v1/projects/commits/diff_service.rb create mode 100644 app/views/api/v1/projects/commits/diff.json.jbuilder diff --git a/app/controllers/api/v1/projects/commits_controller.rb b/app/controllers/api/v1/projects/commits_controller.rb new file mode 100644 index 000000000..1e6c17bea --- /dev/null +++ b/app/controllers/api/v1/projects/commits_controller.rb @@ -0,0 +1,8 @@ +class Api::V1::Projects::CommitsController < Api::V1::BaseController + before_action :require_public_and_member_above, only: [:diff] + + def diff + @result_object = Api::V1::Projects::Commits::DiffService.call(@project, params[:sha], current_user&.gitea_token) + puts @result_object + end +end \ 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 7da740efb..afd099325 100644 --- a/app/docs/slate/source/includes/_repositories.md +++ b/app/docs/slate/source/includes/_repositories.md @@ -1413,72 +1413,170 @@ await octokit.request('GET /api/v1/yystopf/csfjkkj/git/blobs/80dd40214a586223123 Success Data. -## 获取仓库贡献者 -获取仓库贡献者 +## 获取单个提交的blame信息 +根据commit ID获取blame信息 > 示例: ```shell -curl -X GET \ --d "ref=master" \ --d "filepath=lib" \ -http://localhost:3000/api/yystopf/csfjkkj/contributors.json +curl -X GET http://localhost:3000/api/v1/yystopf/csfjkkj/commits/80dd40214a58622312393b2ae693756a4781fab2/diff.json ``` ```javascript -await octokit.request('GET /api/yystopf/csfjkkj/contributors.json') +await octokit.request('GET /api/v1/yystopf/csfjkkj/commits/80dd40214a58622312393b2ae693756a4781fab2/diff.json') ``` ### HTTP 请求 -`GET /api/:owner/:repo/contributors.json` +`GET /api/v1/:owner/:repo/commits/:sha/diff.json` ### 请求参数: 参数 | 必选 | 默认 | 类型 | 字段说明 --------- | ------- | ------- | -------- | ---------- -|owner |是| |string |用户登录名 | -|repo |是| |string |项目标识identifier | -|ref |否| | string |分支名称、tag名称或是提交记录id,默认为整个仓库 | -|filepath |否| | string |子目录名称,默认为空 | - +|owner|是| | string |用户登录名 | +|repo |是| | string |项目标识identifier | +|sha |是| | string |提交记录id | ### 返回字段说明: 参数 | 类型 | 字段说明 --------- | ----------- | ----------- -|total_count |integer|贡献者数量| -|contributions |integer|贡献数量| -|login |string |用户登录名 | -|type |string|用户类型 | -|name |string|用户昵称| -|image_url |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|| +|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|| + > 返回的JSON示例: ```json { - "contributors": [ + "file_nums": 2, + "total_addition": 2, + "total_deletion": 2, + "files": [ { - "contributions": 5, - "login": "testforge2", - "type": "User", - "name": "testforge2", - "image_url": "system/lets/letter_avatars/2/T/236_177_85/120.png" + "name": "xinzeng3", + "oldname": "xinzeng3", + "addition": 1, + "deletion": 0, + "type": 1, + "is_created": true, + "is_deleted": false, + "is_bin": false, + "is_lfs_file": false, + "is_renamed": false, + "is_ambiguous": false, + "is_submodule": false, + "sections": [ + { + "file_name": "xinzeng3", + "name": "", + "lines": [ + { + "left_index": 0, + "right_index": 0, + "match": 0, + "type": 4, + "content": "@@ -0,0 +1 @@", + "section_path": "xinzeng3", + "section_last_left_index": 0, + "section_last_right_index": 0, + "section_left_index": 0, + "section_right_index": 1, + "section_left_hunk_size": 0, + "section_right_hunk_size": 0 + }, + { + "left_index": 0, + "right_index": 1, + "match": -1, + "type": 2, + "content": "+1111122222" + } + ] + } + ], + "is_incomplete": false, + "is_incomplete_line_too_long": false, + "is_protected": false }, { - "contributions": 79, - "login": "yystopf", - "type": "User", - "name": "yystopf", - "image_url": "system/lets/letter_avatars/2/Y/241_125_89/120.png" + "name": "xinzeng4", + "oldname": "xinzeng4", + "addition": 1, + "deletion": 0, + "type": 1, + "is_created": true, + "is_deleted": false, + "is_bin": false, + "is_lfs_file": false, + "is_renamed": false, + "is_ambiguous": false, + "is_submodule": false, + "sections": [ + { + "file_name": "xinzeng4", + "name": "", + "lines": [ + { + "left_index": 0, + "right_index": 0, + "match": 0, + "type": 4, + "content": "@@ -0,0 +1 @@", + "section_path": "xinzeng4", + "section_last_left_index": 0, + "section_last_right_index": 0, + "section_left_index": 0, + "section_right_index": 1, + "section_left_hunk_size": 0, + "section_right_hunk_size": 0 + }, + { + "left_index": 0, + "right_index": 1, + "match": -1, + "type": 2, + "content": "+111112222" + } + ] + } + ], + "is_incomplete": false, + "is_incomplete_line_too_long": false, + "is_protected": false } - ], - "total_count": 2 + ] } ``` - ## 获取仓库webhooks列表 获取仓库webhooks列表 diff --git a/app/services/api/v1/projects/commits/diff_service.rb b/app/services/api/v1/projects/commits/diff_service.rb new file mode 100644 index 000000000..8b12fc318 --- /dev/null +++ b/app/services/api/v1/projects/commits/diff_service.rb @@ -0,0 +1,31 @@ +class Api::V1::Projects::Commits::DiffService < ApplicationService + attr_accessor :project, :sha, :token, :owner, :repo + attr_accessor :gitea_data + + def initialize(project, sha, token = nil) + @project = project + @sha = sha + @owner = project&.owner.login + @repo = project&.identifier + @token = token + end + + def call + load_gitea_data + + gitea_data + end + + private + def request_params + { + access_token: token + } + end + + def load_gitea_data + @gitea_data = $gitea_client.get_repos_commits_diff_by_owner_repo_sha(owner, repo, sha, {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/commits/diff.json.jbuilder b/app/views/api/v1/projects/commits/diff.json.jbuilder new file mode 100644 index 000000000..e0237369f --- /dev/null +++ b/app/views/api/v1/projects/commits/diff.json.jbuilder @@ -0,0 +1,40 @@ +json.file_nums @result_object['NumFiles'] +json.total_addition @result_object['TotalAddition'] +json.total_deletion @result_object['TotalAddition'] +json.files @result_object['Files'].each do |file| + 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'] +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 99684e6d9..789016968 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -28,6 +28,8 @@ defaults format: :json do get :all end end + + get '/commits/:sha/diff', to: 'commits#diff' get '/git/blobs/:sha', to: 'git#blobs' get '/git/trees/:sha', to: 'git#trees' end diff --git a/public/docs/api.html b/public/docs/api.html index 6fedc946e..efc0432b7 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -554,7 +554,7 @@ 获取仓库blobs内容
  • - 获取仓库贡献者 + 获取单个提交的blame信息
  • 获取仓库webhooks列表 @@ -9662,19 +9662,16 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae -

    获取仓库贡献者

    -

    获取仓库贡献者

    +

    获取单个提交的blame信息

    +

    根据commit ID获取blame信息

    示例:

    -
    curl -X GET \
    --d "ref=master" \
    --d "filepath=lib" \
    -http://localhost:3000/api/yystopf/csfjkkj/contributors.json
    -
    await octokit.request('GET /api/yystopf/csfjkkj/contributors.json')
    +
    curl -X GET http://localhost:3000/api/v1/yystopf/csfjkkj/commits/80dd40214a58622312393b2ae693756a4781fab2/diff.json
    +
    await octokit.request('GET /api/v1/yystopf/csfjkkj/commits/80dd40214a58622312393b2ae693756a4781fab2/diff.json')
     

    HTTP 请求

    -

    GET /api/:owner/:repo/contributors.json

    +

    GET /api/v1/:owner/:repo/commits/:sha/diff.json

    请求参数:

    @@ -9700,18 +9697,11 @@ http://localhost:3000/api/yystopf/csfjkkj/contributors.json - - + + - - - - - - - - +
    项目标识identifier
    refsha string分支名称、tag名称或是提交记录id,默认为整个仓库
    filepathstring子目录名称,默认为空提交记录id

    返回字段说明:

    @@ -9723,34 +9713,149 @@ http://localhost:3000/api/yystopf/csfjkkj/contributors.json -total_count -integer -贡献者数量 +file_nums +int +文件数量 -contributions -integer -贡献数量 +total_addition +int +新增行数 -login +total_deletion +int +删除行数 + + +files.name string -用户登录名 +文件名称 -type +files.oldname string -用户类型 +文件修改前名称 -name -string -用户昵称 +files.addition +int +文件新增行数 -image_url +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 + + + +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 + @@ -9758,23 +9863,103 @@ http://localhost:3000/api/yystopf/csfjkkj/contributors.json

    返回的JSON示例:

    {
    -    "contributors": [
    +    "file_nums": 2,
    +    "total_addition": 2,
    +    "total_deletion": 2,
    +    "files": [
             {
    -            "contributions": 5,
    -            "login": "testforge2",
    -            "type": "User",
    -            "name": "testforge2",
    -            "image_url": "system/lets/letter_avatars/2/T/236_177_85/120.png"
    +            "name": "xinzeng3",
    +            "oldname": "xinzeng3",
    +            "addition": 1,
    +            "deletion": 0,
    +            "type": 1,
    +            "is_created": true,
    +            "is_deleted": false,
    +            "is_bin": false,
    +            "is_lfs_file": false,
    +            "is_renamed": false,
    +            "is_ambiguous": false,
    +            "is_submodule": false,
    +            "sections": [
    +                {
    +                    "file_name": "xinzeng3",
    +                    "name": "",
    +                    "lines": [
    +                        {
    +                            "left_index": 0,
    +                            "right_index": 0,
    +                            "match": 0,
    +                            "type": 4,
    +                            "content": "@@ -0,0 +1 @@",
    +                            "section_path": "xinzeng3",
    +                            "section_last_left_index": 0,
    +                            "section_last_right_index": 0,
    +                            "section_left_index": 0,
    +                            "section_right_index": 1,
    +                            "section_left_hunk_size": 0,
    +                            "section_right_hunk_size": 0
    +                        },
    +                        {
    +                            "left_index": 0,
    +                            "right_index": 1,
    +                            "match": -1,
    +                            "type": 2,
    +                            "content": "+1111122222"
    +                        }
    +                    ]
    +                }
    +            ],
    +            "is_incomplete": false,
    +            "is_incomplete_line_too_long": false,
    +            "is_protected": false
             },
             {
    -            "contributions": 79,
    -            "login": "yystopf",
    -            "type": "User",
    -            "name": "yystopf",
    -            "image_url": "system/lets/letter_avatars/2/Y/241_125_89/120.png"
    +            "name": "xinzeng4",
    +            "oldname": "xinzeng4",
    +            "addition": 1,
    +            "deletion": 0,
    +            "type": 1,
    +            "is_created": true,
    +            "is_deleted": false,
    +            "is_bin": false,
    +            "is_lfs_file": false,
    +            "is_renamed": false,
    +            "is_ambiguous": false,
    +            "is_submodule": false,
    +            "sections": [
    +                {
    +                    "file_name": "xinzeng4",
    +                    "name": "",
    +                    "lines": [
    +                        {
    +                            "left_index": 0,
    +                            "right_index": 0,
    +                            "match": 0,
    +                            "type": 4,
    +                            "content": "@@ -0,0 +1 @@",
    +                            "section_path": "xinzeng4",
    +                            "section_last_left_index": 0,
    +                            "section_last_right_index": 0,
    +                            "section_left_index": 0,
    +                            "section_right_index": 1,
    +                            "section_left_hunk_size": 0,
    +                            "section_right_hunk_size": 0
    +                        },
    +                        {
    +                            "left_index": 0,
    +                            "right_index": 1,
    +                            "match": -1,
    +                            "type": 2,
    +                            "content": "+111112222"
    +                        }
    +                    ]
    +                }
    +            ],
    +            "is_incomplete": false,
    +            "is_incomplete_line_too_long": false,
    +            "is_protected": false
             }
    -    ],
    -    "total_count": 2
    +    ]
     }
     
    +## 获取比较提交blame +根据分支名、标签、commit ID来获取代码对比blame + +> 示例: + +```shell +curl -X GET \ +-d "from=hh_ceshi" \ +-d "to=master" \ +http://localhost:3000/api/v1/yystopf/csfjkkj/compare.json +``` + +```javascript +await octokit.request('GET /api/v1/yystopf/csfjkkj/compare.json') +``` + +### HTTP 请求 +`GET /api/v1/:owner/:repo/compare.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|owner|是| | string |用户登录名 | +|repo |是| | string |项目标识identifier | +|from |是| | string |源分支、标签、commitID | +|to|是||string|目标分支、标签、commitID| +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|commits_count|int|提交数量| +|commits.branch|string|提交分支| +|commits.author|object|提交作者| +|commits.committer|object|提交者| +|commits.commit_message|string|提交信息| +|commits.sha|string|提交ID| +|commits.parent_shas|array|提交父节点ID| +|diff.file_nums|int|文件数量| +|diff.total_addition|int|新增行数| +|diff.total_deletion|int|删除行数| +|diff.files.name|string|文件名称| +|diff.files.oldname|string|文件修改前名称| +|diff.files.addition|int|文件新增行数| +|diff.files.deletion|int|文件删除行数| +|diff.files.type|int|文件类型 1: 新增 2: 更改 3: 删除 4: 重命名 5: 复制| +|diff.files.is_created|bool|是否为新建文件| +|diff.files.is_deleted|bool|是否为删除文件| +|diff.files.is_bin|bool|是否为二进制文件| +|diff.files.is_lfs_file|bool|| +|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.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.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|| + + + +> 返回的JSON示例: + +```json +{ + "commits_count": 1, + "last_commit_sha": "80dd40214a58622312393b2ae693756a4781fab2", + "commits": [ + { + "author": { + "id": "2", + "login": "yystopf", + "name": "heh", + "type": "User", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "committer": { + "id": "2", + "login": "yystopf", + "name": "heh", + "type": "User", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "branch": "", + "commit_message": "x拟增\n\nSigned-off-by: yystopf ", + "sha": "7e4d8bb3c28e24d4cd6b205f2eed32513e937524", + "parent_shas": null + } + ], + "diff": { + "file_nums": 1, + "total_addition": 1, + "total_deletion": 0, + "files": [ + { + "name": "ceshi123", + "oldname": "ceshi123", + "addition": 1, + "deletion": 0, + "type": 1, + "is_created": true, + "is_deleted": false, + "is_bin": false, + "is_lfs_file": false, + "is_renamed": false, + "is_ambiguous": false, + "is_submodule": false, + "sections": [ + { + "file_name": "ceshi123", + "name": "", + "lines": [ + { + "left_index": 0, + "right_index": 0, + "match": 0, + "type": 4, + "content": "@@ -0,0 +1 @@", + "section_path": "ceshi123", + "section_last_left_index": 0, + "section_last_right_index": 0, + "section_left_index": 0, + "section_right_index": 1, + "section_left_hunk_size": 0, + "section_right_hunk_size": 0 + }, + { + "left_index": 0, + "right_index": 1, + "match": -1, + "type": 2, + "content": "+1111122222" + } + ] + } + ], + "is_incomplete": false, + "is_incomplete_line_too_long": false, + "is_protected": false + } + ] + } +} +``` + + ## 获取仓库webhooks列表 获取仓库webhooks列表 diff --git a/app/services/api/v1/projects/branches/all_list_service.rb b/app/services/api/v1/projects/branches/all_list_service.rb index 9e97b6dd2..182495cdf 100644 --- a/app/services/api/v1/projects/branches/all_list_service.rb +++ b/app/services/api/v1/projects/branches/all_list_service.rb @@ -11,16 +11,20 @@ class Api::V1::Projects::Branches::AllListService < ApplicationService end def call - $gitea_client.token = token unless token.blank? load_gitea_data - $gitea_client.token = nil unless token.blank? gitea_data end private + def request_params + { + access_token: token + } + end + def load_gitea_data - @gitea_data = $gitea_client.get_repos_branch_name_set_by_owner_repo(owner, repo) + @gitea_data = $gitea_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil raise Error, '获取所有分支失败!' unless @gitea_data.is_a?(Hash) end end \ No newline at end of file diff --git a/app/services/api/v1/projects/branches/create_service.rb b/app/services/api/v1/projects/branches/create_service.rb index a4d9f854b..33e561270 100644 --- a/app/services/api/v1/projects/branches/create_service.rb +++ b/app/services/api/v1/projects/branches/create_service.rb @@ -4,7 +4,7 @@ class Api::V1::Projects::Branches::CreateService < ApplicationService attr_accessor :project, :token, :owner, :repo, :old_branch_name, :new_branch_name attr_accessor :gitea_data - validates :new_branch_name, :old_branch_name, presence: :true + validates :new_branch_name, :old_branch_name, presence: true def initialize(project, params, token=nil) @project = project @@ -17,16 +17,20 @@ class Api::V1::Projects::Branches::CreateService < ApplicationService def call raise Error, errors.full_messages.join(",") unless valid? - $gitea_client.token = token unless token.blank? check_new_branch_exist excute_data_to_gitea - $gitea_client.token = nil unless token.blank? gitea_data end private + def request_params + { + access_token: token + } + end + def request_body { new_branch_name: new_branch_name, @@ -35,12 +39,12 @@ class Api::V1::Projects::Branches::CreateService < ApplicationService end def excute_data_to_gitea - @gitea_data = $gitea_client.post_repos_branches_by_owner_repo(owner, repo, {body: request_body.to_json}) + @gitea_data = $gitea_client.post_repos_branches_by_owner_repo(owner, repo, {body: request_body.to_json, query: request_params}) rescue nil raise Error, '创建分支失败!' unless @gitea_data.is_a?(Hash) end def check_new_branch_exist - result = $gitea_client.get_repos_branch_name_set_by_owner_repo(owner, repo) + result = $gitea_client.get_repos_branch_name_set_by_owner_repo(owner, repo) rescue nil raise Error, '查询分支名称失败!' unless result.is_a?(Hash) raise Error, '分支已存在!' if result['branch_name'].include?(@new_branch_name) end diff --git a/app/services/api/v1/projects/commits/diff_service.rb b/app/services/api/v1/projects/commits/diff_service.rb index 8b12fc318..71dd155a0 100644 --- a/app/services/api/v1/projects/commits/diff_service.rb +++ b/app/services/api/v1/projects/commits/diff_service.rb @@ -1,7 +1,11 @@ class Api::V1::Projects::Commits::DiffService < ApplicationService + include ActiveModel::Model + attr_accessor :project, :sha, :token, :owner, :repo attr_accessor :gitea_data + validates :sha, presence: true + def initialize(project, sha, token = nil) @project = project @sha = sha @@ -11,6 +15,7 @@ class Api::V1::Projects::Commits::DiffService < ApplicationService end def call + raise Error, errors.full_messages.join(",") unless valid? load_gitea_data gitea_data @@ -24,7 +29,7 @@ class Api::V1::Projects::Commits::DiffService < ApplicationService end def load_gitea_data - @gitea_data = $gitea_client.get_repos_commits_diff_by_owner_repo_sha(owner, repo, sha, {query: request_params}) + @gitea_data = $gitea_client.get_repos_commits_diff_by_owner_repo_sha(owner, repo, sha, {query: request_params}) rescue nil raise Error, '获取提交对比失败!' unless @gitea_data.is_a?(Hash) end diff --git a/app/services/api/v1/projects/compare_service.rb b/app/services/api/v1/projects/compare_service.rb new file mode 100644 index 000000000..23a248305 --- /dev/null +++ b/app/services/api/v1/projects/compare_service.rb @@ -0,0 +1,34 @@ +class Api::V1::Projects::CompareService < ApplicationService + include ActiveModel::Model + attr_reader :project, :from, :to, :token, :owner, :repo + attr_accessor :gitea_data + + validates :from, :to, presence: true + + def initialize(project, from, to, token=nil) + @project = project + @owner = project&.owner.login + @repo = project&.identifier + @from = from + @to = to + @token = token + end + + def call + raise Error, errors.full_messages.join(",") unless valid? + load_gitea_data + raise Error, '获取对比信息失败!' unless gitea_data.is_a?(Hash) + gitea_data + end + + private + def request_params + { + access_token: token + } + end + + def load_gitea_data + @gitea_data = $gitea_client.get_repos_compare_by_owner_repo_from_to(owner, repo, from, to, {query: request_params}) rescue nil + end +end \ No newline at end of file diff --git a/app/services/api/v1/projects/get_service.rb b/app/services/api/v1/projects/get_service.rb index 1244938ce..ebb0d1cfa 100644 --- a/app/services/api/v1/projects/get_service.rb +++ b/app/services/api/v1/projects/get_service.rb @@ -11,18 +11,20 @@ class Api::V1::Projects::GetService < ApplicationService end def call - $gitea_client.token = token unless token.blank? load_gitea_data load_gitea_branch_tag_count - $gitea_client.token = nil unless token.blank? - result_object rescue raise Error, "服务器错误,请联系系统管理员!" end private + def request_params + { + access_token: token + } + end def result_object { @@ -39,10 +41,10 @@ class Api::V1::Projects::GetService < ApplicationService end def load_gitea_data - @gitea_data = $gitea_client.get_repos_by_owner_repo(owner, repo) + @gitea_data = $gitea_client.get_repos_by_owner_repo(owner, repo, {query: request_params}) rescue nil end def load_gitea_branch_tag_count - @gitea_branch_tag_count = $gitea_client.get_repos_branch_tag_count_by_owner_repo(owner, repo) + @gitea_branch_tag_count = $gitea_client.get_repos_branch_tag_count_by_owner_repo(owner, repo, {query: request_params}) rescue nil end end \ No newline at end of file diff --git a/app/services/api/v1/projects/git/blobs_service.rb b/app/services/api/v1/projects/git/blobs_service.rb index 0b197c106..e2097d933 100644 --- a/app/services/api/v1/projects/git/blobs_service.rb +++ b/app/services/api/v1/projects/git/blobs_service.rb @@ -16,15 +16,19 @@ class Api::V1::Projects::Git::BlobsService < ApplicationService end def call - $gitea_client.token = token unless token.blank? load_gitea_data - $gitea_client.token = nil unless token.blank? gitea_data end private + def request_params + { + access_token: token + } + end + def load_gitea_data - @gitea_data = $gitea_client.get_repos_git_blobs_by_owner_repo_sha(owner, repo, sha) + @gitea_data = $gitea_client.get_repos_git_blobs_by_owner_repo_sha(owner, repo, sha, {query: request_params}) rescue nil end end \ No newline at end of file diff --git a/app/services/api/v1/projects/git/trees_service.rb b/app/services/api/v1/projects/git/trees_service.rb index 2a72c11a5..4d6f5d181 100644 --- a/app/services/api/v1/projects/git/trees_service.rb +++ b/app/services/api/v1/projects/git/trees_service.rb @@ -33,18 +33,20 @@ class Api::V1::Projects::Git::TreesService < ApplicationService { recursive: recursive, page: page, - per_page: limit + per_page: limit, + access_token: token } else { page: page, - per_page: limit + per_page: limit, + access_token: token } end end def load_gitea_data - @gitea_data = $gitea_client.get_repos_git_trees_by_owner_repo_sha(owner, repo, sha, {query: request_query}) + @gitea_data = $gitea_client.get_repos_git_trees_by_owner_repo_sha(owner, repo, sha, {query: request_query}) rescue nil raise Error, '获取文件树列表失败!' unless @gitea_data.is_a?(Hash) end end \ No newline at end of file diff --git a/app/services/api/v1/projects/webhooks/create_service.rb b/app/services/api/v1/projects/webhooks/create_service.rb index 401ff9ff6..bef0a3405 100644 --- a/app/services/api/v1/projects/webhooks/create_service.rb +++ b/app/services/api/v1/projects/webhooks/create_service.rb @@ -26,12 +26,8 @@ class Api::V1::Projects::Webhooks::CreateService < ApplicationService def call raise Error, errors.full_messages.join(",") unless valid? begin - $gitea_client.token = token unless token.blank? - excute_data_to_gitea - $gitea_client.token = nil unless token.blank? - gitea_data rescue raise Error, "服务器错误,请联系系统管理员!" @@ -39,6 +35,12 @@ class Api::V1::Projects::Webhooks::CreateService < ApplicationService end private + def request_params + { + access_token: token + } + end + def request_body { active: active, @@ -55,6 +57,6 @@ class Api::V1::Projects::Webhooks::CreateService < ApplicationService end def excute_data_to_gitea - @gitea_data = $gitea_client.post_repos_hooks_by_owner_repo(owner, repo, {body: request_body.to_json}) + @gitea_data = $gitea_client.post_repos_hooks_by_owner_repo(owner, repo, {body: request_body.to_json, query: request_params}) rescue nil end end \ No newline at end of file diff --git a/app/services/api/v1/projects/webhooks/delete_service.rb b/app/services/api/v1/projects/webhooks/delete_service.rb index 5dd499e6d..8343a5b20 100644 --- a/app/services/api/v1/projects/webhooks/delete_service.rb +++ b/app/services/api/v1/projects/webhooks/delete_service.rb @@ -12,19 +12,21 @@ class Api::V1::Projects::Webhooks::DeleteService < ApplicationService end def call - $gitea_client.token = token unless token.blank? excute_data_to_gitea - $gitea_client.token = nil unless token.blank? - gitea_data rescue raise Error, "服务器错误,请联系系统管理员!" end private + def request_params + { + access_token: token + } + end def excute_data_to_gitea - @gitea_data = $gitea_client.delete_repos_hooks_by_owner_repo_id(owner, repo, id) + @gitea_data = $gitea_client.delete_repos_hooks_by_owner_repo_id(owner, repo, id, {query: request_params}) rescue nil end end \ No newline at end of file diff --git a/app/services/api/v1/projects/webhooks/get_service.rb b/app/services/api/v1/projects/webhooks/get_service.rb index 1ae5c54e2..5c6c79d3e 100644 --- a/app/services/api/v1/projects/webhooks/get_service.rb +++ b/app/services/api/v1/projects/webhooks/get_service.rb @@ -12,10 +12,8 @@ class Api::V1::Projects::Webhooks::GetService < ApplicationService end def call - $gitea_client.token = token unless token.blank? load_gitea_data - $gitea_client.token = nil unless token.blank? gitea_data rescue @@ -23,8 +21,13 @@ class Api::V1::Projects::Webhooks::GetService < ApplicationService end private + def request_params + { + access_token: token + } + end def load_gitea_data - @gitea_data = $gitea_client.get_repos_hooks_by_owner_repo_id(owner, repo, id) + @gitea_data = $gitea_client.get_repos_hooks_by_owner_repo_id(owner, repo, id, {query: request_params}) rescue nil end end \ No newline at end of file diff --git a/app/services/api/v1/projects/webhooks/hooktasks_service.rb b/app/services/api/v1/projects/webhooks/hooktasks_service.rb index 4dd90ee3e..6be9c67c8 100644 --- a/app/services/api/v1/projects/webhooks/hooktasks_service.rb +++ b/app/services/api/v1/projects/webhooks/hooktasks_service.rb @@ -23,8 +23,13 @@ class Api::V1::Projects::Webhooks::ListService < ApplicationService end private + def request_params + { + access_token: token + } + end def load_gitea_data - @gitea_data = $gitea_client.get_repos_hooks_hooktasks_by_owner_repo(owner, repo, id) + @gitea_data = $gitea_client.get_repos_hooks_hooktasks_by_owner_repo(owner, repo, id, {query: request_params}) rescue nil end end \ No newline at end of file diff --git a/app/services/api/v1/projects/webhooks/list_service.rb b/app/services/api/v1/projects/webhooks/list_service.rb index fb746de48..2a76d196c 100644 --- a/app/services/api/v1/projects/webhooks/list_service.rb +++ b/app/services/api/v1/projects/webhooks/list_service.rb @@ -11,19 +11,21 @@ class Api::V1::Projects::Webhooks::ListService < ApplicationService end def call - $gitea_client.token = token unless token.blank? load_gitea_data - $gitea_client.token = nil unless token.blank? - gitea_data rescue raise Error, "服务器错误,请联系系统管理员!" end private + def request_params + { + access_token: token + } + end def load_gitea_data - @gitea_data = $gitea_client.get_repos_hooks_by_owner_repo(owner, repo) + @gitea_data = $gitea_client.get_repos_hooks_by_owner_repo(owner, repo, {query: request_params}) rescue nil end end \ No newline at end of file diff --git a/app/services/api/v1/projects/webhooks/tests_service.rb b/app/services/api/v1/projects/webhooks/tests_service.rb index 3d8b99c97..3f9fe0642 100644 --- a/app/services/api/v1/projects/webhooks/tests_service.rb +++ b/app/services/api/v1/projects/webhooks/tests_service.rb @@ -12,19 +12,21 @@ class Api::V1::Projects::Webhooks::TestsService < ApplicationService end def call - $gitea_client.token = token unless token.blank? excute_data_to_gitea - $gitea_client.token = nil unless token.blank? - gitea_data rescue raise Error, "服务器错误,请联系系统管理员!" end private + def request_params + { + access_token: token + } + end def excute_data_to_gitea - @gitea_data = $gitea_client.post_repos_hooks_tests_by_owner_repo_id(owner, repo, id) + @gitea_data = $gitea_client.post_repos_hooks_tests_by_owner_repo_id(owner, repo, id, {query: request_params}) rescue nil end end \ No newline at end of file diff --git a/app/services/api/v1/projects/webhooks/update_service.rb b/app/services/api/v1/projects/webhooks/update_service.rb index 19ff4f32b..a632d6f2d 100644 --- a/app/services/api/v1/projects/webhooks/update_service.rb +++ b/app/services/api/v1/projects/webhooks/update_service.rb @@ -27,12 +27,8 @@ class Api::V1::Projects::Webhooks::UpdateService < ApplicationService def call raise Error, errors.full_messages.join(",") unless valid? begin - $gitea_client.token = token unless token.blank? - excute_data_to_gitea - $gitea_client.token = nil unless token.blank? - gitea_data rescue raise Error, "服务器错误,请联系系统管理员!" @@ -40,6 +36,12 @@ class Api::V1::Projects::Webhooks::UpdateService < ApplicationService end private + def request_params + { + access_token: token + } + end + def request_body { active: active, @@ -56,6 +58,6 @@ class Api::V1::Projects::Webhooks::UpdateService < ApplicationService end def excute_data_to_gitea - @gitea_data = $gitea_client.patch_repos_hooks_by_owner_repo_id(owner, repo, id, {body: request_body.to_json}) + @gitea_data = $gitea_client.patch_repos_hooks_by_owner_repo_id(owner, repo, id, {body: request_body.to_json, query: request_params}) rescue nil end end \ No newline at end of file diff --git a/app/views/api/v1/projects/_simple_gitea_diff_detail.json.jbuilder b/app/views/api/v1/projects/_simple_gitea_diff_detail.json.jbuilder new file mode 100644 index 000000000..5dff0b89d --- /dev/null +++ b/app/views/api/v1/projects/_simple_gitea_diff_detail.json.jbuilder @@ -0,0 +1,40 @@ +json.file_nums diff['NumFiles'] +json.total_addition diff['TotalAddition'] +json.total_deletion diff['TotalDeletion'] +json.files diff['Files'].each do |file| + 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'] +end \ No newline at end of file diff --git a/app/views/api/v1/projects/commits/diff.json.jbuilder b/app/views/api/v1/projects/commits/diff.json.jbuilder index e0237369f..8c280b7f5 100644 --- a/app/views/api/v1/projects/commits/diff.json.jbuilder +++ b/app/views/api/v1/projects/commits/diff.json.jbuilder @@ -1,40 +1 @@ -json.file_nums @result_object['NumFiles'] -json.total_addition @result_object['TotalAddition'] -json.total_deletion @result_object['TotalAddition'] -json.files @result_object['Files'].each do |file| - 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'] -end \ No newline at end of file +json.partial! "api/v1/projects/simple_gitea_diff_detail", diff: @result_object \ No newline at end of file diff --git a/app/views/api/v1/projects/compare.json.jbuilder b/app/views/api/v1/projects/compare.json.jbuilder new file mode 100644 index 000000000..2d20c51e0 --- /dev/null +++ b/app/views/api/v1/projects/compare.json.jbuilder @@ -0,0 +1,18 @@ +json.commits_count @result_object['CommitsCount'] +json.last_commit_sha @result_object['LatestSha'] +json.commits @result_object['Commits'] do |commit| + json.author do + json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(commit['Author']), name: commit['Author']['Name'] } + end + + json.committer do + json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(commit['Committer']), name: commit['Committer']['Name'] } + end + json.branch commit['Branch'] + json.commit_message commit['CommitMessage'] + json.sha commit['Sha'] + json.parent_shas commit['Sha']['ParentShas'] +end +json.diff do + json.partial! "api/v1/projects/simple_gitea_diff_detail", diff: @result_object['Diff'] +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 789016968..fc07a9862 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -9,7 +9,11 @@ defaults format: :json do scope ':repo' do # projects - resource :projects, path: '/', only: [:show, :update, :edit, :destroy] + resource :projects, path: '/', only: [:show, :update, :edit, :destroy] do + collection do + get :compare + end + end # projects文件夹下的 scope module: :projects do diff --git a/public/docs/api.html b/public/docs/api.html index efc0432b7..505ab44cf 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -556,6 +556,9 @@
  • 获取单个提交的blame信息
  • +
  • + 获取比较提交blame +
  • 获取仓库webhooks列表
  • @@ -9863,9 +9866,9 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae

    返回的JSON示例:

    {
    -    "file_nums": 2,
    -    "total_addition": 2,
    -    "total_deletion": 2,
    +    "file_nums": 1,
    +    "total_addition": 1,
    +    "total_deletion": 0,
         "files": [
             {
                 "name": "xinzeng3",
    @@ -9912,52 +9915,6 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae
                 "is_incomplete": false,
                 "is_incomplete_line_too_long": false,
                 "is_protected": false
    -        },
    -        {
    -            "name": "xinzeng4",
    -            "oldname": "xinzeng4",
    -            "addition": 1,
    -            "deletion": 0,
    -            "type": 1,
    -            "is_created": true,
    -            "is_deleted": false,
    -            "is_bin": false,
    -            "is_lfs_file": false,
    -            "is_renamed": false,
    -            "is_ambiguous": false,
    -            "is_submodule": false,
    -            "sections": [
    -                {
    -                    "file_name": "xinzeng4",
    -                    "name": "",
    -                    "lines": [
    -                        {
    -                            "left_index": 0,
    -                            "right_index": 0,
    -                            "match": 0,
    -                            "type": 4,
    -                            "content": "@@ -0,0 +1 @@",
    -                            "section_path": "xinzeng4",
    -                            "section_last_left_index": 0,
    -                            "section_last_right_index": 0,
    -                            "section_left_index": 0,
    -                            "section_right_index": 1,
    -                            "section_left_hunk_size": 0,
    -                            "section_right_hunk_size": 0
    -                        },
    -                        {
    -                            "left_index": 0,
    -                            "right_index": 1,
    -                            "match": -1,
    -                            "type": 2,
    -                            "content": "+111112222"
    -                        }
    -                    ]
    -                }
    -            ],
    -            "is_incomplete": false,
    -            "is_incomplete_line_too_long": false,
    -            "is_protected": false
             }
         ]
     }
    @@ -9965,17 +9922,19 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae
     
    -

    获取仓库webhooks列表

    -

    获取仓库webhooks列表

    +

    获取比较提交blame

    +

    根据分支名、标签、commit ID来获取代码对比blame

    示例:

    curl -X GET \
    -http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
    -
    await octokit.request('GET /api/v1/yystopf/ceshi/webhooks.json')
    +-d "from=hh_ceshi" \
    +-d "to=master" \
    +http://localhost:3000/api/v1/yystopf/csfjkkj/compare.json
    +
    await octokit.request('GET /api/v1/yystopf/csfjkkj/compare.json')
     

    HTTP 请求

    -

    GET /api/v1/:owner/:repo/webhooks.json

    +

    GET /api/v1/:owner/:repo/compare.json

    请求参数:

    @@ -10000,6 +9959,20 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json + + + + + + + + + + + + + +
    string 项目标识identifier
    fromstring源分支、标签、commitID
    tostring目标分支、标签、commitID

    返回字段说明:

    @@ -10010,6 +9983,318 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    commits_countint提交数量
    commits.branchstring提交分支
    commits.authorobject提交作者
    commits.committerobject提交者
    commits.commit_messagestring提交信息
    commits.shastring提交ID
    commits.parent_shasarray提交父节点ID
    diff.file_numsint文件数量
    diff.total_additionint新增行数
    diff.total_deletionint删除行数
    diff.files.namestring文件名称
    diff.files.oldnamestring文件修改前名称
    diff.files.additionint文件新增行数
    diff.files.deletionint文件删除行数
    diff.files.typeint文件类型 1: 新增 2: 更改 3: 删除 4: 重命名 5: 复制
    diff.files.is_createdbool是否为新建文件
    diff.files.is_deletedbool是否为删除文件
    diff.files.is_binbool是否为二进制文件
    diff.files.is_lfs_filebool
    diff.files.is_renamedbool是否重命名
    diff.files.is_ambiguousbool
    diff.files.is_submodulebool是否为子模块
    diff.files.sections.file_namestring文件名称
    diff.files.sections.namestring
    diff.files.sections.lines.left_indexint
    diff.files.sections.lines.right_indexint
    diff.files.sections.lines.matchint
    diff.files.sections.lines.typeint
    diff.files.sections.lines.contentstring
    diff.files.sections.lines.section_pathstring
    diff.files.sections.lines.section_last_left_indexint
    diff.files.sections.lines.section_last_right_indexint
    diff.files.sections.lines.section_left_indexint
    diff.files.sections.lines.section_right_indexint
    diff.files.sections.lines.section_left_hunk_sizeint
    diff.files.sections.lines.section_right_hunk_sizeint
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "commits_count": 1,
    +    "last_commit_sha": "80dd40214a58622312393b2ae693756a4781fab2",
    +    "commits": [
    +        {
    +            "author": {
    +                "id": "2",
    +                "login": "yystopf",
    +                "name": "heh",
    +                "type": "User",
    +                "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +            },
    +            "committer": {
    +                "id": "2",
    +                "login": "yystopf",
    +                "name": "heh",
    +                "type": "User",
    +                "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +            },
    +            "branch": "",
    +            "commit_message": "x拟增\n\nSigned-off-by: yystopf <yystopf@163.com>",
    +            "sha": "7e4d8bb3c28e24d4cd6b205f2eed32513e937524",
    +            "parent_shas": null
    +        }
    +    ],
    +    "diff": {
    +        "file_nums": 1,
    +        "total_addition": 1,
    +        "total_deletion": 0,
    +        "files": [
    +            {
    +                "name": "ceshi123",
    +                "oldname": "ceshi123",
    +                "addition": 1,
    +                "deletion": 0,
    +                "type": 1,
    +                "is_created": true,
    +                "is_deleted": false,
    +                "is_bin": false,
    +                "is_lfs_file": false,
    +                "is_renamed": false,
    +                "is_ambiguous": false,
    +                "is_submodule": false,
    +                "sections": [
    +                    {
    +                        "file_name": "ceshi123",
    +                        "name": "",
    +                        "lines": [
    +                            {
    +                                "left_index": 0,
    +                                "right_index": 0,
    +                                "match": 0,
    +                                "type": 4,
    +                                "content": "@@ -0,0 +1 @@",
    +                                "section_path": "ceshi123",
    +                                "section_last_left_index": 0,
    +                                "section_last_right_index": 0,
    +                                "section_left_index": 0,
    +                                "section_right_index": 1,
    +                                "section_left_hunk_size": 0,
    +                                "section_right_hunk_size": 0
    +                            },
    +                            {
    +                                "left_index": 0,
    +                                "right_index": 1,
    +                                "match": -1,
    +                                "type": 2,
    +                                "content": "+1111122222"
    +                            }
    +                        ]
    +                    }
    +                ],
    +                "is_incomplete": false,
    +                "is_incomplete_line_too_long": false,
    +                "is_protected": false
    +            }
    +        ]
    +    }
    +}
    +
    + +

    获取仓库webhooks列表

    +

    获取仓库webhooks列表

    + +
    +

    示例:

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

    HTTP 请求

    +

    GET /api/v1/:owner/:repo/webhooks.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    +

    返回字段说明:

    + + + + + + + + @@ -10094,9 +10379,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
    curl -X GET \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
     
    await octokit.request('GET /api/v1/yystopf/ceshi/webhooks/3.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/webhooks/:id.json

    -

    请求参数:

    +

    请求参数:

    参数类型字段说明
    id int id
    @@ -10128,7 +10413,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -10251,214 +10536,8 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
    curl -X POST \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
     
    await octokit.request('POST /api/v1/yystopf/ceshi/webhooks.json')
    -

    HTTP 请求

    -

    POST /api/v1/:owner/:repo/webhooks.json

    -

    请求参数:

    -
    参数
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    webhook.urlstring目标url
    webhook.http_methodstringhttp方法, POST和GET
    webhook.content_typestringPOST Content Type
    webhook.secretstring密钥文本
    webhook.activebool是否激活
    webhook.branch_filterstring分支过滤
    webhook.eventsarray触发事件
    - -

    触发事件字段说明

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数含义
    create创建分支或标签
    delete分支或标签删除
    pushgit仓库推送
    pull_request合并请求
    pull_request_assign合并请求被指派
    pull_request_review_approved合并请求被批准
    pull_request_review_rejected合并请求被拒绝
    - -
    -

    请求的JSON示例:

    -
    -
    {
    -    "active": true, 
    -    "content_type": "json",
    -    "http_method": "GET",
    -    "secret": "123456",
    -    "url": "http://localhost:10000",
    -    "branch_filter": "*",
    -    "events": ["push"]
    -}
    -

    返回字段说明:

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数类型字段说明
    idintid
    urlstring地址
    content_typestringPOST Content Type
    is_activebool是否激活
    typestring类型
    eventsarray触发事件
    create_timestring创建时间
    - -
    -

    返回的JSON示例:

    -
    -
    {
    -    "id": 68,
    -    "content_type": "json",
    -    "http_method": "GET",
    -    "url": "http://127.0.0.1:3000",
    -    "events": [
    -        "create",
    -        "delete",
    -        "push",
    -        "pull_request",
    -        "pull_request_assign",
    -        "pull_request_review_approved",
    -        "pull_request_review_rejected"
    -    ],
    -    "active": true,
    -    "branch_filter": "*",
    -    "created_at": "2022-06-23 15:52"
    -}
    -
    - -

    更新仓库webhook

    -

    更新仓库webhook

    - -
    -

    示例:

    -
    -
    curl -X PATCH \
    -http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    -
    await octokit.request('PATCH /api/v1/yystopf/ceshi/webhooks/7.json')
     

    HTTP 请求

    -

    PATCH /api/v1/:owner/:repo/webhooks/68.json

    +

    POST /api/v1/:owner/:repo/webhooks.json

    请求参数:

    @@ -10484,13 +10563,6 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json - - - - - - - @@ -10592,6 +10664,219 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json "events": ["push"] }

    返回字段说明:

    +
    项目标识identifier
    idstringwebhook id
    webhook.url
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    idintid
    urlstring地址
    content_typestringPOST Content Type
    is_activebool是否激活
    typestring类型
    eventsarray触发事件
    create_timestring创建时间
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "id": 68,
    +    "content_type": "json",
    +    "http_method": "GET",
    +    "url": "http://127.0.0.1:3000",
    +    "events": [
    +        "create",
    +        "delete",
    +        "push",
    +        "pull_request",
    +        "pull_request_assign",
    +        "pull_request_review_approved",
    +        "pull_request_review_rejected"
    +    ],
    +    "active": true,
    +    "branch_filter": "*",
    +    "created_at": "2022-06-23 15:52"
    +}
    +
    + +

    更新仓库webhook

    +

    更新仓库webhook

    + +
    +

    示例:

    +
    +
    curl -X PATCH \
    +http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    +
    await octokit.request('PATCH /api/v1/yystopf/ceshi/webhooks/7.json')
    +

    HTTP 请求

    +

    PATCH /api/v1/:owner/:repo/webhooks/68.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    idstringwebhook id
    webhook.urlstring目标url
    webhook.http_methodstringhttp方法, POST和GET
    webhook.content_typestringPOST Content Type
    webhook.secretstring密钥文本
    webhook.activebool是否激活
    webhook.branch_filterstring分支过滤
    webhook.eventsarray触发事件
    + +

    触发事件字段说明

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数含义
    create创建分支或标签
    delete分支或标签删除
    pushgit仓库推送
    pull_request合并请求
    pull_request_assign合并请求被指派
    pull_request_review_approved合并请求被批准
    pull_request_review_rejected合并请求被拒绝
    + +
    +

    请求的JSON示例:

    +
    +
    {
    +    "active": true, 
    +    "content_type": "json",
    +    "http_method": "GET",
    +    "secret": "123456",
    +    "url": "http://localhost:10000",
    +    "branch_filter": "*",
    +    "events": ["push"]
    +}
    +

    返回字段说明:

    返回的JSON示例:

    @@ -10626,9 +10911,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    curl -X DELETE \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
     
    await octokit.request('DELETE /api/v1/yystopf/ceshi/webhooks/7.json')
    -

    HTTP 请求

    +

    HTTP 请求

    DELETE /api/v1/:owner/:repo/webhooks/:id.json

    -

    请求参数:

    +

    请求参数:

    @@ -10660,7 +10945,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    参数webhook id
    -

    返回字段说明:

    +

    返回字段说明:

    返回的JSON示例:

    @@ -10681,9 +10966,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    curl -X GET \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
     
    await octokit.request('GET /api/v1/yystopf/ceshi/webhooks/3/hooktasks.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/webhooks/:id/hooktasks.json

    -

    请求参数:

    +

    请求参数:

    @@ -10715,7 +11000,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -10952,9 +11237,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
    curl -X POST \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/tests.json
     
    await octokit.request('POST /api/v1/yystopf/ceshi/webhooks/3/tests.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST /api/v1/:owner/:repo/webhooks/:id/tests.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -10986,7 +11271,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/tests.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    返回的JSON示例:

    From bfd2c1d5c7507cd6619f4bde20692d45ccedff23 Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Tue, 19 Jul 2022 09:31:51 +0800 Subject: [PATCH 21/29] =?UTF-8?q?fixed=20=E5=90=8E=E5=8F=B0=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E4=BC=98=E5=8C=96,issue=E5=BD=93=E6=88=90=E6=B4=BB?= =?UTF-8?q?=E8=B7=83=E9=A1=B9=E7=9B=AE=E6=8C=87=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admins/dashboards_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/admins/dashboards_controller.rb b/app/controllers/admins/dashboards_controller.rb index 5ac1508d1..1c2c49d3c 100644 --- a/app/controllers/admins/dashboards_controller.rb +++ b/app/controllers/admins/dashboards_controller.rb @@ -17,9 +17,9 @@ class Admins::DashboardsController < Admins::BaseController @month_new_user_count = User.where(created_on: current_month).count # 活跃项目数 - day_project_ids = CommitLog.where(created_at: today).pluck(:project_id).uniq - weekly_project_ids = CommitLog.where(created_at: current_week).pluck(:project_id).uniq - month_project_ids = CommitLog.where(created_at: current_month).pluck(:project_id).uniq + day_project_ids = (CommitLog.where(created_at: today).pluck(:project_id).uniq + Issue.where(created_on: today).pluck(:project_id).uniq).uniq + weekly_project_ids = (CommitLog.where(created_at: current_week).pluck(:project_id).uniq + Issue.where(created_on: current_week).pluck(:project_id).uniq).uniq + month_project_ids = (CommitLog.where(created_at: current_month).pluck(:project_id).uniq + Issue.where(created_on: current_month).pluck(:project_id).uniq).uniq @day_active_project_count = Project.where(updated_on: today).or(Project.where(id: day_project_ids)).count @weekly_active_project_count = Project.where(updated_on: current_week).or(Project.where(id: weekly_project_ids)).count @month_active_project_count = Project.where(updated_on: current_month).or(Project.where(id: month_project_ids)).count From 52bd5687891905ab906a9a1da6426a01a6031bb1 Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Tue, 19 Jul 2022 09:43:03 +0800 Subject: [PATCH 22/29] =?UTF-8?q?fixed=20=E5=90=8E=E5=8F=B0=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E4=BC=98=E5=8C=96,7=E5=A4=A9=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E7=B2=BE=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admins/dashboards_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/admins/dashboards_controller.rb b/app/controllers/admins/dashboards_controller.rb index 1c2c49d3c..fac44cca9 100644 --- a/app/controllers/admins/dashboards_controller.rb +++ b/app/controllers/admins/dashboards_controller.rb @@ -65,14 +65,14 @@ class Admins::DashboardsController < Admins::BaseController end def current_week - 7.days.ago.beginning_of_day..Time.now.end_of_day + 7.days.ago.end_of_day..Time.now.end_of_day end def current_month - 30.days.ago.beginning_of_day..Time.now.end_of_day + 30.days.ago.end_of_day..Time.now.end_of_day end def pre_week - 14.days.ago.beginning_of_day..7.days.ago.beginning_of_day + 14.days.ago.end_of_day..7.days.ago.end_of_day end end \ No newline at end of file From 274cd81655ce8f7356db88c44e5fe3f25279d5b6 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 19 Jul 2022 10:41:25 +0800 Subject: [PATCH 23/29] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=8E=B7?= =?UTF-8?q?=E5=8F=96commit=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- .../api/v1/projects/commits_controller.rb | 7 +- .../slate/source/includes/_repositories.md | 83 +++ .../api/v1/projects/commits/list_service.rb | 38 ++ .../v1/projects/commits/index.json.jbuilder | 17 + config/routes/api.rb | 2 +- public/docs/api.html | 632 +++++++++++------- 7 files changed, 543 insertions(+), 238 deletions(-) create mode 100644 app/services/api/v1/projects/commits/list_service.rb create mode 100644 app/views/api/v1/projects/commits/index.json.jbuilder diff --git a/Gemfile b/Gemfile index 37687e78d..a4c7c2414 100644 --- a/Gemfile +++ b/Gemfile @@ -135,4 +135,4 @@ gem 'doorkeeper' gem 'doorkeeper-jwt' -gem 'gitea-client', '~> 0.9.4' \ No newline at end of file +gem 'gitea-client', '~> 0.10.1' \ No newline at end of file diff --git a/app/controllers/api/v1/projects/commits_controller.rb b/app/controllers/api/v1/projects/commits_controller.rb index 873dd4d93..a1545ae6f 100644 --- a/app/controllers/api/v1/projects/commits_controller.rb +++ b/app/controllers/api/v1/projects/commits_controller.rb @@ -1,5 +1,10 @@ class Api::V1::Projects::CommitsController < Api::V1::BaseController - before_action :require_public_and_member_above, only: [:diff] + before_action :require_public_and_member_above, only: [:index, :diff] + + def index + @result_object = Api::V1::Projects::Commits::ListService.call(@project, {page: page, limit: limit, sha: params[:sha]}, current_user&.gitea_token) + puts @result_object + end def diff @result_object = Api::V1::Projects::Commits::DiffService.call(@project, params[:sha], current_user&.gitea_token) diff --git a/app/docs/slate/source/includes/_repositories.md b/app/docs/slate/source/includes/_repositories.md index 2b3ca1326..c760fc624 100644 --- a/app/docs/slate/source/includes/_repositories.md +++ b/app/docs/slate/source/includes/_repositories.md @@ -1413,6 +1413,89 @@ await octokit.request('GET /api/v1/yystopf/csfjkkj/git/blobs/80dd40214a586223123 Success Data. +## 获取仓库提交列表 +根据分支名、标签、commit ID来获取提交列表 + +> 示例: + +```shell +curl -X GET \ +-d "sha=master" \ +-d "page=1" \ +-d "limit=1" \ +http://localhost:3000/api/v1/yystopf/csfjkkj/commits.json +``` + +```javascript +await octokit.request('GET /api/v1/yystopf/csfjkkj/commits.json') +``` + +### HTTP 请求 +`GET /api/v1/:owner/:repo/commits.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|owner|是| | string |用户登录名 | +|repo |是| | string |项目标识identifier | +|sha |否| | string |分支名、标签名或Commit ID| +|page |否| | int |页码| +|limit|否| | int |每页数量| +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|total_count|int|提交总数| +|commits.sha|string|提交ID| +|commits.author|object|提交作者| +|commits.committer|object|提交者| +|commits.commit_message|string|提交信息| +|commits.parent_shas|array|提交父节点ID| +|commits.files|array|提交文件| +|commits.commit_date|string|提交日期| +|commits.commit_time|string|提交时间| +|commits.branch|string|提交分支| + + +> 返回的JSON示例: + +```json +{ + "total_count": 12, + "commits": [ + { + "sha": "86c62a1e91c07b58b8aa6c89b94856d89c0f7e55", + "author": { + "id": null, + "login": "viletyy", + "name": "viletyy", + "type": null, + "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png" + }, + "committer": { + "id": null, + "login": "viletyy", + "name": "viletyy", + "type": null, + "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png" + }, + "commit_message": "fix\n", + "parent_shas": [ + "411e4d259785241f1bd14faf99ca24fd1b802f2a" + ], + "files": [ + "hd.txt" + ], + "commit_date": "2022-07-05", + "commit_time": "2022-07-05 11:00:45", + "branch": "hh_ceshi" + } + ] +} +``` + + ## 获取单个提交的blame信息 根据commit ID获取blame信息 diff --git a/app/services/api/v1/projects/commits/list_service.rb b/app/services/api/v1/projects/commits/list_service.rb new file mode 100644 index 000000000..17818554c --- /dev/null +++ b/app/services/api/v1/projects/commits/list_service.rb @@ -0,0 +1,38 @@ +class Api::V1::Projects::Commits::ListService < ApplicationService + + attr_reader :project, :sha, :page, :limit, :owner, :repo, :token + attr_accessor :gitea_data + + def initialize(project, params, token=nil) + @project = project + @sha = params[:sha] + @page = params[:page] || 1 + @limit = params[:limit] || 15 + @owner = project&.owner.login + @repo = project&.identifier + @token = token + end + + def call + load_gitea_data + + gitea_data + end + + private + def request_params + param = { + access_token: token, + page: page, + limit: limit + } + param.merge!(sha: sha) if sha.present? + + param + end + + def load_gitea_data + @gitea_data = $gitea_client.get_repos_commits_by_owner_repo(owner, repo, {query: request_params}) rescue nil + raise Error, '获取提交列表失败!' unless @gitea_data.is_a?(Hash) + end +end \ No newline at end of file diff --git a/app/views/api/v1/projects/commits/index.json.jbuilder b/app/views/api/v1/projects/commits/index.json.jbuilder new file mode 100644 index 000000000..aa13845a1 --- /dev/null +++ b/app/views/api/v1/projects/commits/index.json.jbuilder @@ -0,0 +1,17 @@ +json.total_count @result_object[:total_data].to_i +json.commits @result_object[:data].each do |commit| + json.sha commit['sha'] + json.author do + json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(commit['commit']['author']), name: commit['commit']['author']['name'] } + end + + json.committer do + json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(commit['commit']['committer']), name: commit['commit']['committer']['name'] } + end + json.commit_message commit['commit']['message'] + json.parent_shas commit['parents'].map{|x|x['sha']} + json.files commit['files'].map{|f|f['filename']} + json.commit_date commit['commit_date'] + json.commit_time commit['commit']['committer']['date'].to_time.strftime("%Y-%m-%d %H:%M:%S") + json.branch commit['branch'] +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index fc07a9862..9c71ea800 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -32,7 +32,7 @@ defaults format: :json do get :all end end - + resources :commits, only: [:index] get '/commits/:sha/diff', to: 'commits#diff' get '/git/blobs/:sha', to: 'git#blobs' get '/git/trees/:sha', to: 'git#trees' diff --git a/public/docs/api.html b/public/docs/api.html index 505ab44cf..f3e56574f 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -553,6 +553,9 @@
  • 获取仓库blobs内容
  • +
  • + 获取仓库提交列表 +
  • 获取单个提交的blame信息
  • @@ -9665,6 +9668,165 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae +

    获取仓库提交列表

    +

    根据分支名、标签、commit ID来获取提交列表

    + +
    +

    示例:

    +
    +
    curl -X GET \
    +-d "sha=master" \
    +-d "page=1" \
    +-d "limit=1" \
    +http://localhost:3000/api/v1/yystopf/csfjkkj/commits.json
    +
    await octokit.request('GET /api/v1/yystopf/csfjkkj/commits.json')
    +

    HTTP 请求

    +

    GET /api/v1/:owner/:repo/commits.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    shastring分支名、标签名或Commit ID
    pageint页码
    limitint每页数量
    +

    返回字段说明:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    total_countint提交总数
    commits.shastring提交ID
    commits.authorobject提交作者
    commits.committerobject提交者
    commits.commit_messagestring提交信息
    commits.parent_shasarray提交父节点ID
    commits.filesarray提交文件
    commits.commit_datestring提交日期
    commits.commit_timestring提交时间
    commits.branchstring提交分支
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "total_count": 12,
    +    "commits": [
    +        {
    +            "sha": "86c62a1e91c07b58b8aa6c89b94856d89c0f7e55",
    +            "author": {
    +                "id": null,
    +                "login": "viletyy",
    +                "name": "viletyy",
    +                "type": null,
    +                "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png"
    +            },
    +            "committer": {
    +                "id": null,
    +                "login": "viletyy",
    +                "name": "viletyy",
    +                "type": null,
    +                "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png"
    +            },
    +            "commit_message": "fix\n",
    +            "parent_shas": [
    +                "411e4d259785241f1bd14faf99ca24fd1b802f2a"
    +            ],
    +            "files": [
    +                "hd.txt"
    +            ],
    +            "commit_date": "2022-07-05",
    +            "commit_time": "2022-07-05 11:00:45",
    +            "branch": "hh_ceshi"
    +        }
    +    ]
    +}
    +
    +

    获取单个提交的blame信息

    根据commit ID获取blame信息

    @@ -9673,9 +9835,9 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae
    curl -X GET http://localhost:3000/api/v1/yystopf/csfjkkj/commits/80dd40214a58622312393b2ae693756a4781fab2/diff.json
     
    await octokit.request('GET /api/v1/yystopf/csfjkkj/commits/80dd40214a58622312393b2ae693756a4781fab2/diff.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/commits/:sha/diff.json

    -

    请求参数:

    +

    请求参数:

    @@ -9707,7 +9869,7 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae
    参数提交记录id
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -9933,9 +10095,9 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae -d"to=master"\ http://localhost:3000/api/v1/yystopf/csfjkkj/compare.json
    await octokit.request('GET /api/v1/yystopf/csfjkkj/compare.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/compare.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -9974,7 +10136,7 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/compare.json
    参数目标分支、标签、commitID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -10259,9 +10421,9 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/compare.json
    curl -X GET \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
     
    await octokit.request('GET /api/v1/yystopf/ceshi/webhooks.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/webhooks.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -10286,7 +10448,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
    参数项目标识identifier
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -10379,9 +10541,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
    curl -X GET \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
     
    await octokit.request('GET /api/v1/yystopf/ceshi/webhooks/3.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/webhooks/:id.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -10413,7 +10575,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -10536,214 +10698,8 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
    curl -X POST \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
     
    await octokit.request('POST /api/v1/yystopf/ceshi/webhooks.json')
    -

    HTTP 请求

    -

    POST /api/v1/:owner/:repo/webhooks.json

    -

    请求参数:

    -
    参数
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    webhook.urlstring目标url
    webhook.http_methodstringhttp方法, POST和GET
    webhook.content_typestringPOST Content Type
    webhook.secretstring密钥文本
    webhook.activebool是否激活
    webhook.branch_filterstring分支过滤
    webhook.eventsarray触发事件
    - -

    触发事件字段说明

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数含义
    create创建分支或标签
    delete分支或标签删除
    pushgit仓库推送
    pull_request合并请求
    pull_request_assign合并请求被指派
    pull_request_review_approved合并请求被批准
    pull_request_review_rejected合并请求被拒绝
    - -
    -

    请求的JSON示例:

    -
    -
    {
    -    "active": true, 
    -    "content_type": "json",
    -    "http_method": "GET",
    -    "secret": "123456",
    -    "url": "http://localhost:10000",
    -    "branch_filter": "*",
    -    "events": ["push"]
    -}
    -

    返回字段说明:

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数类型字段说明
    idintid
    urlstring地址
    content_typestringPOST Content Type
    is_activebool是否激活
    typestring类型
    eventsarray触发事件
    create_timestring创建时间
    - -
    -

    返回的JSON示例:

    -
    -
    {
    -    "id": 68,
    -    "content_type": "json",
    -    "http_method": "GET",
    -    "url": "http://127.0.0.1:3000",
    -    "events": [
    -        "create",
    -        "delete",
    -        "push",
    -        "pull_request",
    -        "pull_request_assign",
    -        "pull_request_review_approved",
    -        "pull_request_review_rejected"
    -    ],
    -    "active": true,
    -    "branch_filter": "*",
    -    "created_at": "2022-06-23 15:52"
    -}
    -
    - -

    更新仓库webhook

    -

    更新仓库webhook

    - -
    -

    示例:

    -
    -
    curl -X PATCH \
    -http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    -
    await octokit.request('PATCH /api/v1/yystopf/ceshi/webhooks/7.json')
     

    HTTP 请求

    -

    PATCH /api/v1/:owner/:repo/webhooks/68.json

    +

    POST /api/v1/:owner/:repo/webhooks.json

    请求参数:

    @@ -10769,13 +10725,6 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json - - - - - - - @@ -10877,6 +10826,219 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json "events": ["push"] }

    返回字段说明:

    +
    项目标识identifier
    idstringwebhook id
    webhook.url
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    idintid
    urlstring地址
    content_typestringPOST Content Type
    is_activebool是否激活
    typestring类型
    eventsarray触发事件
    create_timestring创建时间
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "id": 68,
    +    "content_type": "json",
    +    "http_method": "GET",
    +    "url": "http://127.0.0.1:3000",
    +    "events": [
    +        "create",
    +        "delete",
    +        "push",
    +        "pull_request",
    +        "pull_request_assign",
    +        "pull_request_review_approved",
    +        "pull_request_review_rejected"
    +    ],
    +    "active": true,
    +    "branch_filter": "*",
    +    "created_at": "2022-06-23 15:52"
    +}
    +
    + +

    更新仓库webhook

    +

    更新仓库webhook

    + +
    +

    示例:

    +
    +
    curl -X PATCH \
    +http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    +
    await octokit.request('PATCH /api/v1/yystopf/ceshi/webhooks/7.json')
    +

    HTTP 请求

    +

    PATCH /api/v1/:owner/:repo/webhooks/68.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    idstringwebhook id
    webhook.urlstring目标url
    webhook.http_methodstringhttp方法, POST和GET
    webhook.content_typestringPOST Content Type
    webhook.secretstring密钥文本
    webhook.activebool是否激活
    webhook.branch_filterstring分支过滤
    webhook.eventsarray触发事件
    + +

    触发事件字段说明

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数含义
    create创建分支或标签
    delete分支或标签删除
    pushgit仓库推送
    pull_request合并请求
    pull_request_assign合并请求被指派
    pull_request_review_approved合并请求被批准
    pull_request_review_rejected合并请求被拒绝
    + +
    +

    请求的JSON示例:

    +
    +
    {
    +    "active": true, 
    +    "content_type": "json",
    +    "http_method": "GET",
    +    "secret": "123456",
    +    "url": "http://localhost:10000",
    +    "branch_filter": "*",
    +    "events": ["push"]
    +}
    +

    返回字段说明:

    返回的JSON示例:

    @@ -10911,9 +11073,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    curl -X DELETE \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
     
    await octokit.request('DELETE /api/v1/yystopf/ceshi/webhooks/7.json')
    -

    HTTP 请求

    +

    HTTP 请求

    DELETE /api/v1/:owner/:repo/webhooks/:id.json

    -

    请求参数:

    +

    请求参数:

    @@ -10945,7 +11107,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    参数webhook id
    -

    返回字段说明:

    +

    返回字段说明:

    返回的JSON示例:

    @@ -10966,9 +11128,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    curl -X GET \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
     
    await octokit.request('GET /api/v1/yystopf/ceshi/webhooks/3/hooktasks.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/webhooks/:id/hooktasks.json

    -

    请求参数:

    +

    请求参数:

    @@ -11000,7 +11162,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -11237,9 +11399,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
    curl -X POST \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/tests.json
     
    await octokit.request('POST /api/v1/yystopf/ceshi/webhooks/3/tests.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST /api/v1/:owner/:repo/webhooks/:id/tests.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -11271,7 +11433,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/tests.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    返回的JSON示例:

    From 1882120df314e4c5147da5d6ff2157cf7446d35a Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 19 Jul 2022 11:14:50 +0800 Subject: [PATCH 24/29] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=20=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=8D=95=E6=96=87=E4=BB=B6blame=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- app/controllers/api/v1/projects_controller.rb | 7 +- .../slate/source/includes/_repositories.md | 197 +++++ app/services/api/v1/projects/blame_service.rb | 38 + app/views/api/v1/projects/blame.json.jbuilder | 22 + config/routes/api.rb | 1 + public/docs/api.html | 728 ++++++++++++------ 7 files changed, 759 insertions(+), 236 deletions(-) create mode 100644 app/services/api/v1/projects/blame_service.rb create mode 100644 app/views/api/v1/projects/blame.json.jbuilder diff --git a/Gemfile b/Gemfile index a4c7c2414..3da6f273d 100644 --- a/Gemfile +++ b/Gemfile @@ -135,4 +135,4 @@ gem 'doorkeeper' gem 'doorkeeper-jwt' -gem 'gitea-client', '~> 0.10.1' \ No newline at end of file +gem 'gitea-client', '~> 0.10.2' \ No newline at end of file diff --git a/app/controllers/api/v1/projects_controller.rb b/app/controllers/api/v1/projects_controller.rb index 0873213de..bc51362ae 100644 --- a/app/controllers/api/v1/projects_controller.rb +++ b/app/controllers/api/v1/projects_controller.rb @@ -1,5 +1,5 @@ class Api::V1::ProjectsController < Api::V1::BaseController - before_action :require_public_and_member_above, only: [:show, :compare] + before_action :require_public_and_member_above, only: [:show, :compare, :blame] def index render_ok @@ -12,4 +12,9 @@ class Api::V1::ProjectsController < Api::V1::BaseController def compare @result_object = Api::V1::Projects::CompareService.call(@project, params[:from], params[:to], current_user&.gitea_token) end + + def blame + @result_object = Api::V1::Projects::BlameService.call(@project, params[:sha], params[:filepath], current_user&.gitea_token) + puts @result_object + end end \ 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 c760fc624..5b5067495 100644 --- a/app/docs/slate/source/includes/_repositories.md +++ b/app/docs/slate/source/includes/_repositories.md @@ -1614,6 +1614,203 @@ await octokit.request('GET /api/v1/yystopf/csfjkkj/commits/80dd40214a58622312393 Success Data. +## 获取单个文件的blame信息 +根据分支、标签、commitID获取某个文件的blame信息 + +> 示例: + +```shell +curl -X GET \ +-d "sha=master" \ +-d "filepath=hd.txt" \ +http://localhost:3000/api/v1/yystopf/csfjkkj/blame.json +``` + +```javascript +await octokit.request('GET /api/v1/yystopf/csfjkkj/blame.json') +``` + +### HTTP 请求 +`GET /api/v1/:owner/:repo/blame.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|owner |是| | string |用户登录名 | +|repo |是| | string |项目标识identifier | +|sha |是| | string |分支、标签或提交记录id | +|filepath|是| | string |文件路径| +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|file_size|int|文件大小| +|file_name|string|文件名称| +|num_lines|int|文件总行数| +|blame_parts.commit|object|提交| +|blame_parts.current_number|int|当前行数| +|blame_parts.effect_line|int|影响的行数| +|blame_parts.lines|array|行内容| + +> 返回的JSON示例: + +```json +{ + "file_size": 32, + "file_name": "hd.txt", + "num_lines": 12, + "blame_parts": [ + { + "commit": { + "sha": "40f76e80bf5bc41fcc94c28ca8a6eab506c15215", + "author": { + "id": null, + "login": "viletyy", + "name": "viletyy", + "type": null, + "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png" + }, + "committer": { + "id": null, + "login": "viletyy", + "name": "viletyy", + "type": null, + "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png" + }, + "commit_message": "fix\n", + "authored_time": "2022-07-04 18:41:25", + "committed_time": "2022-07-04 18:41:25", + "created_time": "2022-07-04 18:41:25" + }, + "current_number": 1, + "effect_line": 5, + "lines": [ + "dkfj", + "s", + "324", + "234", + "2" + ] + }, + { + "commit": { + "sha": "86c62a1e91c07b58b8aa6c89b94856d89c0f7e55", + "author": { + "id": null, + "login": "viletyy", + "name": "viletyy", + "type": null, + "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png" + }, + "committer": { + "id": null, + "login": "viletyy", + "name": "viletyy", + "type": null, + "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png" + }, + "commit_message": "fix\n", + "authored_time": "2022-07-05 11:00:45", + "committed_time": "2022-07-05 11:00:45", + "created_time": "2022-07-05 11:00:45" + }, + "current_number": 6, + "effect_line": 1, + "lines": [ + "dd" + ] + }, + { + "commit": { + "sha": "40f76e80bf5bc41fcc94c28ca8a6eab506c15215", + "author": { + "id": null, + "login": "viletyy", + "name": "viletyy", + "type": null, + "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png" + }, + "committer": { + "id": null, + "login": "viletyy", + "name": "viletyy", + "type": null, + "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png" + }, + "commit_message": "fix\n", + "authored_time": "2022-07-04 18:41:25", + "committed_time": "2022-07-04 18:41:25", + "created_time": "2022-07-04 18:41:25" + }, + "current_number": 7, + "effect_line": 3, + "lines": [ + "23", + "4", + "23" + ] + }, + { + "commit": { + "sha": "86c62a1e91c07b58b8aa6c89b94856d89c0f7e55", + "author": { + "id": null, + "login": "viletyy", + "name": "viletyy", + "type": null, + "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png" + }, + "committer": { + "id": null, + "login": "viletyy", + "name": "viletyy", + "type": null, + "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png" + }, + "commit_message": "fix\n", + "authored_time": "2022-07-05 11:00:45", + "committed_time": "2022-07-05 11:00:45", + "created_time": "2022-07-05 11:00:45" + }, + "current_number": 10, + "effect_line": 1, + "lines": [ + "s1" + ] + }, + { + "commit": { + "sha": "40f76e80bf5bc41fcc94c28ca8a6eab506c15215", + "author": { + "id": null, + "login": "viletyy", + "name": "viletyy", + "type": null, + "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png" + }, + "committer": { + "id": null, + "login": "viletyy", + "name": "viletyy", + "type": null, + "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png" + }, + "commit_message": "fix\n", + "authored_time": "2022-07-04 18:41:25", + "committed_time": "2022-07-04 18:41:25", + "created_time": "2022-07-04 18:41:25" + }, + "current_number": 11, + "effect_line": 1, + "lines": [ + "" + ] + } + ] +} +``` + ## 获取比较提交blame 根据分支名、标签、commit ID来获取代码对比blame diff --git a/app/services/api/v1/projects/blame_service.rb b/app/services/api/v1/projects/blame_service.rb new file mode 100644 index 000000000..d419fec14 --- /dev/null +++ b/app/services/api/v1/projects/blame_service.rb @@ -0,0 +1,38 @@ +class Api::V1::Projects::BlameService < ApplicationService + include ActiveModel::Model + + attr_reader :project, :sha, :filepath, :owner, :repo, :token + attr_accessor :gitea_data + + validates :sha, :filepath, presence: true + + def initialize(project, sha, filepath, token=nil) + @project = project + @owner = project&.owner.login + @repo = project&.identifier + @sha = sha + @filepath = filepath + @token = token + end + + def call + raise Error, errors.full_messages.join(",") unless valid? + load_gitea_data + + gitea_data + end + + private + def request_params + { + access_token: token, + sha: sha, + filepath: filepath + } + end + + def load_gitea_data + @gitea_data = $gitea_client.get_repos_blame_by_owner_repo(owner, repo, {query: request_params}) + raise Error, '获取项目blame失败!' unless @gitea_data.is_a?(Hash) + end +end \ No newline at end of file diff --git a/app/views/api/v1/projects/blame.json.jbuilder b/app/views/api/v1/projects/blame.json.jbuilder new file mode 100644 index 000000000..d2e689537 --- /dev/null +++ b/app/views/api/v1/projects/blame.json.jbuilder @@ -0,0 +1,22 @@ +json.file_size @result_object['file_size'] +json.file_name @result_object['file_name'] +json.num_lines @result_object['num_lines'] +json.blame_parts @result_object['blame_parts'] do |part| + json.commit do + json.sha part['commit']['id'] + json.author do + json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(part['commit']['author']), name: part['commit']['author']['Name'] } + end + + json.committer do + json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(part['commit']['commiter']), name: part['commit']['commiter']['Name'] } + end + json.commit_message part['commit']['commit_message'] + json.authored_time part['commit']['authored_time'].to_time.strftime("%Y-%m-%d %H:%M:%S") + json.committed_time part['commit']['committed_time'].to_time.strftime("%Y-%m-%d %H:%M:%S") + json.created_time part['commit']['created_time'].to_time.strftime("%Y-%m-%d %H:%M:%S") + end + json.current_number part['current_number'] + json.effect_line part['effect_line'] + json.lines part['lines'] +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 9c71ea800..6a01d1aba 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -12,6 +12,7 @@ defaults format: :json do resource :projects, path: '/', only: [:show, :update, :edit, :destroy] do collection do get :compare + get :blame end end diff --git a/public/docs/api.html b/public/docs/api.html index f3e56574f..0fcb033ae 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -560,7 +560,10 @@ 获取单个提交的blame信息
  • - 获取比较提交blame + 获取单个文件的blame信息 +
  • +
  • + 获取比较提交blame
  • 获取仓库webhooks列表 @@ -10084,7 +10087,264 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/commits.json -

    获取比较提交blame

    +

    获取单个文件的blame信息

    +

    根据分支、标签、commitID获取某个文件的blame信息

    + +
    +

    示例:

    +
    +
    curl -X GET \
    +-d "sha=master" \
    +-d "filepath=hd.txt" \
    +http://localhost:3000/api/v1/yystopf/csfjkkj/blame.json
    +
    await octokit.request('GET /api/v1/yystopf/csfjkkj/blame.json')
    +

    HTTP 请求

    +

    GET /api/v1/:owner/:repo/blame.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    shastring分支、标签或提交记录id
    filepathstring文件路径
    +

    返回字段说明:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    file_sizeint文件大小
    file_namestring文件名称
    num_linesint文件总行数
    blame_parts.commitobject提交
    blame_parts.current_numberint当前行数
    blame_parts.effect_lineint影响的行数
    blame_parts.linesarray行内容
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "file_size": 32,
    +    "file_name": "hd.txt",
    +    "num_lines": 12,
    +    "blame_parts": [
    +        {
    +            "commit": {
    +                "sha": "40f76e80bf5bc41fcc94c28ca8a6eab506c15215",
    +                "author": {
    +                    "id": null,
    +                    "login": "viletyy",
    +                    "name": "viletyy",
    +                    "type": null,
    +                    "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png"
    +                },
    +                "committer": {
    +                    "id": null,
    +                    "login": "viletyy",
    +                    "name": "viletyy",
    +                    "type": null,
    +                    "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png"
    +                },
    +                "commit_message": "fix\n",
    +                "authored_time": "2022-07-04 18:41:25",
    +                "committed_time": "2022-07-04 18:41:25",
    +                "created_time": "2022-07-04 18:41:25"
    +            },
    +            "current_number": 1,
    +            "effect_line": 5,
    +            "lines": [
    +                "dkfj",
    +                "s",
    +                "324",
    +                "234",
    +                "2"
    +            ]
    +        },
    +        {
    +            "commit": {
    +                "sha": "86c62a1e91c07b58b8aa6c89b94856d89c0f7e55",
    +                "author": {
    +                    "id": null,
    +                    "login": "viletyy",
    +                    "name": "viletyy",
    +                    "type": null,
    +                    "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png"
    +                },
    +                "committer": {
    +                    "id": null,
    +                    "login": "viletyy",
    +                    "name": "viletyy",
    +                    "type": null,
    +                    "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png"
    +                },
    +                "commit_message": "fix\n",
    +                "authored_time": "2022-07-05 11:00:45",
    +                "committed_time": "2022-07-05 11:00:45",
    +                "created_time": "2022-07-05 11:00:45"
    +            },
    +            "current_number": 6,
    +            "effect_line": 1,
    +            "lines": [
    +                "dd"
    +            ]
    +        },
    +        {
    +            "commit": {
    +                "sha": "40f76e80bf5bc41fcc94c28ca8a6eab506c15215",
    +                "author": {
    +                    "id": null,
    +                    "login": "viletyy",
    +                    "name": "viletyy",
    +                    "type": null,
    +                    "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png"
    +                },
    +                "committer": {
    +                    "id": null,
    +                    "login": "viletyy",
    +                    "name": "viletyy",
    +                    "type": null,
    +                    "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png"
    +                },
    +                "commit_message": "fix\n",
    +                "authored_time": "2022-07-04 18:41:25",
    +                "committed_time": "2022-07-04 18:41:25",
    +                "created_time": "2022-07-04 18:41:25"
    +            },
    +            "current_number": 7,
    +            "effect_line": 3,
    +            "lines": [
    +                "23",
    +                "4",
    +                "23"
    +            ]
    +        },
    +        {
    +            "commit": {
    +                "sha": "86c62a1e91c07b58b8aa6c89b94856d89c0f7e55",
    +                "author": {
    +                    "id": null,
    +                    "login": "viletyy",
    +                    "name": "viletyy",
    +                    "type": null,
    +                    "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png"
    +                },
    +                "committer": {
    +                    "id": null,
    +                    "login": "viletyy",
    +                    "name": "viletyy",
    +                    "type": null,
    +                    "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png"
    +                },
    +                "commit_message": "fix\n",
    +                "authored_time": "2022-07-05 11:00:45",
    +                "committed_time": "2022-07-05 11:00:45",
    +                "created_time": "2022-07-05 11:00:45"
    +            },
    +            "current_number": 10,
    +            "effect_line": 1,
    +            "lines": [
    +                "s1"
    +            ]
    +        },
    +        {
    +            "commit": {
    +                "sha": "40f76e80bf5bc41fcc94c28ca8a6eab506c15215",
    +                "author": {
    +                    "id": null,
    +                    "login": "viletyy",
    +                    "name": "viletyy",
    +                    "type": null,
    +                    "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png"
    +                },
    +                "committer": {
    +                    "id": null,
    +                    "login": "viletyy",
    +                    "name": "viletyy",
    +                    "type": null,
    +                    "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png"
    +                },
    +                "commit_message": "fix\n",
    +                "authored_time": "2022-07-04 18:41:25",
    +                "committed_time": "2022-07-04 18:41:25",
    +                "created_time": "2022-07-04 18:41:25"
    +            },
    +            "current_number": 11,
    +            "effect_line": 1,
    +            "lines": [
    +                ""
    +            ]
    +        }
    +    ]
    +}
    +
    + +

    获取比较提交blame

    根据分支名、标签、commit ID来获取代码对比blame

    @@ -10095,9 +10355,9 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/commits.json -d "to=master" \ http://localhost:3000/api/v1/yystopf/csfjkkj/compare.json
    await octokit.request('GET /api/v1/yystopf/csfjkkj/compare.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/compare.json

    -

    请求参数:

    +

    请求参数:

    @@ -10136,7 +10396,7 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/compare.json
    参数目标分支、标签、commitID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -10421,9 +10681,9 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/compare.json
    curl -X GET \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
     
    await octokit.request('GET /api/v1/yystopf/ceshi/webhooks.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/webhooks.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -10448,7 +10708,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
    参数项目标识identifier
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -10541,9 +10801,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
    curl -X GET \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
     
    await octokit.request('GET /api/v1/yystopf/ceshi/webhooks/3.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/webhooks/:id.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -10575,7 +10835,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -10698,214 +10958,8 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
    curl -X POST \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
     
    await octokit.request('POST /api/v1/yystopf/ceshi/webhooks.json')
    -

    HTTP 请求

    -

    POST /api/v1/:owner/:repo/webhooks.json

    -

    请求参数:

    -
    参数
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    webhook.urlstring目标url
    webhook.http_methodstringhttp方法, POST和GET
    webhook.content_typestringPOST Content Type
    webhook.secretstring密钥文本
    webhook.activebool是否激活
    webhook.branch_filterstring分支过滤
    webhook.eventsarray触发事件
    - -

    触发事件字段说明

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数含义
    create创建分支或标签
    delete分支或标签删除
    pushgit仓库推送
    pull_request合并请求
    pull_request_assign合并请求被指派
    pull_request_review_approved合并请求被批准
    pull_request_review_rejected合并请求被拒绝
    - -
    -

    请求的JSON示例:

    -
    -
    {
    -    "active": true, 
    -    "content_type": "json",
    -    "http_method": "GET",
    -    "secret": "123456",
    -    "url": "http://localhost:10000",
    -    "branch_filter": "*",
    -    "events": ["push"]
    -}
    -

    返回字段说明:

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数类型字段说明
    idintid
    urlstring地址
    content_typestringPOST Content Type
    is_activebool是否激活
    typestring类型
    eventsarray触发事件
    create_timestring创建时间
    - -
    -

    返回的JSON示例:

    -
    -
    {
    -    "id": 68,
    -    "content_type": "json",
    -    "http_method": "GET",
    -    "url": "http://127.0.0.1:3000",
    -    "events": [
    -        "create",
    -        "delete",
    -        "push",
    -        "pull_request",
    -        "pull_request_assign",
    -        "pull_request_review_approved",
    -        "pull_request_review_rejected"
    -    ],
    -    "active": true,
    -    "branch_filter": "*",
    -    "created_at": "2022-06-23 15:52"
    -}
    -
    - -

    更新仓库webhook

    -

    更新仓库webhook

    - -
    -

    示例:

    -
    -
    curl -X PATCH \
    -http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    -
    await octokit.request('PATCH /api/v1/yystopf/ceshi/webhooks/7.json')
     

    HTTP 请求

    -

    PATCH /api/v1/:owner/:repo/webhooks/68.json

    +

    POST /api/v1/:owner/:repo/webhooks.json

    请求参数:

    @@ -10931,13 +10985,6 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json - - - - - - - @@ -11039,6 +11086,219 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json "events": ["push"] }

    返回字段说明:

    +
    项目标识identifier
    idstringwebhook id
    webhook.url
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    idintid
    urlstring地址
    content_typestringPOST Content Type
    is_activebool是否激活
    typestring类型
    eventsarray触发事件
    create_timestring创建时间
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "id": 68,
    +    "content_type": "json",
    +    "http_method": "GET",
    +    "url": "http://127.0.0.1:3000",
    +    "events": [
    +        "create",
    +        "delete",
    +        "push",
    +        "pull_request",
    +        "pull_request_assign",
    +        "pull_request_review_approved",
    +        "pull_request_review_rejected"
    +    ],
    +    "active": true,
    +    "branch_filter": "*",
    +    "created_at": "2022-06-23 15:52"
    +}
    +
    + +

    更新仓库webhook

    +

    更新仓库webhook

    + +
    +

    示例:

    +
    +
    curl -X PATCH \
    +http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    +
    await octokit.request('PATCH /api/v1/yystopf/ceshi/webhooks/7.json')
    +

    HTTP 请求

    +

    PATCH /api/v1/:owner/:repo/webhooks/68.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    idstringwebhook id
    webhook.urlstring目标url
    webhook.http_methodstringhttp方法, POST和GET
    webhook.content_typestringPOST Content Type
    webhook.secretstring密钥文本
    webhook.activebool是否激活
    webhook.branch_filterstring分支过滤
    webhook.eventsarray触发事件
    + +

    触发事件字段说明

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数含义
    create创建分支或标签
    delete分支或标签删除
    pushgit仓库推送
    pull_request合并请求
    pull_request_assign合并请求被指派
    pull_request_review_approved合并请求被批准
    pull_request_review_rejected合并请求被拒绝
    + +
    +

    请求的JSON示例:

    +
    +
    {
    +    "active": true, 
    +    "content_type": "json",
    +    "http_method": "GET",
    +    "secret": "123456",
    +    "url": "http://localhost:10000",
    +    "branch_filter": "*",
    +    "events": ["push"]
    +}
    +

    返回字段说明:

    返回的JSON示例:

    @@ -11073,9 +11333,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    curl -X DELETE \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
     
    await octokit.request('DELETE /api/v1/yystopf/ceshi/webhooks/7.json')
    -

    HTTP 请求

    +

    HTTP 请求

    DELETE /api/v1/:owner/:repo/webhooks/:id.json

    -

    请求参数:

    +

    请求参数:

    @@ -11107,7 +11367,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    参数webhook id
    -

    返回字段说明:

    +

    返回字段说明:

    返回的JSON示例:

    @@ -11128,9 +11388,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    curl -X GET \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
     
    await octokit.request('GET /api/v1/yystopf/ceshi/webhooks/3/hooktasks.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/webhooks/:id/hooktasks.json

    -

    请求参数:

    +

    请求参数:

    @@ -11162,7 +11422,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -11399,9 +11659,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
    curl -X POST \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/tests.json
     
    await octokit.request('POST /api/v1/yystopf/ceshi/webhooks/3/tests.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST /api/v1/:owner/:repo/webhooks/:id/tests.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -11433,7 +11693,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/tests.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    返回的JSON示例:

    From b386dc51e4bed47a1fd308d206704634cc9c3555 Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Tue, 19 Jul 2022 14:56:02 +0800 Subject: [PATCH 25/29] =?UTF-8?q?fixed=20=E5=90=8E=E5=8F=B0=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E4=BC=98=E5=8C=96,7=E5=A4=A9=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E7=B2=BE=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admins/dashboards_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/admins/dashboards_controller.rb b/app/controllers/admins/dashboards_controller.rb index 5ac1508d1..fac44cca9 100644 --- a/app/controllers/admins/dashboards_controller.rb +++ b/app/controllers/admins/dashboards_controller.rb @@ -17,9 +17,9 @@ class Admins::DashboardsController < Admins::BaseController @month_new_user_count = User.where(created_on: current_month).count # 活跃项目数 - day_project_ids = CommitLog.where(created_at: today).pluck(:project_id).uniq - weekly_project_ids = CommitLog.where(created_at: current_week).pluck(:project_id).uniq - month_project_ids = CommitLog.where(created_at: current_month).pluck(:project_id).uniq + day_project_ids = (CommitLog.where(created_at: today).pluck(:project_id).uniq + Issue.where(created_on: today).pluck(:project_id).uniq).uniq + weekly_project_ids = (CommitLog.where(created_at: current_week).pluck(:project_id).uniq + Issue.where(created_on: current_week).pluck(:project_id).uniq).uniq + month_project_ids = (CommitLog.where(created_at: current_month).pluck(:project_id).uniq + Issue.where(created_on: current_month).pluck(:project_id).uniq).uniq @day_active_project_count = Project.where(updated_on: today).or(Project.where(id: day_project_ids)).count @weekly_active_project_count = Project.where(updated_on: current_week).or(Project.where(id: weekly_project_ids)).count @month_active_project_count = Project.where(updated_on: current_month).or(Project.where(id: month_project_ids)).count @@ -65,14 +65,14 @@ class Admins::DashboardsController < Admins::BaseController end def current_week - 7.days.ago.beginning_of_day..Time.now.end_of_day + 7.days.ago.end_of_day..Time.now.end_of_day end def current_month - 30.days.ago.beginning_of_day..Time.now.end_of_day + 30.days.ago.end_of_day..Time.now.end_of_day end def pre_week - 14.days.ago.beginning_of_day..7.days.ago.beginning_of_day + 14.days.ago.end_of_day..7.days.ago.end_of_day end end \ No newline at end of file From c41c4f5813cf5f053291dfecfebc90dd636dd996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Tue, 19 Jul 2022 15:04:17 +0800 Subject: [PATCH 26/29] fixed --- app/controllers/admins/dashboards_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/admins/dashboards_controller.rb b/app/controllers/admins/dashboards_controller.rb index fac44cca9..dccff054b 100644 --- a/app/controllers/admins/dashboards_controller.rb +++ b/app/controllers/admins/dashboards_controller.rb @@ -39,7 +39,6 @@ class Admins::DashboardsController < Admins::BaseController { value: count['professional'].to_i, name: '专业人士' }, { value: count[nil].to_i, name: '未选职业' }, ] - render_ok(data: data) end From 25afedcdfd941a01da0d1f7c75c94148d676f1b6 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 19 Jul 2022 16:47:01 +0800 Subject: [PATCH 27/29] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=20=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=9B=B4=E6=94=B9=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/contents_controller.rb | 13 + .../slate/source/includes/_repositories.md | 132 +++ .../v1/projects/branches/create_service.rb | 2 +- .../projects/contents/batch_create_service.rb | 91 ++ app/views/api/v1/projects/blame.json.jbuilder | 6 +- .../_simple_gitea_detail.json.jbuilder | 10 + .../v1/projects/commits/index.json.jbuilder | 2 +- .../v1/projects/contents/batch.json.jbuilder | 14 + config/routes/api.rb | 6 + public/docs/api.html | 801 ++++++++++++------ 10 files changed, 816 insertions(+), 261 deletions(-) create mode 100644 app/controllers/api/v1/projects/contents_controller.rb create mode 100644 app/services/api/v1/projects/contents/batch_create_service.rb create mode 100644 app/views/api/v1/projects/commits/_simple_gitea_detail.json.jbuilder create mode 100644 app/views/api/v1/projects/contents/batch.json.jbuilder diff --git a/app/controllers/api/v1/projects/contents_controller.rb b/app/controllers/api/v1/projects/contents_controller.rb new file mode 100644 index 000000000..a4e65051e --- /dev/null +++ b/app/controllers/api/v1/projects/contents_controller.rb @@ -0,0 +1,13 @@ +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) + puts @result_object + end + + private + def batch_content_params + params.require(:content).permit(:author_email, :author_name, :author_timeunix, :branch, :committer_email, :committer_name, :committer_timeunix, :message, :new_branch, files: [ :action_type, :content, :encoding, :file_path]) + end +end \ 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 5b5067495..ae74dac7f 100644 --- a/app/docs/slate/source/includes/_repositories.md +++ b/app/docs/slate/source/includes/_repositories.md @@ -1093,6 +1093,138 @@ await octokit.request('GET /api/yystopf/ceshi/files.json') ] ``` +## 提交文件到仓库 +提交文件到仓库,支持批量 + +> 示例: + +```shell +curl -X POST \ +-d "files[][action_type]=create" \ +-d "files[][content]=jfksj" \ +-d "files[][encoding]=text" \ +-d "files[][file_path]=heihei8" \ +-d "author_email=yystopf@163.com" \ +-d "author_name=yystopf" \ +-d "author_timeunix=1658214400" \ +-d "committer_email=yystopf@163.com" \ +-d "committer_name=yystopf" \ +-d "committer_timeunix=1658214400" \ +-d "branch=develop" \ +-d "new_branch=develop_ceshi" \ +-d "message=测试提交" \ +http://localhost:3000/api/v1/yystopf/ceshi/contents/batch.json +``` + +```javascript +await octokit.request('POST /api/v1/yystopf/ceshi/contents/batch.json') +``` + +### HTTP 请求 +`POST /api/v1/:owner/:repo/contents/batch` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|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示例: + +```json +{ + "files": [ + { + "action_type": "create", + "content": "jfksj", + "encoding": "text", + "file_path": "heihei7" + } + ], + "author_email": "yystopf@163.com", + "author_name": "yystopf", + "author_timeunix": 1658214400, + "committer_email": "yystopf@163.com", + "committer_name": "yystopf", + "committer_timeunix": 1658214400, + "branch": "hh_ceshi", + "message": "测试提交" +} +``` + +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|commit.sha |string |提交ID| +|commit.author |object |作者| +|commit.committer |object |提交者| +|commit.commit_message|string |提交信息| +|commit.parent_shas |array |父节点commit ID| +|commit.authored_time|int |编码时间| +|commit.commited_time|int |提交时间| +|contents.name |string |文件名称| +|contents.path |string |文件路径| +|contents.sha |string |文件标识| +|contents.type |string |文件类型| +|contents.size |int |文件大小| +|contents.url |string |文件地址| +|contents.encoding |string |编码类型 text 文本 base64 加密 | +|contents.content |string |文件内容| + + +> 返回的JSON示例: + +```json +{ + "commit": { + "sha": "7c1e25f9b974e4b7a3816bd7f5e49b441078e999", + "author": { + "id": "2", + "login": "yystopf", + "name": "heh", + "type": "User", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "committer": { + "id": "2", + "login": "yystopf", + "name": "heh", + "type": "User", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "commit_message": "测试提交\n", + "parent_shas": [ + "9aec816d0f3600082ca77893290a14bd29d805fe" + ], + "authored_time": 1658214400, + "commited_time": 1658214400 + }, + "contents": [ + { + "name": "heihei7", + "path": "heihei7", + "sha": "f0acac8efb3021b0f6a7b13b42d033d86e076a4b", + "type": "file", + "size": 5, + "encoding": "base64", + "content": "amZrc2o=" + } + ] +} +``` ## 获取仓库代码目录 获取仓库代码目录 diff --git a/app/services/api/v1/projects/branches/create_service.rb b/app/services/api/v1/projects/branches/create_service.rb index 33e561270..2837dfcf4 100644 --- a/app/services/api/v1/projects/branches/create_service.rb +++ b/app/services/api/v1/projects/branches/create_service.rb @@ -44,7 +44,7 @@ class Api::V1::Projects::Branches::CreateService < ApplicationService end def check_new_branch_exist - result = $gitea_client.get_repos_branch_name_set_by_owner_repo(owner, repo) rescue nil + 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, '分支已存在!' if result['branch_name'].include?(@new_branch_name) end diff --git a/app/services/api/v1/projects/contents/batch_create_service.rb b/app/services/api/v1/projects/contents/batch_create_service.rb new file mode 100644 index 000000000..d987f9318 --- /dev/null +++ b/app/services/api/v1/projects/contents/batch_create_service.rb @@ -0,0 +1,91 @@ +class Api::V1::Projects::Contents::BatchCreateService < ApplicationService + include ActiveModel::Model + + attr_reader :project, :owner, :repo, :token + attr_reader :files, :author_email, :author_name, :author_timeunix, :branch, :committer_email, :committer_name, :committer_timeunix, :message, :new_branch + attr_accessor :gitea_data + + validates :author_email, :committer_email, presence: true, format: { with: CustomRegexp::EMAIL } + validates :author_name, :committer_name, presence: true, format: { with: /\A(?!_)(?!.*?_$)[a-zA-Z0-9_-]{4,15}\z/ } + validates :author_timeunix, :committer_timeunix, presence: true + validates :branch, presence: true + validates :message, presence: true + + + def initialize(project, params, token=nil) + puts params + @project = project + @owner = project&.owner.login + @repo = project&.identifier + @token = token + @files = params[:files] + @author_email = params[:author_email] + @author_name = params[:author_name] + @author_timeunix = params[:author_timeunix] + @branch = params[:branch] + @committer_email = params[:committer_email] + @committer_name = params[:committer_name] + @committer_timeunix = params[:committer_timeunix] + @message = params[:message] + @new_branch = params[:new_branch] + end + + def call + raise Error, '请输入正确的文件参数Files' unless valid_files? + raise Error, errors.full_messages.join(", ") unless valid? + check_branch_exist + excute_data_to_gitea + + gitea_data + end + + private + def request_params + { + access_token: token + } + end + + def request_body + { + files: files, + header: { + author: { + email: author_email, + name: author_name + }, + committer: { + email: committer_email, + name: committer_name + }, + dates: { + author: Time.at(author_timeunix.to_i), + committer: Time.at(committer_timeunix.to_i) + }, + message: message, + new_branch: new_branch, + signoff: false + } + } + end + + def valid_files? + return false unless files.is_a?(Array) && !files.blank? + files.each do |file| + return false unless file.has_key?(:action_type) && file.has_key?(:content) && file.has_key?(:encoding) && file.has_key?(:file_path) + end + end + + def excute_data_to_gitea + @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 + + 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? + end + +end \ No newline at end of file diff --git a/app/views/api/v1/projects/blame.json.jbuilder b/app/views/api/v1/projects/blame.json.jbuilder index d2e689537..8dfa6c8a4 100644 --- a/app/views/api/v1/projects/blame.json.jbuilder +++ b/app/views/api/v1/projects/blame.json.jbuilder @@ -12,9 +12,9 @@ json.blame_parts @result_object['blame_parts'] do |part| json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(part['commit']['commiter']), name: part['commit']['commiter']['Name'] } end json.commit_message part['commit']['commit_message'] - json.authored_time part['commit']['authored_time'].to_time.strftime("%Y-%m-%d %H:%M:%S") - json.committed_time part['commit']['committed_time'].to_time.strftime("%Y-%m-%d %H:%M:%S") - json.created_time part['commit']['created_time'].to_time.strftime("%Y-%m-%d %H:%M:%S") + json.authored_time render_unix_time(part['commit']['authored_time']) + json.committed_time render_unix_time(part['commit']['committed_time']) + json.created_time render_unix_time(part['commit']['created_time']) end json.current_number part['current_number'] json.effect_line part['effect_line'] diff --git a/app/views/api/v1/projects/commits/_simple_gitea_detail.json.jbuilder b/app/views/api/v1/projects/commits/_simple_gitea_detail.json.jbuilder new file mode 100644 index 000000000..36e3cc160 --- /dev/null +++ b/app/views/api/v1/projects/commits/_simple_gitea_detail.json.jbuilder @@ -0,0 +1,10 @@ +json.sha commit['sha'] +json.author do + json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(commit['author']), name: commit['author']['name'] } +end + +json.committer do + json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(commit['committer']), name: commit['committer']['name'] } +end +json.commit_message commit['message'] +json.parent_shas commit['parents'].map{|x|x['sha']} \ No newline at end of file diff --git a/app/views/api/v1/projects/commits/index.json.jbuilder b/app/views/api/v1/projects/commits/index.json.jbuilder index aa13845a1..bd085535c 100644 --- a/app/views/api/v1/projects/commits/index.json.jbuilder +++ b/app/views/api/v1/projects/commits/index.json.jbuilder @@ -12,6 +12,6 @@ json.commits @result_object[:data].each do |commit| json.parent_shas commit['parents'].map{|x|x['sha']} json.files commit['files'].map{|f|f['filename']} json.commit_date commit['commit_date'] - json.commit_time commit['commit']['committer']['date'].to_time.strftime("%Y-%m-%d %H:%M:%S") + json.commit_time render_unix_time(commit['commit']['committer']['date']) json.branch commit['branch'] end \ No newline at end of file diff --git a/app/views/api/v1/projects/contents/batch.json.jbuilder b/app/views/api/v1/projects/contents/batch.json.jbuilder new file mode 100644 index 000000000..a9ef08fa6 --- /dev/null +++ b/app/views/api/v1/projects/contents/batch.json.jbuilder @@ -0,0 +1,14 @@ +json.commit do + json.partial! "api/v1/projects/commits/simple_gitea_detail", commit: @result_object['commit'] + 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'] +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 6a01d1aba..81668804e 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -37,6 +37,12 @@ defaults format: :json do get '/commits/:sha/diff', to: 'commits#diff' get '/git/blobs/:sha', to: 'git#blobs' get '/git/trees/:sha', to: 'git#trees' + + resources :contents, only: [:index] do + collection do + post :batch + end + end end end diff --git a/public/docs/api.html b/public/docs/api.html index 0fcb033ae..52e114d72 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -538,6 +538,9 @@
  • 获取仓库所有文件
  • +
  • + 提交文件到仓库 +
  • 获取仓库代码目录
  • @@ -9056,6 +9059,292 @@ http://localhost:3000/api/yystopf/ceshi/files.json "html_url": "http://localhost:10080/yystopf/ceshi/src/branch/master/README.md" } ] +

    提交文件到仓库

    +

    提交文件到仓库,支持批量

    + +
    +

    示例:

    +
    +
    curl -X POST \
    +-d "files[][action_type]=create" \
    +-d "files[][content]=jfksj" \
    +-d "files[][encoding]=text" \
    +-d "files[][file_path]=heihei8" \
    +-d "author_email=yystopf@163.com" \
    +-d "author_name=yystopf" \
    +-d "author_timeunix=1658214400" \
    +-d "committer_email=yystopf@163.com" \
    +-d "committer_name=yystopf" \
    +-d "committer_timeunix=1658214400" \
    +-d "branch=develop" \
    +-d "new_branch=develop_ceshi" \
    +-d "message=测试提交" \
    +http://localhost:3000/api/v1/yystopf/ceshi/contents/batch.json
    +
    await octokit.request('POST /api/v1/yystopf/ceshi/contents/batch.json')
    +

    HTTP 请求

    +

    POST /api/v1/:owner/:repo/contents/batch

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    files.action_typestring操作类型 create: 创建 update: 更新 delete: 删除
    files.contentstring文件内容
    files.encodingstring文件编码方式 text 文本 base64 加密
    files.file_pathstring文件路径
    author_emailstring作者邮箱
    author_namestring作者名称
    author_timeunixint编码时间,精确到秒
    committer_emailstring提交者邮箱
    committer_namestring提交者名称
    committer_timeunixint提交时间戳,精确到秒
    branchstring提交分支
    new_branchstring如果需要创建新分支,这个需要填
    messagestring提交信息
    + +
    +

    请求的JSON示例:

    +
    +
    {
    +    "files": [
    +        {
    +            "action_type": "create",
    +            "content": "jfksj",
    +            "encoding": "text",
    +            "file_path": "heihei7"
    +        }
    +    ],
    +    "author_email": "yystopf@163.com",
    +    "author_name": "yystopf",
    +    "author_timeunix": 1658214400,
    +    "committer_email": "yystopf@163.com",
    +    "committer_name": "yystopf",
    +    "committer_timeunix": 1658214400,
    +    "branch": "hh_ceshi",
    +    "message": "测试提交"
    +}
    +

    返回字段说明:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    commit.shastring提交ID
    commit.authorobject作者
    commit.committerobject提交者
    commit.commit_messagestring提交信息
    commit.parent_shasarray父节点commit ID
    commit.authored_timeint编码时间
    commit.commited_timeint提交时间
    contents.namestring文件名称
    contents.pathstring文件路径
    contents.shastring文件标识
    contents.typestring文件类型
    contents.sizeint文件大小
    contents.urlstring文件地址
    contents.encodingstring编码类型 text 文本 base64 加密
    contents.contentstring文件内容
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "commit": {
    +        "sha": "7c1e25f9b974e4b7a3816bd7f5e49b441078e999",
    +        "author": {
    +            "id": "2",
    +            "login": "yystopf",
    +            "name": "heh",
    +            "type": "User",
    +            "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +        },
    +        "committer": {
    +            "id": "2",
    +            "login": "yystopf",
    +            "name": "heh",
    +            "type": "User",
    +            "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +        },
    +        "commit_message": "测试提交\n",
    +        "parent_shas": [
    +            "9aec816d0f3600082ca77893290a14bd29d805fe"
    +        ],
    +        "authored_time": 1658214400,
    +        "commited_time": 1658214400
    +    },
    +    "contents": [
    +        {
    +            "name": "heihei7",
    +            "path": "heihei7",
    +            "sha": "f0acac8efb3021b0f6a7b13b42d033d86e076a4b",
    +            "type": "file",
    +            "size": 5,
    +            "encoding": "base64",
    +            "content": "amZrc2o="
    +        }
    +    ]
    +}
     

    获取仓库代码目录

    获取仓库代码目录

    @@ -9066,9 +9355,9 @@ http://localhost:3000/api/yystopf/ceshi/files.json -d "ref=develop" \ http://localhost:3000//api/jasder/jasder_test/entries.json
    await octokit.request('GET /api/jasder/jasder_test/entries.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/entries.json

    -

    请求参数:

    +

    请求参数:

    @@ -9100,7 +9389,7 @@ http://localhost:3000//api/jasder/jasder_test/entries.json
    参数分支名称、tag名称或是提交记录id,默认为master分支
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -9214,9 +9503,9 @@ http://localhost:3000//api/jasder/jasder_test/entries.json -d"filepath=file"\ http://localhost:3000//api/jasder/jasder_test/sub_entries.json
    await octokit.request('GET /api/jasder/jasder_test/sub_entries.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/sub_entries.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -9255,7 +9544,7 @@ http://localhost:3000//api/jasder/jasder_test/sub_entries.json
    参数分支名称、tag名称或是提交记录id,默认为master分支
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -9352,9 +9641,9 @@ http://localhost:3000//api/jasder/jasder_test/sub_entries.json -d"filepath=lib"\ http://localhost:3000/api/yystopf/csfjkkj/readme.json
    await octokit.request('GET /api/yystopf/csfjkkj/readme.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/readme.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -9393,7 +9682,7 @@ http://localhost:3000/api/yystopf/csfjkkj/readme.json
    参数子目录名称,默认为空
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -9466,9 +9755,9 @@ http://localhost:3000/api/yystopf/csfjkkj/readme.json -d"limit=1"\ http://localhost:3000/api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae693756a4781fab2.json
    await octokit.request('GET /api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae693756a4781fab2.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/git/trees/:sha.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -9521,7 +9810,7 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae
    参数分页个数
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -9594,9 +9883,9 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae
    curl -X GET http://localhost:3000/api/v1/yystopf/csfjkkj/git/blobs/80dd40214a58622312393b2ae693756a4781fab2.json
     
    await octokit.request('GET /api/v1/yystopf/csfjkkj/git/blobs/80dd40214a58622312393b2ae693756a4781fab2.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/git/blobs/:sha.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -9628,7 +9917,7 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae
    参数提交记录id
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -9683,9 +9972,9 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/git/trees/80dd40214a58622312393b2ae -d"limit=1"\ http://localhost:3000/api/v1/yystopf/csfjkkj/commits.json
    await octokit.request('GET /api/v1/yystopf/csfjkkj/commits.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/commits.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -9731,7 +10020,7 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/commits.json
    参数每页数量
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -9838,9 +10127,9 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/commits.json
    curl -X GET http://localhost:3000/api/v1/yystopf/csfjkkj/commits/80dd40214a58622312393b2ae693756a4781fab2/diff.json
     
    await octokit.request('GET /api/v1/yystopf/csfjkkj/commits/80dd40214a58622312393b2ae693756a4781fab2/diff.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/commits/:sha/diff.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -9872,7 +10161,7 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/commits.json
    参数提交记录id
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -10098,9 +10387,9 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/commits.json -d"filepath=hd.txt"\ http://localhost:3000/api/v1/yystopf/csfjkkj/blame.json
    await octokit.request('GET /api/v1/yystopf/csfjkkj/blame.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/blame.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -10139,7 +10428,7 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/blame.json
    参数文件路径
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -10355,9 +10644,9 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/blame.json -d"to=master"\ http://localhost:3000/api/v1/yystopf/csfjkkj/compare.json
    await octokit.request('GET /api/v1/yystopf/csfjkkj/compare.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/compare.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -10396,7 +10685,7 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/compare.json
    参数目标分支、标签、commitID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -10681,9 +10970,9 @@ http://localhost:3000/api/v1/yystopf/csfjkkj/compare.json
    curl -X GET \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
     
    await octokit.request('GET /api/v1/yystopf/ceshi/webhooks.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/webhooks.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -10708,7 +10997,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
    参数项目标识identifier
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -10801,9 +11090,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
    curl -X GET \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
     
    await octokit.request('GET /api/v1/yystopf/ceshi/webhooks/3.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/webhooks/:id.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -10835,7 +11124,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -10958,214 +11247,8 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3.json
    curl -X POST \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json
     
    await octokit.request('POST /api/v1/yystopf/ceshi/webhooks.json')
    -

    HTTP 请求

    -

    POST /api/v1/:owner/:repo/webhooks.json

    -

    请求参数:

    -
    参数
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    webhook.urlstring目标url
    webhook.http_methodstringhttp方法, POST和GET
    webhook.content_typestringPOST Content Type
    webhook.secretstring密钥文本
    webhook.activebool是否激活
    webhook.branch_filterstring分支过滤
    webhook.eventsarray触发事件
    - -

    触发事件字段说明

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数含义
    create创建分支或标签
    delete分支或标签删除
    pushgit仓库推送
    pull_request合并请求
    pull_request_assign合并请求被指派
    pull_request_review_approved合并请求被批准
    pull_request_review_rejected合并请求被拒绝
    - -
    -

    请求的JSON示例:

    -
    -
    {
    -    "active": true, 
    -    "content_type": "json",
    -    "http_method": "GET",
    -    "secret": "123456",
    -    "url": "http://localhost:10000",
    -    "branch_filter": "*",
    -    "events": ["push"]
    -}
    -

    返回字段说明:

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数类型字段说明
    idintid
    urlstring地址
    content_typestringPOST Content Type
    is_activebool是否激活
    typestring类型
    eventsarray触发事件
    create_timestring创建时间
    - -
    -

    返回的JSON示例:

    -
    -
    {
    -    "id": 68,
    -    "content_type": "json",
    -    "http_method": "GET",
    -    "url": "http://127.0.0.1:3000",
    -    "events": [
    -        "create",
    -        "delete",
    -        "push",
    -        "pull_request",
    -        "pull_request_assign",
    -        "pull_request_review_approved",
    -        "pull_request_review_rejected"
    -    ],
    -    "active": true,
    -    "branch_filter": "*",
    -    "created_at": "2022-06-23 15:52"
    -}
    -
    - -

    更新仓库webhook

    -

    更新仓库webhook

    - -
    -

    示例:

    -
    -
    curl -X PATCH \
    -http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    -
    await octokit.request('PATCH /api/v1/yystopf/ceshi/webhooks/7.json')
     

    HTTP 请求

    -

    PATCH /api/v1/:owner/:repo/webhooks/68.json

    +

    POST /api/v1/:owner/:repo/webhooks.json

    请求参数:

    @@ -11191,13 +11274,6 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json - - - - - - - @@ -11299,6 +11375,219 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json "events": ["push"] }

    返回字段说明:

    +
    项目标识identifier
    idstringwebhook id
    webhook.url
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    idintid
    urlstring地址
    content_typestringPOST Content Type
    is_activebool是否激活
    typestring类型
    eventsarray触发事件
    create_timestring创建时间
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "id": 68,
    +    "content_type": "json",
    +    "http_method": "GET",
    +    "url": "http://127.0.0.1:3000",
    +    "events": [
    +        "create",
    +        "delete",
    +        "push",
    +        "pull_request",
    +        "pull_request_assign",
    +        "pull_request_review_approved",
    +        "pull_request_review_rejected"
    +    ],
    +    "active": true,
    +    "branch_filter": "*",
    +    "created_at": "2022-06-23 15:52"
    +}
    +
    + +

    更新仓库webhook

    +

    更新仓库webhook

    + +
    +

    示例:

    +
    +
    curl -X PATCH \
    +http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    +
    await octokit.request('PATCH /api/v1/yystopf/ceshi/webhooks/7.json')
    +

    HTTP 请求

    +

    PATCH /api/v1/:owner/:repo/webhooks/68.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    idstringwebhook id
    webhook.urlstring目标url
    webhook.http_methodstringhttp方法, POST和GET
    webhook.content_typestringPOST Content Type
    webhook.secretstring密钥文本
    webhook.activebool是否激活
    webhook.branch_filterstring分支过滤
    webhook.eventsarray触发事件
    + +

    触发事件字段说明

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数含义
    create创建分支或标签
    delete分支或标签删除
    pushgit仓库推送
    pull_request合并请求
    pull_request_assign合并请求被指派
    pull_request_review_approved合并请求被批准
    pull_request_review_rejected合并请求被拒绝
    + +
    +

    请求的JSON示例:

    +
    +
    {
    +    "active": true, 
    +    "content_type": "json",
    +    "http_method": "GET",
    +    "secret": "123456",
    +    "url": "http://localhost:10000",
    +    "branch_filter": "*",
    +    "events": ["push"]
    +}
    +

    返回字段说明:

    返回的JSON示例:

    @@ -11333,9 +11622,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    curl -X DELETE \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
     
    await octokit.request('DELETE /api/v1/yystopf/ceshi/webhooks/7.json')
    -

    HTTP 请求

    +

    HTTP 请求

    DELETE /api/v1/:owner/:repo/webhooks/:id.json

    -

    请求参数:

    +

    请求参数:

    @@ -11367,7 +11656,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    参数webhook id
    -

    返回字段说明:

    +

    返回字段说明:

    返回的JSON示例:

    @@ -11388,9 +11677,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/7.json
    curl -X GET \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
     
    await octokit.request('GET /api/v1/yystopf/ceshi/webhooks/3/hooktasks.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/v1/:owner/:repo/webhooks/:id/hooktasks.json

    -

    请求参数:

    +

    请求参数:

    @@ -11422,7 +11711,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -11659,9 +11948,9 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/hooktasks.json
    curl -X POST \
     http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/tests.json
     
    await octokit.request('POST /api/v1/yystopf/ceshi/webhooks/3/tests.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST /api/v1/:owner/:repo/webhooks/:id/tests.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -11693,7 +11982,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks/3/tests.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    返回的JSON示例:

    From 88fb11ea92c84454c4236825de21f97adb05f1f4 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 21 Jul 2022 10:41:24 +0800 Subject: [PATCH 28/29] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=BA=AF=E6=BA=90pdf=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/trace/pdf_report_service.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/services/trace/pdf_report_service.rb b/app/services/trace/pdf_report_service.rb index aa7312739..7f9947624 100644 --- a/app/services/trace/pdf_report_service.rb +++ b/app/services/trace/pdf_report_service.rb @@ -1,6 +1,7 @@ # 代码溯源 导出pdf require 'open-uri' require 'fileutils' +require 'zip' class Trace::PdfReportService < Trace::ClientService @@ -15,8 +16,16 @@ class Trace::PdfReportService < Trace::ClientService content = open("#{domain}#{base_url}#{url}?task_id=#{task_id}", "Authorization" => token) if content.is_a?(Tempfile) check_file_path - IO.copy_stream(content, "#{save_path}/#{task_id}.pdf") - return {code: 200, download_url: "/trace_task_results/#{task_id}.pdf"} + IO.copy_stream(content, "#{save_path}/report.zip") + Zip::File.open("#{save_path}/report.zip") do |zip_file| + zip_file.each do |f| + name = f.name.force_encoding('utf-8') + next unless name == '/report.pdf' + fpath = File.join(save_path, name) + zip_file.extract(f, fpath) + end + end + return {code: 200, download_url: "/trace_task_results/#{task_id}/report.pdf"} else return {code: 404} end @@ -28,7 +37,7 @@ class Trace::PdfReportService < Trace::ClientService end def save_path - "public/trace_task_results" + "public/trace_task_results/#{task_id}" end def url From abac8b9c4626de5d4770a3992b5453f503a41c30 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 21 Jul 2022 10:52:21 +0800 Subject: [PATCH 29/29] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=BA=AF=E6=BA=90pdf=E5=8F=AA=E9=9C=80=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/traces/projects_controller.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/controllers/traces/projects_controller.rb b/app/controllers/traces/projects_controller.rb index 62573a1d8..e39d77a9e 100644 --- a/app/controllers/traces/projects_controller.rb +++ b/app/controllers/traces/projects_controller.rb @@ -69,12 +69,18 @@ class Traces::ProjectsController < Traces::BaseController def task_pdf - return render_error("task_id错误") if params[:task_id].blank? - result = Trace::PdfReportService.call(current_user.trace_token, params[:task_id]) - if result.is_a?(Hash) && result[:code] == 200 - redirect_to result[:download_url] + task_id = params[:task_id] + return render_error("task_id错误") if task_id.blank? + file_save_path = "public/trace_task_results/#{task_id}/report.pdf" + if File.exists?(file_save_path) + redirect_to "/trace_task_results/#{task_id}/report.pdf" else - render_error("下载报告失败!") + result = Trace::PdfReportService.call(current_user.trace_token, task_id) + if result.is_a?(Hash) && result[:code] == 200 + redirect_to result[:download_url] + else + render_error("下载报告失败!") + end end rescue Exception => exception puts exception.message