class Ciflows::CLI

Public Class Methods

git() click to toggle source
# File lib/ciflows/cli.rb, line 27
def git
  @git ||= Git.open(Dir.pwd)
end
git_branch() click to toggle source
# File lib/ciflows/cli.rb, line 23
def git_branch
  git.current_branch
end
git_repo() click to toggle source
# 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

Public Instance Methods

process() click to toggle source
# 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