Class: Release::Gem::Cli::VcsAction

Inherits:
Object
  • Object
show all
Defined in:
lib/release/gem/vcs_cli_action.rb

Instance Method Summary collapse

Constructor Details

#initialize(root, opts = { }) ⇒ VcsAction

Returns a new instance of VcsAction.



10
11
12
13
14
15
# File 'lib/release/gem/vcs_cli_action.rb', line 10

def initialize(root, opts = {  })
  opts = {} if opts.nil?
  opts[:ui] = TTY::Prompt.new
  @inst = Action::VcsAction.new(root,opts)
  @prmt = TTY::Prompt.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mtd, *args, &block) ⇒ Object

push



224
225
226
# File 'lib/release/gem/vcs_cli_action.rb', line 224

def method_missing(mtd, *args, &block)
  @inst.send(mtd, *args, &block)
end

Instance Method Details

#commit(*args, &block) ⇒ Object



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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/release/gem/vcs_cli_action.rb', line 21

def commit(*args, &block)
  res = @inst.commit do |ops, *args|
    
    preset = false
    if block
      res = block.call(ops, *args)
      if res.nil?
        preset = true
      else
        res
      end
    else
      preset = true
    end

    if preset

      case ops
      when :select_files_to_commit
        mfiles = args.first
        @prmt.puts "\n Files already added to staging : ".yellow
        mfiles[:staged].each do |k,v|
          v.each do |vv|
            @prmt.puts " * #{vv}"
          end
        end

        @prmt.puts ""

        sel = @prmt.multi_select "\n Following are files that could be added to version control : ".yellow do |m|

          [:modified, :new, :deleted].each do |cat|
            mfiles[cat].each do |k,v|
              v.each do |vv|
                m.choice vv, vv.path
              end
            end

          end

          m.choice "Skip", :skip if mfiles[:counter] == 0
          m.choice "Done", :done
          m.choice "Abort", :abort
        end

        if sel.include?(:abort)
          raise Release::Gem::Abort, "User aborted"
        elsif sel.include?(:skip)
          :skip 
        else
          res = :done if sel.include?(:done)
          s = sel.clone
          s.delete_if { |e| e == :done }
          if not_empty?(s)
            st, cres = add_to_staging(*s) if not_empty?(s)
            if st
              @prmt.puts "\n Files added successfully".green
            else
              @prmt.puts "\n Files failed to be added. Message was : #{cres}".red
            end
          end

          res

        end

      when :commit_message
        msg = ""
        loop do
          msg = @prmt.ask("\n Commit message : ".yellow, required: true)
          confirm = @prmt.yes?(" Commit message : #{msg}\n Proceed? No to provide a new commit message ".yellow)
          if confirm
            break
          end
        end

        msg

      when :staged_elements_of_commit

        elements = args.first
        @prmt.puts "\n Following files/directories shall be committed in this session : ".yellow
        elements.each do |k,v|
          v.each do |vv|
            @prmt.puts " * #{vv}"
          end
        end

      when :commit_successful
        @prmt.puts "\n Changes committed".green
        @prmt.puts args.first

      when :commit_failed
        @prmt.puts "\n Changes failed to be committed. Error was : #{args.first}"

      end
    end
  end # commit

end

#exec(&block) ⇒ Object



17
18
19
# File 'lib/release/gem/vcs_cli_action.rb', line 17

def exec(&block)
  instance_eval(&block) if block
end

#push(*args, &block) ⇒ Object

tag



161
162
163
164
165
166
167
168
169
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/release/gem/vcs_cli_action.rb', line 161

def push(*args, &block)

  @inst.push do |ops, *args|
    preset = false
    if block
      res = block.call(ops, *args)
      if res.nil?
        preset = true
      else
        res
      end
    else
      preset = true
    end

    if preset

      case ops
      when :select_remote
        val = args.first
        sel = @prmt.select("\n Please select one of the remote config below : ") do |m|
          val.each do |k,v|
            m.choice k, k
          end
          m.choice "Skip pushing source code", :skip
          m.choice "Abort", :abort
        end
        raise Release::Gem::Abort, "User aborted" if sel == :abort

        sel

      when :no_remote_repos_defined
        add = @prmt.yes?("\n No remote configuration defined. Add one now?")
        if add
          name = @prmt.ask("\n Name of the repository : ", value: "origin", required: true)
          url = @prmt.ask("\n URL of the repository : ", required: true)

          st, res = add_remote(name, url)
          if st
            @prmt.puts "\n Remote configuration added successfully".green
            name
          else
            raise Release::Gem::Abort, "Failed to add remote configuration. Error was : #{res}"
          end
        end

      when :push_successful
        @prmt.puts "\n Push success!".green
        @prmt.puts args.first

      when :push_failed
        @prmt.puts "\nPush failed. Error was : #{args.first}".red

      when :no_changes_to_push
        val = args.first
        @prmt.puts "\n Local is in sync with remote (#{val[:remote]}/#{val[:branch]}). Push is not required. "
      end
    end

  end

end

#tag(*args, &block) ⇒ Object

Commit



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/release/gem/vcs_cli_action.rb', line 122

def tag(*args, &block)

  @inst.tag(*args) do |ops, *args|

    preset = false
    if block
      res = block.call(ops, *args)
      if res.nil?
        preset = true
      else
        res
      end
    else
      preset = true
    end

    if preset

      case ops
      when :tag_message
        @prmt.ask("\n Please provide message for the tag : ".yellow, value: "Auto tagging by gem-release gem during releasing version #{@selVer}", required: true)

      when :tagging_success
        @prmt.puts "\n Tagging of source code is successful.".green
        @prmt.puts args.first

      when :tagging_failed
        @prmt.puts "\n Tagging of source code failed. Error was : #{args.first}".red

      when :no_tagging_required
        @prmt.puts "\n No tagging required. Source head is the tagged item ".green

      end
    end # preset ?

  end

end