Class WebhookManager

java.lang.Object
org.jenkinsci.plugins.github.webhook.WebhookManager

public class WebhookManager extends Object
Class to incapsulate manipulation with webhooks on GH Each manager works with only one hook url (created with forHookUrl(URL))
Since:
1.12.0
Author:
lanwen (Merkushev Kirill)
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    WebhookManager(URL endpoint)
    Use forHookUrl(URL) to create new one
  • Method Summary

    Modifier and Type
    Method
    Description
    protected com.google.common.base.Function<GitHubRepositoryName,org.kohsuke.github.GHHook>
    createHookSubscribedTo(List<org.kohsuke.github.GHEvent> events)
    Main logic of registerFor(Item).
    protected com.google.common.base.Function<org.kohsuke.github.GHRepository,org.kohsuke.github.GHHook>
    createWebhook(URL url, Set<org.kohsuke.github.GHEvent> events)
     
    protected com.google.common.base.Predicate<org.kohsuke.github.GHHook>
     
    protected com.google.common.base.Function<org.kohsuke.github.GHHook,Iterable<org.kohsuke.github.GHEvent>>
     
    protected com.google.common.base.Function<org.kohsuke.github.GHRepository,List<org.kohsuke.github.GHHook>>
     
    forHookUrl(URL endpoint)
     
    protected com.google.common.base.Predicate<org.kohsuke.github.GHHook>
    log(String format)
    Mostly debug method.
    Creates runnable with ability to create hooks for given project For each GH repo name contributed by GitHubRepositoryNameContributor, this runnable creates hook (with clean old one).
    registerFor(Job<?,?> project)
    Deprecated.
    protected com.google.common.base.Predicate<org.kohsuke.github.GHHook>
    Finds "Jenkins (GitHub)" service webhook
    void
    Used to cleanup old hooks in case of removed or reconfigured trigger since JENKINS-28138 this method permanently removes service hooks So if the trigger for given name was only reconfigured, this method filters only service hooks (with help of aliveRepos names list), otherwise this method removes all hooks for managed url
    protected com.google.common.base.Predicate<org.kohsuke.github.GHHook>
    Finds hook with endpoint url
    protected com.google.common.base.Predicate<org.kohsuke.github.GHRepository>
    Filters repos with admin rights (to manage hooks)

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WebhookManager

      protected WebhookManager(URL endpoint)
      Use forHookUrl(URL) to create new one
      Parameters:
      endpoint - url which will be created as hook on GH
  • Method Details

    • forHookUrl

      public static WebhookManager forHookUrl(URL endpoint)
      See Also:
    • registerFor

      @Deprecated public Runnable registerFor(Job<?,?> project)
      Deprecated.
      Creates runnable with ability to create hooks for given project For each GH repo name contributed by GitHubRepositoryNameContributor, this runnable creates hook (with clean old one). Hook events job interested in, contributes to full set instances of GHEventsSubscriber. New events will be merged with old ones from existent hook. By default only push event is registered
      Parameters:
      project - to find for which repos we should create hooks
      Returns:
      runnable to create hooks on run
      See Also:
    • registerFor

      public Runnable registerFor(Item item)
      Creates runnable with ability to create hooks for given project For each GH repo name contributed by GitHubRepositoryNameContributor, this runnable creates hook (with clean old one). Hook events job interested in, contributes to full set instances of GHEventsSubscriber. New events will be merged with old ones from existent hook. By default only push event is registered
      Parameters:
      item - to find for which repos we should create hooks
      Returns:
      runnable to create hooks on run
      Since:
      1.25.0
      See Also:
    • unregisterFor

      public void unregisterFor(GitHubRepositoryName name, List<GitHubRepositoryName> aliveRepos)
      Used to cleanup old hooks in case of removed or reconfigured trigger since JENKINS-28138 this method permanently removes service hooks So if the trigger for given name was only reconfigured, this method filters only service hooks (with help of aliveRepos names list), otherwise this method removes all hooks for managed url
      Parameters:
      name - repository to clean hooks
      aliveRepos - repository list which has enabled trigger in jobs
    • createHookSubscribedTo

      protected com.google.common.base.Function<GitHubRepositoryName,org.kohsuke.github.GHHook> createHookSubscribedTo(List<org.kohsuke.github.GHEvent> events)
      Main logic of registerFor(Item). Updates hooks with replacing old ones with merged new ones
      Parameters:
      events - calculated events list to be registered in hook
      Returns:
      function to register hooks for given events
    • log

      protected com.google.common.base.Predicate<org.kohsuke.github.GHHook> log(String format)
      Mostly debug method. Logs hook manipulation result
      Parameters:
      format - prepended comment for log
      Returns:
      always true predicate
    • withAdminAccess

      protected com.google.common.base.Predicate<org.kohsuke.github.GHRepository> withAdminAccess()
      Filters repos with admin rights (to manage hooks)
      Returns:
      true if we have admin rights for repo
    • serviceWebhookFor

      protected com.google.common.base.Predicate<org.kohsuke.github.GHHook> serviceWebhookFor(URL url)
      Finds "Jenkins (GitHub)" service webhook
      Parameters:
      url - jenkins endpoint url
      Returns:
      true if hook is service hook
    • webhookFor

      protected com.google.common.base.Predicate<org.kohsuke.github.GHHook> webhookFor(URL url)
      Finds hook with endpoint url
      Parameters:
      url - jenkins endpoint url
      Returns:
      true if hook is standard webhook
    • eventsFromHook

      protected com.google.common.base.Function<org.kohsuke.github.GHHook,Iterable<org.kohsuke.github.GHEvent>> eventsFromHook()
      Returns:
      converter to extract events from each hook
    • fetchHooks

      protected com.google.common.base.Function<org.kohsuke.github.GHRepository,List<org.kohsuke.github.GHHook>> fetchHooks()
      Returns:
      converter to fetch from GH hooks list for each repo
    • createWebhook

      protected com.google.common.base.Function<org.kohsuke.github.GHRepository,org.kohsuke.github.GHHook> createWebhook(URL url, Set<org.kohsuke.github.GHEvent> events)
      Parameters:
      url - jenkins endpoint url
      events - list of GH events jenkins interested in
      Returns:
      converter to create GH hook for given url with given events
    • deleteWebhook

      protected com.google.common.base.Predicate<org.kohsuke.github.GHHook> deleteWebhook()
      Returns:
      annihilator for hook, returns true if deletion was successful