Class 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)
    • 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 by GitHubServerConfig.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 by secretFor(String) Returns UNKNOWN_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 find StringCredentials 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