Skip to content Navigation Menu Toggle navigation Sign in Appearance settings PlatformAI CODE CREATIONGitHub CopilotWrite better code with AIGitHub Copilot appDirect agents from issue to mergeMCP RegistryNewIntegrate external toolsDEVELOPER WORKFLOWSActionsAutomate any workflowCodespacesInstant dev environmentsIssuesPlan and track workCode ReviewManage code changesAPPLICATION SECURITYGitHub Advanced SecurityFind and fix vulnerabilitiesCode securitySecure your code as you buildSecret protectionStop leaks before they startEXPLOREWhy GitHubDocumentationBlogChangelogMarketplaceView all featuresSolutionsBY COMPANY SIZEEnterprisesSmall and medium teamsStartupsNonprofitsBY USE CASEApp ModernizationDevSecOpsDevOpsCI/CDView all use casesBY INDUSTRYHealthcareFinancial servicesManufacturingGovernmentView all industriesView all solutionsResourcesEXPLORE BY TOPICAISoftware DevelopmentDevOpsSecurityView all topicsEXPLORE BY TYPECustomer storiesEvents & webinarsEbooks & reportsBusiness insightsGitHub SkillsSUPPORT & SERVICESDocumentationCustomer supportCommunity forumTrust centerPartnersView all resourcesOpen SourceCOMMUNITYGitHub SponsorsFund open source developersPROGRAMSSecurity LabMaintainer CommunityAcceleratorGitHub StarsArchive ProgramREPOSITORIESTopicsTrendingCollectionsEnterpriseENTERPRISE SOLUTIONSEnterprise platformAI-powered developer platformAVAILABLE ADD-ONSGitHub Advanced SecurityEnterprise-grade security featuresCopilot for BusinessEnterprise-grade AI featuresPremium SupportEnterprise-grade 24/7 supportPricing Search or jump to... Search code, repositories, users, issues, pull requests... Search Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. Include my email address so I can be contacted Saved searches Use saved searches to filter your results more quickly Name Query To see all available qualifiers, see our documentation. Sign in Sign up Appearance settings Resetting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} lstarby / github-api Public forked from hub4j/github-api Notifications You must be signed in to change notification settings Fork 0 Star 0 Code Pull requests 0 Actions Projects Security and quality 0 Insights Additional navigation options Code Pull requests Actions Projects Security and quality Insights FilesExpand file tree masterBreadcrumbsgithub-api/src/main/java/org/kohsuke/github/GHHooks.javaCopy pathBlameMore file actionsBlameMore file actions Latest commit HistoryHistoryHistory166 lines (139 loc) · 4.66 KB masterBreadcrumbsgithub-api/src/main/java/org/kohsuke/github/GHHooks.javaCopy pathTopFile metadata and controlsCodeBlame166 lines (139 loc) · 4.66 KBRawCopy raw fileDownload raw fileOpen symbols panelEdit and raw actions123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166package org.kohsuke.github; import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import java.util.Collection;import java.util.List;import java.util.Map; /** * Utility class for creating and retrieving webhooks; removes duplication between GHOrganization and GHRepository * functionality */class GHHooks { static abstract class Context extends GitHubInteractiveObject { private Context(GitHub root) { this.root = root; } /** * Gets hooks. * * @return the hooks * @throws IOException * the io exception */ public List<GHHook> getHooks() throws IOException { GHHook[] hookArray = root.createRequest().withUrlPath(collection()).fetch(collectionClass()); // jdk/eclipse // bug // requires this // to be on separate line List<GHHook> list = new ArrayList<GHHook>(Arrays.asList(hookArray)); for (GHHook h : list) wrap(h); return list; } /** * Gets hook. * * @param id * the id * @return the hook * @throws IOException * the io exception */ public GHHook getHook(int id) throws IOException { GHHook hook = root.createRequest().withUrlPath(collection() + "/" + id).fetch(clazz()); return wrap(hook); } /** * Create hook gh hook. * * @param name * the name * @param config * the config * @param events * the events * @param active * the active * @return the gh hook * @throws IOException * the io exception */ public GHHook createHook(String name, Map<String, String> config, Collection<GHEvent> events, boolean active) throws IOException { List<String> ea = null; if (events != null) { ea = new ArrayList<String>(); for (GHEvent e : events) ea.add(e.symbol()); } GHHook hook = root.createRequest() .method("POST") .with("name", name) .with("active", active) .with("config", config) .with("events", ea) .withUrlPath(collection()) .fetch(clazz()); return wrap(hook); } abstract String collection(); abstract Class<? extends GHHook[]> collectionClass(); abstract Class<? extends GHHook> clazz(); abstract GHHook wrap(GHHook hook); } private static class RepoContext extends Context { private final GHRepository repository; private final GHUser owner; private RepoContext(GHRepository repository, GHUser owner) { super(repository.root); this.repository = repository; this.owner = owner; } @Override String collection() { return String.format("/repos/%s/%s/hooks", owner.getLogin(), repository.getName()); } @Override Class<? extends GHHook[]> collectionClass() { return GHRepoHook[].class; } @Override Class<? extends GHHook> clazz() { return GHRepoHook.class; } @Override GHHook wrap(GHHook hook) { return ((GHRepoHook) hook).wrap(repository); } } private static class OrgContext extends Context { private final GHOrganization organization; private OrgContext(GHOrganization organization) { super(organization.root); this.organization = organization; } @Override String collection() { return String.format("/orgs/%s/hooks", organization.getLogin()); } @Override Class<? extends GHHook[]> collectionClass() { return GHOrgHook[].class; } @Override Class<? extends GHHook> clazz() { return GHOrgHook.class; } @Override GHHook wrap(GHHook hook) { return ((GHOrgHook) hook).wrap(organization); } } static Context repoContext(GHRepository repository, GHUser owner) { return new RepoContext(repository, owner); } static Context orgContext(GHOrganization organization) { return new OrgContext(organization); }} You can’t perform that action at this time.