新增:最新提交列表接口
This commit is contained in:
parent
feec49d4bd
commit
6a4f63d8ea
2
Gemfile
2
Gemfile
|
@ -143,4 +143,4 @@ gem 'doorkeeper'
|
||||||
|
|
||||||
gem 'doorkeeper-jwt'
|
gem 'doorkeeper-jwt'
|
||||||
|
|
||||||
gem 'gitea-client', '~> 1.4.4'
|
gem 'gitea-client', '~> 1.4.5'
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class Api::V1::Projects::CommitsController < Api::V1::BaseController
|
class Api::V1::Projects::CommitsController < Api::V1::BaseController
|
||||||
before_action :require_public_and_member_above, only: [:index, :diff]
|
before_action :require_public_and_member_above, only: [:index, :diff, :recent]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@result_object = Api::V1::Projects::Commits::ListService.call(@project, {page: page, limit: limit, sha: params[:sha]}, current_user&.gitea_token)
|
@result_object = Api::V1::Projects::Commits::ListService.call(@project, {page: page, limit: limit, sha: params[:sha]}, current_user&.gitea_token)
|
||||||
|
@ -9,4 +9,8 @@ class Api::V1::Projects::CommitsController < Api::V1::BaseController
|
||||||
def diff
|
def diff
|
||||||
@result_object = Api::V1::Projects::Commits::DiffService.call(@project, params[:sha], current_user&.gitea_token)
|
@result_object = Api::V1::Projects::Commits::DiffService.call(@project, params[:sha], current_user&.gitea_token)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def recent
|
||||||
|
@result_object = Api::V1::Projects::Commits::RecentService.call(@project, {page: page, limit: limit}, current_user&.gitea_token)
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -0,0 +1,37 @@
|
||||||
|
class Api::V1::Projects::Commits::RecentService < ApplicationService
|
||||||
|
|
||||||
|
attr_reader :project, :page, :limit, :owner, :repo, :token
|
||||||
|
attr_accessor :gitea_data
|
||||||
|
|
||||||
|
def initialize(project, params, token=nil)
|
||||||
|
@project = project
|
||||||
|
@page = params[:page] || 1
|
||||||
|
@limit = params[:limit] || 15
|
||||||
|
@owner = project&.owner&.login
|
||||||
|
@repo = project&.identifier
|
||||||
|
@token = token
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
load_gitea_data
|
||||||
|
|
||||||
|
gitea_data
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def request_params
|
||||||
|
param = {
|
||||||
|
access_token: token,
|
||||||
|
page: page,
|
||||||
|
limit: limit
|
||||||
|
}
|
||||||
|
|
||||||
|
param
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_gitea_data
|
||||||
|
@gitea_data = $gitea_hat_client.get_repos_recent_commits_by_owner_repo(owner, repo, {query: request_params}) rescue nil
|
||||||
|
raise Error, "获取最近提交列表失败" unless @gitea_data.is_a?(Hash)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,13 @@
|
||||||
|
json.total_count @result_object[:total_data].to_i
|
||||||
|
json.commits @result_object[:data].each do |commit|
|
||||||
|
json.sha commit['sha']
|
||||||
|
json.author do
|
||||||
|
json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(commit['commit']['author']), name: commit['commit']['author']['name'] }
|
||||||
|
end
|
||||||
|
|
||||||
|
json.committer do
|
||||||
|
json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(commit['commit']['committer']), name: commit['commit']['committer']['name'] }
|
||||||
|
end
|
||||||
|
json.commit_message commit['commit']['message']
|
||||||
|
json.parent_shas commit['parents'].map{|x|x['sha']}
|
||||||
|
end
|
|
@ -90,7 +90,11 @@ defaults format: :json do
|
||||||
delete 'tags/*name', to: "tags#destroy", via: :all
|
delete 'tags/*name', to: "tags#destroy", via: :all
|
||||||
get 'tags/*name', to: "tags#show", via: :all
|
get 'tags/*name', to: "tags#show", via: :all
|
||||||
|
|
||||||
resources :commits, only: [:index]
|
resources :commits, only: [:index] do
|
||||||
|
collection do
|
||||||
|
get :recent
|
||||||
|
end
|
||||||
|
end
|
||||||
resources :code_stats, only: [:index]
|
resources :code_stats, only: [:index]
|
||||||
resources :contributors, only: [:index] do
|
resources :contributors, only: [:index] do
|
||||||
collection do
|
collection do
|
||||||
|
|
Loading…
Reference in New Issue