class Api::V1::Projects::Webhooks::TestsService < ApplicationService

  attr_reader :project, :id, :token, :owner, :repo
  attr_accessor :gitea_data

  def initialize(project, id, token=nil)
    @project = project
    @id = id
    @owner = project&.owner.login 
    @repo = project&.identifier
    @token = token
  end

  def call 
    excute_data_to_gitea

    gitea_data
  rescue 
    raise Error, "服务器错误，请联系系统管理员！"
  end

  private 
  def request_params 
    {
      access_token: token
    }
  end

  def excute_data_to_gitea 
    @gitea_data = $gitea_client.post_repos_hooks_tests_by_owner_repo_id(owner, repo, id, {query: request_params}) rescue nil
  end
end