Class WebhookManager
java.lang.Object
org.jenkinsci.plugins.github.webhook.WebhookManager
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
ModifierConstructorDescriptionprotected
WebhookManager
(URL endpoint) UseforHookUrl(URL)
to create new one -
Method Summary
Modifier and TypeMethodDescriptionprotected 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> 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>> static WebhookManager
forHookUrl
(URL endpoint) protected com.google.common.base.Predicate
<org.kohsuke.github.GHHook> Mostly debug method.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).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> Filters repos with admin rights (to manage hooks)
-
Constructor Details
-
WebhookManager
UseforHookUrl(URL)
to create new one- Parameters:
endpoint
- url which will be created as hook on GH
-
-
Method Details
-
forHookUrl
- See Also:
-
registerFor
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:
-
registerFor
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:
-
unregisterFor
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
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
Finds "Jenkins (GitHub)" service webhook- Parameters:
url
- jenkins endpoint url- Returns:
- true if hook is service hook
-
webhookFor
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
-
registerFor(Item)