/** * 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 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 String getSha1(String branchName) throws IOException { return ghRepo.getBranch(branchName).getSHA1(); }
@Deprecated public void enableProtection(EnforcementLevel level, Collection<String> contexts) throws IOException { switch (level) { case OFF: disableProtection(); break; case NON_ADMINS: case EVERYONE: enableProtection() .addRequiredChecks(contexts) .includeAdmins(level==EnforcementLevel.EVERYONE) .enable(); break; } }
public GHBranch getBranch(String name) throws IOException { return root.retrieve().to(getApiTailUrl("branches/"+name),GHBranch.class).wrap(this); }
public Optional<String> getLatestCommitShaOnBranch(String githubRepo, String branchName) { try { return Optional.of(gitHub.getRepository(githubRepo).getBranch(branchName).getSHA1()); } catch (Exception e) { logger.warn("Could not get latest commit on branch from Github!", e); return Optional.empty(); } }
for (final GHBranch branch : request.getBranches()) { count++; String branchName = branch.getName(); listener.getLogger().format("%n Checking branch %s%n", HyperlinkNote .encodeTo(repositoryUrl + "/tree/" + branchName, branchName)); BranchSCMHead head = new BranchSCMHead(branchName); if (request.process(head, new SCMRevisionImpl(head, branch.getSHA1()), new SCMSourceRequest.ProbeLambda<BranchSCMHead, SCMRevisionImpl>() { @NonNull
GHCompare.Commit[] getComparedCommits(GitHubBranch localBranch, GHBranch remoteBranch) throws IOException { String previous = localBranch.getCommitSha(); String current = remoteBranch.getSHA1(); LOG.debug("Comparing previous hash [{}] with current hash [{}]", previous, current); return remoteBranch.getOwner() .getCompare(previous, current) .getCommits(); }
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()); }
@Deprecated public void enableProtection(EnforcementLevel level, Collection<String> contexts) throws IOException { switch (level) { case OFF: disableProtection(); break; case NON_ADMINS: case EVERYONE: enableProtection() .addRequiredChecks(contexts) .includeAdmins(level==EnforcementLevel.EVERYONE) .enable(); break; } }
public GHBranch getBranch(String name) throws IOException { return root.retrieve().to(getApiTailUrl("branches/"+name),GHBranch.class).wrap(this); }
@Test(dependsOnMethods = {"testIdempotency", "testSameNameAcrossDifferentOrgs"}) public void testStoreUpdate() throws Exception { String user = github.getMyself().getLogin(); GHRepository storeRepo = github.getRepository(Paths.get(user, STORE_NAME).toString()); String latestCommit = storeRepo.getBranches().get(storeRepo.getDefaultBranch()).getSHA1(); GHContent store = storeRepo.getFileContent("store.json", latestCommit); try (InputStream stream = store.read(); InputStreamReader streamR = new InputStreamReader(stream)) { JsonElement json = new JsonParser().parse(streamR); assertNotNull(json); JsonElement images = json.getAsJsonObject().get("images"); assertNotNull(images); Object image1 = images.getAsJsonObject().get(IMAGE_1); assertNotNull(image1); Object image2 = images.getAsJsonObject().get(IMAGE_2); assertNotNull(image2); assertEquals(images.getAsJsonObject().get(IMAGE_1).getAsString(), TAG); assertEquals(images.getAsJsonObject().get(IMAGE_2).getAsString(), TAG); } }
/** * 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; }
@Override public boolean test(GHBranch remoteBranch) { if (skipFirstRun) { logger.info("Skipping first run for branch '{}'", remoteBranch.getName()); return false; } return true; } }
@Override public GitHubBranchCause check(@Nonnull GitHubBranchDecisionContext context) throws IOException { GHBranch remoteBranch = context.getRemoteBranch(); GitHubBranch localBranch = context.getLocalBranch(); TaskListener listener = context.getListener(); GitHubBranchCause cause = null; if (nonNull(localBranch) && nonNull(remoteBranch)) { // didn't exist before final String localBranchSHA1 = localBranch.getCommitSha(); final String remoteBranchSHA1 = remoteBranch.getSHA1(); if (!localBranchSHA1.equals(remoteBranchSHA1)) { final PrintStream logger = listener.getLogger(); logger.printf("%s: hash has changed '%s' -> '%s'%n", DISPLAY_NAME, localBranchSHA1, remoteBranchSHA1); LOG.debug("{}: hash has changed '{}' -> '{}'", DISPLAY_NAME, localBranchSHA1, remoteBranchSHA1); cause = context.newCause(DISPLAY_NAME, false); } } return cause; }