Class: Octokit::Client

Inherits:
Object
  • Object
show all
Includes:
Authentication, ActionsArtifacts, ActionsSecrets, ActionsWorkflowJobs, ActionsWorkflowRuns, ActionsWorkflows, Apps, Checks, CodeScanning, CodespacesSecrets, CommitBranches, CommitComments, CommitPulls, Commits, CommunityProfile, Contents, DependabotSecrets, Deployments, Downloads, Emojis, Environments, Events, Feeds, Gists, Gitignore, Hooks, Issues, Labels, LegacySearch, Licenses, Markdown, Marketplace, Meta, Milestones, Notifications, OauthApplications, Objects, Organizations, Pages, Projects, PullRequests, RateLimit, Reactions, Refs, Releases, Repositories, RepositoryInvitations, Reviews, Say, Search, ServiceStatus, SourceImport, Stats, Statuses, Tokens, Traffic, Users, Configurable, Connection, Warnable
Defined in:
lib/octokit/client.rb,
lib/octokit/client/say.rb,
lib/octokit/client/apps.rb,
lib/octokit/client/meta.rb,
lib/octokit/client/refs.rb,
lib/octokit/client/feeds.rb,
lib/octokit/client/gists.rb,
lib/octokit/client/hooks.rb,
lib/octokit/client/pages.rb,
lib/octokit/client/stats.rb,
lib/octokit/client/users.rb,
lib/octokit/client/checks.rb,
lib/octokit/client/emojis.rb,
lib/octokit/client/events.rb,
lib/octokit/client/issues.rb,
lib/octokit/client/labels.rb,
lib/octokit/client/search.rb,
lib/octokit/client/tokens.rb,
lib/octokit/client/commits.rb,
lib/octokit/client/objects.rb,
lib/octokit/client/reviews.rb,
lib/octokit/client/traffic.rb,
lib/octokit/client/contents.rb,
lib/octokit/client/licenses.rb,
lib/octokit/client/markdown.rb,
lib/octokit/client/projects.rb,
lib/octokit/client/releases.rb,
lib/octokit/client/statuses.rb,
lib/octokit/client/downloads.rb,
lib/octokit/client/gitignore.rb,
lib/octokit/client/reactions.rb,
lib/octokit/client/milestones.rb,
lib/octokit/client/rate_limit.rb,
lib/octokit/client/deployments.rb,
lib/octokit/client/marketplace.rb,
lib/octokit/client/commit_pulls.rb,
lib/octokit/client/environments.rb,
lib/octokit/client/repositories.rb,
lib/octokit/client/code_scanning.rb,
lib/octokit/client/legacy_search.rb,
lib/octokit/client/notifications.rb,
lib/octokit/client/organizations.rb,
lib/octokit/client/pull_requests.rb,
lib/octokit/client/source_import.rb,
lib/octokit/client/service_status.rb,
lib/octokit/client/actions_secrets.rb,
lib/octokit/client/commit_branches.rb,
lib/octokit/client/commit_comments.rb,
lib/octokit/client/actions_artifacts.rb,
lib/octokit/client/actions_workflows.rb,
lib/octokit/client/community_profile.rb,
lib/octokit/client/codespaces_secrets.rb,
lib/octokit/client/dependabot_secrets.rb,
lib/octokit/client/oauth_applications.rb,
lib/octokit/client/actions_workflow_jobs.rb,
lib/octokit/client/actions_workflow_runs.rb,
lib/octokit/client/repository_invitations.rb

Overview

Client for the GitHub API

Defined Under Namespace

Modules: ActionsArtifacts, ActionsSecrets, ActionsWorkflowJobs, ActionsWorkflowRuns, ActionsWorkflows, Apps, Checks, CodeScanning, CodespacesSecrets, CommitBranches, CommitComments, CommitPulls, Commits, CommunityProfile, Contents, DependabotSecrets, Deployments, Downloads, Emojis, Environments, Events, Feeds, Gists, Gitignore, Hooks, Issues, Labels, LegacySearch, Licenses, Markdown, Marketplace, Meta, Milestones, Notifications, OauthApplications, Objects, Organizations, Pages, Projects, PullRequests, RateLimit, Reactions, Refs, Releases, Repositories, RepositoryInvitations, Reviews, Say, Search, ServiceStatus, SourceImport, Stats, Statuses, Tokens, Traffic, Users

Constant Summary collapse

CONVENIENCE_HEADERS =

Header keys that can be passed in options hash to Octokit::Connection#get,Octokit::Connection#head

