From 8bf4e9b8d23029070ca525192de3eed3074cf8e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Tue, 2 Aug 2022 18:10:01 +0800 Subject: [PATCH 1/5] fixed Repository.url --- app/models/repository.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 03c4e98e0..c60164001 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -49,7 +49,7 @@ class Repository < ApplicationRecord end def url - self['url'].blank? ? "#{Gitea.gitea_config[:domain]}/#{self.owner&.login}/#{self.identifier}.git" : self['url'] + self['url'].blank? ? "#{GiteaService.gitea_config[:domain]}/#{self.owner&.login}/#{self.identifier}.git" : self['url'] end # with repository is mirror From ab5d273f9888339cc72512a12239f2bcd696b8bb Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 2 Aug 2022 19:03:54 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=89=88?= =?UTF-8?q?=E6=9C=ACdiff=E6=96=B0=E5=A2=9Ediff=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/_simple_gitea_diff_detail.json.jbuilder | 1 + .../api/v1/projects/_simple_gitea_diff_file_detail.json.jbuilder | 1 + 2 files changed, 2 insertions(+) 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 index 5dff0b89d..f313d2edd 100644 --- a/app/views/api/v1/projects/_simple_gitea_diff_detail.json.jbuilder +++ b/app/views/api/v1/projects/_simple_gitea_diff_detail.json.jbuilder @@ -14,6 +14,7 @@ json.files diff['Files'].each do |file| json.is_renamed file['IsRenamed'] json.is_ambiguous file['IsAmbiguous'] json.is_submodule file['IsSubmodule'] + json.diff file['Diff'] json.sections file['Sections'] do |section| json.file_name section['FileName'] json.name section['Name'] diff --git a/app/views/api/v1/projects/_simple_gitea_diff_file_detail.json.jbuilder b/app/views/api/v1/projects/_simple_gitea_diff_file_detail.json.jbuilder index 13f833338..9bbcafd5f 100644 --- a/app/views/api/v1/projects/_simple_gitea_diff_file_detail.json.jbuilder +++ b/app/views/api/v1/projects/_simple_gitea_diff_file_detail.json.jbuilder @@ -10,6 +10,7 @@ json.name file['Name'] json.is_renamed file['IsRenamed'] json.is_ambiguous file['IsAmbiguous'] json.is_submodule file['IsSubmodule'] + json.diff file['Diff'] json.sections file['Sections'] do |section| json.file_name section['FileName'] json.name section['Name'] From fea11bdc2ec9b0a5c44d3863cc0832571187c6c7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 3 Aug 2022 14:20:25 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Awebhook=20type?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/webhooks_controller.rb | 7 ++++++- app/docs/slate/source/includes/_pulls.md | 1 + app/docs/slate/source/includes/_repositories.md | 2 +- .../api/v1/projects/webhooks/create_service.rb | 7 ++++--- .../projects/webhooks/_simple_detail.json.jbuilder | 2 +- .../webhooks/_simple_gitea_detail.json.jbuilder | 1 + public/docs/api.html | 12 ++++++++++++ 7 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/v1/projects/webhooks_controller.rb b/app/controllers/api/v1/projects/webhooks_controller.rb index bb2c2172c..1dec26d21 100644 --- a/app/controllers/api/v1/projects/webhooks_controller.rb +++ b/app/controllers/api/v1/projects/webhooks_controller.rb @@ -5,11 +5,12 @@ class Api::V1::Projects::WebhooksController < Api::V1::BaseController def index # @result_object = Api::V1::Projects::Webhooks::ListService.call(@project, current_user&.gitea_token) @webhooks = @project.webhooks + @webhooks = @webhooks.where(type: params[:type]) if params[:type].present? @webhooks = kaminari_paginate(@webhooks) end def create - @result_object = Api::V1::Projects::Webhooks::CreateService.call(@project, webhook_params, current_user&.gitea_token) + @result_object = Api::V1::Projects::Webhooks::CreateService.call(@project, create_webhook_params, current_user&.gitea_token) end def show @@ -44,6 +45,10 @@ class Api::V1::Projects::WebhooksController < Api::V1::BaseController end private + def create_webhook_params + params.require(:webhook).permit(:active, :branch_filter, :http_method, :url, :content_type, :secret, :type, events: []) + end + def webhook_params params.require(:webhook).permit(:active, :branch_filter, :http_method, :url, :content_type, :secret, events: []) end diff --git a/app/docs/slate/source/includes/_pulls.md b/app/docs/slate/source/includes/_pulls.md index adc6e3cc4..671c7fbd5 100644 --- a/app/docs/slate/source/includes/_pulls.md +++ b/app/docs/slate/source/includes/_pulls.md @@ -903,6 +903,7 @@ await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/versions/33/diff |is_renamed|bool|是否重命名| |is_ambiguous|bool|| |is_submodule|bool|是否为子模块| +|diff|string|git diff内容| |sections.file_name|string|文件名称| |sections.name|string|| |sections.lines.left_index|int|文件变动之前所在行数| diff --git a/app/docs/slate/source/includes/_repositories.md b/app/docs/slate/source/includes/_repositories.md index a9fa42e2c..b06325090 100644 --- a/app/docs/slate/source/includes/_repositories.md +++ b/app/docs/slate/source/includes/_repositories.md @@ -2283,7 +2283,7 @@ await octokit.request('POST /api/v1/yystopf/ceshi/webhooks.json') |webhook.active |是| | bool | 是否激活| |webhook.branch_filter|否| |string|分支过滤| |webhook.events |否| |array|触发事件| - +|webhook.type |否| gitea |string| hook类型,gitea slack discord dingtalk telegram msteams feishu matrix jianmu| 触发事件字段说明 参数| 含义| diff --git a/app/services/api/v1/projects/webhooks/create_service.rb b/app/services/api/v1/projects/webhooks/create_service.rb index bef0a3405..edc8b2263 100644 --- a/app/services/api/v1/projects/webhooks/create_service.rb +++ b/app/services/api/v1/projects/webhooks/create_service.rb @@ -1,14 +1,14 @@ class Api::V1::Projects::Webhooks::CreateService < ApplicationService include ActiveModel::Model - attr_reader :project, :token, :owner, :repo, :active, :branch_filter, :content_type, :url, :http_method, :secret, :events + attr_reader :project, :token, :owner, :repo, :active, :branch_filter, :content_type, :url, :http_method, :secret, :events, :type attr_accessor :gitea_data validates :url, format: { with: URI::regexp(%w[http https]), message: "请输入正确的地址" } validates :active, inclusion: {in: [true, false]} validates :http_method, inclusion: { in: %w(POST GET), message: "请输入正确的请求方式"} validates :content_type, inclusion: { in: %w(json form), message: "请输入正确的Content Type"} - + validates :type, inclusion: {in: %w(gitea slack discord dingtalk telegram msteams feishu matrix jianmu), message: "请输入正确的Webhook Type"} def initialize(project, params, token=nil) @project = project @owner = project&.owner.login @@ -20,6 +20,7 @@ class Api::V1::Projects::Webhooks::CreateService < ApplicationService @http_method = params[:http_method] @secret = params[:secret] @events = params[:events] + @type = params[:type] || "gitea" @token = token end @@ -52,7 +53,7 @@ class Api::V1::Projects::Webhooks::CreateService < ApplicationService secret: secret }, events: events || [], - type: 'gitea', + type: type, } end diff --git a/app/views/api/v1/projects/webhooks/_simple_detail.json.jbuilder b/app/views/api/v1/projects/webhooks/_simple_detail.json.jbuilder index 145b3e59b..6926cfd32 100644 --- a/app/views/api/v1/projects/webhooks/_simple_detail.json.jbuilder +++ b/app/views/api/v1/projects/webhooks/_simple_detail.json.jbuilder @@ -1,3 +1,3 @@ -json.(webhook, :id, :url, :http_method, :is_active) +json.(webhook, :id, :url, :http_method, :is_active, :type) json.last_status webhook.last_status json.create_time Time.at(webhook.created_unix).strftime("%Y-%m-%d %H:%M:%S") \ No newline at end of file diff --git a/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder b/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder index ca180d8b1..96c9eac12 100644 --- a/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder +++ b/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder @@ -1,4 +1,5 @@ json.id webhook["id"] +json.type webhook["type"] json.content_type webhook['config']['content_type'] json.http_method webhook['config']['http_method'] json.url webhook['config']['url'] diff --git a/public/docs/api.html b/public/docs/api.html index bcc4da5c9..a9909eb91 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -11364,6 +11364,13 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json array 触发事件 + +webhook.type +否 +gitea +string +hook类型,gitea slack discord dingtalk telegram msteams feishu matrix jianmu +

