From 34984d12cb4ac4963d71a80a6613488e874a1200 Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Wed, 3 Jun 2020 11:18:46 +0800 Subject: [PATCH] Update get branches api --- app/controllers/issues_controller.rb | 12 ++++----- app/controllers/projects_controller.rb | 8 +++--- app/controllers/pull_requests_controller.rb | 2 +- .../version_releases_controller.rb | 2 +- .../gitea/repository/branches/get_service.rb | 27 +++++++++++++++++++ .../list_service.rb} | 2 +- 6 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 app/services/gitea/repository/branches/get_service.rb rename app/services/gitea/repository/{branches_service.rb => branches/list_service.rb} (82%) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index e56b4dcdd..ae7e44a97 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -258,7 +258,7 @@ class IssuesController < ApplicationController end end - def clean + def clean issue_ids = params[:ids] if issue_ids.present? if Issue.where(id: issue_ids).destroy_all @@ -266,13 +266,13 @@ class IssuesController < ApplicationController else normal_status(-1, "删除失败") end - else + else normal_status(-1, "请选择任务") end end - def series_update - + def series_update + update_hash = {} update_hash.merge!(assigned_to_id: params[:assigned_to_id]) if params[:assigned_to_id].present? update_hash.merge!(fixed_version_id: params[:fixed_version_id]) if params[:fixed_version_id].present? @@ -287,7 +287,7 @@ class IssuesController < ApplicationController else normal_status(-1, "批量更新失败") end - else + else normal_status(-1, "请选择任务") end end @@ -428,7 +428,7 @@ class IssuesController < ApplicationController def get_branches all_branches = [] - get_all_branches = Gitea::Repository::BranchesService.new(@user, @project&.repository.try(:identifier)).call + get_all_branches = Gitea::Repository::Branches::ListService.new(@user, @project&.repository.try(:identifier)).call if get_all_branches && get_all_branches.size > 0 get_all_branches.each do |b| all_branches.push(b["name"]) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index aeadbd930..a70a380da 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -35,7 +35,7 @@ class ProjectsController < ApplicationController end def branches - @branches = Gitea::Repository::BranchesService.new(@project.owner, @project.identifier).call + @branches = Gitea::Repository::Branches::ListService.new(@project.owner, @project.identifier).call end def group_type_list @@ -94,8 +94,8 @@ class ProjectsController < ApplicationController @praises = paginate(praises) end - def fork_users - fork_users = @project.fork_users.includes(:user, :project).order("fork_users.created_at asc").distinct + def fork_users + fork_users = @project.fork_users.includes(:user, :project).order("fork_users.created_at asc").distinct @forks_count = fork_users.size @fork_users = paginate(fork_users) end @@ -111,7 +111,7 @@ class ProjectsController < ApplicationController :auth_password, :project_category_id, :project_language_id, :clone_addr, :private) end - def project_public? + def project_public? unless @project.is_public || current_user&admin? tip_exception(403, "..") end diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index ff212c977..c214503b1 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -25,7 +25,7 @@ class PullRequestsController < ApplicationController def new @all_branches = [] - get_all_branches = Gitea::Repository::BranchesService.new(@user, @repository.try(:identifier)).call + get_all_branches = Gitea::Repository::Branches::ListService.new(@user, @repository.try(:identifier)).call if get_all_branches && get_all_branches.size > 0 get_all_branches.each do |b| @all_branches.push(b["name"]) diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index 8a944475e..6717bf064 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -14,7 +14,7 @@ class VersionReleasesController < ApplicationController def new #获取所有的分支 @all_branches = [] - get_all_branches = Gitea::Repository::BranchesService.new(@user, @repository.try(:identifier)).call + get_all_branches = Gitea::Repository::Branches::ListService.new(@user, @repository.try(:identifier)).call if get_all_branches && get_all_branches.size > 0 get_all_branches.each do |b| @all_branches.push(b["name"]) diff --git a/app/services/gitea/repository/branches/get_service.rb b/app/services/gitea/repository/branches/get_service.rb new file mode 100644 index 000000000..d833b86bb --- /dev/null +++ b/app/services/gitea/repository/branches/get_service.rb @@ -0,0 +1,27 @@ +# Retrieve a specific branch from a repository, including its effective branch protection +class Gitea::Repository::Branches::GetService < Gitea::ClientService + attr_reader :owner, :repo, :branch, :token + + # ex: + # Gitea::Repository::Branches::GetService.new(@project.owner, @project.identifier, 'master', current_user.gitea_token).call + def initialize(owner, repo, branch, token) + @owner = owner + @repo = repo + @branch = branch + @token = token + end + + def call + response = get(url, params) + render_data(response) + end + + private + def params + Hash.new.merge(token: token) + end + + def url + "/repos/#{owner}/#{repo}/branches/#{branch}".freeze + end +end diff --git a/app/services/gitea/repository/branches_service.rb b/app/services/gitea/repository/branches/list_service.rb similarity index 82% rename from app/services/gitea/repository/branches_service.rb rename to app/services/gitea/repository/branches/list_service.rb index 4e4c67527..17702259c 100644 --- a/app/services/gitea/repository/branches_service.rb +++ b/app/services/gitea/repository/branches/list_service.rb @@ -1,4 +1,4 @@ -class Gitea::Repository::BranchesService < Gitea::ClientService +class Gitea::Repository::Branches::ListService < Gitea::ClientService attr_reader :user, :repo def initialize(user, repo)