Set.new(%i[accept content_type])

Constants included from ServiceStatus

ServiceStatus::COMPONENTS_ROOT, ServiceStatus::STATUS_ROOT

Constants included from Authentication

Authentication::FARADAY_BASIC_AUTH_KEYS

Instance Attribute Summary

Attributes included from Configurable

#access_token, #api_endpoint, #auto_paginate, #bearer_token, #client_id, #client_secret, #connection_options, #default_media_type, #login, #manage_ghes_endpoint, #manage_ghes_password, #manage_ghes_username, #management_console_endpoint, #management_console_password, #middleware, #netrc, #netrc_file, #password, #per_page, #proxy, #ssl_verify_mode, #user_agent, #web_endpoint

Instance Method Summary collapse

Methods included from Users

#add_email, #add_key, #all_users, #delete_user_migration_archive, #emails, #exchange_code_for_token, #follow, #followers, #following, #follows?, #key, #keys, #refresh_access_token, #remove_email, #remove_key, #starred, #starred?, #start_user_migration, #subscriptions, #unfollow, #unlock_user_repository, #update_key, #update_user, #user, #user_keys, #user_migration_archive_url, #user_migration_repositories, #user_migration_status, #user_migrations, #validate_credentials

Methods included from Traffic

#clones, #top_paths, #top_referrers, #views

Methods included from Tokens

#scopes

Methods included from Statuses

#combined_status, #create_status, #statuses

Methods included from Stats

#code_frequency_stats, #commit_activity_stats, #contributors_stats, #participation_stats, #punch_card_stats

Methods included from SourceImport

#cancel_source_import, #map_source_import_commit_author, #set_source_import_lfs_preference, #source_import_commit_authors, #source_import_large_files, #source_import_progress, #start_source_import, #update_source_import

Methods included from ServiceStatus

#github_status, #github_status_last_message, #github_status_messages, #github_status_summary

Methods included from Search

#search_code, #search_commits, #search_issues, #search_repositories, #search_topics, #search_users

Methods included from Say

#say

Methods included from Reviews

#create_pull_request_review, #delete_pull_request_review, #delete_pull_request_review_request, #dismiss_pull_request_review, #pull_request_review, #pull_request_review_comments, #pull_request_review_requests, #pull_request_reviews, #request_pull_request_review, #submit_pull_request_review, #update_pull_request_review

Methods included from RepositoryInvitations

#accept_repository_invitation, #decline_repository_invitation, #delete_repository_invitation, #invite_user_to_repository, #repository_invitations, #update_repository_invitation, #user_repository_invitations

Methods included from Repositories

#add_collaborator, #add_deploy_key, #all_repositories, #automated_security_fixes_enabled?, #branch, #branch_protection, #branches, #check_assignee, #collaborator?, #collaborators, #contributors, #create_repository, #create_repository_from_template, #delete_repository, #delete_subscription, #deploy_key, #deploy_keys, #disable_automated_security_fixes, #disable_vulnerability_alerts, #dispatch_event, #edit_deploy_key, #edit_repository, #enable_automated_security_fixes, #enable_vulnerability_alerts, #fork, #forks, #languages, #permission_level, #protect_branch, #remove_collaborator, #remove_deploy_key, #rename_branch, #replace_all_topics, #repositories, #repository, #repository?, #repository_assignees, #repository_teams, #set_private, #set_public, #star, #stargazers, #subscribers, #subscription, #tags, #topics, #transfer_repository, #unprotect_branch, #unstar, #unwatch, #update_subscription, #vulnerability_alerts_enabled?, #watch, #watchers

Methods included from Releases

#create_release, #delete_release, #delete_release_asset, #latest_release, #release, #release_asset, #release_assets, #release_for_tag, #releases, #update_release, #update_release_asset, #upload_asset

Methods included from Refs

#create_ref, #delete_branch, #delete_ref, #matching_refs, #ref, #refs, #update_branch, #update_ref

Methods included from Reactions

#commit_comment_reactions, #create_commit_comment_reaction, #create_issue_comment_reaction, #create_issue_reaction, #create_pull_request_review_comment_reaction, #create_release_reaction, #delete_issue_reaction, #delete_release_reaction, #issue_comment_reactions, #issue_reactions, #pull_request_review_comment_reactions, #release_reactions

Methods included from RateLimit

#rate_limit, #rate_limit!, #rate_limit_remaining, #rate_limit_remaining!

Methods included from PullRequests

