Class: Ciflows::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/ciflows/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.gitObject



27
28
29
# File 'lib/ciflows/cli.rb', line 27

def git
  @git ||= Git.open(Dir.pwd)
end

.git_branchObject



23
24
25
# File 'lib/ciflows/cli.rb', line 23

def git_branch
  git.current_branch
end

.git_repoObject

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
# File 'lib/ciflows/cli.rb', line 15

def git_repo
  @git_repo ||= File.basename(git.config['remote.origin.url'].to_s).gsub('.git', '')

  raise ArgumentError, 'Remote git repository not found' unless @git_repo

  @git_repo
end

Instance Method Details

#processObject



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
# File 'lib/ciflows/cli.rb', line 39

def process
  flow = Ciflows::Project.new(options[:repo], options[:branch], options[:build], options[:job])

  begin
    flow.process

    build_icon = flow.build['status'] == 'success' ? "": ""

    say("Workflow INFO: #{build_icon}", :blue)
    print_table(flow.build)

    case flow.build['status']
    when 'failed', 'failing'
      say("\n")
      say("Workflow #{flow.build['id']} failed/failing", :red)
      say('Failed Jobs', :blue)
      print_table(flow.failed_jobs.map(&:to_h).map(&:values))

      say("\n Actions: " \
        "\n 1. Rerun from failed" \
        "\n 2. Rerun from begining" \
        "\n 3. Go to workflow (only support Google Chrome)")

      answer = ask('What do you want to go next?', :yellow, limited_to: %w[1 2 3])
      case answer.to_i
      when 1
        flow.rerun_workflow_from('failed')
      when 2
        flow.rerun_workflow_from('beginning')
      when 3
        Launchy.open("https://circleci.com/workflow-run/#{flow.build['id']}")
      else
        say_status('failed', "failed #{self}")
      end

    when 'on_hold', 'running'
      say("Workflow #{flow.build['id']} is on_hold/running", :yellow)

      if options[:run] == 'true' || yes?('Do you want to approve it? (y/n)', :yellow)
        flow.approve_workflow
      end
    when 'success'
      say('success', "Workflow #{flow.build['id']} succeeded", :green)
    end
  rescue Graphlient::Errors::ExecutionError => e
    say_status('fail', e.message, :red)
  end
end