Class: DevFlow::App
- Inherits:
-
Object
show all
- Defined in:
- lib/dev_flow/app.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config, command) ⇒ App
Returns a new instance of App.
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
|
# File 'lib/dev_flow/app.rb', line 6
def initialize config, command
@config, @commnad = config, command
@logger = Logger.new(STDOUT)
@logger.level = config[:verbose] ? Logger::INFO : Logger::WARN
@logger.formatter = proc {|severity, datetime, progname, msg| "#{msg.to_s}\n"}
@git = DevFlow::Girc.new 'git', config[:verbose]
error "Please use dw in a git directory" unless @git.in_git_dir?
if @config[:members_file] and File.exists? (@config[:members_file])
info "Load member information form #{@config[:members_file]}"
@config = @config.merge(YAML.load(File.open(@config[:members_file], 'r:utf-8').read))
else
warn "No member file to load"
end
if @config[:local_config] and File.exists? (@config[:local_config])
info "Load local configuration from #{@config[:local_config]}"
@config = @config.merge(YAML.load(File.open(@config[:local_config], 'r:utf-8').read))
end
error "Do not work on master branch. Please swith to develop branch." if @git.current_branch == 'master'
load_roadmap
@waiting = Hash.new
end
|
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
4
5
6
|
# File 'lib/dev_flow/app.rb', line 4
def command
@command
end
|
#config ⇒ Object
Returns the value of attribute config.
4
5
6
|
# File 'lib/dev_flow/app.rb', line 4
def config
@config
end
|
#git ⇒ Object
Returns the value of attribute git.
4
5
6
|
# File 'lib/dev_flow/app.rb', line 4
def git
@git
end
|
#logger ⇒ Object
Returns the value of attribute logger.
4
5
6
|
# File 'lib/dev_flow/app.rb', line 4
def logger
@logger
end
|
#members ⇒ Object
Returns the value of attribute members.
4
5
6
|
# File 'lib/dev_flow/app.rb', line 4
def members
@members
end
|
#roadmap ⇒ Object
Returns the value of attribute roadmap.
4
5
6
|
# File 'lib/dev_flow/app.rb', line 4
def roadmap
@roadmap
end
|
#waiting ⇒ Object
Returns the value of attribute waiting.
4
5
6
|
# File 'lib/dev_flow/app.rb', line 4
def waiting
@waiting
end
|
Instance Method Details
#all_member_names ⇒ Object
83
84
85
|
# File 'lib/dev_flow/app.rb', line 83
def all_member_names
@members.keys
end
|
#ask_rebase(force = false) ⇒ Object
interactive methods with git remote server
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/dev_flow/app.rb', line 201
def ask_rebase force = false
if sync?
info "Rebase you working directory from #{@config["git_remote"]}/devleop"
@git.rebase! @config["git_remote"], 'develop'
load_roadmap else
warn "Git remote not defined, skip rebase."
end
end
|
#debug(msg) ⇒ Object
77
78
79
|
# File 'lib/dev_flow/app.rb', line 77
def debug msg
@logger.debug "[DEBUG] " + msg
end
|
#display_close_waiting ⇒ Object
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
# File 'lib/dev_flow/app.rb', line 155
def display_close_waiting
return false unless self.tasks_for_close.size > 0
puts "There have tasks marked completed and need you to review it:".bold.red
i = 0
self.tasks_for_close.each do |task|
i += 1
if @git.wd_clean?
puts task.as_title i.to_s
@waiting[i] = task
else
puts task.as_title " "
end
end
end
|
#display_tasks ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/dev_flow/app.rb', line 170
def display_tasks
i = 0
j = 0
remain = 0
@roadmap.tasks.each do |task|
next if task.parent and task.parent.is_completed?
next if task.is_pending? or task.is_deleted?
if i > 31 remain += 1
next
end
= nil
= '+'.bold.green if task.is_completed?
= '-' unless or task.is_workable?
= '=' if @git.current_branch == task.branch_name
unless
j += 1
= j.to_s.bold
= ' ' unless @git.wd_clean?
@waiting[j] = task if @git.wd_clean?
end
puts task.as_title()
i += 1
end
puts "There #{remain.to_s.bold} more tasks not show here." if remain > 0
end
|
#error(msg) ⇒ Object
64
65
66
67
|
# File 'lib/dev_flow/app.rb', line 64
def error msg
@logger.fatal ("[ERROR] " + msg).bold.red
exit
end
|
#hello ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/dev_flow/app.rb', line 143
def hello
puts hrbh
puts "Hello, #{user_name.bold}."
puts "This is the DevFlow console, version: " + VERSION
puts hrh
puts "You are on branch #{@git.current_branch.bold.green}" if @git.current_branch
puts "You task is: #{self.task.display_name.bold}, progress #{self.task.progress.to_s.bold}" if self.task
puts "You are the #{'leader'.bold} of the project." if self.i_am_leader?
puts "You are the #{'moderator'.bold} of the project." if self.i_am_moderator?
puts "You are the #{'supervisor'.bold} of the project." if self.i_am_supervisor?
end
|
#hr ⇒ Object
138
|
# File 'lib/dev_flow/app.rb', line 138
def hr; "-"*76 end
|
#hrb ⇒ Object
140
|
# File 'lib/dev_flow/app.rb', line 140
def hrb; "="*76 end
|
#hrbh ⇒ Object
141
|
# File 'lib/dev_flow/app.rb', line 141
def hrbh; hrb.bold end
|
#hrh ⇒ Object
139
|
# File 'lib/dev_flow/app.rb', line 139
def hrh; hr.bold end
|
#i_am_leader? ⇒ Boolean
112
113
114
|
# File 'lib/dev_flow/app.rb', line 112
def i_am_leader?
@config["whoami"] and @config["leader"] == @config["whoami"]
end
|
#i_am_moderator? ⇒ Boolean
116
117
118
|
# File 'lib/dev_flow/app.rb', line 116
def i_am_moderator?
@config["whoami"] and @config["moderator"] == @config["whoami"]
end
|
#i_am_supervisor? ⇒ Boolean
120
121
122
|
# File 'lib/dev_flow/app.rb', line 120
def i_am_supervisor?
@config["whoami"] and @config["supervisor"] == @config["whoami"]
end
|
#i_have_power? ⇒ Boolean
124
125
126
|
# File 'lib/dev_flow/app.rb', line 124
def i_have_power?
[@config["leader"], @config["supervisor"], @config["moderator"]].include? @config["whoami"]
end
|
#in_release? ⇒ Boolean
108
109
110
|
# File 'lib/dev_flow/app.rb', line 108
def in_release?
task and task.is_release?
end
|
#in_trunk? ⇒ Boolean
104
105
106
|
# File 'lib/dev_flow/app.rb', line 104
def in_trunk?
%w[master develop staging production].include? @git.current_branch
end
|
#info(msg) ⇒ Object
73
74
75
|
# File 'lib/dev_flow/app.rb', line 73
def info msg
@logger.info "[INFO] " + msg
end
|
#leader_name ⇒ Object
92
93
94
|
# File 'lib/dev_flow/app.rb', line 92
def leader_name
@members[@config["leader"]].display_name
end
|
#load_roadmap ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/dev_flow/app.rb', line 40
def load_roadmap
if @config[:roadmap] and File.exists? (@config[:roadmap])
info "Load roadmap from #{@config[:roadmap]}"
@roadmap = RoadMap.new(@config[:roadmap], @config).parse
@config = @roadmap.config
error "No leader defined for your porject!" unless @config['leader']
end
@members = Hash.new
@config["members"].each do |name, ary|
@members[name] = Member.new(name, *ary)
end
error "No known members defined!" unless all_member_names.size > 0
if @config["whoami"]
error "You (#{user_name}) are not in the known member list. You may use 'dw init' to setup the working environment." unless all_member_names.include? @config["whoami"]
end
end
|
#new_version(branch_name) ⇒ Object
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
# File 'lib/dev_flow/app.rb', line 254
def new_version branch_name
if branch_name =~ /^release\_v/
return branch_name.gsub('release_v', 'version-')
elsif branch_name =~ /^hotfix\_/
last_v = ''
`git tag`.split("\n").each do |t|
if /^version\-\d+\.\d+\.(?<nm_>\d+)$/ =~ t last_v = t.gsub(/\d+$/, (nm_.to_i + 1).to_s)
elsif /^version\-\d+\.\d+$/ =~ t last_v = t + '.1'
end
end
return last_v
else
return ''
end
end
|
#switch_to!(branch) ⇒ Object
221
222
223
224
225
226
227
228
229
|
# File 'lib/dev_flow/app.rb', line 221
def switch_to! branch
if @git.branches.include? branch
info "Switch to branch #{branch}"
`git checkout #{branch}`
else
info "Switch to new branch #{branch}"
`git checkout -b #{branch}`
end
end
|
#sync? ⇒ Boolean
132
133
134
|
# File 'lib/dev_flow/app.rb', line 132
def sync?
@config["git_remote"] and (not @config[:offline])
end
|
#task(branch = nil) ⇒ Object
96
97
98
99
100
101
102
|
# File 'lib/dev_flow/app.rb', line 96
def task branch = nil
branch = @git.current_branch unless branch
@roadmap.tasks.each do |task|
return task if task.branch_name == branch
end
nil
end
|
#tasks_for_close ⇒ Object
128
129
130
|
# File 'lib/dev_flow/app.rb', line 128
def tasks_for_close
@roadmap.tasks.select {|task| task.progress == 99}
end
|
#upload_progress!(task, progress, is_complete = false) ⇒ Object
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
# File 'lib/dev_flow/app.rb', line 231
def upload_progress! task, progress, is_complete = false
current_branch = @git.current_branch
switch_to! 'develop' unless current_branch == 'develop'
info "Rewrite #{@config[:roadmap]} file"
@roadmap.rewrite! task.ln => progress
info "Set progress of #{task.display_name} to #{progress}"
`git commit -am 'update progress of task #{task.branch_name} to #{progress}'`
`git push #{@config["git_remote"]} develop` if @config["git_remote"]
unless (is_complete or current_branch == 'develop')
switch_to! current_branch
`git merge develop`
if @config["git_remote"]
`git push #{@config["git_remote"]} #{current_branch}`
ask_rebase true end
end
end
|
#user_name ⇒ Object
87
88
89
90
|
# File 'lib/dev_flow/app.rb', line 87
def user_name
wi = @config["whoami"]
@members[wi] ? @members[wi].display_name : wi
end
|
#warn(msg) ⇒ Object
69
70
71
|
# File 'lib/dev_flow/app.rb', line 69
def warn msg
@logger.warn ("[WARN] " + msg).yellow
end
|