From 2a09ced1ceec6b8bf067ed8844e5edccee5fb825 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 7 Jan 2022 15:41:50 +0800 Subject: [PATCH] fix: branches use branch name api --- app/controllers/projects_controller.rb | 5 +-- app/views/projects/branches.json.jbuilder | 37 ++++++++++++----------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 77b818cad..571805324 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -82,8 +82,9 @@ class ProjectsController < ApplicationController def branches return @branches = [] unless @project.forge? - result = Gitea::Repository::Branches::ListService.call(@owner, @project.identifier) - @branches = result.is_a?(Hash) && result.key?(:status) ? [] : result + # result = Gitea::Repository::Branches::ListService.call(@owner, @project.identifier) + result = Gitea::Repository::Branches::ListNameService.call(@owner, @project.identifier) + @branches = result.is_a?(Hash) ? (result.key?(:status) ? [] : result["branch_name"]) : result end def branches_slice diff --git a/app/views/projects/branches.json.jbuilder b/app/views/projects/branches.json.jbuilder index c7c2025b3..3bfc9f46b 100644 --- a/app/views/projects/branches.json.jbuilder +++ b/app/views/projects/branches.json.jbuilder @@ -1,21 +1,22 @@ json.array! @branches do |branch| - json.name branch['name'] - json.user_can_push branch['user_can_push'] - json.user_can_merge branch['user_can_merge'] - json.protected branch['protected'] + branch_name = branch.is_a?(Hash) ? branch['name'] : branch + json.name branch_name + # json.user_can_push branch['user_can_push'] + # json.user_can_merge branch['user_can_merge'] + # json.protected branch['protected'] json.http_url render_http_url(@project) - json.zip_url render_zip_url(@owner, @repository, branch['name']) - json.tar_url render_tar_url(@owner, @repository, branch['name']) - json.last_commit do - json.sha branch['commit']['id'] - json.message branch['commit']['message'] - json.timestamp render_unix_time(branch['commit']['timestamp']) - json.time_from_now time_from_now(branch['commit']['timestamp']) - json.author do - json.partial! 'repositories/commit_author', user: render_cache_commit_author(branch['commit']['author']), name: branch['commit']['author']['name'] - end - json.committer do - json.partial! 'repositories/commit_author', user: render_cache_commit_author(branch['commit']['committer']), name: branch['commit']['committer']['name'] - end - end + json.zip_url render_zip_url(@owner, @repository, branch_name) + json.tar_url render_tar_url(@owner, @repository, branch_name) + # json.last_commit do + # json.sha branch['commit']['id'] + # json.message branch['commit']['message'] + # json.timestamp render_unix_time(branch['commit']['timestamp']) + # json.time_from_now time_from_now(branch['commit']['timestamp']) + # json.author do + # json.partial! 'repositories/commit_author', user: render_cache_commit_author(branch['commit']['author']), name: branch['commit']['author']['name'] + # end + # json.committer do + # json.partial! 'repositories/commit_author', user: render_cache_commit_author(branch['commit']['committer']), name: branch['commit']['committer']['name'] + # end + # end end