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 withforHookUrl(URL)
)- Since:
- 1.12.0
- Author:
- lanwen (Merkushev Kirill)
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
WebhookManager(URL endpoint)
UseforHookUrl(URL)
to create new one
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 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 ofregisterFor(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>
deleteWebhook()
protected com.google.common.base.Function<org.kohsuke.github.GHHook,Iterable<org.kohsuke.github.GHEvent>>
eventsFromHook()
protected com.google.common.base.Function<org.kohsuke.github.GHRepository,List<org.kohsuke.github.GHHook>>
fetchHooks()
static WebhookManager
forHookUrl(URL endpoint)
protected com.google.common.base.Predicate<org.kohsuke.github.GHHook>
log(String format)
Mostly debug method.Runnable
registerFor(Item item)
Creates runnable with ability to create hooks for given project For each GH repo name contributed byGitHubRepositoryNameContributor
, this runnable creates hook (with clean old one).Runnable
registerFor(Job<?,?> project)
Deprecated.protected com.google.common.base.Predicate<org.kohsuke.github.GHHook>
serviceWebhookFor(URL url)
Finds "Jenkins (GitHub)" service webhookvoid
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 urlprotected com.google.common.base.Predicate<org.kohsuke.github.GHHook>
webhookFor(URL url)
Finds hook with endpoint urlprotected com.google.common.base.Predicate<org.kohsuke.github.GHRepository>
withAdminAccess()
Filters repos with admin rights (to manage hooks)
-
-
-
Constructor Detail
-
WebhookManager
protected WebhookManager(URL endpoint)
UseforHookUrl(URL)
to create new one- Parameters:
endpoint
- url which will be created as hook on GH
-
-
Method Detail
-
forHookUrl
public static WebhookManager forHookUrl(URL endpoint)
- See Also:
WebhookManager(URL)
-
registerFor
@Deprecated public Runnable registerFor(Job<?,?> project)
Deprecated.Creates runnable with ability to create hooks for given project For each GH repo name contributed byGitHubRepositoryNameContributor
, this runnable creates hook (with clean old one). Hook events job interested in, contributes to full set instances ofGHEventsSubscriber
. 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:
createHookSubscribedTo(List)
-
registerFor
public Runnable registerFor(Item item)
Creates runnable with ability to create hooks for given project For each GH repo name contributed byGitHubRepositoryNameContributor
, this runnable creates hook (with clean old one). Hook events job interested in, contributes to full set instances ofGHEventsSubscriber
. 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:
createHookSubscribedTo(List)
-
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 hooksaliveRepos
- 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 ofregisterFor(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 urlevents
- 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
-
-