Module: Legion::Extensions::Github::App::Runners::Manifest

Includes:
Helpers::Client, Helpers::Lex
Included in:
CLI::App, Client
Defined in:
lib/legion/extensions/github/app/runners/manifest.rb

Constant Summary collapse

DEFAULT_PERMISSIONS =
{
  contents: 'write', issues: 'write', pull_requests: 'write',
  metadata: 'read', administration: 'write', members: 'read',
  checks: 'write', statuses: 'write', actions: 'read',
  workflows: 'write', webhooks: 'write', repository_hooks: 'write'
}.freeze
DEFAULT_EVENTS =
%w[
  push pull_request pull_request_review issues issue_comment
  create delete check_run check_suite status workflow_run
  repository installation
].freeze

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

#exchange_manifest_code(code:) ⇒ Object



42
43
44
45
46
# File 'lib/legion/extensions/github/app/runners/manifest.rb', line 42

def exchange_manifest_code(code:, **)
  conn = connection(**)
  response = conn.post("/app-manifests/#{code}/conversions")
  { result: response.body }
end

#generate_manifest(name:, url:, webhook_url:, callback_url:, permissions: DEFAULT_PERMISSIONS, events: DEFAULT_EVENTS, public: true) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/legion/extensions/github/app/runners/manifest.rb', line 28

def generate_manifest(name:, url:, webhook_url:, callback_url:,
                      permissions: DEFAULT_PERMISSIONS, events: DEFAULT_EVENTS,
                      public: true, **)
  manifest = {
    name: name, url: url, public: public,
    hook_attributes: { url: webhook_url, active: true },
    setup_url: callback_url,
    redirect_url: callback_url,
    default_permissions: permissions,
    default_events: events
  }
  { result: manifest }
end

#manifest_url(manifest:, org: nil) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/legion/extensions/github/app/runners/manifest.rb', line 48

def manifest_url(manifest:, org: nil, **)
  base = if org
           "https://github.com/organizations/#{org}/settings/apps/new"
         else
           'https://github.com/settings/apps/new'
         end
  json_str = ::JSON.generate(manifest)
  { result: "#{base}?manifest=#{URI.encode_www_form_component(json_str)}" }
end