Class: Bard::CLI::CI::GithubActions::API

Inherits:
Struct
  • Object
show all
Defined in:
lib/bard/ci/github_actions.rb

Instance Method Summary collapse

Instance Method Details

#create_run!(branch) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/bard/ci/github_actions.rb', line 74

def create_run! branch
  start_time = Time.now
  client.post("workflows/ci.yml/dispatches", ref: branch, inputs: { "git-ref": branch })
  sha = `git rev-parse #{branch}`.chomp

  loop do
    runs = client.get("runs", head_sha: sha, created: ">#{start_time.iso8601}")
    if json = runs["workflow_runs"].first
      return Run.new(self, json)
    end
    sleep 1
  end
end

#download_logs_by_job_id(job_id) ⇒ Object



94
95
96
# File 'lib/bard/ci/github_actions.rb', line 94

def download_logs_by_job_id job_id
  client.get("jobs/#{job_id}/logs")
end

#find_job_by_run_id(run_id) ⇒ Object



88
89
90
91
92
# File 'lib/bard/ci/github_actions.rb', line 88

def find_job_by_run_id run_id
  jobs = client.get("runs/#{run_id}/jobs", filter: "latest", per_page: 1)
  job_json = jobs["jobs"][0]
  Job.new(self, job_json)
end

#find_run(id) ⇒ Object



69
70
71
72
# File 'lib/bard/ci/github_actions.rb', line 69

def find_run id
  json = client.get("runs/#{id}")
  Run.new(self, json)
end

#last_runObject



55
56
57
58
59
60
# File 'lib/bard/ci/github_actions.rb', line 55

def last_run
  response = client.get("runs", event: "workflow_dispatch", per_page: 1)
  if json = response["workflow_runs"][0]
    Run.new(self, json)
  end
end

#last_successful_runObject



62
63
64
65
66
67
# File 'lib/bard/ci/github_actions.rb', line 62

def last_successful_run
  successful_runs = client.get("runs", event: "workflow_dispatch", status: "success", per_page: 1)
  if json = successful_runs["workflow_runs"][0]
    Run.new(self, json)
  end
end