FIX commits api bug
This commit is contained in:
parent
37fa25d57d
commit
f64243d188
|
@ -44,7 +44,8 @@ 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
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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 = {}
|
||||
|
|
Loading…
Reference in New Issue