public class GitHub extends Object
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.
| Modifier and Type | Method and Description |
|---|---|
void |
checkApiUrlValidity()
Tests the connection.
|
GHAuthorization |
checkAuth(String clientId,
String accessToken)
Check auth gh authorization.
|
static GitHub |
connect()
Obtains the credential from "~/.github" or from the System Environment Properties.
|
static GitHub |
connect(String login,
String oauthAccessToken)
Connect git hub.
|
static GitHub |
connect(String login,
String oauthAccessToken,
String password)
Deprecated.
Either OAuth token or password is sufficient, so there's no point in passing both. Use
connectUsingPassword(String, String) or connectUsingOAuth(String). |
static GitHub |
connectAnonymously()
Connects to GitHub anonymously.
|
static GitHub |
connectToEnterprise(String apiUrl,
String oauthAccessToken)
Deprecated.
|
static GitHub |
connectToEnterprise(String apiUrl,
String login,
String password)
Deprecated.
Use with caution. Login with password is not a preferred method.
|
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.
|
static GitHub |
connectUsingPassword(String login,
String password)
Connect using password git hub.
|
GHGistBuilder |
createGist()
Create gist gh gist builder.
|
GHAuthorization |
createOrGetAuth(String clientId,
String clientSecret,
List<String> scopes,
String note,
String note_url)
Create or get auth gh authorization.
|
GHCreateRepositoryBuilder |
createRepository(String name)
Starts a builder that creates a new repository.
|
GHRepository |
createRepository(String name,
String description,
String homepage,
boolean isPublic)
Deprecated.
Use
createRepository(String) that uses a builder pattern to let you control every aspect. |
GHAuthorization |
createToken(Collection<String> scope,
String note,
String noteUrl)
Creates a new authorization.
|
GHAuthorization |
createToken(Collection<String> scope,
String note,
String noteUrl,
Supplier<String> OTP)
Creates a new authorization using an OTP.
|
void |
deleteAuth(long id)
Delete auth.
|
String |
getApiUrl()
Gets api url.
|
GHApp |
getApp()
Deprecated.
|
HttpConnector |
getConnector()
Gets connector.
|
List<GHEventInfo> |
getEvents()
Public events visible to you.
|
GHGist |
getGist(String id)
Gets a single gist by ID.
|
GHLicense |
getLicense(String key)
Returns the full details for a license
|
GHMeta |
getMeta()
Provides a list of GitHub's IP addresses.
|
List<GHInvitation> |
getMyInvitations()
Gets complete list of open invitations for current user.
|
PagedIterable<GHMarketplaceUserPurchase> |
getMyMarketplacePurchases()
Returns only active subscriptions.
|
Map<String,GHOrganization> |
getMyOrganizations()
This method returns shallowly populated organizations.
|
GHMyself |
getMyself()
Gets the
GHUser that represents yourself. |
Map<String,Set<GHTeam>> |
getMyTeams()
Gets complete map of organizations/teams that current user belongs to.
|
GHOrganization |
getOrganization(String name)
Gets
GHOrganization specified by name. |
GHProject |
getProject(long id)
Gets project.
|
GHProjectCard |
getProjectCard(long id)
Gets project card.
|
GHProjectColumn |
getProjectColumn(long id)
Gets project column.
|
GHRateLimit |
getRateLimit()
Gets the current rate limit.
|
GHRepository |
getRepository(String name)
Gets the repository object from 'user/reponame' string that GitHub calls as "repository name"
|
GHRepository |
getRepositoryById(String id)
Gets the repository object from its ID
|
GHTeam |
getTeam(int id)
Gets a sigle team by ID.
|
protected GHUser |
getUser(GHUser orig)
Interns the given
GHUser. |
GHUser |
getUser(String login)
Obtains the object that represents the named user.
|
Map<String,GHOrganization> |
getUserPublicOrganizations(GHUser user)
Alias for
getUserPublicOrganizations(String). |
Map<String,GHOrganization> |
getUserPublicOrganizations(String login)
This method returns a shallowly populated organizations.
|
boolean |
isAnonymous()
Is this an anonymous connection
|
boolean |
isCredentialValid()
Ensures that the credential is valid.
|
boolean |
isOffline()
Is this an always offline "connection".
|
GHRateLimit |
lastRateLimit()
Returns the most recently observed rate limit data or
null if either there is no rate limit (for example
GitHub Enterprise) or if no requests have been made. |
PagedIterable<GHRepository> |
listAllPublicRepositories()
This provides a dump of every public repository, in the order that they were created.
|
PagedIterable<GHRepository> |
listAllPublicRepositories(String since)
This provides a dump of every public repository, in the order that they were created.
|
PagedIterable<GHLicense> |
listLicenses()
Returns a list of popular open source licenses
|
PagedIterable<GHMarketplacePlan> |
listMarketplacePlans()
Returns a list all plans for your Marketplace listing
|
PagedIterable<GHAuthorization> |
listMyAuthorizations()
Returns a list of all authorizations.
|
GHNotificationStream |
listNotifications()
List all the notifications.
|
PagedIterable<GHOrganization> |
listOrganizations()
Gets a list of all organizations.
|
PagedIterable<GHOrganization> |
listOrganizations(String since)
Gets a list of all organizations starting after the organization identifier specified by 'since'.
|
PagedIterable<GHUser> |
listUsers()
Returns a list of all users.
|
static GitHub |
offline()
An offline-only
GitHub useful for parsing event notification from an unknown source. |
<T extends GHEventPayload> |
parseEventPayload(Reader r,
Class<T> type)
Parses the GitHub event object.
|
GHRateLimit |
rateLimit()
Gets the current rate limit while trying not to actually make any remote requests unless absolutely necessary.
|
void |
refreshCache()
clears all cached data in order for external changes (modifications and del) to be reflected
|
Reader |
renderMarkdown(String text)
Render a Markdown document in raw mode.
|
GHAuthorization |
resetAuth(String clientId,
String accessToken)
Reset auth gh authorization.
|
GHCommitSearchBuilder |
searchCommits()
Deprecated.
|
GHContentSearchBuilder |
searchContent()
Search content.
|
GHIssueSearchBuilder |
searchIssues()
Search issues.
|
GHRepositorySearchBuilder |
searchRepositories()
Search repositories.
|
GHUserSearchBuilder |
searchUsers()
Search users.
|
void |
setConnector(HttpConnector connector)
Sets the custom connector used to make requests to GitHub.
|
public static GitHub connect() throws IOException
IOException - the io exception@Deprecated public static GitHub connectToEnterprise(String apiUrl, String oauthAccessToken) throws IOException
connectToEnterpriseWithOAuth(String, String, String)apiUrl - the api urloauthAccessToken - the oauth access tokenIOException - the io exceptionpublic static GitHub connectToEnterpriseWithOAuth(String apiUrl, String login, String oauthAccessToken) throws IOException
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 tokenIOException - the io exception@Deprecated public static GitHub connectToEnterprise(String apiUrl, String login, String password) throws IOException
apiUrl - the api urllogin - the loginpassword - the passwordIOException - the io exceptionpublic static GitHub connect(String login, String oauthAccessToken) throws IOException
login - the loginoauthAccessToken - the oauth access tokenIOException - the io exception@Deprecated public static GitHub connect(String login, String oauthAccessToken, String password) throws IOException
connectUsingPassword(String, String) or connectUsingOAuth(String).login - the loginoauthAccessToken - the oauth access tokenpassword - the passwordIOException - the io exceptionpublic static GitHub connectUsingPassword(String login, String password) throws IOException
login - the loginpassword - the passwordIOException - the io exceptionpublic static GitHub connectUsingOAuth(String oauthAccessToken) throws IOException
oauthAccessToken - the oauth access tokenIOException - the io exceptionpublic static GitHub connectUsingOAuth(String githubServer, String oauthAccessToken) throws IOException
githubServer - the github serveroauthAccessToken - the oauth access tokenIOException - the io exceptionpublic static GitHub connectAnonymously() throws IOException
All operations that require authentication will fail.
IOException - the io exceptionpublic static GitHub connectToEnterpriseAnonymously(String apiUrl) throws IOException
All operations that require authentication will fail.
apiUrl - the api urlIOException - the io exceptionpublic static GitHub offline()
GitHub useful for parsing event notification from an unknown source.
All operations that require a connection will fail.
GitHub.public boolean isAnonymous()
true if operations that require authentication will fail.public boolean isOffline()
true if this is an always offline "connection".public HttpConnector getConnector()
public String getApiUrl()
public void setConnector(HttpConnector connector)
connector - the connectorpublic GHRateLimit getRateLimit() throws IOException
IOException - the io exception@CheckForNull public GHRateLimit lastRateLimit()
null if either there is no rate limit (for example
GitHub Enterprise) or if no requests have been made.null.@Nonnull public GHRateLimit rateLimit() throws IOException
IOException - if we couldn't get the current rate limit data.@WithBridgeMethods(value=GHUser.class) public GHMyself getMyself() throws IOException
GHUser that represents yourself.IOException - the io exceptionpublic GHUser getUser(String login) throws IOException
login - the loginIOException - the io exceptionpublic void refreshCache()
protected GHUser getUser(GHUser orig)
GHUser.orig - the origpublic GHOrganization getOrganization(String name) throws IOException
GHOrganization specified by name.name - the nameIOException - the io exceptionpublic PagedIterable<GHOrganization> listOrganizations()
public PagedIterable<GHOrganization> listOrganizations(String since)
since - the sincepublic GHRepository getRepository(String name) throws IOException
name - the nameIOException - the io exceptionGHRepository#getName()public GHRepository getRepositoryById(String id) throws IOException
id - the idIOException - the io exceptionpublic PagedIterable<GHLicense> listLicenses() throws IOException
IOException - the io exceptionpublic PagedIterable<GHUser> listUsers() throws IOException
IOException - the io exceptionpublic GHLicense getLicense(String key) throws IOException
key - The license key provided from the APIIOException - the io exceptionGHLicense#getKey()public PagedIterable<GHMarketplacePlan> listMarketplacePlans() throws IOException
GitHub 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.
IOException - the io exceptionpublic List<GHInvitation> getMyInvitations() throws IOException
IOException - the io exceptionpublic Map<String,GHOrganization> getMyOrganizations() throws IOException
To retrieve full organization details, you need to call getOrganization(String) TODO: make this
automatic.
IOException - the io exceptionpublic PagedIterable<GHMarketplaceUserPurchase> getMyMarketplacePurchases() throws IOException
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.
IOException - the io exceptionpublic Map<String,GHOrganization> getUserPublicOrganizations(GHUser user) throws IOException
getUserPublicOrganizations(String).user - the userIOException - the io exceptionpublic Map<String,GHOrganization> getUserPublicOrganizations(String login) throws IOException
To retrieve full organization details, you need to call getOrganization(String)
login - the user to retrieve public Organization membership information forIOException - the io exceptionpublic Map<String,Set<GHTeam>> getMyTeams() throws IOException
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.
IOException - the io exceptionpublic GHTeam getTeam(int id) throws IOException
id - the idIOException - the io exceptionpublic List<GHEventInfo> getEvents() throws IOException
IOException - the io exceptionpublic GHGist getGist(String id) throws IOException
id - the idIOException - the io exceptionpublic GHGistBuilder createGist()
public <T extends GHEventPayload> T parseEventPayload(Reader r, Class<T> type) throws IOException
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.
T - the type parameterr - the rtype - the typeIOException - the io exception@Deprecated public GHRepository createRepository(String name, String description, String homepage, boolean isPublic) throws IOException
createRepository(String) that uses a builder pattern to let you control every aspect.name - the namedescription - the descriptionhomepage - the homepageisPublic - the is publicIOException - the io exceptionpublic GHCreateRepositoryBuilder createRepository(String name)
You use the returned builder to set various properties, then call GHCreateRepositoryBuilder.create() to
finally create a repository.
To create a repository in an organization, see
GHOrganization.createRepository(String, String, String, GHTeam, boolean)
name - the namepublic GHAuthorization createToken(Collection<String> scope, String note, String noteUrl) throws IOException
The token created can be then used for connectUsingOAuth(String) in the future.
scope - the scopenote - the notenoteUrl - the note urlIOException - the io exceptionpublic GHAuthorization createToken(Collection<String> scope, String note, String noteUrl, Supplier<String> OTP) throws IOException
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.
scope - the scopenote - the notenoteUrl - the note urlOTP - the otpIOException - the io exceptionpublic GHAuthorization createOrGetAuth(String clientId, String clientSecret, List<String> scopes, String note, String note_url) throws IOException
clientId - the client idclientSecret - the client secretscopes - the scopesnote - the notenote_url - the note urlIOException - the io exceptionpublic void deleteAuth(long id)
throws IOException
id - the idIOException - the io exceptionpublic GHAuthorization checkAuth(@Nonnull String clientId, @Nonnull String accessToken) throws IOException
clientId - the client idaccessToken - the access tokenIOException - the io exceptionpublic GHAuthorization resetAuth(@Nonnull String clientId, @Nonnull String accessToken) throws IOException
clientId - the client idaccessToken - the access tokenIOException - the io exceptionpublic PagedIterable<GHAuthorization> listMyAuthorizations() throws IOException
IOException - the io exception@Preview @Deprecated public GHApp getApp() throws IOException
You must use a JWT to access this endpoint.
IOException - the io exceptionpublic boolean isCredentialValid()
public GHMeta getMeta() throws IOException
GHMetaIOException - if the credentials supplied are invalid or if you're trying to access it as a GitHub App via the JWT
authenticationpublic GHProject getProject(long id) throws IOException
id - the idIOException - the io exceptionpublic GHProjectColumn getProjectColumn(long id) throws IOException
id - the idIOException - the io exceptionpublic GHProjectCard getProjectCard(long id) throws IOException
id - the idIOException - the io exceptionpublic void checkApiUrlValidity()
throws IOException
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.
IOException - the io exception@Preview @Deprecated public GHCommitSearchBuilder searchCommits()
public GHIssueSearchBuilder searchIssues()
public GHUserSearchBuilder searchUsers()
public GHRepositorySearchBuilder searchRepositories()
public GHContentSearchBuilder searchContent()
public GHNotificationStream listNotifications()
public PagedIterable<GHRepository> listAllPublicRepositories()
public PagedIterable<GHRepository> listAllPublicRepositories(String since)
since - The numeric ID of the last Repository that you’ve seen. See GHObject.getId()public Reader renderMarkdown(String text) throws IOException
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).
text - the textIOException - the io exceptionGHRepository#renderMarkdown(String, MarkdownMode)Copyright © 2020. All rights reserved.