@Override public boolean test(GHBranch remoteBranch) { if (skipFirstRun) { logger.info("Skipping first run for branch '{}'", remoteBranch.getName()); return false; } return true; } }
public static void deleteUpdateBotBranch(GHRepository ghRepository, GHBranch ghBranch) throws IOException { deleteUpdateBotBranch(ghRepository, ghBranch.getName()); }
private <T> GitHubBranchCause check(GHBranch remoteBranch, GitHubBranchRepository localRepo, Supplier<List<String>> supplier) { if (matchCriteria.isEmpty()) { LOG.warn("Commit message event added but no match criteria set, all commits are allowed."); return null; } String name = remoteBranch.getName(); List<String> messages = supplier.get(); if (commitsAreAllowed(messages)) { LOG.debug("Commit messages {} for branch [{}] allowed, commit ignored.", messages, name); return null; } return toCause(remoteBranch, localRepo, true, "Commit messages %s for branch [%s] not allowed by check.", messages, name); }
private GitHubBranchCause check(GHBranch remoteBranch, Function<GitHubBranchCommitCheck, GitHubBranchCause> function, PrintStream logger) { List<GitHubBranchCause> causes = checks.stream() .map(function::apply) .filter(Objects::nonNull) .collect(Collectors.toList()); String name = remoteBranch.getName(); if (causes.isEmpty()) { LOG.debug("Commits for branch [{}] had no effect, not triggering run.", name); return null; } GitHubBranchCause cause = causes.get(0); LOG.info("Building branch [{}] skipped due to commit check: {}", name, cause.getReason()); logger.printf("Building branch [%s] skipped due to commit check: %s", name, cause.getReason()); return cause; }
public GHCompare getCompare(GHBranch id1, GHBranch id2) throws IOException { GHRepository owner1 = id1.getOwner(); GHRepository owner2 = id2.getOwner(); // If the owner of the branches is different, we have a cross-fork compare. if (owner1!=null && owner2!=null) { String ownerName1 = owner1.getOwnerName(); String ownerName2 = owner2.getOwnerName(); if (!StringUtils.equals(ownerName1, ownerName2)) { String qualifiedName1 = String.format("%s:%s", ownerName1, id1.getName()); String qualifiedName2 = String.format("%s:%s", ownerName2, id2.getName()); return getCompare(qualifiedName1, qualifiedName2); } } return getCompare(id1.getName(), id2.getName()); }
public GHCompare getCompare(GHBranch id1, GHBranch id2) throws IOException { GHRepository owner1 = id1.getOwner(); GHRepository owner2 = id2.getOwner(); // If the owner of the branches is different, we have a cross-fork compare. if (owner1!=null && owner2!=null) { String ownerName1 = owner1.getOwnerName(); String ownerName2 = owner2.getOwnerName(); if (!StringUtils.equals(ownerName1, ownerName2)) { String qualifiedName1 = String.format("%s:%s", ownerName1, id1.getName()); String qualifiedName2 = String.format("%s:%s", ownerName2, id2.getName()); return getCompare(qualifiedName1, qualifiedName2); } } return getCompare(id1.getName(), id2.getName()); }
@Override public GitHubBranchCause check(@Nonnull GitHubBranchDecisionContext context) throws IOException { GHBranch remoteBranch = context.getRemoteBranch(); GitHubBranch localBranch = context.getLocalBranch(); TaskListener listener = context.getListener(); if (isNull(remoteBranch) && isNull(localBranch)) { // just in case LOG.debug("Remote and local branch are null"); return null; } else if (isNull(remoteBranch)) { LOG.debug("Remote branch is null for localBranch '{}'. Branch can't be 'created'", localBranch.getName()); return null; } GitHubBranchCause cause = null; if (isNull(localBranch)) { // didn't exist before final PrintStream logger = listener.getLogger(); logger.println(DISPLAY_NAME + ": '" + remoteBranch.getName() + "'"); LOG.debug("{}: '{}'", DISPLAY_NAME, remoteBranch.getName()); cause = context.newCause(DISPLAY_NAME, false); } return cause; }
@Override public GitHubBranchCause check(@Nonnull GitHubBranchDecisionContext context) throws IOException { GHBranch remoteBranch = context.getRemoteBranch(); GitHubBranchRepository localRepo = context.getLocalRepo(); String name = remoteBranch.getName(); if (matchCriteria.isEmpty() || branchIsAllowed(name)) { if (matchCriteria.isEmpty()) { LOGGER.warn("Branch restriction filter added but no match criteria set, all branches allowed"); } // filter allows checking other events return null; } return toCause(context, true, "Branch [%s] filtered by branch name restriction filter", name); }
public GitHubBranch(GHBranch ghBranch) { this(ghBranch.getName(), ghBranch.getSHA1(), ghBranch.getOwner()); }
/** * Gets branches by {@linkplain GHBranch#getName() their names}. */ public Map<String,GHBranch> getBranches() throws IOException { Map<String,GHBranch> r = new TreeMap<String,GHBranch>(); for (GHBranch p : root.retrieve().to(getApiTailUrl("branches"), GHBranch[].class)) { p.wrap(this); r.put(p.getName(),p); } return r; }
public static void updateLocalRepository(@CheckForNull String requestedBranch, Set<GHBranch> remoteBranches, GitHubBranchRepository localRepository) { //refresh checked local state for checked branches long count = remoteBranches.stream() .map(updateLocalRepo(localRepository)) .count(); LOG.trace("Updated local branch details with [{}] repositories.", count); // remove deleted branches from local state Map<String, GitHubBranch> localBranches; if (nonNull(requestedBranch)) { localBranches = new HashMap<>(); if (localRepository.getBranches().containsKey(requestedBranch)) { localBranches.put(requestedBranch, localRepository.getBranches().get(requestedBranch)); } } else { localBranches = localRepository.getBranches(); } final Iterator<String> iterator = localBranches.keySet().iterator(); while (iterator.hasNext()) { final String localBranch = iterator.next(); final boolean present = remoteBranches.stream() .filter(br -> br.getName().equals(localBranch)) .findFirst() .isPresent(); if (!present) { LOG.debug("Removing {}, from localBranches", localBranch); iterator.remove(); } } }
/** * Gets branches by {@linkplain GHBranch#getName() their names}. */ public Map<String,GHBranch> getBranches() throws IOException { Map<String,GHBranch> r = new TreeMap<String,GHBranch>(); for (GHBranch p : root.retrieve().to(getApiTailUrl("branches"), GHBranch[].class)) { p.wrap(this); r.put(p.getName(),p); } return r; }
/** * Gets branches by {@linkplain GHBranch#getName() their names}. */ public Map<String,GHBranch> getBranches() throws IOException { Map<String,GHBranch> r = new TreeMap<String,GHBranch>(); for (GHBranch p : root.retrieve().to(getApiTailUrl("branches"), GHBranch[].class)) { p.wrap(this); r.put(p.getName(),p); } return r; }
public GitHubBranchCause(@Nonnull GHBranch remoteBranch, @Nonnull GitHubBranchRepository localRepo, String reason, boolean skip) { this(remoteBranch.getName(), remoteBranch.getSHA1()); withReason(reason); withSkip(skip); withLocalRepo(localRepo); withRemoteData(remoteBranch); }
@Override protected void readDocumentsFromListingFile(GitHubLocation location, List<String> documents, String listingFileName) { try { final GHRepository repo = openRepo(location); final GHBranch branch = selectBranch(location, repo); try { final GHContent content = repo.getFileContent(listingFileName, branch.getName()); final byte[] data = Base64.decodeBase64(content .getEncodedContent().getBytes()); try (Reader in = new InputStreamReader( new ByteArrayInputStream(data))) { final Listing listing = parser.parse(in); for (final String file : listing.getFiles()) { documents.add(MountPointUtil.apply(location, file)); } } } catch (Exception e) { log.debug( "Could not read listing file. That's propably ok if it's missing. msg={}, file={}", e.getMessage(), listingFileName); } } catch (final Exception e) { log.error("failed", e); } }
private GitHubBranchCause toCause(GitHubBranchEvent event, GitHubBranchDecisionContext context) { try { return context.checkEvent(event); } catch (IOException e) { String branch = null; if (nonNull(context.getLocalBranch())) { branch = context.getLocalBranch().getName(); } else if (nonNull(context.getRemoteBranch())) { branch = context.getRemoteBranch().getName(); } LOGGER.error("Event check failed, skipping branch '{}'.", branch, e); listener.error("Event check failed, skipping branch '{}' {}", branch, e); return null; } }
@Override protected ResourceInfo getResource(final GitHubLocation location, final String path) throws FileNotFoundException { GitHub github = null; GHRepository repo = null; GHBranch branch = null; try { github = location.open(); repo = github.getRepository(location.getRepoName()); log.debug("Using branch={}", location.getBranch()); branch = repo.getBranches().get(location.getBranch()); final GHContent content = repo.getFileContent(path, branch.getName()); final byte[] data = Base64.decodeBase64(content.getEncodedContent() .getBytes()); return new ResourceInfo(path, location, new ByteArrayInputStream( data)); } catch (final FileNotFoundException e) { throw e; } catch (final IOException e) { if (e.getMessage().contains("too_large")) { return getLargeResource(github, repo, branch, location, path); } throw new FileNotFoundException( "Could not locate the file at path " + path + ". e"); } }
private void listRepo(final List<String> documents, final GitHubLocation location, final GHRepository repo, final GHBranch branch, final String path) throws IOException { final List<GHContent> content = repo.getDirectoryContent(path, branch.getName()); for (final GHContent c : content) { switch (c.getType()) { case "file": handleFile(documents, location, c); break; case "dir": handleDir(documents, location, repo, branch, c); break; default: log.info("ignoring {}", c.getName()); } } }