新增:获取commit列表

This commit is contained in:
2022-07-19 10:41:25 +08:00
parent 6273349334
commit 274cd81655
7 changed files with 543 additions and 238 deletions

View File

@@ -0,0 +1,38 @@
class Api::V1::Projects::Commits::ListService < ApplicationService
attr_reader :project, :sha, :page, :limit, :owner, :repo, :token
attr_accessor :gitea_data
def initialize(project, params, token=nil)
@project = project
@sha = params[:sha]
@page = params[:page] || 1
@limit = params[:limit] || 15
@owner = project&.owner.login
@repo = project&.identifier
@token = token
end
def call
load_gitea_data
gitea_data
end
private
def request_params
param = {
access_token: token,
page: page,
limit: limit
}
param.merge!(sha: sha) if sha.present?
param
end
def load_gitea_data
@gitea_data = $gitea_client.get_repos_commits_by_owner_repo(owner, repo, {query: request_params}) rescue nil
raise Error, '获取提交列表失败!' unless @gitea_data.is_a?(Hash)
end
end