Class: Bard::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



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/bard/ci/github_actions.rb', line 99

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

  loop do
    runs = client.get("actions/runs", event: "workflow_dispatch", 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



119
120
121
# File 'lib/bard/ci/github_actions.rb', line 119

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

#find_job_by_run_id(run_id) ⇒ Object



113
114
115
116
117
# File 'lib/bard/ci/github_actions.rb', line 113

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

#find_run(id) ⇒ Object



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

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

#last_runObject



80
81
82
83
84
85
# File 'lib/bard/ci/github_actions.rb', line 80

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

#last_successful_runObject



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

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