Merge branch 'dev_trustie' of http://gitea.trustie.net/jasder/forgeplus into dev_trustie

This commit is contained in:
sylor_huang@126.com 2020-06-02 14:13:53 +08:00
commit 8b21ed18b8
8 changed files with 26 additions and 16 deletions

View File

@ -1632,6 +1632,8 @@ http://localhost:3000/api/repositories/5845/commits/b0c4a4a1487d53acebf2addc544b
|-- IsCreated |boolean|是否为新添加的文件true false否|
|-- IsDeleted |boolean|是否为删除的文件truefalse否|
|-- IsRenamed |boolean|是否为重命名的文件truefalse否|
|-- IsBin |boolean|是否为二进制文件truefalse否|
|-- IsLFSFile |boolean|是否git lfs操作的大文件truefalse否|
|-- IsSubmodule |boolean|收否为子模块truefalse否|
|-- Sections |array| |
|---- Name |string|文件名称|

View File

@ -10,7 +10,8 @@ class RepositoriesController < ApplicationController
def show
@branches_count = Gitea::Repository::BranchesService.new(@project.owner, @project.identifier).call&.size
@commits_count = Gitea::Repository::Commits::ListService.new(@project.owner, @project.identifier).call[:total_count]
@commits_count = 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[:total_count]
@tags_count = Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @project.owner.login, @project.identifier).call&.size
@result = Gitea::Repository::GetService.new(@project.owner, @project.identifier).call
@project_fork_id = @project.try(:forked_from_project_id)
@ -44,12 +45,12 @@ class RepositoriesController < ApplicationController
end
def commits
@hash_commit = Gitea::Repository::Commits::ListService.new(@project.owner, @project.identifier, sha: params[:sha], page: params[:page]).call
@hash_commit = 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
end
def commit
@commit = Gitea::Repository::Commits::GetService.new(@repo.user.login, @repo.identifier, params[:sha], current_user.gitea_token).call
@custom_commit = Gitea::Repository::Commits::GetService.new(@repo.user.login, @repo.identifier, params[:sha], current_user.gitea_token, true).call
end
def tags

View File

@ -1,6 +1,9 @@
class Gitea::ClientService < ApplicationService
attr_reader :username, :secret, :token, :url, :params
PAGINATE_DEFAULT_PAGE = 1
PAGINATE_DEFAULT_LIMIT = 20
def initialize(options={})
@username = options[:username]
@secret = options[:password]

View File

@ -1,12 +1,15 @@
# Get a list of all commits from a repository
class Gitea::Repository::Commits::ListService < Gitea::ClientService
attr_reader :user, :repo_name, :args
attr_reader :owner, :repo_name, :args
# sha: SHA or branch to start listing commits from (usually 'master')
def initialize(user, repo_name, **args)
@user = user
# 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 = { sha: 'master', page: 1 }.merge(args.compact)
@args = args
end
def call
@ -16,15 +19,14 @@ class Gitea::Repository::Commits::ListService < Gitea::ClientService
private
def params
@args.merge(token: user.gitea_token)
{ sha: args[:sha] || 'master', page: args[:page] || PAGINATE_DEFAULT_PAGE, limit: args[:limit] || PAGINATE_DEFAULT_LIMIT, token: args[:token] || "" }
end
def url
"/repos/#{user.login}/#{repo_name}/commits".freeze
"/repos/#{owner}/#{repo_name}/commits".freeze
end
def render_result(response)
case response.status
when 200
result = {}

View File

@ -21,11 +21,11 @@ class Gitea::Repository::Tags::ListService < Gitea::ClientService
end
def set_page
(params[:page] || 1).to_i
(params[:page] || PAGINATE_DEFAULT_PAGE).to_i
end
def set_limit
(params[:limit] || 50).to_i
(params[:limit] || PAGINATE_DEFAULT_LIMIT).to_i
end
def url

View File

@ -13,7 +13,7 @@ json.array! @branches do |branch|
json.time_from_now time_from_now(branch['commit']['timestamp'])
end
user = find_user_by_login_or_mail(branch['commit']['author']['username'])
user = find_user_by_login_or_mail(branch['commit']['author']['name'])
json.author do
if user
json.login user.login

View File

@ -4,6 +4,7 @@ json.projects @projects do |project|
next if user.blank?
json.id project.id
json.repo_id project&.repository.id
json.identifier project.identifier
json.name project.name
json.description Nokogiri::HTML(project.description).text

View File

@ -1,12 +1,13 @@
json.key_format! camelize: :lower
json.additions @custom_commit['TotalAddition']
json.deletions @custom_commit['TotalDeletion']
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
@ -23,4 +24,4 @@ json.parents @commit['parents'] do |parent|
json.url EduSetting.get('host_name') + commit_repository_path(@repo, parent['sha'])
end
json.files @custom_commit['Files']
json.files @commit['commit_diff']['Files']