Class: SOULs::Github

Inherits:
Thor
  • Object
show all
Defined in:
lib/souls/cli/github/index.rb

Instance Method Summary collapse

Instance Method Details

#add_envObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/souls/cli/github/index.rb', line 20

def add_env
  prompt = TTY::Prompt.new
  key = prompt.ask("Set Key:")
  value = prompt.ask("Set Value:")
  update_env_production(key: key, value: value, dqm: options[:dqm])
  update_api_env(key: key, value: value, dqm: options[:dqm])
  update_workers_env(key: key, value: value, dqm: options[:dqm])
  update_github_actions(key: key)
  system("gh secret set #{key} -b \"#{value.strip}\"")
end

#secret_setObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/souls/cli/github/index.rb', line 4

def secret_set
  Dir.chdir(SOULs.get_mother_path.to_s) do
    file_path = ".env.production"
    File.open(file_path, "r") do |file|
      file.each_line do |line|
        key_and_value = line.match(/([A-Z_]+)="?([^"]*)"?/)
        next if key_and_value.nil?

        system("gh secret set #{key_and_value[1]} -b \"#{key_and_value[2].strip}\"")
      end
    end
  end
end

#watchObject



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
# File 'lib/souls/cli/github/index.rb', line 32

def watch
  remote_url = `git remote get-url origin`
  split_url = %r{(https://|git@)(github.com)(:|/)([^.]+/[^.]+)(\.git)?}.match(remote_url)
  if split_url.nil? || split_url.size != 6
    SOULs::Painter.error("Cannot access Github, please check your credentials")
    return
  end

  api_request = "gh api -X GET 'repos/#{split_url[4]}/actions/runs'"
  workflows = JSON.parse(`#{api_request}`)

  if workflows.nil? || !workflows.key?("workflow_runs")
    SOULs::Painter.error("Failed to parse JSON response from Github")
    return
  end

  wf_info =
    workflows["workflow_runs"].filter_map do |wf|
      { wf["name"].to_sym => wf["id"] } if wf["status"] == "in_progress"
    end

  wf_id =
    case wf_info.size
    when 0
      SOULs::Painter.error("No workflow is running")
      return
    when 1
      wf_info[0].values[0]
    else
      prompt = TTY::Prompt.new
      prompt.select("Which workflow would you like to watch?", wf_info.inject(:merge))
    end

  system("gh run watch #{wf_id}")
end