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



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/bard/ci/github_actions.rb', line 69

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", 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



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

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

#find_job_by_run_id(run_id) ⇒ Object



83
84
85
86
87
# File 'lib/bard/ci/github_actions.rb', line 83

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



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

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

#last_runObject



50
51
52
53
54
55
# File 'lib/bard/ci/github_actions.rb', line 50

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



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

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