mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-27 00:11:23 +00:00
167 lines
7.5 KiB
HTML
167 lines
7.5 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>GHHooks.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">GitHub API for Java</a> > <a href="index.source.html" class="el_package">org.kohsuke.github</a> > <span class="el_source">GHHooks.java</span></div><h1>GHHooks.java</h1><pre class="source lang-java linenums">package 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
|
|
*/
|
|
<span class="nc" id="L14">class GHHooks {</span>
|
|
static abstract class Context extends GitHubInteractiveObject {
|
|
|
|
<span class="fc" id="L17"> private Context(GitHub root) {</span>
|
|
<span class="fc" id="L18"> this.root = root;</span>
|
|
<span class="fc" id="L19"> }</span>
|
|
|
|
/**
|
|
* Gets hooks.
|
|
*
|
|
* @return the hooks
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public List<GHHook> getHooks() throws IOException {
|
|
|
|
<span class="fc" id="L30"> GHHook[] hookArray = root.createRequest().withUrlPath(collection()).fetch(collectionClass()); // jdk/eclipse</span>
|
|
// bug
|
|
// requires this
|
|
// to be on separate line
|
|
<span class="fc" id="L34"> List<GHHook> list = new ArrayList<GHHook>(Arrays.asList(hookArray));</span>
|
|
<span class="pc bpc" id="L35" title="1 of 2 branches missed."> for (GHHook h : list)</span>
|
|
<span class="nc" id="L36"> wrap(h);</span>
|
|
<span class="fc" id="L37"> return list;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets hook.
|
|
*
|
|
* @param id
|
|
* the id
|
|
* @return the hook
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHHook getHook(int id) throws IOException {
|
|
<span class="fc" id="L50"> GHHook hook = root.createRequest().withUrlPath(collection() + "/" + id).fetch(clazz());</span>
|
|
<span class="fc" id="L51"> return wrap(hook);</span>
|
|
}
|
|
|
|
/**
|
|
* 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 {
|
|
<span class="fc" id="L71"> List<String> ea = null;</span>
|
|
<span class="pc bpc" id="L72" title="1 of 2 branches missed."> if (events != null) {</span>
|
|
<span class="nc" id="L73"> ea = new ArrayList<String>();</span>
|
|
<span class="nc bnc" id="L74" title="All 2 branches missed."> for (GHEvent e : events)</span>
|
|
<span class="nc" id="L75"> ea.add(e.symbol());</span>
|
|
}
|
|
|
|
<span class="fc" id="L78"> GHHook hook = root.createRequest()</span>
|
|
<span class="fc" id="L79"> .method("POST")</span>
|
|
<span class="fc" id="L80"> .with("name", name)</span>
|
|
<span class="fc" id="L81"> .with("active", active)</span>
|
|
<span class="fc" id="L82"> .with("config", config)</span>
|
|
<span class="fc" id="L83"> .with("events", ea)</span>
|
|
<span class="fc" id="L84"> .withUrlPath(collection())</span>
|
|
<span class="fc" id="L85"> .fetch(clazz());</span>
|
|
|
|
<span class="fc" id="L87"> return wrap(hook);</span>
|
|
}
|
|
|
|
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) {
|
|
<span class="fc" id="L104"> super(repository.root);</span>
|
|
<span class="fc" id="L105"> this.repository = repository;</span>
|
|
<span class="fc" id="L106"> this.owner = owner;</span>
|
|
<span class="fc" id="L107"> }</span>
|
|
|
|
@Override
|
|
String collection() {
|
|
<span class="fc" id="L111"> return String.format("/repos/%s/%s/hooks", owner.getLogin(), repository.getName());</span>
|
|
}
|
|
|
|
@Override
|
|
Class<? extends GHHook[]> collectionClass() {
|
|
<span class="fc" id="L116"> return GHRepoHook[].class;</span>
|
|
}
|
|
|
|
@Override
|
|
Class<? extends GHHook> clazz() {
|
|
<span class="fc" id="L121"> return GHRepoHook.class;</span>
|
|
}
|
|
|
|
@Override
|
|
GHHook wrap(GHHook hook) {
|
|
<span class="fc" id="L126"> return ((GHRepoHook) hook).wrap(repository);</span>
|
|
}
|
|
}
|
|
|
|
private static class OrgContext extends Context {
|
|
private final GHOrganization organization;
|
|
|
|
private OrgContext(GHOrganization organization) {
|
|
<span class="fc" id="L134"> super(organization.root);</span>
|
|
<span class="fc" id="L135"> this.organization = organization;</span>
|
|
<span class="fc" id="L136"> }</span>
|
|
|
|
@Override
|
|
String collection() {
|
|
<span class="fc" id="L140"> return String.format("/orgs/%s/hooks", organization.getLogin());</span>
|
|
}
|
|
|
|
@Override
|
|
Class<? extends GHHook[]> collectionClass() {
|
|
<span class="nc" id="L145"> return GHOrgHook[].class;</span>
|
|
}
|
|
|
|
@Override
|
|
Class<? extends GHHook> clazz() {
|
|
<span class="fc" id="L150"> return GHOrgHook.class;</span>
|
|
}
|
|
|
|
@Override
|
|
GHHook wrap(GHHook hook) {
|
|
<span class="fc" id="L155"> return ((GHOrgHook) hook).wrap(organization);</span>
|
|
}
|
|
}
|
|
|
|
static Context repoContext(GHRepository repository, GHUser owner) {
|
|
<span class="fc" id="L160"> return new RepoContext(repository, owner);</span>
|
|
}
|
|
|
|
static Context orgContext(GHOrganization organization) {
|
|
<span class="fc" id="L164"> return new OrgContext(organization);</span>
|
|
}
|
|
}
|
|
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html> |