新增: 获取单文件blame信息

This commit is contained in:
2022-07-19 11:14:50 +08:00
parent 274cd81655
commit 1882120df3
7 changed files with 759 additions and 236 deletions

View File

@@ -0,0 +1,38 @@
class Api::V1::Projects::BlameService < ApplicationService
include ActiveModel::Model
attr_reader :project, :sha, :filepath, :owner, :repo, :token
attr_accessor :gitea_data
validates :sha, :filepath, presence: true
def initialize(project, sha, filepath, token=nil)
@project = project
@owner = project&.owner.login
@repo = project&.identifier
@sha = sha
@filepath = filepath
@token = token
end
def call
raise Error, errors.full_messages.join(",") unless valid?
load_gitea_data
gitea_data
end
private
def request_params
{
access_token: token,
sha: sha,
filepath: filepath
}
end
def load_gitea_data
@gitea_data = $gitea_client.get_repos_blame_by_owner_repo(owner, repo, {query: request_params})
raise Error, '获取项目blame失败' unless @gitea_data.is_a?(Hash)
end
end