Class GitHubServerConfig
java.lang.Object
hudson.model.AbstractDescribableImpl<GitHubServerConfig>
org.jenkinsci.plugins.github.config.GitHubServerConfig
- All Implemented Interfaces:
Describable<GitHubServerConfig>
This object represents configuration of each credentials-github pair.
If no api url explicitly defined, default url used.
So one github server can be used with many creds and one token can be used multiply times in lot of gh servers
- Since:
- 1.13.0
- Author:
- lanwen (Merkushev Kirill)
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Default value in MB for client cache sizestatic final String
Because ofGitHub
hide this const from external use we need to store it here -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic com.google.common.base.Predicate
<GitHubServerConfig> Returns true if config can be used in hooks managingprotected org.kohsuke.github.GitHub
int
Capacity of cache for GitHub client in MB.Gets the formatted display name (which will always include the api url)getName()
Gets the optional display name of this server.boolean
static boolean
isUrlCustom
(String apiUrl) Checks GH url for equality to default api urlstatic com.google.common.base.Function
<GitHubServerConfig, org.kohsuke.github.GitHub> Converts server config to authorized GH instance.static com.google.common.base.Optional
<Secret> Tries to findStringCredentials
by id and returns secret from it.void
Set the API endpoint.protected void
setCachedClient
(org.kohsuke.github.GitHub cachedClient) Used byGitHubServerConfig.ClientCacheFunction
void
setClientCacheSize
(int clientCacheSize) void
setCustomApiUrl
(boolean customApiUrl) Deprecated.simply remove usage of this method, it ignored now.void
setManageHooks
(boolean manageHooks) This server config will be used to manage GH Hooks if truevoid
Sets the optional display name.static String
Extracts token from secret found bysecretFor(String)
ReturnsUNKNOWN_TOKEN
if no any creds secret found with this id.static com.google.common.base.Predicate
<GitHubServerConfig> Returns true if given host is part of stored (or default if blank) api url For example: withHost(api.github.com).apply(config for ~empty~) = true withHost(api.github.com).apply(config for api.github.com) = true withHost(api.github.com).apply(config for github.company.com) = falseMethods inherited from class hudson.model.AbstractDescribableImpl
getDescriptor
-
Field Details
-
GITHUB_URL
Because ofGitHub
hide this const from external use we need to store it here- See Also:
-
DEFAULT_CLIENT_CACHE_SIZE_MB
public static final int DEFAULT_CLIENT_CACHE_SIZE_MBDefault value in MB for client cache size- See Also:
-
-
Constructor Details
-
GitHubServerConfig
-
-
Method Details
-
setName
Sets the optional display name.- Parameters:
name
- the optional display name.
-
setApiUrl
Set the API endpoint.- Parameters:
apiUrl
- custom url if GH. Default value will be used in case of custom is unchecked or value is blank
-
setManageHooks
@DataBoundSetter public void setManageHooks(boolean manageHooks) This server config will be used to manage GH Hooks if true- Parameters:
manageHooks
- false to ignore this config on hook auto-management
-
setCustomApiUrl
Deprecated.simply remove usage of this method, it ignored now. Should be removed after 20 sep 2016.This method was introduced to hide custom api url under checkbox, but now UI simplified to show url all the time see jenkinsci/github-plugin/pull/112 for more details- Parameters:
customApiUrl
- ignored
-
getName
Gets the optional display name of this server.- Returns:
- the optional display name of this server, may be empty or
null
but best effort is made to ensure that it has some meaningful text. - Since:
- 1.28.0
-
getDisplayName
Gets the formatted display name (which will always include the api url)- Returns:
- the formatted display name.
- Since:
- 1.28.0
-
getApiUrl
-
isManageHooks
public boolean isManageHooks() -
getCredentialsId
-
getClientCacheSize
public int getClientCacheSize()Capacity of cache for GitHub client in MB. Defaults to 20 MB- Since:
- 1.14.0
-
setClientCacheSize
@DataBoundSetter public void setClientCacheSize(int clientCacheSize) - Parameters:
clientCacheSize
- capacity of cache for GitHub client in MB, set to <= 0 to turn off this feature
-
getCachedClient
protected org.kohsuke.github.GitHub getCachedClient()- Returns:
- cached GH client or null
-
setCachedClient
protected void setCachedClient(org.kohsuke.github.GitHub cachedClient) Used byGitHubServerConfig.ClientCacheFunction
- Parameters:
cachedClient
- updated client. Maybe null to invalidate cache
-
isUrlCustom
Checks GH url for equality to default api url- Parameters:
apiUrl
- should be not blank and not equal to default url to return true- Returns:
- true if url not blank and not equal to default
-
loginToGithub
@CheckForNull public static com.google.common.base.Function<GitHubServerConfig,org.kohsuke.github.GitHub> loginToGithub()Converts server config to authorized GH instance. If login process is not successful it returns null- Returns:
- function to convert config to gh instance
- See Also:
-
tokenFor
Extracts token from secret found bysecretFor(String)
ReturnsUNKNOWN_TOKEN
if no any creds secret found with this id.- Parameters:
credentialsId
- id to find creds- Returns:
- token from creds or default non empty string
-
secretFor
Tries to findStringCredentials
by id and returns secret from it.- Parameters:
credentialsId
- id to find creds- Returns:
- secret from creds or empty optional
-
withHost
Returns true if given host is part of stored (or default if blank) api url For example: withHost(api.github.com).apply(config for ~empty~) = true withHost(api.github.com).apply(config for api.github.com) = true withHost(api.github.com).apply(config for github.company.com) = false- Parameters:
host
- host to find in api url- Returns:
- predicate to match against
GitHubServerConfig
-
allowedToManageHooks
Returns true if config can be used in hooks managing- Returns:
- predicate to match against
GitHubServerConfig
-