class Api::V1::Projects::Webhooks::GetService < 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 
    load_gitea_data


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

  private 
  def request_params 
    {
      access_token: token
    }
  end

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