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()); }
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 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); } }
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; }