FIX commits api bug
This commit is contained in:
parent
37fa25d57d
commit
f64243d188
|
@ -44,7 +44,8 @@ class RepositoriesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def commits
|
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
|
end
|
||||||
|
|
||||||
def commit
|
def commit
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
class Gitea::ClientService < ApplicationService
|
class Gitea::ClientService < ApplicationService
|
||||||
attr_reader :username, :secret, :token, :url, :params
|
attr_reader :username, :secret, :token, :url, :params
|
||||||
|
|
||||||
|
PAGINATE_DEFAULT_PAGE = 1
|
||||||
|
PAGINATE_DEFAULT_LIMIT = 20
|
||||||
|
|
||||||
def initialize(options={})
|
def initialize(options={})
|
||||||
@username = options[:username]
|
@username = options[:username]
|
||||||
@secret = options[:password]
|
@secret = options[:password]
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
# Get a list of all commits from a repository
|
# Get a list of all commits from a repository
|
||||||
class Gitea::Repository::Commits::ListService < Gitea::ClientService
|
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')
|
# sha: SHA or branch to start listing commits from (usually 'master')
|
||||||
def initialize(user, repo_name, **args)
|
# ex:
|
||||||
@user = user
|
# 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
|
@repo_name = repo_name
|
||||||
@args = { sha: 'master', page: 1 }.merge(args.compact)
|
@args = args
|
||||||
end
|
end
|
||||||
|
|
||||||
def call
|
def call
|
||||||
|
@ -16,15 +19,14 @@ class Gitea::Repository::Commits::ListService < Gitea::ClientService
|
||||||
|
|
||||||
private
|
private
|
||||||
def params
|
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
|
end
|
||||||
|
|
||||||
def url
|
def url
|
||||||
"/repos/#{user.login}/#{repo_name}/commits".freeze
|
"/repos/#{owner}/#{repo_name}/commits".freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_result(response)
|
def render_result(response)
|
||||||
|
|
||||||
case response.status
|
case response.status
|
||||||
when 200
|
when 200
|
||||||
result = {}
|
result = {}
|
||||||
|
|
Loading…
Reference in New Issue