触发事件字段说明

@@ -14032,6 +14039,11 @@ http://localhost:3000/api/v1/yystopf/ceshi_commit/pulls/3/versions/33/diff.json 是否为子模块 +diff +string +git diff内容 + + sections.file_name string 文件名称 From 96d34d0237f20b38293fba47aef551974d32a1e9 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 3 Aug 2022 15:31:04 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E8=AF=B7=E6=B1=82=E5=AE=A1=E6=9F=A5=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pulls/reviews_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/projects/pulls/reviews_controller.rb b/app/controllers/api/v1/projects/pulls/reviews_controller.rb index 039a6c4df..11df824e8 100644 --- a/app/controllers/api/v1/projects/pulls/reviews_controller.rb +++ b/app/controllers/api/v1/projects/pulls/reviews_controller.rb @@ -13,7 +13,7 @@ class Api::V1::Projects::Pulls::ReviewsController < Api::V1::Projects::Pulls::Ba private def require_reviewer - return render_forbidden('您没有审查权限,请联系项目管理员') if !current_user.admin? && !@pull_request.reviewers.exists?(current_user.id) + return render_forbidden('您没有审查权限,请联系项目管理员') if !current_user.admin? && !@pull_request.reviewers.exists?(current_user.id) && !@project.manager?(current_user) end def review_params From 024bc289defc5ba36d311cca07620ef491574561 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 3 Aug 2022 17:13:45 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9:=20=E5=90=88=E5=B9=B6?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E8=AF=84=E8=AE=BA=E5=BF=85=E9=80=89=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=BB=A5=E5=8F=8A=E5=AE=A1=E6=9F=A5=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pulls/reviews_controller.rb | 3 ++- app/docs/slate/source/includes/_pulls.md | 3 ++- .../api/v1/projects/pulls/journals/create_service.rb | 2 +- .../api/v1/projects/pulls/reviews/index.json.jbuilder | 3 ++- public/docs/api.html | 9 ++++++++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/projects/pulls/reviews_controller.rb b/app/controllers/api/v1/projects/pulls/reviews_controller.rb index 11df824e8..622296c6c 100644 --- a/app/controllers/api/v1/projects/pulls/reviews_controller.rb +++ b/app/controllers/api/v1/projects/pulls/reviews_controller.rb @@ -2,7 +2,8 @@ class Api::V1::Projects::Pulls::ReviewsController < Api::V1::Projects::Pulls::Ba def index @reviews = @pull_request.reviews - @reviews = kaminari_paginate(@reviews) + @reviews = @reviews.where(status: params[:status]) if params[:status].present? + # @reviews = kaminari_paginate(@reviews) end before_action :require_reviewer, only: [:create] diff --git a/app/docs/slate/source/includes/_pulls.md b/app/docs/slate/source/includes/_pulls.md index 671c7fbd5..9733f958b 100644 --- a/app/docs/slate/source/includes/_pulls.md +++ b/app/docs/slate/source/includes/_pulls.md @@ -1029,6 +1029,7 @@ await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/reviews.json') |owner |是| |string |用户登录名 | |repo |是| |string |项目标识identifier | |index |是| | int |合并请求序号| +|status |否| |string |审查类型, common: 评论类型, approved: 已通过, rejected: 已拒绝| ### 返回字段说明: 参数 | 类型 | 字段说明 @@ -1373,7 +1374,7 @@ await octokit.request('POST /api/v1/yystopf/ceshi/pulls/1/journals.json') |index |是| | integer|合并请求序号| |type |是| | string |评论类型 comment: 普通, problem: 需要回应的评论| |note |否| | string |评论内容| -|review_id |是| | string |审查ID| +|review_id |否| | string |审查ID| |line_code |否| | string |行号| |commit_id |否| | bool |commitID| |path |否| | integer|文件路径| diff --git a/app/services/api/v1/projects/pulls/journals/create_service.rb b/app/services/api/v1/projects/pulls/journals/create_service.rb index 45b5ec030..7b0401c90 100644 --- a/app/services/api/v1/projects/pulls/journals/create_service.rb +++ b/app/services/api/v1/projects/pulls/journals/create_service.rb @@ -23,7 +23,7 @@ class Api::V1::Projects::Pulls::Journals::CreateService < ApplicationService def call raise Error, errors.full_messages.join(", ") unless valid? - check_review_is_exists + check_review_is_exists if review_id.present? if type == 'problem' create_problem_journal else diff --git a/app/views/api/v1/projects/pulls/reviews/index.json.jbuilder b/app/views/api/v1/projects/pulls/reviews/index.json.jbuilder index 04792d5c6..567df1b75 100644 --- a/app/views/api/v1/projects/pulls/reviews/index.json.jbuilder +++ b/app/views/api/v1/projects/pulls/reviews/index.json.jbuilder @@ -1,4 +1,5 @@ -json.total_count @reviews.total_count +# json.total_count @reviews.total_count +json.total_count @reviews.count json.reviews @reviews.each do |review| json.partial! 'api/v1/projects/pulls/reviews/simple_detail', review: review end \ No newline at end of file diff --git a/public/docs/api.html b/public/docs/api.html index a9909eb91..943f8c361 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -14254,6 +14254,13 @@ http://localhost:3000/api/v1/yystopf/ceshi_commit/pulls/3/versions/33/diff.json int 合并请求序号 + +status +否 + +string +审查类型, common: 评论类型, approved: 已通过, rejected: 已拒绝 +

返回字段说明:

@@ -15000,7 +15007,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/journals.json - +
review_id string 审查ID