require 'fileutils' require 'erubis' module DevFlow class Gantt < App ## fetch git log def git_log git_log = '' committer = '' last_header = '' `git log --graph --format=email --date=relative -n 50`.split(/\n/).each do |line| # {{{ line.chomp! line.gsub!(">", ">") line.gsub!("<", "<") if /^(?\W+)From\s+(?\w+)/ =~ line git_log += "#{header_}#{hash_code_}\n" elsif /^(?\W+)From\:\s+(?.+)$/ =~ line committer = committer_ last_header = header_ elsif /^(?\W+)Date\:\s*(?.+)$/ =~ line git_log += sprintf("%s%s By %s\n", last_header, DateTime.parse(date_).strftime("%F %R"), committer) git_log += header_ elsif /^(?\W+)Subject\:\s+\[PATCH\]\s*(?.+)$/ =~ line color = 'green' git_log += "#{header_}#{message_}\n" else git_log += line + "\n" end end git_log end ## create gantt chart from templates def process! error "Not on the develop trunk" unless @git.current_branch == 'develop' # error "Only leader/moderator and supervisor can edit ROADMAP" unless i_have_power? docs = @config[:docs] html_file = "#{docs}/gantt.html" FileUtils.mkdir_p "#{docs}" unless File.directory? "#{docs}" tpl_dir = File.expand_path(File.dirname(__FILE__) + "/../../../templates") FileUtils.cp_r "#{tpl_dir}/css", docs FileUtils.cp_r "#{tpl_dir}/js", docs wfh = File.open(html_file, "w:utf-8") wfh.puts Erubis::Eruby.new(File.read("#{tpl_dir}/jsgantt.html.erb")).result(:rm => @roadmap, :is_roadmap => true, :git_log => git_log, :resource => nil) wfh.close # update to server if sync? `git add .` `git commit -am 'update Gantt chart'` `git push #{@config["git_remote"]} develop` end end end end