add: project branch_slice
This commit is contained in:
parent
1c3ca34efc
commit
91feb8cf89
|
@ -86,6 +86,13 @@ class ProjectsController < ApplicationController
|
||||||
@branches = result.is_a?(Hash) && result.key?(:status) ? [] : result
|
@branches = result.is_a?(Hash) && result.key?(:status) ? [] : result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def branches_slice
|
||||||
|
return @branches = [] unless @project.forge?
|
||||||
|
|
||||||
|
slice_result = Gitea::Repository::Branches::ListSliceService.call(@owner, @project.identifier)
|
||||||
|
@branches_slice = slice_result.is_a?(Hash) && slice_result.key?(:status) ? [] : slice_result
|
||||||
|
end
|
||||||
|
|
||||||
def group_type_list
|
def group_type_list
|
||||||
project_statics = ProjectStatistic.first
|
project_statics = ProjectStatistic.first
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
class Gitea::Repository::Branches::ListSliceService < Gitea::ClientService
|
||||||
|
attr_reader :user, :repo
|
||||||
|
|
||||||
|
def initialize(user, repo)
|
||||||
|
@user = user
|
||||||
|
@repo = repo
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
response = get(url, params)
|
||||||
|
render_200_response(response)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def params
|
||||||
|
Hash.new.merge(token: user.gitea_token)
|
||||||
|
end
|
||||||
|
|
||||||
|
def url
|
||||||
|
"/repos/#{user.login}/#{repo}/branches/branches_slice".freeze
|
||||||
|
end
|
||||||
|
end
|
|
@ -13,6 +13,7 @@ class Repositories::DetailService < ApplicationService
|
||||||
repo: {},
|
repo: {},
|
||||||
release: [],
|
release: [],
|
||||||
branch: [],
|
branch: [],
|
||||||
|
branch_type: [],
|
||||||
tag: [],
|
tag: [],
|
||||||
contributor: [],
|
contributor: [],
|
||||||
language: {},
|
language: {},
|
||||||
|
@ -23,6 +24,7 @@ class Repositories::DetailService < ApplicationService
|
||||||
repo: repo_suitable,
|
repo: repo_suitable,
|
||||||
release: release_suitable,
|
release: release_suitable,
|
||||||
branch: branch_suitable,
|
branch: branch_suitable,
|
||||||
|
branch_slice: branch_slice_suitable,
|
||||||
tag: tag_suitable,
|
tag: tag_suitable,
|
||||||
contributor: contributor_suitable,
|
contributor: contributor_suitable,
|
||||||
language: language_suitable,
|
language: language_suitable,
|
||||||
|
@ -43,7 +45,12 @@ class Repositories::DetailService < ApplicationService
|
||||||
|
|
||||||
def branch_suitable
|
def branch_suitable
|
||||||
branches = Gitea::Repository::Branches::ListService.call(@owner, @repo.identifier)
|
branches = Gitea::Repository::Branches::ListService.call(@owner, @repo.identifier)
|
||||||
branches.is_a?(Hash) && branches[:status] == :error ? [] : branches
|
branches.is_a?(Hash) && branches.key?(:status) ? [] : branches
|
||||||
|
end
|
||||||
|
|
||||||
|
def branch_slice_suitable
|
||||||
|
branches = Gitea::Repository::Branches::ListSliceService.call(@owner, @repo.identifier)
|
||||||
|
branches.is_a?(Hash) && branches.key?(:status) == :error ? [] : branches
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_suitable
|
def tag_suitable
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
json.array! @branches_slice do |branch_slice|
|
||||||
|
json.branch_type branch_slice['branch_name']
|
||||||
|
json.list branch_slice['branches'].each 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']
|
||||||
|
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 branch['commit']['author']
|
||||||
|
json.committer branch['commit']['committer']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -72,6 +72,15 @@ json.branches do
|
||||||
end
|
end
|
||||||
json.total_count @result[:branch].size
|
json.total_count @result[:branch].size
|
||||||
end
|
end
|
||||||
|
json.branches_slice do
|
||||||
|
json.list @result[:branch_slice].each do |branch_slice|
|
||||||
|
json.branch_type branch_slice["branch_name"]
|
||||||
|
json.list branch_slice["branches"].each do |branch|
|
||||||
|
json.name branch["name"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
json.total_count @result[:branch_slice].size
|
||||||
|
end
|
||||||
json.tags do
|
json.tags do
|
||||||
json.list @result[:tag].each do |tag|
|
json.list @result[:tag].each do |tag|
|
||||||
json.name tag["name"]
|
json.name tag["name"]
|
||||||
|
|
|
@ -416,6 +416,7 @@ Rails.application.routes.draw do
|
||||||
member do
|
member do
|
||||||
get :menu_list
|
get :menu_list
|
||||||
get :branches
|
get :branches
|
||||||
|
get :branches_slice
|
||||||
get :simple
|
get :simple
|
||||||
get :watchers, to: 'projects#watch_users'
|
get :watchers, to: 'projects#watch_users'
|
||||||
get :stargazers, to: 'projects#praise_users'
|
get :stargazers, to: 'projects#praise_users'
|
||||||
|
|
Loading…
Reference in New Issue