Class: DevFlow::Close

Inherits:
App
  • Object
show all
Defined in:
lib/dev_flow/commands/close.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

#process!Object



4
5
6
7
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/dev_flow/commands/close.rb', line 4

def process!
  self.hello

  error "Only leader (#{leader_name.bold}) can close a branch." unless i_am_leader?

  # whether I am working on a proper task branch
  current_task = self.task
  error "Not on a known task branch. Can not continue." unless current_task      
  error "Can not close task offline" unless sync?

  if current_task and (in_release? or current_task.branch_name =~ /^hotfix\_/)
    error "Use command 'release' to close a release/hotfix branch." unless @config[:release]
  else
    error "Use command 'close' to close a non-release branch." if @config[:release]
  end

  if in_release? and @config[:release]
    error "You should use release only on branches just completed." unless current_task and current_task.progress == 99 
  end
  

  self.ask_rebase # force rebase
  puts hr

  # commit you current branch and push
  progress = 100
  message = ARGV[2] || "close the branch by set progress to 100."
  message = "[close] " + message

  info "commit progress"
  `git commit -am '#{message}'`
  info "push your progress to remote server"
  `git push #{@config["git_remote"]} #{current_task.branch_name}`
  
  # goto develop branch and merge
  `git checkout develop`
  rslt = `git merge --no-ff #{current_task.branch_name}`
  error "Not fast forward merge failed: #{rslt}" unless $?.success?

  # rewrite progress in ROADMAP file under develop trunk
  upload_progress! current_task, progress, true
  
  # merge into the master
  if @config[:release]
    info "Merge the release branch into master trunk"
    `git checkout master`
    `git merge --no-ff develop`
    tag = new_version current_task.branch_name
    if tag
      info "Tag your release as #{tag}"
      `git tag #{tag}`
    end
    info "Push your change to remote server"
    `git push #{@config["git_remote"]} --tags master` if @config["git_remote"]

    puts "Now your are on branch #{'master'.bold.red}"
    puts "You may want to review and test the program again and then switch back to develop trunk."
  end
  
  info "Delete closed branch #{current_task.branch_name}"
  `git branch -d #{current_task.branch_name}`
  
  info "Delete closed branch remotely"
  `git push #{@config["git_remote"]} :#{current_task.branch_name}`
end