module ErrandBoy class Brain def initialize @git = Git.new(Dir.pwd) @requests = requests end def command case @git.branch when /master/ then run when /.*request.*/ then validate end end def run @requests.each do |request| gateway = Gateway.build(request) csv = CSV.build(request) gateway.call next if processed?(gateway, csv) csv.push request.delete @git.commit "[auto][ci skip] add request to index" @git.push end end def validate @requests.each do |request| Validator.build(request).run request.rename @git.commit '[auto][ci skip] rename request file' @git.push end end private def requests entries.map {|path| Request.new(path) } end def entries Dir.glob("#{Request.dir}/*.toml").sort end def processed?(gateway, csv) gateway.processed? && csv.duplicated? end end end