FIX 完善 项目标签api

This commit is contained in:
Jasder 2020-05-19 18:34:25 +08:00
parent b02efc3609
commit 5a0b3c8f80
4 changed files with 30 additions and 16 deletions

View File

@ -1348,19 +1348,24 @@ curl -X GET http://localhost:3000/api/projects/mirror_demo/branches | jq
``` ```
--- ---
### 获取版本列表 ### 获取代码库标签列表
``` ```
GET /api/repositories/:id/tags GET /api/repositories/:id/tags
``` ```
*示例* *示例*
``` ```
curl -X GET http://localhost:3000/api/repositories/124/tags.json | jq curl -X GET \
-d "limit=20" \
-d "page=1" \
http://localhost:3000/api/repositories/5836/tags.json | jq
``` ```
*请求参数说明:* *请求参数说明:*
|参数名|必选|类型|说明| |参数名|必选|类型|说明|
|-|-|-|-| |-|-|-|-|
|id |是|int |项目id | |id |是|int |仓库id |
|page |否|string |页数,第几页 |
|limit |否|string |每页多少条数据默认20条 |
*返回参数说明:* *返回参数说明:*

View File

@ -2,8 +2,8 @@ class RepositoriesController < ApplicationController
include ApplicationHelper include ApplicationHelper
include OperateProjectAbilityAble include OperateProjectAbilityAble
before_action :require_login, only: %i[edit update create_file update_file delete_file sync_mirror] before_action :require_login, only: %i[edit update create_file update_file delete_file sync_mirror]
before_action :find_project, :authorizate! before_action :find_project, :authorizate!, except: :tags
before_action :find_repository, only: %i[sync_mirror] before_action :find_repository, only: %i[sync_mirror tags]
before_action :authorizate_user_can_edit_project!, only: %i[sync_mirror] before_action :authorizate_user_can_edit_project!, only: %i[sync_mirror]
def show def show
@ -49,7 +49,7 @@ class RepositoriesController < ApplicationController
end end
def tags def tags
@tags = Gitea::Repository::Tags::ListService.new(@project, @project.identifier).call @tags = Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @repo.user.login, @repo.identifier, {page: params[:page], limit: params[:limit]}).call
end end
def edit def edit

View File

@ -17,7 +17,6 @@ class Gitea::ClientService < ApplicationService
# } # }
def post(url, params={}) def post(url, params={})
puts "[gitea] request params: #{params}" puts "[gitea] request params: #{params}"
Rails.logger.info("##########___________post_params__________########{params}")
request_url = [api_url, url].join('').freeze request_url = [api_url, url].join('').freeze
auth_token = authen_params(params[:token]) auth_token = authen_params(params[:token])
response = conn(auth_token).post do |req| response = conn(auth_token).post do |req|

View File

@ -1,25 +1,35 @@
class Gitea::Repository::Tags::ListService < Gitea::ClientService class Gitea::Repository::Tags::ListService < Gitea::ClientService
attr_reader :user, :repo_name attr_reader :token, :owner, :repo, :params
# ref: The name of the commit/branch/tag. Default the repositorys default branch (usually master) # ref: The name of the commit/branch/tag. Default the repositorys default branch (usually master)
# repo_name: the name of repository # repo: the name of repository
def initialize(user, repo_name) def initialize(token, owner, repo, params={})
@user = user @token = token
@repo_name = repo_name @owner = owner
@repo = repo
@params = params
end end
def call def call
response = get(url, params) response = get(url, request_params)
render_result(response) render_result(response)
end end
private private
def params def request_params
Hash.new.merge(token: user.gitea_token) Hash.new.merge(token: token, page: set_page, limit: set_limit)
end
def set_page
(params[:page] || 1).to_i
end
def set_limit
(params[:limit] || 50).to_i
end end
def url def url
"/repos/#{user.login}/#{repo_name}/tags".freeze "/repos/#{owner}/#{repo}/tags".freeze
end end
def render_result(response) def render_result(response)