Class: DevFlow::Gantt

Inherits:
App
  • Object
show all
Defined in:
lib/dev_flow/commands/gantt.rb

Instance Attribute Summary

Attributes inherited from App

#command, #config, #git, #logger, #members, #roadmap, #waiting

Instance Method Summary collapse

Methods inherited from App

#all_member_names, #ask_rebase, #debug, #display_close_waiting, #display_tasks, #error, #hello, #hr, #hrb, #hrbh, #hrh, #i_am_leader?, #i_am_moderator?, #i_am_supervisor?, #i_have_power?, #in_release?, #in_trunk?, #info, #initialize, #leader_name, #load_roadmap, #new_version, #switch_to!, #sync?, #task, #tasks_for_close, #upload_progress!, #user_name, #warn

Constructor Details

This class inherits a constructor from DevFlow::App

Instance Method Details

#git_logObject

fetch git log



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dev_flow/commands/gantt.rb', line 8

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!("<", "&lt;")
    if /^(?<header_>\W+)From\s+(?<hash_code_>\w+)/ =~ line
      git_log += "#{header_}<em style='color:grey'>#{hash_code_}</em>\n"
    elsif /^(?<header_>\W+)From\:\s+(?<committer_>.+)$/ =~ line
      committer = committer_
      last_header = header_
    elsif /^(?<header_>\W+)Date\:\s*(?<date_>.+)$/ =~ line
      git_log += sprintf("%s<strong>%s</strong> By %s\n", last_header, DateTime.parse(date_).strftime("%F %R"), committer)
      git_log += header_
    elsif /^(?<header_>\W+)Subject\:\s+\[PATCH\]\s*(?<message_>.+)$/ =~ line
      color = 'green'
      git_log += "#{header_}<strong style='color:#{color}'>#{message_}</strong>\n"
    else
      git_log += line + "\n"
    end
  end
  git_log
end

#process!Object

create gantt chart from templates



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dev_flow/commands/gantt.rb', line 36

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