#close_pull_request, #create_pull_request, #create_pull_request_comment, #create_pull_request_comment_reply, #create_pull_request_for_issue, #delete_pull_request_comment, #merge_pull_request, #pull_merged?, #pull_request, #pull_request_comment, #pull_request_comments, #pull_request_commits, #pull_request_files, #pull_requests, #pull_requests_comments, #update_pull_request, #update_pull_request_branch, #update_pull_request_comment

Methods included from Projects

#column_cards, #create_org_project, #create_project, #create_project_card, #create_project_column, #delete_project, #delete_project_card, #delete_project_column, #move_project_card, #move_project_column, #org_projects, #project, #project_card, #project_column, #project_columns, #projects, #update_project, #update_project_card, #update_project_column

Methods included from Pages

#latest_pages_build, #pages, #pages_build, #pages_builds, #request_page_build

Methods included from Organizations

#add_team_member, #add_team_membership, #add_team_repository, #all_organizations, #billing_actions, #child_teams, #convert_to_outside_collaborator, #create_team, #delete_migration_archive, #delete_organization, #delete_team, #migration_archive_url, #migration_status, #migrations, #organization, #organization_audit_log, #organization_invitations, #organization_member?, #organization_members, #organization_membership, #organization_memberships, #organization_public_member?, #organization_public_members, #organization_repositories, #organization_teams, #organizations, #outside_collaborators, #publicize_membership, #remove_organization_member, #remove_organization_membership, #remove_outside_collaborator, #remove_team_member, #remove_team_membership, #remove_team_repository, #start_migration, #team, #team_by_name, #team_invitations, #team_member?, #team_members, #team_membership, #team_permissions_for_repo, #team_repositories, #team_repository?, #unlock_repository, #unpublicize_membership, #update_organization, #update_organization_membership, #update_team, #user_teams

Methods included from Objects

#blob, #create_blob, #create_tag, #create_tree, #tag, #tree

Methods included from OauthApplications

#check_token, #delete_app_authorization, #delete_app_token, #reset_token

Methods included from Notifications

#delete_thread_subscription, #mark_notifications_as_read, #mark_repository_notifications_as_read, #mark_thread_as_read, #notifications, #repository_notifications, #thread_notifications, #thread_subscription, #update_thread_subscription

Methods included from Milestones

#create_milestone, #delete_milestone, #list_milestones, #milestone, #update_milestone

Methods included from Marketplace

#list_accounts_for_plan, #list_plans, #marketplace_purchases, #plan_for_account

Methods included from Markdown

#markdown

Methods included from Meta

#meta

Methods included from Licenses

#license, #licenses, #repository_license_contents

Methods included from LegacySearch

#legacy_search_issues, #legacy_search_repositories, #legacy_search_users

Methods included from Labels

#add_label, #add_labels_to_an_issue, #delete_label!, #label, #labels, #labels_for_issue, #labels_for_milestone, #remove_all_labels, #remove_label, #replace_all_labels, #update_label

Methods included from Issues

#add_assignees, #add_comment, #close_issue, #create_issue, #delete_comment, #issue, #issue_comment, #issue_comments, #issue_timeline, #issues_comments, #list_assignees, #list_issues, #lock_issue, #org_issues, #remove_assignees, #reopen_issue, #unlock_issue, #update_comment, #update_issue, #user_issues

Methods included from Apps

#add_repository_to_app_installation, #app, #app_hook_delivery, #create_app_installation_access_token, #delete_installation, #deliver_app_hook, #find_installation_repositories_for_user, #find_organization_installation, #find_repository_installation, #find_user_installation, #installation, #list_app_hook_deliveries, #list_app_installation_repositories, #list_app_installations, #list_user_installations, #remove_repository_from_app_installation

Methods included from ActionsWorkflowRuns

#cancel_workflow_run, #delete_workflow_run, #delete_workflow_run_logs, #repository_workflow_runs, #rerun_workflow_run, #workflow_run, #workflow_run_logs, #workflow_run_usage, #workflow_runs

Methods included from ActionsWorkflowJobs

#workflow_run_attempt_jobs, #workflow_run_job, #workflow_run_job_logs, #workflow_run_jobs

Methods included from ActionsWorkflows

#workflow, #workflow_disable, #workflow_dispatch, #workflow_enable, #workflows

Methods included from Hooks

#create_hook, #create_org_hook, #edit_hook, #edit_org_hook, #hook, #hooks, #org_hook, #org_hooks, #parse_payload, #ping_hook, #ping_org_hook, #remove_hook, #remove_org_hook, #test_hook

Methods included from Gitignore

#gitignore_template, #gitignore_templates

