/** * Updates this ref to the specified commit. * * @param sha * The SHA1 value to set this reference to */ public void updateTo(String sha) throws IOException { updateTo(sha, false); }
public static void deleteUpdateBotBranch(GHRepository ghRepository, String branchName) throws IOException { if (branchName.startsWith("updatebot-")) { //delete as per https://github.com/kohsuke/github-api/pull/164#issuecomment-78391771 //heads needed as per https://developer.github.com/v3/git/refs/#get-a-reference ghRepository.getRef("heads/" + branchName).delete(); LOG.info("deleted branch " + branchName + " for " + ghRepository.getFullName()); } }
/*package*/ static GHRef[] wrap(GHRef[] in, GitHub root) { for (GHRef r : in) { r.wrap(root); } return in; }
public String getDefaultBranchSha() throws IOException { return getReferenceToDefaultBranch().getObject().getSha(); }
/** * Creates reference to the new branch with {@code branch} from default branch. * * @param branchName name of the branch which should be created * @return reference to the new branch * @throws IOException */ public GHRef createBranch(String branchName) throws IOException { GHRef defaultBranch = getReferenceToDefaultBranch(); return ghRepo.createRef("refs/heads/" + branchName, defaultBranch.getObject().getSha()); }
/*package*/ static GHRef[] wrap(GHRef[] in, GitHub root) { for (GHRef r : in) { r.wrap(root); } return in; }
/** * Creates reference to the new tag with {@code tagName} from default branch. * * @param tagName is a name of new tag * @return reference to the new tag * @throws IOException */ public GHRef createTag(String tagName) throws IOException { GHRef defaultBranch = getReferenceToDefaultBranch(); return ghRepo.createRef("refs/tags/" + tagName, defaultBranch.getObject().getSha()); }
/** * Updates this ref to the specified commit. * * @param sha * The SHA1 value to set this reference to */ public void updateTo(String sha) throws IOException { updateTo(sha, false); }
private void deleteBranch(Run<?, ?> build, Launcher launcher, final TaskListener listener) { if (!getDeleteOnMerge()) { return; } String branchName = pr.getHead().getRef(); try { GHRepository repo = pr.getRepository(); GHRef ref = repo.getRef("heads/" + branchName); ref.delete(); listener.getLogger().println("Deleted branch " + branchName); } catch (IOException e) { listener.getLogger().println("Unable to delete branch " + branchName); e.printStackTrace(listener.getLogger()); } }
/*package*/ static GHRef[] wrap(GHRef[] in, GitHub root) { for (GHRef r : in) { r.wrap(root); } return in; }
@Override public long lastModified() { if (repo == null) { return 0L; } synchronized (this) { if (!open) { return 0L; } } if (revision instanceof AbstractGitSCMSource.SCMRevisionImpl) { try { GHCommit commit = repo.getCommit(((AbstractGitSCMSource.SCMRevisionImpl) revision).getHash()); return commit.getCommitDate().getTime(); } catch (IOException e) { // ignore } } else if (revision == null) { try { GHRef ref = repo.getRef(this.ref); GHCommit commit = repo.getCommit(ref.getObject().getSha()); return commit.getCommitDate().getTime(); } catch (IOException e) { // ignore } } return 0; }
/** * Updates this ref to the specified commit. * * @param sha * The SHA1 value to set this reference to */ public void updateTo(String sha) throws IOException { updateTo(sha, false); }
/** * Retrieves all refs for the github repository. * @return an array of GHRef elements coresponding with the refs in the remote repository. * @throws IOException on failure communicating with GitHub */ public GHRef[] getRefs() throws IOException { return GHRef.wrap(root.retrieve().to(String.format("/repos/%s/%s/git/refs", owner.login, name), GHRef[].class),root); }
public org.kohsuke.github.GHCommit getHeadCommitForBranch(final String branch) throws IOException { String sha; final GitBranch gitBranch = new GitBranch(branch); if (gitBranch.isPullRequest()) { try { sha = getGithubRepository().getPullRequest(gitBranch.pullRequestNumber()).getHead().getSha(); } catch (final IOException e) { throw new RuntimeException(e); } } else { try { final GHRef ref = getRef("heads/" + gitBranch); sha = ref.getObject().getSha(); } catch (final IOException e) { sha = gitBranch.toString(); } } return getGithubRepository().getCommit(sha); }
private void createSubmodule( TestGitHubRepository pathToRootContentDirectory, String pathForSubmodule) throws IOException { String submoduleSha = createTreeWithSubmodule(pathToRootContentDirectory, pathForSubmodule); GHCommit treeCommit = ghRepo.createCommit().tree(submoduleSha).message("Create submodule").create(); getReferenceToDefaultBranch().updateTo(treeCommit.getSHA1(), true); setupSubmoduleConfig(pathToRootContentDirectory, pathForSubmodule); }
/** * Retrieves all refs of the given type for the current GitHub repository. * @param refType the type of reg to search for e.g. <tt>tags</tt> or <tt>commits</tt> * @return an array of all refs matching the request type * @throws IOException on failure communicating with GitHub, potentially due to an invalid ref type being requested */ public GHRef[] getRefs(String refType) throws IOException { return GHRef.wrap(root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refType), GHRef[].class),root); } /**
/** * Retrive a ref of the given type for the current GitHub repository. * * @param refName * eg: heads/branch * @return refs matching the request type * @throws IOException * on failure communicating with GitHub, potentially due to an * invalid ref type being requested */ public GHRef getRef(String refName) throws IOException { return root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refName), GHRef.class).wrap(root); } /**
/** * Retrieves all refs for the github repository. * @return an array of GHRef elements coresponding with the refs in the remote repository. * @throws IOException on failure communicating with GitHub */ public GHRef[] getRefs() throws IOException { return GHRef.wrap(root.retrieve().to(String.format("/repos/%s/%s/git/refs", getOwnerName(), name), GHRef[].class), root); }
/** * Retrieves all refs for the github repository. * @return an array of GHRef elements coresponding with the refs in the remote repository. * @throws IOException on failure communicating with GitHub */ public GHRef[] getRefs() throws IOException { return GHRef.wrap(root.retrieve().to(String.format("/repos/%s/%s/git/refs", getOwnerName(), name), GHRef[].class), root); }