code: protected Function<GitHubRepositoryName, GHHook> createHookSubscribedTo(final List<GHEvent> events) {
          return new NullSafeFunction<GitHubRepositoryName, GHHook>() {
              @Override
              protected GHHook applyNullSafe(@Nonnull GitHubRepositoryName name) {
                  try {
                      GHRepository repo = checkNotNull(
                              from(name.resolve(allowedToManageHooks())).firstMatch(withAdminAccess()).orNull(),
                              "There are no credentials with admin access to manage hooks on %s", name
                      );
  
                      Validate.notEmpty(events, "Events list for hook can't be empty");
  
                      Set<GHHook> hooks = from(fetchHooks().apply(repo))
                              .filter(webhookFor(endpoint))
                              .toSet();
  
                      Set<GHEvent> alreadyRegistered = from(hooks)
                              .transformAndConcat(eventsFromHook()).toSet();
  
                      if (hooks.size() == 1 && isEqualCollection(alreadyRegistered, events)) {
                          LOGGER.debug("Hook already registered for events {}", events);
                          return null;
                      }
  
                      Set<GHEvent> merged = from(alreadyRegistered).append(events).toSet();
  
                      from(hooks)
                              .filter(deleteWebhook())
                              .filter(log("Replaced hook")).toList();
  
                      return createWebhook(endpoint, merged).apply(repo);
                  } catch (Exception e) {
                      LOGGER.warn("Failed to add GitHub webhook for {}", name, e);
                      GitHubHookRegisterProblemMonitor.get().registerProblem(name, e);
                  }
                  return null;
              }
          };
      }
docs: Main logic of {@link #registerFor(Item)}.
  Updates hooks with replacing old ones with merged new ones
  
  @param events calculated events list to be registered in hook
  
  @return function to register hooks for given events