Methods included from Gists

#create_gist, #create_gist_comment, #delete_gist, #delete_gist_comment, #edit_gist, #fork_gist, #gist, #gist_comment, #gist_comments, #gist_commits, #gist_forks, #gist_starred?, #gists, #public_gists, #star_gist, #starred_gists, #unstar_gist, #update_gist_comment

Methods included from Feeds

#feed, #feeds

Methods included from Events

#issue_event, #issue_events, #organization_events, #organization_public_events, #public_events, #received_events, #received_public_events, #repository_events, #repository_issue_events, #repository_network_events, #user_events, #user_public_events

Methods included from Emojis

#emojis

Methods included from Environments

#create_or_update_environment, #delete_environment, #environment, #environments

Methods included from Downloads

#delete_download, #download, #downloads

Methods included from Deployments

#create_deployment, #create_deployment_status, #delete_deployment, #deployment, #deployment_statuses, #deployments

Methods included from DependabotSecrets

#create_or_update_dependabot_secret, #create_or_update_org_dependabot_secret, #delete_dependabot_secret, #delete_org_dependabot_secret, #get_dependabot_public_key, #get_dependabot_secret, #get_org_dependabot_public_key, #get_org_dependabot_secret, #list_dependabot_secrets, #list_org_dependabot_secrets

Methods included from Contents

#archive_link, #contents, #create_contents, #delete_contents, #readme, #update_contents

Methods included from CommunityProfile

#community_profile

Methods included from CommitBranches

#commit_branches

Methods included from CommitPulls

#commit_pulls

Methods included from CommitComments

#commit_comment, #commit_comments, #create_commit_comment, #delete_commit_comment, #list_commit_comments, #update_commit_comment

Methods included from Commits

#commit, #commits, #commits_before, #commits_between, #commits_on, #commits_since, #compare, #create_commit, #git_commit, #merge

Methods included from CodespacesSecrets

#create_or_update_codespaces_secret, #create_or_update_org_codespaces_secret, #delete_codespaces_secret, #delete_org_codespaces_secret, #get_codespaces_public_key, #get_codespaces_secret, #get_org_codespaces_public_key, #get_org_codespaces_secret, #list_codespaces_secrets, #list_org_codespaces_secrets

Methods included from CodeScanning

#delete_code_scanning_analysis, #get_code_scanning_alert, #get_code_scanning_analysis, #get_code_scanning_default_config, #get_codeql_database_for_repo, #get_sarif_upload_information, #list_code_scanning_alerts_for_org, #list_code_scanning_alerts_for_repo, #list_code_scanning_analysis, #list_codeql_database_for_repo, #list_instances_of_code_scanning_alert, #update_code_scanning_alert, #update_code_scanning_default_config, #upload_sarif_data

Methods included from Checks

#check_run, #check_run_annotations, #check_runs_for_check_suite, #check_runs_for_ref, #check_suite, #check_suites_for_ref, #create_check_run, #create_check_suite, #rerequest_check_suite, #set_check_suite_preferences, #update_check_run

Methods included from ActionsSecrets

#create_or_update_actions_environment_secret, #create_or_update_actions_secret, #create_or_update_org_actions_secret, #delete_actions_environment_secret, #delete_actions_secret, #delete_org_actions_secret, #get_actions_environment_public_key, #get_actions_environment_secret, #get_actions_public_key, #get_actions_secret, #get_org_actions_public_key, #get_org_actions_secret, #list_actions_environment_secrets, #list_actions_secrets, #list_org_actions_secrets

Methods included from ActionsArtifacts

#artifact, #artifact_download_url, #delete_artifact, #repository_artifacts, #workflow_run_artifacts

Methods included from Warnable

octokit_warn

Methods included from Connection

#agent, #delete, #get, #head, #last_response, #paginate, #patch, #post, #put, #root

Methods included from Authentication

#application_authenticated?, #basic_authenticated?, #bearer_authenticated?, #token_authenticated?, #user_authenticated?

Methods included from Configurable

#configure, keys, #netrc?, #reset!, #same_options?

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/octokit/client.rb', line 141

def initialize(options = {})
  # Use options passed in, but fall back to module defaults
  #
  # rubocop:disable Style/HashEachMethods
  #
  # This may look like a `.keys.each` which should be replaced with `#each_key`, but
  # this doesn't actually work, since `#keys` is just a method we've defined ourselves.
  # The class doesn't fulfill the whole `Enumerable` contract.
  Octokit::Configurable.keys.each do |key|
    # rubocop:enable Style/HashEachMethods
    value = options[key].nil? ? Octokit.instance_variable_get(:"@#{key}") : options[key]
    instance_variable_set(:"@#{key}", value)
  end

   unless user_authenticated? || application_authenticated?
