新增:查看标签详情api
This commit is contained in:
parent
cdf62b4626
commit
b2250db79a
|
@ -1,10 +1,13 @@
|
|||
class Api::V1::Projects::TagsController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above, only: [:index]
|
||||
before_action :require_public_and_member_above, only: [:index, :show]
|
||||
|
||||
def index
|
||||
@release_tags = @repository.version_releases.pluck(:tag_name)
|
||||
@result_object = Api::V1::Projects::Tags::ListService.call(@project, {page: page, limit: limit}, current_user&.gitea_token)
|
||||
puts @result_object
|
||||
end
|
||||
|
||||
def show
|
||||
@result_object = Api::V1::Projects::Tags::GetService.call(@project, params[:name], current_user&.gitea_token)
|
||||
end
|
||||
|
||||
before_action :require_operate_above, only: [:destroy]
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
class Api::V1::Projects::Tags::GetService < ApplicationService
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_reader :project, :token, :owner, :repo, :tag_name
|
||||
attr_accessor :gitea_data
|
||||
|
||||
validates :tag_name, presence: true
|
||||
|
||||
def initialize(project, tag_name, token=nil)
|
||||
@project = project
|
||||
@owner = project&.owner&.login
|
||||
@repo = project&.identifier
|
||||
@tag_name = tag_name.to_s
|
||||
@token = token
|
||||
Rails.logger.info project&.owner&.login
|
||||
Rails.logger.info project&.identifier
|
||||
Rails.logger.info tag_name
|
||||
Rails.logger.info token
|
||||
end
|
||||
|
||||
def call
|
||||
|
||||
raise Error, errors.full_messages.join(",") unless valid?
|
||||
|
||||
check_tag_exist
|
||||
|
||||
load_gitea_data
|
||||
|
||||
gitea_data
|
||||
rescue
|
||||
raise Error, "服务器错误,请联系系统管理员!"
|
||||
end
|
||||
|
||||
private
|
||||
def request_params
|
||||
params = {
|
||||
access_token: token
|
||||
}
|
||||
|
||||
params
|
||||
end
|
||||
|
||||
def load_gitea_data
|
||||
@gitea_data = $gitea_hat_client.get_repos_tags_by_owner_repo_tag(owner, repo, tag_name, {query: request_params}) rescue nil
|
||||
raise Error, '获取标签失败!' unless @gitea_data.is_a?(Hash)
|
||||
end
|
||||
|
||||
def check_tag_exist
|
||||
result = $gitea_hat_client.get_repos_tag_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil
|
||||
|
||||
raise Error, '查询标签名称失败!' unless result.is_a?(Array)
|
||||
raise Error, '标签不存在!' if !result.include?(@tag_name)
|
||||
end
|
||||
end
|
|
@ -4,7 +4,11 @@ if tag.present? && tag.is_a?(Hash)
|
|||
json.zipball_url render_zip_url(@owner, @repository, tag['name'])
|
||||
json.tarball_url render_tar_url(@owner, @repository, tag['name'])
|
||||
json.tagger do
|
||||
json.partial! 'api/v1/users/commit_user', user: render_cache_commit_author(tag['tagger']), name: tag['tagger']['name']
|
||||
if tag['tagger'].present?
|
||||
json.partial! 'api/v1/users/commit_user', user: render_cache_commit_author(tag['tagger']), name: tag['tagger']['name']
|
||||
else
|
||||
json.nil!
|
||||
end
|
||||
end
|
||||
json.time_ago time_from_now(tag['tagger']['date'].to_time)
|
||||
json.created_at_unix tag['tagger']['date'].to_time.to_i
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
json.partial! "api/v1/projects/tags/simple_gitea_index_detail", tag: @result_object
|
|
@ -85,8 +85,9 @@ defaults format: :json do
|
|||
end
|
||||
match 'branches/*name', to: "branches#destroy", via: :all
|
||||
|
||||
resources :tags, param: :name, only: [:index, :destroy]
|
||||
match 'tags/*name', to: "tags#destroy", via: :all
|
||||
resources :tags, param: :name, only: [:index, :show, :destroy]
|
||||
delete 'tags/*name', to: "tags#destroy", via: :all
|
||||
get 'tags/*name', to: "tags#show", via: :all
|
||||
|
||||
resources :commits, only: [:index]
|
||||
resources :code_stats, only: [:index]
|
||||
|
|
Loading…
Reference in New Issue