use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project Aeron by real-logic.
the class TutorialPublishTask method publish.
/**
* Task action implementation.
*
* @throws Exception in case of errors.
*/
@TaskAction
public void publish() throws Exception {
final String wikiUri = getWikiUri();
final File directory = new File(getProject().getBuildDir(), "tmp/tutorialPublish");
// Use Personal Access Token or GITHUB_TOKEN for workflows
final CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(apiKey, "");
final Git git = Git.cloneRepository().setURI(wikiUri).setCredentialsProvider(credentialsProvider).setDirectory(directory).call();
final File[] asciidocFiles = AsciidocUtil.filterAsciidocFiles(source);
System.out.println("Publishing from: " + source);
System.out.println("Found files: " + Arrays.stream(asciidocFiles).map(File::getName).collect(joining(", ")));
for (final File asciidocFile : asciidocFiles) {
Files.copy(asciidocFile.toPath(), new File(directory, asciidocFile.getName()).toPath(), StandardCopyOption.REPLACE_EXISTING);
}
git.add().addFilepattern(".").setUpdate(false).call();
git.commit().setMessage("Update Docs").call();
System.out.println("Publishing to: " + wikiUri);
git.push().setCredentialsProvider(credentialsProvider).call();
}
use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project ArTEMiS by ls1intum.
the class GitServiceIntTest method testPull.
@Test
public void testPull() throws IOException, GitAPIException {
Participation participation = new Participation();
participation.setRepositoryUrl(remoteTestRepo);
Repository repo = gitService.getOrCheckoutRepository(participation);
Ref oldHead = repo.findRef("HEAD");
// commit
File tempDir = Files.createTempDir();
Git git = Git.cloneRepository().setURI(remoteTestRepo).setCredentialsProvider(new UsernamePasswordCredentialsProvider(GIT_USER, GIT_PASSWORD)).setDirectory(tempDir).call();
git.commit().setMessage("a commit").setAllowEmpty(true).call();
git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(GIT_USER, GIT_PASSWORD)).call();
// pull
PullResult pullResult = gitService.pull(repo);
Ref newHead = repo.findRef("HEAD");
assertThat(oldHead).isNotEqualTo(newHead);
RevWalk walk = new RevWalk(repo);
RevCommit commit = walk.parseCommit(newHead.getObjectId());
assertThat(commit.getFullMessage()).isEqualTo("a commit");
FileUtils.deleteDirectory(tempDir);
}
use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project cas by apereo.
the class GitRepositoryBuilder method newInstance.
/**
* New instance of git repository builder.
*
* @param props the registry
* @return the git repository builder
*/
@SneakyThrows
public static GitRepositoryBuilder newInstance(final BaseGitProperties props) {
val resolver = SpringExpressionLanguageValueResolver.getInstance();
val builder = GitRepositoryBuilder.builder().repositoryUri(resolver.resolve(props.getRepositoryUrl())).activeBranch(resolver.resolve(props.getActiveBranch())).branchesToClone(props.getBranchesToClone()).repositoryDirectory(props.getCloneDirectory().getLocation()).privateKeyPassphrase(props.getPrivateKeyPassphrase()).sshSessionPassword(props.getSshSessionPassword()).timeoutInSeconds(Beans.newDuration(props.getTimeout()).toSeconds()).signCommits(props.isSignCommits()).clearExistingIdentities(props.isClearExistingIdentities()).strictHostKeyChecking(props.isStrictHostKeyChecking()).httpClientType(props.getHttpClientType());
if (StringUtils.hasText(props.getUsername())) {
val providers = CollectionUtils.wrapList(new UsernamePasswordCredentialsProvider(props.getUsername(), props.getPassword()), new NetRCCredentialsProvider());
builder.credentialsProviders(providers);
}
if (props.getPrivateKey().getLocation() != null) {
val resource = ResourceUtils.prepareClasspathResourceIfNeeded(props.getPrivateKey().getLocation());
if (resource != null && resource.exists()) {
builder.privateKeyPath(resource.getFile().getCanonicalPath());
}
}
return builder.build();
}
use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project winery by eclipse.
the class GitBasedRepository method pull.
public void pull() throws GitAPIException {
try (Git git = getGit()) {
PullCommand pull = git.pull();
if (Environments.getInstance().getGitConfig().getAccessToken() != null) {
pull.setCredentialsProvider(new UsernamePasswordCredentialsProvider(Environments.getInstance().getGitConfig().getAccessToken(), ""));
}
pull.call();
pull.getRepository().close();
} catch (IOException e) {
LOGGER.error("Error pulling Repository.", e);
}
}
use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project winery by eclipse.
the class GitBasedRepository method push.
public void push() throws GitAPIException {
try (Git git = getGit()) {
PushCommand push = git.push();
if (Environments.getInstance().getGitConfig().getAccessToken() != null) {
push.setCredentialsProvider(new UsernamePasswordCredentialsProvider(Environments.getInstance().getGitConfig().getAccessToken(), ""));
}
push.call();
push.getRepository().close();
} catch (IOException e) {
LOGGER.error("Error pushing Repository.", e);
}
}
Aggregations