From 72ba784e70eaf8a5f11c54d40e4c8764210a351d Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Thu, 13 Aug 2020 11:06:34 +0800 Subject: [PATCH 1/7] =?UTF-8?q?FIX=20=E7=89=88=E6=9C=AC=E5=BA=93=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E3=80=81=E5=88=9B=E5=BB=BA=E3=80=81=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E6=9D=83=E9=99=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 6 +++--- app/interactors/gitea/create_file_interactor.rb | 12 ++++++------ app/interactors/gitea/delete_file_interactor.rb | 13 +++++++------ app/interactors/gitea/update_file_interactor.rb | 13 +++++++------ .../gitea/repository/entries/create_service.rb | 13 +++++++------ .../gitea/repository/entries/delete_service.rb | 11 ++++++----- .../gitea/repository/entries/update_service.rb | 11 ++++++----- 7 files changed, 42 insertions(+), 37 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index c8ab51cba..2e2711aa9 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -66,7 +66,7 @@ class RepositoriesController < ApplicationController end def create_file - interactor = Gitea::CreateFileInteractor.call(current_user, content_params) + interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @project.owner.login, content_params) if interactor.success? @file = interactor.result create_new_pr(params) @@ -76,7 +76,7 @@ class RepositoriesController < ApplicationController end def update_file - interactor = Gitea::UpdateFileInteractor.call(current_user, params.merge(identifier: @project.identifier)) + interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @project.owner.login, params.merge(identifier: @project.identifier)) if interactor.success? @file = interactor.result create_new_pr(params) @@ -87,7 +87,7 @@ class RepositoriesController < ApplicationController end def delete_file - interactor = Gitea::DeleteFileInteractor.call(current_user, params.merge(identifier: @project.identifier)) + interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @project.owner.login, params.merge(identifier: @project.identifier)) if interactor.success? @file = interactor.result render_result(1, "文件删除成功") diff --git a/app/interactors/gitea/create_file_interactor.rb b/app/interactors/gitea/create_file_interactor.rb index d8232379a..27a381e73 100644 --- a/app/interactors/gitea/create_file_interactor.rb +++ b/app/interactors/gitea/create_file_interactor.rb @@ -1,15 +1,15 @@ module Gitea class CreateFileInteractor - def self.call(user, params={}) - interactor = new(user, params) + def self.call(token, owner, params={}) + interactor = new(token, owner, params) interactor.run interactor end attr_reader :error, :result - def initialize(user, params) - @user = user + def initialize(token, owner, params) + @owner = owner @params = params end @@ -23,7 +23,7 @@ module Gitea def run Contents::CreateForm.new(valid_params).validate! - response = Gitea::Repository::Entries::CreateService.new(user, @params[:identifier], @params[:filepath], file_params).call + response = Gitea::Repository::Entries::CreateService.new(token, owner, @params[:identifier], @params[:filepath], file_params).call render_result(response) rescue Exception => exception Rails.logger.info "Exception ===========> #{exception.message}" @@ -33,7 +33,7 @@ module Gitea private - attr_reader :params, :user + attr_reader :params, :owner, :token def fail!(error) @error = error diff --git a/app/interactors/gitea/delete_file_interactor.rb b/app/interactors/gitea/delete_file_interactor.rb index d68988d19..9a48c9e56 100644 --- a/app/interactors/gitea/delete_file_interactor.rb +++ b/app/interactors/gitea/delete_file_interactor.rb @@ -1,15 +1,16 @@ module Gitea class DeleteFileInteractor - def self.call(user, params={}) - interactor = new(user, params) + def self.call(token, owner, params={}) + interactor = new(token, owner, params) interactor.run interactor end attr_reader :error, :result - def initialize(user, params) - @user = user + def initialize(token, owner, params) + @token = token + @owner = owner @params = params end @@ -23,7 +24,7 @@ module Gitea def run Contents::DeleteForm.new(valid_params).validate! - response = Gitea::Repository::Entries::DeleteService.new(user, @params[:identifier], @params[:filepath], file_params).call + response = Gitea::Repository::Entries::DeleteService.new(token, owner, @params[:identifier], @params[:filepath], file_params).call render_result(response) rescue Exception => exception fail!(exception.message) @@ -31,7 +32,7 @@ module Gitea private - attr_reader :params, :user + attr_reader :params, :owner, :token def fail!(error) puts "[exception]: error" diff --git a/app/interactors/gitea/update_file_interactor.rb b/app/interactors/gitea/update_file_interactor.rb index af895d481..7dc0c017f 100644 --- a/app/interactors/gitea/update_file_interactor.rb +++ b/app/interactors/gitea/update_file_interactor.rb @@ -1,15 +1,16 @@ module Gitea class UpdateFileInteractor - def self.call(user, params={}) - interactor = new(user, params) + def self.call(token, owner, params={}) + interactor = new(token, owner, params) interactor.run interactor end attr_reader :error, :result - def initialize(user, params) - @user = user + def initialize(token, owner, params) + @owner = owner + @token = token @params = params end @@ -23,7 +24,7 @@ module Gitea def run Contents::UpdateForm.new(valid_params).validate! - response = Gitea::Repository::Entries::UpdateService.new(user, @params[:identifier], @params[:filepath], file_params).call + response = Gitea::Repository::Entries::UpdateService.new(token, owner, @params[:identifier], @params[:filepath], file_params).call render_result(response) rescue Exception => exception fail!(exception.message) @@ -31,7 +32,7 @@ module Gitea private - attr_reader :params, :user + attr_reader :params, :owner, :token def fail!(error) puts "[exception]: error" diff --git a/app/services/gitea/repository/entries/create_service.rb b/app/services/gitea/repository/entries/create_service.rb index 62514fadb..86dd3b2fc 100644 --- a/app/services/gitea/repository/entries/create_service.rb +++ b/app/services/gitea/repository/entries/create_service.rb @@ -1,5 +1,5 @@ class Gitea::Repository::Entries::CreateService < Gitea::ClientService - attr_reader :user, :repo_name, :filepath, :body + attr_reader :token, :owner, :repo_name, :filepath, :body # ref: The name of the commit/branch/tag. Default the repository’s default branch (usually master) # filepath: path of the dir, file, symlink or submodule in the repo @@ -20,11 +20,12 @@ class Gitea::Repository::Entries::CreateService < Gitea::ClientService # "new_branch": "string" # } # - def initialize(user, repo_name, filepath, body) - @user = user + def initialize(token, owner, repo_name, filepath, body) + @token = token + @owner = owner @repo_name = repo_name @filepath = filepath - @body = body + @body = bodys end def call @@ -33,11 +34,11 @@ class Gitea::Repository::Entries::CreateService < Gitea::ClientService private def params - Hash.new.merge(token: user.gitea_token, data: body) + Hash.new.merge(token: token, data: body) end def url - "/repos/#{user.login}/#{repo_name}/contents/#{filepath}".freeze + "/repos/#{owner}/#{repo_name}/contents/#{filepath}".freeze end end diff --git a/app/services/gitea/repository/entries/delete_service.rb b/app/services/gitea/repository/entries/delete_service.rb index cfc79a5b6..f9f412903 100644 --- a/app/services/gitea/repository/entries/delete_service.rb +++ b/app/services/gitea/repository/entries/delete_service.rb @@ -1,5 +1,5 @@ class Gitea::Repository::Entries::DeleteService < Gitea::ClientService - attr_reader :user, :repo_name, :filepath, :body + attr_reader :token, :owner, :repo_name, :filepath, :body # ref: The name of the commit/branch/tag. Default the repository’s default branch (usually master) # filepath: path of the dir, file, symlink or submodule in the repo @@ -19,8 +19,9 @@ class Gitea::Repository::Entries::DeleteService < Gitea::ClientService # "new_branch": "string", # "sha": "string", #require # } - def initialize(user, repo_name, filepath, body) - @user = user + def initialize(token, owner, repo_name, filepath, body) + @token = token + @owner = owner @repo_name = repo_name @filepath = filepath @body = body @@ -32,11 +33,11 @@ class Gitea::Repository::Entries::DeleteService < Gitea::ClientService private def params - Hash.new.merge(token: user.gitea_token, data: body) + Hash.new.merge(token: token, data: body) end def url - "/repos/#{user.login}/#{repo_name}/contents/#{filepath}".freeze + "/repos/#{owner}/#{repo_name}/contents/#{filepath}".freeze end end diff --git a/app/services/gitea/repository/entries/update_service.rb b/app/services/gitea/repository/entries/update_service.rb index 3f0ddf944..dadabc388 100644 --- a/app/services/gitea/repository/entries/update_service.rb +++ b/app/services/gitea/repository/entries/update_service.rb @@ -1,5 +1,5 @@ class Gitea::Repository::Entries::UpdateService < Gitea::ClientService - attr_reader :user, :repo_name, :filepath, :body + attr_reader :token, :owner, :repo_name, :filepath, :body # ref: The name of the commit/branch/tag. Default the repository’s default branch (usually master) # filepath: path of the dir, file, symlink or submodule in the repo @@ -20,8 +20,9 @@ class Gitea::Repository::Entries::UpdateService < Gitea::ClientService # "new_branch": "string" # } # - def initialize(user, repo_name, filepath, body) - @user = user + def initialize(token, owner, repo_name, filepath, body) + @token = token + @owner = owner @repo_name = repo_name @filepath = filepath @body = body @@ -33,11 +34,11 @@ class Gitea::Repository::Entries::UpdateService < Gitea::ClientService private def params - Hash.new.merge(token: user.gitea_token, data: body) + Hash.new.merge(token: token, data: body) end def url - "/repos/#{user.login}/#{repo_name}/contents/#{filepath}".freeze + "/repos/#{owner}/#{repo_name}/contents/#{filepath}".freeze end end From 28c7199ce669df62920799c8ab8f0e2994e76609 Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Thu, 13 Aug 2020 11:38:05 +0800 Subject: [PATCH 2/7] FIX bug --- app/services/gitea/repository/entries/create_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/gitea/repository/entries/create_service.rb b/app/services/gitea/repository/entries/create_service.rb index 86dd3b2fc..7f1a6b529 100644 --- a/app/services/gitea/repository/entries/create_service.rb +++ b/app/services/gitea/repository/entries/create_service.rb @@ -25,7 +25,7 @@ class Gitea::Repository::Entries::CreateService < Gitea::ClientService @owner = owner @repo_name = repo_name @filepath = filepath - @body = bodys + @body = body end def call From 425a3743322d7d2af6bdca332dad050da05e1af9 Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Thu, 13 Aug 2020 14:40:35 +0800 Subject: [PATCH 3/7] ADD fork info for repositories show action --- app/views/repositories/show.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/repositories/show.json.jbuilder b/app/views/repositories/show.json.jbuilder index 0298c5a94..539f713a8 100644 --- a/app/views/repositories/show.json.jbuilder +++ b/app/views/repositories/show.json.jbuilder @@ -31,6 +31,7 @@ json.fork_info do if @fork_project.present? json.fork_form_name @fork_project.try(:name) json.fork_project_user_login @fork_project_user.try(:login) + json.fork_project_identifier @fork_project.identifier json.fork_project_user_name @fork_project_user.try(:show_real_name) end end From 7a2b496d953622b73e8babf725571d70cb1f009b Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Thu, 13 Aug 2020 15:58:07 +0800 Subject: [PATCH 4/7] =?UTF-8?q?FIX=20=E5=8F=96=E6=B6=88=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E7=82=B9=E8=B5=9E=E3=80=81=E5=85=B3=E6=B3=A8=E3=80=81fork?= =?UTF-8?q?=E7=AD=89=E5=88=97=E8=A1=A8=E9=9C=80=E8=A6=81=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E7=9A=84=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 97753a5f5..b810e8298 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -2,7 +2,7 @@ class ProjectsController < ApplicationController include ApplicationHelper include OperateProjectAbilityAble include ProjectsHelper - before_action :require_login, except: %i[index branches group_type_list simple show] + before_action :require_login, except: %i[index branches group_type_list simple show fork_users praise_users watch_users] before_action :load_project, except: %i[index group_type_list migrate] before_action :authorizate_user_can_edit_project!, only: %i[update] before_action :project_public?, only: %i[fork_users praise_users watch_users] From 622e5512718420e322293779b748ce1f8d44cc6d Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Thu, 13 Aug 2020 16:06:07 +0800 Subject: [PATCH 5/7] FIX repository edit routes bug --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 7012142cb..1cfe1b2a3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -237,7 +237,7 @@ Rails.application.routes.draw do ) end - resource :projects, path: '/', except: [:show] do + resource :projects, path: '/', except: [:show, :edit] do member do get :branches get :simple From 8d46eecc2c6bb73430f40b0e9889ba5183f7b1cc Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Thu, 13 Aug 2020 16:32:23 +0800 Subject: [PATCH 6/7] Delete create labels for gitea platform --- app/controllers/issue_tags_controller.rb | 36 ++++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/app/controllers/issue_tags_controller.rb b/app/controllers/issue_tags_controller.rb index fa12aefae..312de7842 100644 --- a/app/controllers/issue_tags_controller.rb +++ b/app/controllers/issue_tags_controller.rb @@ -38,12 +38,12 @@ class IssueTagsController < ApplicationController begin issue_tag = IssueTag.new(tag_params.merge(project_id: @project.id, user_id: current_user.id)) if issue_tag.save - gitea_tag = Gitea::Labels::CreateService.new(current_user, @repository.try(:identifier), tag_params).call - if gitea_tag && issue_tag.update_attributes(gid: gitea_tag["id"], gitea_url: gitea_tag["url"]) - normal_status(0, "标签创建成功") - else - normal_status(-1, "标签创建失败") - end + # gitea_tag = Gitea::Labels::CreateService.new(current_user, @repository.try(:identifier), tag_params).call + # if gitea_tag && issue_tag.update_attributes(gid: gitea_tag["id"], gitea_url: gitea_tag["url"]) + # normal_status(0, "标签创建成功") + # else + # normal_status(-1, "标签创建失败") + # end else normal_status(-1, "标签创建失败") end @@ -79,12 +79,12 @@ class IssueTagsController < ApplicationController ActiveRecord::Base.transaction do begin if @issue_tag.update_attributes(tag_params) - gitea_tag = Gitea::Labels::UpdateService.new(current_user, @repository.try(:identifier),@issue_tag.try(:gid), tag_params).call - if gitea_tag - normal_status(0, "标签更新成功") - else - normal_status(-1, "标签更新失败") - end + # gitea_tag = Gitea::Labels::UpdateService.new(current_user, @repository.try(:identifier),@issue_tag.try(:gid), tag_params).call + # if gitea_tag + # normal_status(0, "标签更新成功") + # else + # normal_status(-1, "标签更新失败") + # end else normal_status(-1, "标签更新失败") end @@ -103,12 +103,12 @@ class IssueTagsController < ApplicationController ActiveRecord::Base.transaction do begin if @issue_tag.destroy - issue_tag = Gitea::Labels::DeleteService.new(@user, @repository.try(:identifier), @issue_tag.try(:gid)).call - if issue_tag - normal_status(0, "标签删除成功") - else - normal_status(-1, "标签删除失败") - end + # issue_tag = Gitea::Labels::DeleteService.new(@user, @repository.try(:identifier), @issue_tag.try(:gid)).call + # if issue_tag + # normal_status(0, "标签删除成功") + # else + # normal_status(-1, "标签删除失败") + # end else normal_status(-1, "标签删除失败") end From 5bd8079386c898e3327652951657d7e444404815 Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Thu, 13 Aug 2020 17:15:54 +0800 Subject: [PATCH 7/7] FIX create project bug --- app/controllers/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index b810e8298..f46945f80 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -3,7 +3,7 @@ class ProjectsController < ApplicationController include OperateProjectAbilityAble include ProjectsHelper before_action :require_login, except: %i[index branches group_type_list simple show fork_users praise_users watch_users] - before_action :load_project, except: %i[index group_type_list migrate] + before_action :load_project, except: %i[index group_type_list migrate create] before_action :authorizate_user_can_edit_project!, only: %i[update] before_action :project_public?, only: %i[fork_users praise_users watch_users]