@Nonnull public String getCommitSha() { return commit.getSHA1(); }
public GithubLogEntry(final GHCommit commit) throws IOException { this.message = commit.getCommitShortInfo().getMessage(); this.githubUrl = commit.getHtmlUrl().toExternalForm(); this.commitId = commit.getSHA1(); this.affectedPaths = commit.getFiles().stream().map(file -> file.getFileName()).collect(Collectors.toList()); }
@Override public long lastModified() throws IOException, InterruptedException { return commit.getCommitDate().getTime(); }
Properties props = new Properties(); props.setProperty("login", "somebody@somewhere.com"); props.setProperty("password", "YourGithubPassword"); GitHub gitHub = GitHubBuilder.fromProperties(props).build(); GHRepository repository = gitHub.getRepository("your/repo"); Calendar cal = Calendar.getInstance(); cal.set(2014, 0, 4); Date since = cal.getTime(); cal.set(2014, 0, 14); Date until = cal.getTime(); GHCommitQueryBuilder queryBuilder = repository.queryCommits().since(since).until(until); PagedIterable<GHCommit> commits = queryBuilder.list(); Iterator<GHCommit> iterator = commits.iterator(); while (iterator.hasNext()) { GHCommit commit = iterator.next(); System.out.println("Commit: " + commit.getSHA1() + ", info: " + commit.getCommitShortInfo().getMessage() + ", author: " + commit.getAuthor()); }
public CommitInfo(final GHCommit commit, final GitBranch branch) { this.sha = commit.getSHA1(); try { this.message = commit.getCommitShortInfo().getMessage(); this.committerName = commit.getCommitShortInfo().getCommitter().getName(); this.committerEmail = commit.getCommitShortInfo().getCommitter().getEmail(); this.commitUrl = commit.getOwner().getHtmlUrl() + "/commit/" + this.sha; } catch (final IOException e) { throw new RuntimeException(e); } this.branch = branch.toString(); this.avatarUrl = null; }
public Optional<CommitDetails> getCommitDetails(String githubRepo, String sha) { try { logger.info("Getting commit details for sha {} on url {}", sha, githubRepo); GHCommit commit = gitHub.getRepository(githubRepo).getCommit(sha); GHUser author = commit.getAuthor(); String committerName = (author == null) ? null : author.getName(); if (committerName == null || committerName.isEmpty()) { committerName = author.getLogin(); } CommitDetails commitDetails = new CommitDetails(sha, commit.getHtmlUrl().toString(), commit.getCommitShortInfo().getMessage(), commit.getCommitDate(), commit.getLastStatus(), author.getAvatarUrl(), committerName); return Optional.of(commitDetails); } catch (IOException e) { logger.warn("Could not get commit details from Github!", e); return Optional.empty(); } }
private Commit createCommitForMetrics(PullRequest prInformation, boolean base) { Commit commit = new Commit(); GHCommitPointer ghCommitPointer; GHCommit ghCommit; if (base) { ghCommitPointer = prInformation.getBaseRef(); } else { ghCommitPointer = prInformation.getHeadRef(); } try { ghCommit = ghCommitPointer.getCommit(); String branchLabel = ghCommitPointer.getLabel(); String branchName = branchLabel.substring(branchLabel.indexOf(":") + 1, branchLabel.length()); commit.setRepoName(ghCommitPointer.getRepository().getFullName()); commit.setBranchName(branchName); commit.setSha(ghCommit.getSHA1()); commit.setUrl(ghCommit.getHtmlUrl().toString()); commit.setDate(ghCommit.getCommitDate()); return commit; } catch (IOException e) { this.addStepError("Exception while writing properties related to commits.", e); } return null; }
/** * Use this method to walk the tree */ public GHTree getTree() throws IOException { return owner.getTree(getCommitShortInfo().tree.sha); }
public DotCiUpstreamTriggerCause(DynamicBuild sourceBuild, DynamicProject targetJob, Map<String, String> jobOptions) { branch = new GitBranch(jobOptions.get("BRANCH")); GHCommit commit; if (jobOptions.containsKey("SHA")) { commit = getCommitFromSha(targetJob, jobOptions.get("SHA")); } else { commit = getHeadCommitForBranch(targetJob, branch.toString()); } this.pusher = sourceBuild.getCause().getPusher(); this.description = "Started by upstream job " + sourceBuild.getParent().getFullDisplayName() + ".: " + sourceBuild.getNumber(); this.sha = commit.getSHA1(); this.parentSha = commit.getParentSHA1s().size() > 0 ? commit.getParentSHA1s().get(0) : null; this.commitInfo = new CommitInfo(commit, branch); }
GHRepository repository = gitHub.getRepository(repoName); GHCommit commit = repository.getCommit(currentCommitId); parentCommitId = commit.getParents().get(0).getSHA1(); List<GHCommit.File> commitFiles = commit.getFiles(); for (GHCommit.File commitFile : commitFiles) { if (commitFile.getFileName().endsWith(".java")) {
/** * Resolves the parent commit objects and return them. */ public List<GHCommit> getParents() throws IOException { List<GHCommit> r = new ArrayList<GHCommit>(); for (String sha1 : getParentSHA1s()) r.add(owner.getCommit(sha1)); return r; }
private String getLastKnowParent(GitHub gh, GHRepository ghRepo, Git git, String oldCommitSha, AbstractStep step) throws IOException { showGitHubRateInformation(gh, step); GHCommit commit = ghRepo.getCommit(oldCommitSha); // get the deleted // commit from GH List<String> commitParents = commit.getParentSHA1s(); if (commitParents.isEmpty()) { step.addStepError("The following commit does not have any parent in GitHub: " + oldCommitSha + ". It cannot be resolved."); return null; } if (commitParents.size() > 1) { this.getLogger().debug("Step " + step.getName() + " - The commit has more than one parent : " + commit.getHtmlUrl()); } String parent = commitParents.get(0); try { ObjectId commitObject = git.getRepository().resolve(parent); git.getRepository().open(commitObject); return parent; } catch (MissingObjectException e) { return getLastKnowParent(gh, ghRepo, git, parent, step); } }
public GHCommitComment createComment(String body) throws IOException { return createComment(body, null, null, null); }
/** * Gets the date the change was authored on. * @return the date the change was authored on. * @throws IOException if the information was not already fetched and an attempt at fetching the information failed. */ public Date getAuthoredDate() throws IOException { return getCommitShortInfo().getAuthoredDate(); }
/** * Resolves the parent commit objects and return them. */ public List<GHCommit> getParents() throws IOException { List<GHCommit> r = new ArrayList<GHCommit>(); for (String sha1 : getParentSHA1s()) r.add(owner.getCommit(sha1)); return r; }
public GHCommitComment createComment(String body) throws IOException { return createComment(body, null, null, null); }
/** * Gets the date the change was committed on. * * @return the date the change was committed on. * @throws IOException if the information was not already fetched and an attempt at fetching the information failed. */ public Date getCommitDate() throws IOException { return getCommitShortInfo().getCommitDate(); }
/** * Resolves the parent commit objects and return them. */ public List<GHCommit> getParents() throws IOException { List<GHCommit> r = new ArrayList<GHCommit>(); for (String sha1 : getParentSHA1s()) r.add(owner.getCommit(sha1)); return r; }
@Override public long lastModified() { Object rd = revision.getRemoteData(); if (rd instanceof GHPullRequest) { GHPullRequest pr = (GHPullRequest) rd; if (pr != null) { try { return pr.getUpdatedAt().getTime(); } catch (IOException e) { // never thrown } } } try { return commit().getCommitDate().getTime(); } catch (IOException e) { return 0L; } }