@Nonnull public String getCommitSha() { return commit.getSHA1(); }
public UnknownBuildCause(final GitBranch branch, final GHCommit commit, final String parentSha) { this.branch = branch; this.parentSha = parentSha; this.sha = commit.getSHA1(); this.commitInfo = new CommitInfo(commit, branch); }
public boolean isCommitInBranchHistory(String githubRepo, String branch, String sha) { // First get the initial commit so we can reduce the number of requests to github Optional<CommitDetails> commit = getCommitDetails(githubRepo, sha); if (commit.isPresent()) { Optional<List<GHCommit>> allCommitsOnABranch = getAllCommitsOnABranch(githubRepo, branch, commit.get().getCommitDate()); return allCommitsOnABranch.map(ghCommits -> ghCommits .stream() .anyMatch(ghCommit -> ghCommit.getSHA1().equals(sha))) .orElse(false); } return false; }
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 ManualBuildCause(final GitBranch branch, final GHCommit commit, final String parentSha, final String user) throws IOException { this.branch = branch; this.parentSha = parentSha; this.sha = commit.getSHA1(); this.user = user; this.commitInfo = new CommitInfo(commit, branch); this.changeLogEntries = getChangeLogEntriescommit(commit); }
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()); }
/** * Check used to determine if some associated commit property, such as the commit message, should prevent a build from being triggered. * <p> * This method is called when the repository is not yet known to the plugin. * </p> * * @param remoteBranch current branch state from GH. * @param localRepo local repository state. * @param commit last commit in the remote repository. * @return <code>GitHubBranchCause</code> instance indicating if the build should be skipped, <code>null</code> otherwise. */ public GitHubBranchCause check(GHBranch remoteBranch, GitHubBranchRepository localRepo, GHCommit commit) { try { return doCheck(remoteBranch, localRepo, commit); } catch (IOException e) { LOG.error("Failed to check commit for hash [{}]", commit.getSHA1(), e); return new GitHubBranchCause(remoteBranch, localRepo, e.getMessage(), true); } }
public String getSha() { try { return new GithubRepositoryService(getProjectUrl()).getHeadCommitForBranch(getBranch()).getSHA1(); } catch (final IOException e) { throw new RuntimeException(e); } }
public GitHubTag(GHTag ghTag) { this(ghTag.getName(), ghTag.getCommit().getSHA1(), ghTag.getOwner()); }
public GitHubTagCause(@Nonnull GHTag remoteTag, @Nonnull GitHubTagRepository localRepo, String reason, boolean skip) { this(remoteTag.getName(), remoteTag.getCommit().getSHA1()); withReason(reason); withSkip(skip); withLocalRepo(localRepo); withRemoteData(remoteTag); }
@Override public String fetchHeadSha(GHRepository remoteRepo) throws IOException { GHTag tag = GitHubTag.findRemoteTag(remoteRepo, getName()); if (tag == null) { throw new IOException("No tag " + getName() + " in " + remoteRepo.getFullName()); } return tag.getCommit().getSHA1(); }
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) {
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; }
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; }
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); }
String commitHeadSha = this.testCommitExistence(git, prInformation.getHead().getSHA1(), step, build); String commitBaseSha = this.testCommitExistence(git, prInformation.getBase().getSHA1(), step, build); + prInformation.getHead().getSHA1() + ". Operation aborted."); return false; + prInformation.getBase().getSHA1() + ". Operation aborted."); return false;