ADD get a commit api

This commit is contained in:
Jasder
2020-11-06 17:23:14 +08:00
parent 181bb05d4a
commit a8c3328bd6
4 changed files with 74 additions and 172 deletions

View File

@@ -82,11 +82,12 @@ class RepositoriesController < ApplicationController
end
def commit
@commit = Gitea::Repository::Commits::GetService.new(@repository.user.login, @repository.identifier, params[:sha], current_user.gitea_token).call
@commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, params[:sha], current_user.gitea_token)
@commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, params[:sha], current_user.gitea_token, {diff: true})
end
def tags
@tags = Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @project.owner.login, @project.identifier, {page: params[:page], limit: params[:limit]}).call
@tags = Gitea::Repository::Tags::ListService.call(current_user&.gitea_token, @project.owner.login, @project.identifier, {page: params[:page], limit: params[:limit]})
end
def edit

View File

@@ -1,16 +1,16 @@
# Get a single commit from a repository
class Gitea::Repository::Commits::GetService < Gitea::ClientService
attr_reader :token, :owner, :repo, :sha, :custom
attr_reader :token, :owner, :repo, :sha, :hash
# sha: the commit hash
# ex: Gitea::Repository::Commits::GetService.new(@repo.user.login, repo.identifier, params[:sha], current_user.gitea_token)
# TODO custom参数用于判断调用哪个api
def initialize(owner, repo, sha, token, custom=false)
def initialize(owner, repo, sha, token, hash={})
@token = token
@owner = owner
@sha = sha
@repo = repo
@custom = custom
@hash = hash
end
def call
@@ -24,10 +24,10 @@ class Gitea::Repository::Commits::GetService < Gitea::ClientService
end
def url
if custom
if hash[:diff]
# TODO
# 平台自己编写的gitea接口后续可能会通过提交pr的形式合并到gitea原有的接口上
"/repos/#{owner}/#{repo}/commits/diff/#{sha}".freeze
"/repos/#{owner}/#{repo}/commits/#{sha}/diff".freeze
else
"/repos/#{owner}/#{repo}/git/commits/#{sha}".freeze
end

View File

@@ -1,27 +1,11 @@
json.key_format! camelize: :lower
json.additions @commit['commit_diff']['TotalAddition']
json.deletions @commit['commit_diff']['TotalDeletion']
json.sha @commit['sha']
json.url request.url
json.commit do
@commit['commit'].delete('url')
json.author @commit['commit']['author']
json.committer @commit['commit']['committer']
json.message @commit['commit']['message']
json.tree do
@commit['commit']['tree']['sha']
end
end
json.author do
json.partial! 'commit_author', user: render_commit_author(@commit['author'])
end
json.committer do
json.partial! 'commit_author', user: render_commit_author(@commit['committer'])
end
# json.key_format! camelize: :lower
json.files_count @commit_diff['NumFiles']
json.total_addition @commit_diff['TotalAddition']
json.total_deletion @commit_diff['TotalDeletion']
json.files @commit_diff['Files'], partial: 'pull_requests/diff_file', as: :file
json.partial! 'commit', commit: @commit, project: @project
json.parents @commit['parents'] do |parent|
json.sha parent['sha']
json.url EduSetting.get('host_name') + commit_repository_path(@repo, parent['sha'])
# json.url EduSetting.get('host_name') + commit_repository_path(@repo, parent['sha'])
end
json.files @commit['commit_diff']['Files']