Search in sources :

Example 71 with UsernamePasswordCredentialsProvider

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();
}
Also used : UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Git(org.eclipse.jgit.api.Git) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) File(java.io.File) TaskAction(org.gradle.api.tasks.TaskAction)

Example 72 with UsernamePasswordCredentialsProvider

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);
}
Also used : Participation(de.tum.in.www1.artemis.domain.Participation) Repository(de.tum.in.www1.artemis.domain.Repository) Ref(org.eclipse.jgit.lib.Ref) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Git(org.eclipse.jgit.api.Git) RevWalk(org.eclipse.jgit.revwalk.RevWalk) File(java.io.File) PullResult(org.eclipse.jgit.api.PullResult) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 73 with UsernamePasswordCredentialsProvider

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();
}
Also used : lombok.val(lombok.val) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) NetRCCredentialsProvider(org.eclipse.jgit.transport.NetRCCredentialsProvider) SneakyThrows(lombok.SneakyThrows)

Example 74 with UsernamePasswordCredentialsProvider

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);
    }
}
Also used : PullCommand(org.eclipse.jgit.api.PullCommand) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Git(org.eclipse.jgit.api.Git) IOException(java.io.IOException)

Example 75 with UsernamePasswordCredentialsProvider

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);
    }
}
Also used : UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Git(org.eclipse.jgit.api.Git) IOException(java.io.IOException) PushCommand(org.eclipse.jgit.api.PushCommand)

Aggregations

UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)75 Git (org.eclipse.jgit.api.Git)47 File (java.io.File)33 CredentialsProvider (org.eclipse.jgit.transport.CredentialsProvider)23 IOException (java.io.IOException)18 Test (org.junit.Test)18 CloneCommand (org.eclipse.jgit.api.CloneCommand)17 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)15 RepositoryModel (com.gitblit.models.RepositoryModel)12 PushResult (org.eclipse.jgit.transport.PushResult)12 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)9 FileOutputStream (java.io.FileOutputStream)8 PushCommand (org.eclipse.jgit.api.PushCommand)8 RevCommit (org.eclipse.jgit.revwalk.RevCommit)8 BufferedWriter (java.io.BufferedWriter)7 OutputStreamWriter (java.io.OutputStreamWriter)7 Date (java.util.Date)7 Ref (org.eclipse.jgit.lib.Ref)7 Repository (org.eclipse.jgit.lib.Repository)7 RefSpec (org.eclipse.jgit.transport.RefSpec)7