use of org.eclipse.jgit.storage.file.FileRepositoryBuilder in project zaproxy by zaproxy.
the class CreateTagAndGitHubRelease method createTag.
private void createTag() throws Exception {
Repository repository = new FileRepositoryBuilder().setGitDir(new File(getProject().getRootDir(), ".git")).build();
try (Git git = new Git(repository)) {
URIish originUri = new URIish(GITHUB_BASE_URL + getRepo().get());
git.remoteSetUrl().setRemoteName(GIT_REMOTE_ORIGIN).setRemoteUri(originUri).call();
GitHubUser ghUser = getUser().get();
PersonIdent personIdent = new PersonIdent(ghUser.getName(), ghUser.getEmail());
Ref tag = git.tag().setName(getTag().get()).setMessage(getTagMessage().get()).setAnnotated(true).setTagger(personIdent).call();
git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(ghUser.getName(), ghUser.getAuthToken())).add(tag).call();
}
}
use of org.eclipse.jgit.storage.file.FileRepositoryBuilder in project zaproxy by zaproxy.
the class GradleBuildWithGitRepos method buildWeeklyAddOns.
@TaskAction
public void buildWeeklyAddOns() throws GitAPIException, IOException {
Path reposDir = repositoriesDirectory.get().getAsFile().toPath();
List<RepoData> reposData = readRepoData();
for (RepoData repoData : reposData) {
String cloneUrl = repoData.getCloneUrl();
String repoName = extractRepoName(cloneUrl);
Path repoDir = reposDir.resolve(repoName);
if (Files.notExists(repoDir)) {
if (!cloneRepositories.get()) {
getLogger().warn("The directory {} does not exist, the {} add-on(s) will not be built.", repoDir, repoName);
continue;
}
getProject().mkdir(reposDir);
// XXX Rely just on JGit once it supports depth arg:
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=475615
getProject().exec(spec -> {
spec.setWorkingDir(reposDir);
spec.setExecutable("git");
spec.setEnvironment(Collections.emptyMap());
List<String> execArgs = new ArrayList<>();
execArgs.add("clone");
if (quiet.get()) {
execArgs.add("-q");
}
String branch = repoData.getBranch();
if (branch != null && !branch.isEmpty()) {
execArgs.add("--branch");
execArgs.add(branch);
}
execArgs.add("--depth");
execArgs.add("1");
execArgs.add(cloneUrl);
execArgs.add(repoName);
spec.args(execArgs);
}).assertNormalExitValue();
getLogger().lifecycle("Cloned {} into {}", cloneUrl, repoDir);
} else if (updateRepositories.get()) {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(repoDir.resolve(".git").toFile()).build();
try (Git git = new Git(repository)) {
git.pull().call();
getLogger().lifecycle("Pulled from {} into {}", cloneUrl, repoDir);
}
}
List<String> projects = repoData.getProjects() == null || repoData.getProjects().isEmpty() ? Arrays.asList("") : repoData.getProjects();
if (clean.get()) {
// Execute clean separately to avoid Gradle issue:
// https://github.com/gradle/gradle/issues/2488
getLogger().lifecycle("Running clean task for {}", repoDir.getFileName());
runGradle(repoDir, Arrays.asList("clean"));
}
runTasks(repoDir, projects);
}
}
use of org.eclipse.jgit.storage.file.FileRepositoryBuilder in project zaproxy by zaproxy.
the class CreatePullRequest method pullRequest.
@TaskAction
public void pullRequest() throws Exception {
GitHubRepo ghRepo = getRepo().get();
Repository repository = new FileRepositoryBuilder().setGitDir(new File(ghRepo.getDir(), ".git")).build();
try (Git git = new Git(repository)) {
if (git.status().call().getModified().isEmpty()) {
return;
}
GitHubUser ghUser = getUser().get();
URIish originUri = new URIish(GITHUB_BASE_URL + ghUser.getName() + "/" + ghRepo.getName());
git.remoteSetUrl().setRemoteName(GIT_REMOTE_ORIGIN).setRemoteUri(originUri).call();
git.checkout().setCreateBranch(true).setName(getBranchName().get()).setStartPoint(GIT_REMOTE_ORIGIN + "/" + baseBranchName.get()).call();
PersonIdent personIdent = new PersonIdent(ghUser.getName(), ghUser.getEmail());
git.commit().setAll(true).setSign(false).setAuthor(personIdent).setCommitter(personIdent).setMessage(getCommitSummary().get() + "\n\n" + getCommitDescription().get() + signedOffBy(personIdent)).call();
git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(ghUser.getName(), ghUser.getAuthToken())).setForce(true).add(getBranchName().get()).call();
GHRepository ghRepository = GitHub.connect(ghUser.getName(), ghUser.getAuthToken()).getRepository(ghRepo.toString());
List<GHPullRequest> pulls = ghRepository.queryPullRequests().base(baseBranchName.get()).head(ghUser.getName() + ":" + getBranchName().get()).state(GHIssueState.OPEN).list().asList();
String description = getPullRequestDescription().getOrElse(getCommitDescription().get());
if (pulls.isEmpty()) {
String title = getPullRequestTitle().getOrElse(getCommitSummary().get());
createPullRequest(ghRepository, title, description);
} else {
pulls.get(0).setBody(description);
}
}
}
use of org.eclipse.jgit.storage.file.FileRepositoryBuilder in project gitblit by gitblit.
the class GitBlitSuite method getRepository.
private static Repository getRepository(String name) {
try {
File gitDir = FileKey.resolve(new File(REPOSITORIES, name), FS.DETECTED);
Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
return repository;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of org.eclipse.jgit.storage.file.FileRepositoryBuilder in project gitblit by gitblit.
the class GitServletTest method testPushLog.
@Test
public void testPushLog() throws IOException {
String name = "refchecks/ticgit.git";
File refChecks = new File(GitBlitSuite.REPOSITORIES, name);
Repository repository = new FileRepositoryBuilder().setGitDir(refChecks).build();
List<RefLogEntry> pushes = RefLogUtils.getRefLog(name, repository);
GitBlitSuite.close(repository);
assertTrue("Repository has an empty push log!", pushes.size() > 0);
}
Aggregations