mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-21 20:25:45 +08:00
新增:标签列表和删除接口
This commit is contained in:
@@ -17,7 +17,7 @@ class Api::V1::Projects::Branches::DeleteService < ApplicationService
|
||||
def call
|
||||
raise Error, errors.full_messages.join(",") unless valid?
|
||||
|
||||
# check_branch_exist
|
||||
check_branch_exist
|
||||
excute_data_to_gitea
|
||||
|
||||
true
|
||||
|
||||
42
app/services/api/v1/projects/tags/delete_service.rb
Normal file
42
app/services/api/v1/projects/tags/delete_service.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
class Api::V1::Projects::Tags::DeleteService < ApplicationService
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :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
|
||||
@token = token
|
||||
end
|
||||
|
||||
def call
|
||||
raise Error, errors.full_messages.join(",") unless valid?
|
||||
|
||||
check_tag_exist
|
||||
excute_data_to_gitea
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
private
|
||||
def request_params
|
||||
{
|
||||
access_token: token
|
||||
}
|
||||
end
|
||||
|
||||
def excute_data_to_gitea
|
||||
@gitea_data = $gitea_client.delete_repos_tags_by_owner_repo_tag(owner, repo, tag_name, {query: request_params}) rescue nil
|
||||
end
|
||||
|
||||
def check_tag_exist
|
||||
result = $gitea_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
|
||||
36
app/services/api/v1/projects/tags/list_service.rb
Normal file
36
app/services/api/v1/projects/tags/list_service.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
class Api::V1::Projects::Tags::ListService < ApplicationService
|
||||
|
||||
attr_accessor :project, :token, :owner, :repo, :page, :limit
|
||||
attr_accessor :gitea_data
|
||||
|
||||
def initialize(project, params, token=nil)
|
||||
@project = project
|
||||
@owner = project&.owner.login
|
||||
@repo = project&.identifier
|
||||
@token = token
|
||||
@page = params[:page]
|
||||
@limit = params[:limit]
|
||||
end
|
||||
|
||||
def call
|
||||
load_gitea_data
|
||||
|
||||
gitea_data
|
||||
end
|
||||
|
||||
private
|
||||
def request_params
|
||||
params = {
|
||||
access_token: token,
|
||||
page: page,
|
||||
limit: limit
|
||||
}
|
||||
|
||||
params
|
||||
end
|
||||
|
||||
def load_gitea_data
|
||||
@gitea_data = $gitea_client.get_repos_tags_by_owner_repo(owner, repo, {query: request_params}) rescue nil
|
||||
raise Error, '获取标签列表失败!' unless @gitea_data.is_a?(Hash)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user