end

Instance Method Details

#access_token=(value) ⇒ Object

Set OAuth access token for authentication

Parameters:

  • value (String)

    40 character GitHub OAuth access token



226
227
228
229
# File 'lib/octokit/client.rb', line 226

def access_token=(value)
  reset_agent
  @access_token = value
end

#as_app(key = client_id, secret = client_secret) {|app_client| ... } ⇒ Object

Duplicate client using client_id and client_secret as Basic Authentication credentials.

Examples:

Octokit.client_id = "foo"
Octokit.client_secret = "bar"

# GET https://api.github.com/?client_id=foo&client_secret=bar
Octokit.get "/"

Octokit.client.as_app do |client|
  # GET https://foo:[email protected]/
  client.get "/"
end

Yields:

  • (app_client)


194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/octokit/client.rb', line 194

def as_app(key = client_id, secret = client_secret)
  if key.to_s.empty? || secret.to_s.empty?
    raise ApplicationCredentialsRequired, 'client_id and client_secret required'
  end

  app_client = dup
  app_client.client_id = app_client.client_secret = nil
  app_client.    = key
  app_client.password = secret

  yield app_client if block_given?
end

#bearer_token=(value) ⇒ Object

Set Bearer Token for authentication

Parameters:

  • value (String)

    JWT



234
235
236
237
# File 'lib/octokit/client.rb', line 234

def bearer_token=(value)
  reset_agent
  @bearer_token = value
end

#client_id=(value) ⇒ Object

Set OAuth app client_id

Parameters:

  • value (String)

    20 character GitHub OAuth app client_id



242
243
244
245
# File 'lib/octokit/client.rb', line 242

def client_id=(value)
  reset_agent
  @client_id = value
end

#client_secret=(value) ⇒ Object

Set OAuth app client_secret

Parameters:

  • value (String)

    40 character GitHub OAuth app client_secret



250
251
252
253
# File 'lib/octokit/client.rb', line 250

def client_secret=(value)
  reset_agent
  @client_secret = value
end

#client_without_redirects(options = {}) ⇒ Object



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/octokit/client.rb', line 255

def client_without_redirects(options = {})
  conn_opts = @connection_options
  conn_opts[:url] = @api_endpoint
  conn_opts[:builder] = @middleware.dup if @middleware
  conn_opts[:proxy] = @proxy if @proxy
  conn_opts[:ssl] = { verify_mode: @ssl_verify_mode } if @ssl_verify_mode
  conn = Faraday.new(conn_opts) do |http|
    http_cache_middleware = http.builder.handlers.delete(Faraday::HttpCache) if Faraday.const_defined?(:HttpCache)
    if basic_authenticated?
      http.request(*FARADAY_BASIC_AUTH_KEYS, @login, @password)
    elsif token_authenticated?
      http.request :authorization, 'token', @access_token
    elsif bearer_authenticated?
      http.request :authorization, 'Bearer', @bearer_token
    end
    http.builder.handlers.push(http_cache_middleware) unless http_cache_middleware.nil?
    http.headers['accept'] = options[:accept] if options.key?(:accept)
  end
  conn.builder.delete(Octokit::Middleware::FollowRedirects)

  conn
end

#inspectString

Text representation of the client, masking tokens and passwords

Returns:

  • (String)


161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/octokit/client.rb', line 161

def inspect
  inspected = super

  # mask password
  inspected.gsub! @password, '*******' if @password
  if @management_console_password
    inspected.gsub! @management_console_password, '*******'
  end
  inspected.gsub! @bearer_token, '********' if @bearer_token
  # Only show last 4 of token, secret
  if @access_token
    inspected.gsub! @access_token, "#{'*' * 36}#{@access_token[36..]}"
  end
  if @client_secret
    inspected.gsub! @client_secret, "#{'*' * 36}#{@client_secret[36..]}"
  end

  inspected
end

#login=(value) ⇒ Object

Set username for authentication

Parameters:

  • value (String)

    GitHub username



210
211
212
213
# File 'lib/octokit/client.rb', line 210

def login=(value)
  reset_agent
  @login = value
end

#password=(value) ⇒ Object

Set password for authentication

Parameters:

  • value (String)

    GitHub password



218
219
220
221
# File 'lib/octokit/client.rb', line 218

def password=(value)
  reset_agent
  @password = value
end