class Api::V1::Projects::Branches::AllListService < ApplicationService 

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

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

  def call 
    load_gitea_data
    
    gitea_data
  end

  private 
  def request_params 
    {
      access_token: token 
    }
  end

  def load_gitea_data 
    @gitea_data = $gitea_hat_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil
    raise Error, '获取所有分支失败！' unless @gitea_data.is_a?(Array)
  end
end