Thread safety
This library aims to be safe for use by multiple threads concurrently, although the library itself makes no attempt to control/serialize potentially conflicting operations to GitHub, such as updating & deleting a repository at the same time.
- Author:
- Kohsuke Kawaguchi
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
The Class DependentAuthorizationProvider. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Tests the connection.Check auth gh authorization.static GitHub
connect()
Obtains the credential from "~/.github" or from the System Environment Properties.static GitHub
Connect git hub.static GitHub
Connects to GitHub anonymously.static GitHub
connectToEnterpriseAnonymously
(String apiUrl) Connects to GitHub Enterprise anonymously.static GitHub
connectToEnterpriseWithOAuth
(String apiUrl, String login, String oauthAccessToken) Version that connects to GitHub Enterprise.static GitHub
connectUsingOAuth
(String oauthAccessToken) Connect using o auth git hub.static GitHub
connectUsingOAuth
(String githubServer, String oauthAccessToken) Connect using o auth git hub.createAppFromManifest
(String code) Creates a GitHub App from a manifest.Create gist gh gist builder.createOrGetAuth
(String clientId, String clientSecret, List<String> scopes, String note, String note_url) Create or get auth gh authorization.createRepository
(String name) Starts a builder that creates a new repository.createToken
(Collection<String> scope, String note, String noteUrl) Creates a new authorization.createToken
(Collection<String> scope, String note, String noteUrl, Supplier<String> OTP) Creates a new authorization using an OTP.void
deleteAuth
(long id) Delete auth.Gets api url.getApp()
Returns the GitHub App associated with the authentication credentials used.Returns the GitHub App identified by the given slugPublic events visible to you.Gets a single gist by ID.Returns the GitHub App Installation associated with the authentication credentials used.getLicense
(String key) Returns the full details for a license.static com.fasterxml.jackson.databind.ObjectReader
Gets anObjectReader
that can be used to convert JSON into library data objects.static com.fasterxml.jackson.databind.ObjectWriter
Gets anObjectWriter
that can be used to convert data objects in this library to JSON.getMeta()
Provides a list of GitHub's IP addresses.Gets complete list of open invitations for current user.Returns only active subscriptions.This method returns shallowly populated organizations.Gets theGHUser
that represents yourself.Gets complete map of organizations/teams that current user belongs to.getOrganization
(String name) GetsGHOrganization
specified by name.getProject
(long id) Gets project.getProjectCard
(long id) Gets project card.getProjectColumn
(long id) Gets project column.Gets the current full rate limit information from the server.getRepository
(String name) Gets the repository object from 'owner/repo' string that GitHub calls as "repository name".getRepositoryById
(long id) Gets the repository object from its ID.Obtains the object that represents the named user.protected GHUser
Interns the givenGHUser
.getUserPublicEvents
(String login) List public events for a user see API documentationgetUserPublicOrganizations
(String login) This method returns a shallowly populated organizations.Alias forgetUserPublicOrganizations(String)
.boolean
Is this an anonymous connection.boolean
Ensures that the credential is valid.boolean
Is this an always offline "connection".Deprecated.This provides a dump of every public repository, in the order that they were created.listAllPublicRepositories
(String since) This provides a dump of every public repository, in the order that they were created.Returns a list of popular open source licenses.Returns a list all plans for your Marketplace listingReturns a list of all authorizations.List all the notifications.Gets a list of all organizations.listOrganizations
(String since) Gets a list of all organizations starting after the organization identifier specified by 'since'.Returns a list of all users.static GitHub
offline()
An offline-onlyGitHub
useful for parsing event notification from an unknown source.<T extends GHEventPayload>
TparseEventPayload
(Reader r, Class<T> type) Parses the GitHub event object.Deprecated.implement aRateLimitChecker
and add it viaGitHubBuilder.withRateLimitChecker(RateLimitChecker)
.void
clears all cached data in order for external changes (modifications and del) to be reflected.renderMarkdown
(String text) Render a Markdown document in raw mode.Reset auth gh authorization.Search commits.Search content.Search issues.Search for pull requests.Search repositories.Search users.
-
Method Details
-
connect
Obtains the credential from "~/.github" or from the System Environment Properties.- Returns:
- the git hub
- Throws:
IOException
- the io exception
-
connectToEnterpriseWithOAuth
public static GitHub connectToEnterpriseWithOAuth(String apiUrl, String login, String oauthAccessToken) throws IOException Version that connects to GitHub Enterprise.- Parameters:
apiUrl
- The URL of GitHub (or GitHub Enterprise) API endpoint, such as "https://api.github.com" or "http://ghe.acme.com/api/v3". Note that GitHub Enterprise has/api/v3
in the URL. For historical reasons, this parameter still accepts the bare domain name, but that's considered deprecated.login
- the loginoauthAccessToken
- the oauth access token- Returns:
- the git hub
- Throws:
IOException
- the io exception
-
connect
Connect git hub.- Parameters:
login
- the loginoauthAccessToken
- the oauth access token- Returns:
- the git hub
- Throws:
IOException
- the io exception
-
connectUsingOAuth
Connect using o auth git hub.- Parameters:
oauthAccessToken
- the oauth access token- Returns:
- the git hub
- Throws:
IOException
- the io exception
-
connectUsingOAuth
public static GitHub connectUsingOAuth(String githubServer, String oauthAccessToken) throws IOException Connect using o auth git hub.- Parameters:
githubServer
- the github serveroauthAccessToken
- the oauth access token- Returns:
- the git hub
- Throws:
IOException
- the io exception
-
connectAnonymously
Connects to GitHub anonymously.All operations that require authentication will fail.
- Returns:
- the git hub
- Throws:
IOException
- the io exception
-
connectToEnterpriseAnonymously
Connects to GitHub Enterprise anonymously.All operations that require authentication will fail.
- Parameters:
apiUrl
- the api url- Returns:
- the git hub
- Throws:
IOException
- the io exception
-
offline
An offline-onlyGitHub
useful for parsing event notification from an unknown source.All operations that require a connection will fail.
- Returns:
- An offline-only
GitHub
.
-
isAnonymous
public boolean isAnonymous()Is this an anonymous connection.- Returns:
true
if operations that require authentication will fail.
-
isOffline
public boolean isOffline()Is this an always offline "connection".- Returns:
true
if this is an always offline "connection".
-
getApiUrl
Gets api url.- Returns:
- the api url
-
getRateLimit
Gets the current full rate limit information from the server. For some versions of GitHub Enterprise, the/rate_limit
endpoint returns a404 Not Found
. In that case, the most recentGHRateLimit
information will be returned, including rate limit information returned in the response header for this request in if was present. For most use cases it would be better to implement aRateLimitChecker
and add it viaGitHubBuilder.withRateLimitChecker(RateLimitChecker)
.- Returns:
- the rate limit
- Throws:
IOException
- the io exception
-
lastRateLimit
Deprecated.implement aRateLimitChecker
and add it viaGitHubBuilder.withRateLimitChecker(RateLimitChecker)
.Returns the most recently observed rate limit data ornull
if either there is no rate limit (for example GitHub Enterprise) or if no requests have been made.- Returns:
- the most recently observed rate limit data or
null
.
-
rateLimit
Deprecated.implement aRateLimitChecker
and add it viaGitHubBuilder.withRateLimitChecker(RateLimitChecker)
.Gets the current rate limit while trying not to actually make any remote requests unless absolutely necessary.- Returns:
- the current rate limit data.
- Throws:
IOException
- if we couldn't get the current rate limit data.
-
getMyself
Gets theGHUser
that represents yourself.- Returns:
- the myself
- Throws:
IOException
- the io exception
-
getUser
Obtains the object that represents the named user.- Parameters:
login
- the login- Returns:
- the user
- Throws:
IOException
- the io exception
-
refreshCache
public void refreshCache()clears all cached data in order for external changes (modifications and del) to be reflected. -
getUser
Interns the givenGHUser
.- Parameters:
orig
- the orig- Returns:
- the user
-
getOrganization
GetsGHOrganization
specified by name.- Parameters:
name
- the name- Returns:
- the organization
- Throws:
IOException
- the io exception
-
listOrganizations
Gets a list of all organizations.- Returns:
- the paged iterable
-
listOrganizations
Gets a list of all organizations starting after the organization identifier specified by 'since'.- Parameters:
since
- the since- Returns:
- the paged iterable
- See Also:
-
getRepository
Gets the repository object from 'owner/repo' string that GitHub calls as "repository name".- Parameters:
name
- the name- Returns:
- the repository
- Throws:
IOException
- the io exception- See Also:
-
getRepositoryById
Gets the repository object from its ID.- Parameters:
id
- the id- Returns:
- the repository by id
- Throws:
IOException
- the io exception
-
listLicenses
Returns a list of popular open source licenses.- Returns:
- a list of popular open source licenses
- Throws:
IOException
- the io exception- See Also:
-
listUsers
Returns a list of all users.- Returns:
- the paged iterable
- Throws:
IOException
- the io exception
-
getLicense
Returns the full details for a license.- Parameters:
key
- The license key provided from the API- Returns:
- The license details
- Throws:
IOException
- the io exception- See Also:
-
listMarketplacePlans
Returns a list all plans for your Marketplace listingGitHub Apps must use a JWT to access this endpoint.
OAuth Apps must use basic authentication with their client ID and client secret to access this endpoint.
- Returns:
- the paged iterable
- Throws:
IOException
- the io exception- See Also:
-
getMyInvitations
Gets complete list of open invitations for current user.- Returns:
- the my invitations
- Throws:
IOException
- the io exception
-
getMyOrganizations
This method returns shallowly populated organizations.To retrieve full organization details, you need to call
getOrganization(String)
TODO: make this automatic.- Returns:
- the my organizations
- Throws:
IOException
- the io exception
-
getMyMarketplacePurchases
Returns only active subscriptions.You must use a user-to-server OAuth access token, created for a user who has authorized your GitHub App, to access this endpoint
OAuth Apps must authenticate using an OAuth token.
- Returns:
- the paged iterable of GHMarketplaceUserPurchase
- Throws:
IOException
- the io exception- See Also:
-
getUserPublicOrganizations
Alias forgetUserPublicOrganizations(String)
.- Parameters:
user
- the user- Returns:
- the user public organizations
- Throws:
IOException
- the io exception
-
getUserPublicOrganizations
This method returns a shallowly populated organizations.To retrieve full organization details, you need to call
getOrganization(String)
- Parameters:
login
- the user to retrieve public Organization membership information for- Returns:
- the public Organization memberships for the user
- Throws:
IOException
- the io exception
-
getMyTeams
Gets complete map of organizations/teams that current user belongs to.Leverages the new GitHub API /user/teams made available recently to get in a single call the complete set of organizations, teams and permissions in a single call.
- Returns:
- the my teams
- Throws:
IOException
- the io exception
-
getEvents
Public events visible to you. Equivalent of what's displayed on https://github.com/- Returns:
- the events
- Throws:
IOException
- the io exception
-
getUserPublicEvents
List public events for a user see API documentation- Parameters:
login
- the login (user) to look public events for- Returns:
- the events
- Throws:
IOException
- the io exception
-
getGist
Gets a single gist by ID.- Parameters:
id
- the id- Returns:
- the gist
- Throws:
IOException
- the io exception
-
createGist
Create gist gh gist builder.- Returns:
- the gh gist builder
-
parseEventPayload
Parses the GitHub event object.This is primarily intended for receiving a POST HTTP call from a hook. Unfortunately, hook script payloads aren't self-descriptive, so you need to know the type of the payload you are expecting.
- Type Parameters:
T
- the type parameter- Parameters:
r
- the rtype
- the type- Returns:
- the t
- Throws:
IOException
- the io exception
-
createRepository
Starts a builder that creates a new repository.You use the returned builder to set various properties, then call
GHCreateRepositoryBuilder.create()
to finally create a repository.- Parameters:
name
- the name- Returns:
- the gh create repository builder
-
createToken
public GHAuthorization createToken(Collection<String> scope, String note, String noteUrl) throws IOException Creates a new authorization.The token created can be then used for
connectUsingOAuth(String)
in the future.- Parameters:
scope
- the scopenote
- the notenoteUrl
- the note url- Returns:
- the gh authorization
- Throws:
IOException
- the io exception- See Also:
-
createToken
public GHAuthorization createToken(Collection<String> scope, String note, String noteUrl, Supplier<String> OTP) throws IOException Creates a new authorization using an OTP.Start by running createToken, if exception is thrown, prompt for OTP from user
Once OTP is received, call this token request
The token created can be then used for
connectUsingOAuth(String)
in the future.- Parameters:
scope
- the scopenote
- the notenoteUrl
- the note urlOTP
- the otp- Returns:
- the gh authorization
- Throws:
IOException
- the io exception- See Also:
-
createOrGetAuth
public GHAuthorization createOrGetAuth(String clientId, String clientSecret, List<String> scopes, String note, String note_url) throws IOException Create or get auth gh authorization.- Parameters:
clientId
- the client idclientSecret
- the client secretscopes
- the scopesnote
- the notenote_url
- the note url- Returns:
- the gh authorization
- Throws:
IOException
- the io exception- See Also:
-
deleteAuth
Delete auth.- Parameters:
id
- the id- Throws:
IOException
- the io exception- See Also:
-
checkAuth
public GHAuthorization checkAuth(@Nonnull String clientId, @Nonnull String accessToken) throws IOException Check auth gh authorization.- Parameters:
clientId
- the client idaccessToken
- the access token- Returns:
- the gh authorization
- Throws:
IOException
- the io exception- See Also:
-
resetAuth
public GHAuthorization resetAuth(@Nonnull String clientId, @Nonnull String accessToken) throws IOException Reset auth gh authorization.- Parameters:
clientId
- the client idaccessToken
- the access token- Returns:
- the gh authorization
- Throws:
IOException
- the io exception- See Also:
-
listMyAuthorizations
Returns a list of all authorizations.- Returns:
- the paged iterable
- Throws:
IOException
- the io exception- See Also:
-
getApp
Returns the GitHub App associated with the authentication credentials used.You must use a JWT to access this endpoint.
- Returns:
- the app
- Throws:
IOException
- the io exception- See Also:
-
getApp
Returns the GitHub App identified by the given slug- Parameters:
slug
- the slug of the application- Returns:
- the app
- Throws:
IOException
- the IO exception- See Also:
-
createAppFromManifest
Creates a GitHub App from a manifest.- Parameters:
code
- temporary code returned during the manifest flow- Returns:
- the app
- Throws:
IOException
- the IO exception- See Also:
-
getInstallation
Returns the GitHub App Installation associated with the authentication credentials used.You must use an installation token to access this endpoint; otherwise consider
getApp()
and its various ways of retrieving installations.- Returns:
- the app
- Throws:
IOException
- the io exception- See Also:
-
isCredentialValid
public boolean isCredentialValid()Ensures that the credential is valid.- Returns:
- the boolean
-
getMeta
Provides a list of GitHub's IP addresses.- Returns:
- an instance of
GHMeta
- Throws:
IOException
- if the credentials supplied are invalid or if you're trying to access it as a GitHub App via the JWT authentication- See Also:
-
getProject
Gets project.- Parameters:
id
- the id- Returns:
- the project
- Throws:
IOException
- the io exception
-
getProjectColumn
Gets project column.- Parameters:
id
- the id- Returns:
- the project column
- Throws:
IOException
- the io exception
-
getProjectCard
Gets project card.- Parameters:
id
- the id- Returns:
- the project card
- Throws:
IOException
- the io exception
-
checkApiUrlValidity
Tests the connection.Verify that the API URL and credentials are valid to access this GitHub.
This method returns normally if the endpoint is reachable and verified to be GitHub API URL. Otherwise this method throws
IOException
to indicate the problem.- Throws:
IOException
- the io exception
-
searchCommits
Search commits.- Returns:
- the gh commit search builder
-
searchIssues
Search issues.- Returns:
- the gh issue search builder
-
searchPullRequests
Search for pull requests.- Returns:
- gh pull request search builder
-
searchUsers
Search users.- Returns:
- the gh user search builder
-
searchRepositories
Search repositories.- Returns:
- the gh repository search builder
-
searchContent
Search content.- Returns:
- the gh content search builder
-
listNotifications
List all the notifications.- Returns:
- the gh notification stream
-
listAllPublicRepositories
This provides a dump of every public repository, in the order that they were created.- Returns:
- the paged iterable
- See Also:
-
listAllPublicRepositories
This provides a dump of every public repository, in the order that they were created.- Parameters:
since
- The numeric ID of the last Repository that you’ve seen. SeeGHObject.getId()
- Returns:
- the paged iterable
- See Also:
-
renderMarkdown
Render a Markdown document in raw mode.It takes a Markdown document as plaintext and renders it as plain Markdown without a repository context (just like a README.md file is rendered – this is the simplest way to preview a readme online).
- Parameters:
text
- the text- Returns:
- the reader
- Throws:
IOException
- the io exception- See Also:
-
getMappingObjectWriter
@Nonnull public static com.fasterxml.jackson.databind.ObjectWriter getMappingObjectWriter()Gets anObjectWriter
that can be used to convert data objects in this library to JSON. If you must convert data object in this library to JSON, theObjectWriter
returned by this method is the only supported way of doing so. ThisObjectWriter
can be used to convert any library data object to JSON without throwing an exception. WARNING: While the JSON generated is generally expected to be stable, it is not part of the API of this library and may change without warning. Use with extreme caution.- Returns:
- an
ObjectWriter
instance that can be further configured.
-
getMappingObjectReader
@Nonnull public static com.fasterxml.jackson.databind.ObjectReader getMappingObjectReader()Gets anObjectReader
that can be used to convert JSON into library data objects. If you must manually create library data objects from JSON, theObjectReader
returned by this method is the only supported way of doing so. WARNING: Objects generated from this method have limited functionality. They will not throw when being crated from valid JSON matching the expected object, but they are not guaranteed to be usable beyond that. Use with extreme caution.- Returns:
- an
ObjectReader
instance that can be further configured.
-
RateLimitChecker
and add it viaGitHubBuilder.withRateLimitChecker(RateLimitChecker)
.