add: project commit_slice
This commit is contained in:
parent
91feb8cf89
commit
af7488505d
|
@ -107,6 +107,11 @@ class RepositoriesController < ApplicationController
|
||||||
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
|
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def commits_slice
|
||||||
|
@hash_commit = Gitea::Repository::Commits::ListSliceService.call(@owner.login, @project.identifier,
|
||||||
|
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token)
|
||||||
|
end
|
||||||
|
|
||||||
def commit
|
def commit
|
||||||
@sha = params[:sha]
|
@sha = params[:sha]
|
||||||
@commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token)
|
@commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token)
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
# Get a list of all commits from a repository
|
||||||
|
class Gitea::Repository::Commits::ListSliceService < Gitea::ClientService
|
||||||
|
attr_reader :owner, :repo_name, :args
|
||||||
|
|
||||||
|
# sha: SHA or branch to start listing commits from (usually 'master')
|
||||||
|
# ex:
|
||||||
|
# Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier,
|
||||||
|
# sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
|
||||||
|
def initialize(owner, repo_name, **args)
|
||||||
|
@owner = owner
|
||||||
|
@repo_name = repo_name
|
||||||
|
@args = args
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
response = get(url, params)
|
||||||
|
render_result(response)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def params
|
||||||
|
{ sha: args[:sha] || 'master', page: args[:page] || PAGINATE_DEFAULT_PAGE, limit: args[:limit] || PAGINATE_DEFAULT_LIMIT, token: args[:token] || "" }
|
||||||
|
end
|
||||||
|
|
||||||
|
def url
|
||||||
|
"/repos/#{owner}/#{repo_name}/commits_slice".freeze
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_result(response)
|
||||||
|
case response.status
|
||||||
|
when 200
|
||||||
|
result = {}
|
||||||
|
headers = response.headers.to_hash
|
||||||
|
body = JSON.parse(response.body)
|
||||||
|
total_count = headers["x-total"]
|
||||||
|
result.merge(total_count: total_count.to_i, body: body)
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
# {status: -1, message: "#{body['message']}"}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,38 @@
|
||||||
|
if @hash_commit.blank? #如果有状态值,则表示报错了
|
||||||
|
json.total_count 0
|
||||||
|
json.commits []
|
||||||
|
else
|
||||||
|
json.total_count @hash_commit[:total_count]
|
||||||
|
json.commit_dates do
|
||||||
|
json.array! @hash_commit[:body] do |commit_date|
|
||||||
|
json.commit_date commit_date["commit_date"]
|
||||||
|
json.commits do
|
||||||
|
json.array! commit_date["Commits"] do |commit|
|
||||||
|
commiter = commit['committer']
|
||||||
|
|
||||||
|
forge_user =
|
||||||
|
if commiter.present?
|
||||||
|
User.simple_select.find_by(gitea_uid: commiter['id'])
|
||||||
|
end
|
||||||
|
|
||||||
|
json.sha commit['sha']
|
||||||
|
json.message commit['commit']['message']
|
||||||
|
json.timestamp render_unix_time(commit['commit']['author']['date'])
|
||||||
|
json.time_from_now time_from_now(commit['commit']['author']['date'])
|
||||||
|
if forge_user
|
||||||
|
json.partial! 'author', user: forge_user
|
||||||
|
else
|
||||||
|
json.author do
|
||||||
|
json.id nil
|
||||||
|
json.login commit['commit']['author']['name']
|
||||||
|
json.type nil
|
||||||
|
json.name commit['commit']['author']['name']
|
||||||
|
json.image_url User::Avatar.get_letter_avatar_url(commit['commit']['author']['name'])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -432,6 +432,7 @@ Rails.application.routes.draw do
|
||||||
get :entries
|
get :entries
|
||||||
match :sub_entries, :via => [:get, :put]
|
match :sub_entries, :via => [:get, :put]
|
||||||
get :commits
|
get :commits
|
||||||
|
get :commits_slice
|
||||||
get :tags
|
get :tags
|
||||||
get :contributors
|
get :contributors
|
||||||
post :create_file
|
post :create_file
|
||||||
|
|
Loading…
Reference in New Issue