Class GitHubServerConfig
- java.lang.Object
-
- hudson.model.AbstractDescribableImpl<GitHubServerConfig>
-
- org.jenkinsci.plugins.github.config.GitHubServerConfig
-
- All Implemented Interfaces:
Describable<GitHubServerConfig>
public class GitHubServerConfig extends AbstractDescribableImpl<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
Nested Classes Modifier and Type Class Description static class
GitHubServerConfig.DescriptorImpl
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_CLIENT_CACHE_SIZE_MB
Default value in MB for client cache sizestatic String
GITHUB_URL
Because ofGitHub
hide this const from external use we need to store it here
-
Constructor Summary
Constructors Constructor Description GitHubServerConfig(String credentialsId)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static com.google.common.base.Predicate<GitHubServerConfig>
allowedToManageHooks()
Returns true if config can be used in hooks managingString
getApiUrl()
protected org.kohsuke.github.GitHub
getCachedClient()
int
getClientCacheSize()
Capacity of cache for GitHub client in MB.String
getCredentialsId()
String
getDisplayName()
Gets the formatted display name (which will always include the api url)String
getName()
Gets the optional display name of this server.boolean
isManageHooks()
static boolean
isUrlCustom(String apiUrl)
Checks GH url for equality to default api urlstatic com.google.common.base.Function<GitHubServerConfig,org.kohsuke.github.GitHub>
loginToGithub()
Converts server config to authorized GH instance.static com.google.common.base.Optional<Secret>
secretFor(String credentialsId)
Tries to findStringCredentials
by id and returns secret from it.void
setApiUrl(String apiUrl)
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
setName(String name)
Sets the optional display name.static String
tokenFor(String credentialsId)
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>
withHost(String host)
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-
Methods inherited from class hudson.model.AbstractDescribableImpl
getDescriptor
-
-
-
-
Field Detail
-
GITHUB_URL
public static final String GITHUB_URL
Because ofGitHub
hide this const from external use we need to store it here- See Also:
- Constant Field Values
-
DEFAULT_CLIENT_CACHE_SIZE_MB
public static final int DEFAULT_CLIENT_CACHE_SIZE_MB
Default value in MB for client cache size- See Also:
getClientCacheSize()
, Constant Field Values
-
-
Constructor Detail
-
GitHubServerConfig
@DataBoundConstructor public GitHubServerConfig(String credentialsId)
-
-
Method Detail
-
setName
@DataBoundSetter public void setName(@CheckForNull String name)
Sets the optional display name.- Parameters:
name
- the optional display name.
-
setApiUrl
@DataBoundSetter public void setApiUrl(String apiUrl)
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 public void setCustomApiUrl(boolean customApiUrl)
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
public String 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
public String getDisplayName()
Gets the formatted display name (which will always include the api url)- Returns:
- the formatted display name.
- Since:
- 1.28.0
-
getApiUrl
public String getApiUrl()
-
isManageHooks
public boolean isManageHooks()
-
getCredentialsId
public String 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
public static boolean isUrlCustom(String apiUrl)
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:
GitHubServerConfig.ClientCacheFunction
-
tokenFor
@NonNull public static String tokenFor(String credentialsId)
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
@NonNull public static com.google.common.base.Optional<Secret> secretFor(String credentialsId)
Tries to findStringCredentials
by id and returns secret from it.- Parameters:
credentialsId
- id to find creds- Returns:
- secret from creds or empty optional
-
withHost
public static com.google.common.base.Predicate<GitHubServerConfig> withHost(String host)
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
public static com.google.common.base.Predicate<GitHubServerConfig> allowedToManageHooks()
Returns true if config can be used in hooks managing- Returns:
- predicate to match against
GitHubServerConfig
-
-