Module: Legion::Extensions::Github::Runners::Actions

Includes:
Helpers::Client, Helpers::Lex
Included in:
Client
Defined in:
lib/legion/extensions/github/runners/actions.rb

Constant Summary

Constants included from Helpers::Client

Helpers::Client::CREDENTIAL_RESOLVERS

Constants included from Helpers::TokenCache

Helpers::TokenCache::TOKEN_BUFFER_SECONDS

Instance Method Summary collapse

Methods included from Helpers::Client

#connection, #gh_cli_token_output, #max_fallback_retries, #on_rate_limit, #on_scope_authorized, #on_scope_denied, #resolve_broker_app, #resolve_credential, #resolve_env, #resolve_gh_cli, #resolve_next_credential, #resolve_settings_app, #resolve_settings_delegated, #resolve_settings_pat, #resolve_vault_app, #resolve_vault_delegated, #resolve_vault_pat

Methods included from Helpers::ScopeRegistry

#credential_fingerprint, #invalidate_scope, #mark_rate_limited, #rate_limited?, #register_scope, #scope_status

Methods included from Helpers::TokenCache

#fetch_token, #mark_rate_limited, #rate_limited?, #store_token

Instance Method Details

#cancel_workflow_run(owner:, repo:, run_id:) ⇒ Object



50
51
52
53
54
55
# File 'lib/legion/extensions/github/runners/actions.rb', line 50

def cancel_workflow_run(owner:, repo:, run_id:, **)
  response = connection(owner: owner, repo: repo, **).post(
    "/repos/#{owner}/#{repo}/actions/runs/#{run_id}/cancel"
  )
  { result: [202, 204].include?(response.status) }
end

#download_workflow_run_logs(owner:, repo:, run_id:) ⇒ Object



79
80
81
82
83
84
# File 'lib/legion/extensions/github/runners/actions.rb', line 79

def download_workflow_run_logs(owner:, repo:, run_id:, **)
  response = connection(owner: owner, repo: repo, **).get(
    "/repos/#{owner}/#{repo}/actions/runs/#{run_id}/logs"
  )
  { result: { status: response.status, headers: response.headers.to_h, body: response.body } }
end

#get_workflow(owner:, repo:, workflow_id:) ⇒ Object



19
20
21
22
23
24
# File 'lib/legion/extensions/github/runners/actions.rb', line 19

def get_workflow(owner:, repo:, workflow_id:, **)
  response = connection(owner: owner, repo: repo, **).get(
    "/repos/#{owner}/#{repo}/actions/workflows/#{workflow_id}"
  )
  { result: response.body }
end

#get_workflow_run(owner:, repo:, run_id:) ⇒ Object



35
36
37
38
39
40
# File 'lib/legion/extensions/github/runners/actions.rb', line 35

def get_workflow_run(owner:, repo:, run_id:, **)
  response = connection(owner: owner, repo: repo, **).get(
    "/repos/#{owner}/#{repo}/actions/runs/#{run_id}"
  )
  { result: response.body }
end

#list_workflow_run_artifacts(owner:, repo:, run_id:, per_page: 30, page: 1) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/legion/extensions/github/runners/actions.rb', line 86

def list_workflow_run_artifacts(owner:, repo:, run_id:, per_page: 30, page: 1, **)
  params = { per_page: per_page, page: page }
  response = connection(owner: owner, repo: repo, **).get(
    "/repos/#{owner}/#{repo}/actions/runs/#{run_id}/artifacts", params
  )
  { result: response.body }
end

#list_workflow_run_jobs(owner:, repo:, run_id:, filter: 'latest', per_page: 30, page: 1) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/legion/extensions/github/runners/actions.rb', line 71

def list_workflow_run_jobs(owner:, repo:, run_id:, filter: 'latest', per_page: 30, page: 1, **)
  params = { filter: filter, per_page: per_page, page: page }
  response = connection(owner: owner, repo: repo, **).get(
    "/repos/#{owner}/#{repo}/actions/runs/#{run_id}/jobs", params
  )
  { result: response.body }
end

#list_workflow_runs(owner:, repo:, workflow_id:, status: nil, branch: nil, per_page: 30, page: 1) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/legion/extensions/github/runners/actions.rb', line 26

def list_workflow_runs(owner:, repo:, workflow_id:, status: nil, branch: nil,
                       per_page: 30, page: 1, **)
  params = { per_page: per_page, page: page, status: status, branch: branch }.compact
  response = connection(owner: owner, repo: repo, **).get(
    "/repos/#{owner}/#{repo}/actions/workflows/#{workflow_id}/runs", params
  )
  { result: response.body }
end

#list_workflows(owner:, repo:, per_page: 30, page: 1) ⇒ Object



12
13
14
15
16
17
# File 'lib/legion/extensions/github/runners/actions.rb', line 12

def list_workflows(owner:, repo:, per_page: 30, page: 1, **)
  response = connection(owner: owner, repo: repo, **).get(
    "/repos/#{owner}/#{repo}/actions/workflows", per_page: per_page, page: page
  )
  { result: response.body }
end

#rerun_failed_jobs(owner:, repo:, run_id:) ⇒ Object



64
65
66
67
68
69
# File 'lib/legion/extensions/github/runners/actions.rb', line 64

def rerun_failed_jobs(owner:, repo:, run_id:, **)
  response = connection(owner: owner, repo: repo, **).post(
    "/repos/#{owner}/#{repo}/actions/runs/#{run_id}/rerun-failed-jobs"
  )
  { result: [201, 204].include?(response.status) }
end

#rerun_workflow(owner:, repo:, run_id:) ⇒ Object



57
58
59
60
61
62
# File 'lib/legion/extensions/github/runners/actions.rb', line 57

def rerun_workflow(owner:, repo:, run_id:, **)
  response = connection(owner: owner, repo: repo, **).post(
    "/repos/#{owner}/#{repo}/actions/runs/#{run_id}/rerun"
  )
  { result: [201, 204].include?(response.status) }
end

#trigger_workflow(owner:, repo:, workflow_id:, ref:, inputs: {}) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/legion/extensions/github/runners/actions.rb', line 42

def trigger_workflow(owner:, repo:, workflow_id:, ref:, inputs: {}, **)
  payload = { ref: ref, inputs: inputs }
  response = connection(owner: owner, repo: repo, **).post(
    "/repos/#{owner}/#{repo}/actions/workflows/#{workflow_id}/dispatches", payload
  )
  { result: response.status == 204 }
end