Rakefiles: support interactive push in `rake workflow:push`
When invoking `rake workflow:push` from an interactive terminal,
for each repository ask user whether or not push changes.
--- a/rakelib/support.rb Wed Nov 03 22:09:33 2021 +0000
+++ b/rakelib/support.rb Thu Nov 04 16:23:15 2021 +0000
@@ -43,6 +43,26 @@
(user == 'jv') or (user == 'vranyj1') ? true : false
end
+# When on interactive terminal, ask user a yes/no question and return
+# user's answer. If terminal is not interactive, return false.
+def yesNO(question)
+ if STDIN.tty? then
+ puts "#{question} [y/N]?"
+ answer = STDIN.gets.chomp
+ case answer
+ when ''
+ return false
+ when /[nN]([oO])?/
+ return false
+ when /[yY]([eE][sS])?/
+ return true
+ end
+ else
+ return false
+ end
+end
+
+
# ArtifactRepository module provides API for downloading (binary) files from
# some sort of - well - artifact repository. A repository contains multiple
# builds (currently the API provides only access to `latestBuild()`), build
--- a/rakelib/workflow.rake Wed Nov 03 22:09:33 2021 +0000
+++ b/rakelib/workflow.rake Thu Nov 04 16:23:15 2021 +0000
@@ -48,29 +48,34 @@
puts''
end
else
- if review_only
+ has_changes_in_this_repo = false
+ if review_only or STDIN.tty?
opts[:rev] = '.'
remote_url = hg.paths[remote_used] || remote_used
bookmark = hg.bookmark
hg.outgoing(remote_used, **opts) do | status, stdout |
case status.exitstatus
- when 0
+ when 0
puts ''
puts "== changes going to #{remote_url} =="
STDOUT.print stdout
puts "Will update bookmark '#{bookmark}" if push_bookmark and bookmark
puts '===================================='
has_changes = true
+ has_changes_in_this_repo = true
when 1
# nothing
- else
+ else
raise Exception.new("Failed to do 'outgoing' from #{remote} (exit code #{status.exitstatus})")
end
end
- else
- (push_bookmark && bookmark) ? (opts[:bookmarks] = ['.']) : (opts[:rev] = '.') # bookmark can be uninitialized
- hg.push(remote_used, **opts)
- has_changes = true
+ end
+ if not review_only
+ if not STDIN.tty? or (has_changes_in_this_repo and yesNO("Push to #{remote_url}")) then
+ (push_bookmark && bookmark) ? (opts[:bookmarks] = ['.']) : (opts[:rev] = '.') # bookmark can be uninitialized
+ hg.push(remote_used, **opts)
+ has_changes = true
+ end
end
end
end