lib/bard/ci/github_actions.rb in bard-0.51.2 vs lib/bard/ci/github_actions.rb in bard-0.52.0

- old
+ new

@@ -5,11 +5,10 @@ class Bard::CLI < Thor class CI class GithubActions < Struct.new(:project_name, :branch, :sha) def run - api = API.new(project_name) last_time_elapsed = api.last_successful_run&.time_elapsed @run = api.create_run!(branch) start_time = Time.new.to_i while @run.building? @@ -31,11 +30,37 @@ end def last_response end + def status + last_run = api.last_run + if last_run.building? + puts "Building..." + elsif last_run.success? + puts "Succeeded!" + elsif last_run.failure? + puts "Failed!\n\n#{last_run.console}" + else + raise "Unknown job status: #{last_run.inspect}" + end + end + + private + + def api + @api ||= API.new(project_name) + end + class API < Struct.new(:project_name) + 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 + 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 @@ -90,18 +115,46 @@ %w[in_progress queued requested waiting pending] .include?(json["status"]) end def success? - json["status"] == "completed" && json["conclusion"] == "success" + status == "completed" && conclusion == "success" end + def failure? + conclusion == "failure" + end + def job @job ||= api.find_job_by_run_id(id) end def console job.logs + end + + def branch + json["head_branch"] + end + + def sha + json["head_sha"] + end + + def status + json["status"] + end + + def conclusion + json["conclusion"] + end + + def started_at + Time.parse(json["run_started_at"]) + end + + def updated_at + Time.parse(json["updated_at"]) end end class Job < Struct.new(:api, :json) def id