org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider Java Examples
The following examples show how to use
org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OldGitHubNotebookRepo.java From zeppelin with Apache License 2.0 | 7 votes |
private void pullFromRemoteStream() { try { LOG.debug("Pulling latest changes from remote stream"); PullCommand pullCommand = git.pull(); pullCommand.setCredentialsProvider( new UsernamePasswordCredentialsProvider( zeppelinConfiguration.getZeppelinNotebookGitUsername(), zeppelinConfiguration.getZeppelinNotebookGitAccessToken() ) ); pullCommand.call(); } catch (GitAPIException e) { LOG.error("Error when pulling latest changes from remote repository", e); } }
Example #2
Source File: GitUtils.java From submarine with Apache License 2.0 | 7 votes |
/** * To execute clone command * @param remotePath * @param localPath * @param token * @param branch * @throws GitAPIException */ public void clone(String remotePath, String localPath, String token, String branch) { // Clone the code base command // Sets the token on the remote server CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider("PRIVATE-TOKEN", token); Git git = null; try { git = Git.cloneRepository().setURI(remotePath) // Set remote URI .setBranch(branch) // Set the branch down from clone .setDirectory(new File(localPath)) // Set the download path .setCredentialsProvider(credentialsProvider) // Set permission validation .call(); } catch (GitAPIException e) { LOG.error(e.getMessage(), e); } finally { if (git != null) { git.close(); } } LOG.info("git.tag(): {}", git.tag()); }
Example #3
Source File: JGitOperator.java From verigreen with Apache License 2.0 | 6 votes |
public JGitOperator(String repositoryPath, String gitUser, String gitPassword) { try { // need to verify repo was created successfully - this is not enough /*if(!repositoryPath.contains("\\.git") && !repositoryPath.equals(".")) { repositoryPath=repositoryPath.concat("\\.git"); }*/ _repo = new FileRepository(repositoryPath); _git = new Git(_repo); if(gitUser != null) _cp = new UsernamePasswordCredentialsProvider(gitUser, gitPassword); } catch (IOException e) { throw new RuntimeException(String.format( "Failed creating git repository for path [%s]", repositoryPath), e); } }
Example #4
Source File: JGitTemplate.java From piper with Apache License 2.0 | 6 votes |
private synchronized Repository getRepository() { try { clear(); logger.info("Cloning {} {}", url,branch); Git git = Git.cloneRepository() .setURI(url) .setBranch(branch) .setDirectory(repositoryDir) .setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password)) .call(); return (git.getRepository()); } catch (Exception e) { throw Throwables.propagate(e); } }
Example #5
Source File: GithubApi.java From karamel with Apache License 2.0 | 6 votes |
/** * Synchronizes your updates on your local repository with github. * * @param owner * @param repoName * @throws KaramelException */ public synchronized static void commitPush(String owner, String repoName) throws KaramelException { if (email == null || user == null) { throw new KaramelException("You forgot to call registerCredentials. You must call this method first."); } File repoDir = getRepoDirectory(repoName); Git git = null; try { git = Git.open(repoDir); git.commit().setAuthor(user, email).setMessage("Code generated by Karamel.") .setAll(true).call(); git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)).call(); } catch (IOException | GitAPIException ex) { logger.error("error during github push", ex); throw new KaramelException(ex.getMessage()); } finally { if (git != null) { git.close(); } } }
Example #6
Source File: XdocPublisher.java From contribution with GNU Lesser General Public License v2.1 | 6 votes |
/** * Publish release notes. * * @throws IOException if problem with access to files appears. * @throws GitAPIException for problems with jgit. */ public void publish() throws IOException, GitAPIException { changeLocalRepoXdoc(); final FileRepositoryBuilder builder = new FileRepositoryBuilder(); final File localRepo = new File(localRepoPath); final Repository repo = builder.findGitDir(localRepo).readEnvironment().build(); final Git git = new Git(repo); git.add() .addFilepattern(PATH_TO_XDOC_IN_REPO) .call(); git.commit() .setMessage(String.format(Locale.ENGLISH, COMMIT_MESSAGE_TEMPLATE, releaseNumber)) .call(); if (doPush) { final CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(authToken, ""); git.push() .setCredentialsProvider(credentialsProvider) .call(); } }
Example #7
Source File: CloneRepositoryAdapter.java From coderadar with MIT License | 6 votes |
@Override public void cloneRepository(CloneRepositoryCommand cloneRepositoryCommand) throws UnableToCloneRepositoryException { try { // TODO: support progress monitoring CloneCommand cloneCommand = Git.cloneRepository() .setURI(cloneRepositoryCommand.getRemoteUrl()) .setDirectory(new File(cloneRepositoryCommand.getLocalDir())) .setBare(true); if (cloneRepositoryCommand.getUsername() != null && cloneRepositoryCommand.getPassword() != null) { cloneCommand.setCredentialsProvider( new UsernamePasswordCredentialsProvider( cloneRepositoryCommand.getUsername(), cloneRepositoryCommand.getPassword())); } cloneCommand.call().close(); } catch (GitAPIException e) { throw new UnableToCloneRepositoryException(e.getMessage()); } }
Example #8
Source File: RestGitBackupService.java From EDDI with Apache License 2.0 | 6 votes |
@Override public Response gitInit(String botId) { try { deleteFileIfExists(Paths.get(tmpPath + botId)); Path gitPath = Files.createDirectories(Paths.get(tmpPath + botId)); Git git = Git.cloneRepository() .setBranch(gitBranch) .setURI(gitUrl) .setCredentialsProvider(new UsernamePasswordCredentialsProvider(gitUsername, gitPassword)) .setDirectory(gitPath.toFile()) .call(); StoredConfig config = git.getRepository().getConfig(); config.setString( CONFIG_BRANCH_SECTION, "local-branch", "remote", gitBranch); config.setString( CONFIG_BRANCH_SECTION, "local-branch", "merge", "refs/heads/" + gitBranch ); config.save(); } catch (IOException | GitAPIException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(); } return Response.accepted().build(); }
Example #9
Source File: GitHubNotebookRepo.java From zeppelin with Apache License 2.0 | 6 votes |
private void pushToRemoteSteam() { try { LOG.debug("Pushing latest changes to remote stream"); PushCommand pushCommand = git.push(); pushCommand.setCredentialsProvider( new UsernamePasswordCredentialsProvider( zeppelinConfiguration.getZeppelinNotebookGitUsername(), zeppelinConfiguration.getZeppelinNotebookGitAccessToken() ) ); pushCommand.call(); } catch (GitAPIException e) { LOG.error("Error when pushing latest changes to remote repository", e); } }
Example #10
Source File: JGitUtil.java From mcg-helper with Apache License 2.0 | 6 votes |
public static boolean cloneRepository(String remoteUrl, String branch, String projectPath, String user, String pwd) throws InvalidRemoteException, TransportException, GitAPIException { File projectDir = new File(projectPath); UsernamePasswordCredentialsProvider provider = new UsernamePasswordCredentialsProvider(user, pwd); try (Git git = Git.cloneRepository() .setURI(remoteUrl) .setBranch(branch) .setDirectory(projectDir) .setCredentialsProvider(provider) .setProgressMonitor(new CloneProgressMonitor()) .call()) { } return true; }
Example #11
Source File: StudioNodeSyncGlobalRepoTask.java From studio with GNU General Public License v3.0 | 6 votes |
private <T extends TransportCommand> void configureBasicAuthentication( ClusterMember remoteNode, T gitCommand, TextEncryptor encryptor, boolean sshProtocol) throws CryptoException { String password = encryptor.decrypt(remoteNode.getGitPassword()); UsernamePasswordCredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider( remoteNode.getGitUsername(), password); if (sshProtocol) { gitCommand.setTransportConfigCallback(transport -> { SshTransport sshTransport = (SshTransport) transport; sshTransport.setSshSessionFactory(new StrictHostCheckingOffSshSessionFactory() { @Override protected void configure(OpenSshConfig.Host host, Session session) { super.configure(host, session); session.setPassword(password); } }); }); } gitCommand.setCredentialsProvider(credentialsProvider); }
Example #12
Source File: GitService.java From Refactoring-Bot with MIT License | 6 votes |
/** * This method fetches data from the 'upstrem' remote. * * @param gitConfig * @throws GitWorkflowException */ public void fetchRemote(GitConfiguration gitConfig) throws GitWorkflowException { try (Git git = Git.open(new File(botConfig.getBotRefactoringDirectory() + gitConfig.getConfigurationId()))) { // Fetch data if (gitConfig.getRepoService().equals(FileHoster.github)) { git.fetch().setRemote("upstream") .setCredentialsProvider(new UsernamePasswordCredentialsProvider(gitConfig.getBotToken(), "")) .call(); } else { git.fetch().setRemote("upstream").setCredentialsProvider( new UsernamePasswordCredentialsProvider(gitConfig.getBotName(), gitConfig.getBotToken())) .call(); } } catch (Exception e) { logger.error(e.getMessage(), e); throw new GitWorkflowException("Could not fetch data from 'upstream'!"); } }
Example #13
Source File: GitUtilities.java From carbon-commons with Apache License 2.0 | 6 votes |
/** * Creates and return a UsernamePasswordCredentialsProvider instance for a tenant * * @param tenantId tenant Id * @param repositoryManager RepositoryManager instance * @return UsernamePasswordCredentialsProvider instance or null if username/password is not valid */ public static UsernamePasswordCredentialsProvider createCredentialsProvider (RepositoryManager repositoryManager, int tenantId) { RepositoryInformation repoInfo = repositoryManager.getCredentialsInformation(tenantId); if(repoInfo == null) { return null; } String userName = repoInfo.getUserName(); String password = repoInfo.getPassword(); if (userName!= null && password != null) { return new UsernamePasswordCredentialsProvider(userName, password); } else { return new UsernamePasswordCredentialsProvider("", ""); } }
Example #14
Source File: GitBasedArtifactRepository.java From carbon-commons with Apache License 2.0 | 6 votes |
/** * Pushes the artifacts of the tenant to relevant remote repository * * @param gitRepoCtx TenantGitRepositoryContext instance for the tenant */ private void pushToRemoteRepo(TenantGitRepositoryContext gitRepoCtx) { PushCommand pushCmd = gitRepoCtx.getGit().push(); UsernamePasswordCredentialsProvider credentialsProvider = GitUtilities.createCredentialsProvider(repositoryManager, gitRepoCtx.getTenantId()); if (credentialsProvider == null) { log.warn ("Remote repository credentials not available for tenant " + gitRepoCtx.getTenantId() + ", aborting push"); return; } pushCmd.setCredentialsProvider(credentialsProvider); try { pushCmd.call(); } catch (GitAPIException e) { log.error("Pushing artifacts to remote repository failed for tenant " + gitRepoCtx.getTenantId(), e); } }
Example #15
Source File: GitHubNotebookRepo.java From zeppelin with Apache License 2.0 | 6 votes |
private void pullFromRemoteStream() { try { LOG.debug("Pulling latest changes from remote stream"); PullCommand pullCommand = git.pull(); pullCommand.setCredentialsProvider( new UsernamePasswordCredentialsProvider( zeppelinConfiguration.getZeppelinNotebookGitUsername(), zeppelinConfiguration.getZeppelinNotebookGitAccessToken() ) ); pullCommand.call(); } catch (GitAPIException e) { LOG.error("Error when pulling latest changes from remote repository", e); } }
Example #16
Source File: GitBasedArtifactRepository.java From attic-stratos with Apache License 2.0 | 6 votes |
/** * Pushes the artifacts of the tenant to relevant remote repository * * @param gitRepoCtx RepositoryContext instance for the tenant */ private void pushToRemoteRepo(RepositoryContext gitRepoCtx) { PushCommand pushCmd = gitRepoCtx.getGit().push(); if (!gitRepoCtx.getKeyBasedAuthentication()) { UsernamePasswordCredentialsProvider credentialsProvider = createCredentialsProvider(gitRepoCtx); if (credentialsProvider != null) pushCmd.setCredentialsProvider(credentialsProvider); } try { pushCmd.call(); if (log.isDebugEnabled()) { log.debug("Pushed artifacts for tenant : " + gitRepoCtx.getTenantId()); } } catch (GitAPIException e) { log.error("Pushing artifacts to remote repository failed for tenant " + gitRepoCtx.getTenantId(), e); } }
Example #17
Source File: GitProctorCore.java From proctor with Apache License 2.0 | 6 votes |
/** * clones from the git URL to local workspace * @param gitUrl remote git url from which to clone * @param username * @param password * @param testDefinitionsDirectory typically matrices/test-definitions * @param workspaceProvider where local non-bare copy will be cloned to (unless exists) * @param pullPushTimeoutSeconds * @param cloneTimeoutSeconds * @param cleanInitialization * @param branchName */ public GitProctorCore(final String gitUrl, final String username, final String password, final String testDefinitionsDirectory, final GitWorkspaceProvider workspaceProvider, final int pullPushTimeoutSeconds, final int cloneTimeoutSeconds, final boolean cleanInitialization, @Nullable final String branchName) { this.gitUrl = gitUrl; this.refName = Constants.HEAD; this.workspaceProvider = Preconditions .checkNotNull(workspaceProvider, "GitWorkspaceProvider should not be null"); this.username = username; this.password = password; user = new UsernamePasswordCredentialsProvider(username, password); this.testDefinitionsDirectory = testDefinitionsDirectory; gcExecutor = Executors.newSingleThreadScheduledExecutor(); this.pullPushTimeoutSeconds = pullPushTimeoutSeconds; this.cloneTimeoutSeconds = cloneTimeoutSeconds; this.branchName = branchName; this.gitAPIExceptionWrapper = new GitAPIExceptionWrapper(); this.gitAPIExceptionWrapper.setGitUrl(gitUrl); initializeRepository(cleanInitialization); }
Example #18
Source File: GitService.java From Refactoring-Bot with MIT License | 6 votes |
/** * This method clones an repository with its git url. * * @param gitConfig * @throws GitWorkflowException */ public void cloneRepository(GitConfiguration gitConfig) throws GitWorkflowException { Git git = null; try { if (gitConfig.getRepoService().equals(FileHoster.github)) { git = Git.cloneRepository().setURI(gitConfig.getForkGitLink()) .setDirectory(new File(botConfig.getBotRefactoringDirectory() + gitConfig.getConfigurationId())) .setCredentialsProvider(new UsernamePasswordCredentialsProvider(gitConfig.getBotToken(), "")) .call(); } else { git = Git.cloneRepository().setURI(gitConfig.getForkGitLink()) .setDirectory(new File(botConfig.getBotRefactoringDirectory() + gitConfig.getConfigurationId())) .setCredentialsProvider(new UsernamePasswordCredentialsProvider(gitConfig.getBotName(), gitConfig.getBotToken())) .call(); } } catch (Exception e) { logger.error(e.getMessage(), e); throw new GitWorkflowException("Faild to clone " + "'" + gitConfig.getForkGitLink() + "' successfully!"); } finally { // Close git if possible if (git != null) { git.close(); } } }
Example #19
Source File: OldGitHubNotebookRepo.java From zeppelin with Apache License 2.0 | 6 votes |
private void pushToRemoteSteam() { try { LOG.debug("Pushing latest changes to remote stream"); PushCommand pushCommand = git.push(); pushCommand.setCredentialsProvider( new UsernamePasswordCredentialsProvider( zeppelinConfiguration.getZeppelinNotebookGitUsername(), zeppelinConfiguration.getZeppelinNotebookGitAccessToken() ) ); pushCommand.call(); } catch (GitAPIException e) { LOG.error("Error when pushing latest changes to remote repository", e); } }
Example #20
Source File: GHRule.java From github-integration-plugin with MIT License | 5 votes |
public void pushAll() throws GitAPIException { git.push() .setPushAll() .setProgressMonitor(new TextProgressMonitor()) .setCredentialsProvider(new UsernamePasswordCredentialsProvider(GH_TOKEN, "")) .call(); }
Example #21
Source File: GHRule.java From github-integration-plugin with MIT License | 5 votes |
public void commitFileToBranch(String branch, String fileName, String content, String commitMessage) throws IOException, GitAPIException { final String beforeBranch = git.getRepository().getBranch(); final List<Ref> refList = git.branchList().call(); boolean exist = false; for (Ref ref : refList) { if (ref.getName().endsWith(branch)) { exist = true; break; } } if (!exist) { git.branchCreate().setName(branch).call(); } git.checkout().setName(branch).call(); writeStringToFile(new File(gitRootDir, fileName), content); git.add().addFilepattern(".").call(); git.commit().setAll(true).setMessage(commitMessage).call(); git.push() .setPushAll() .setProgressMonitor(new TextProgressMonitor()) .setCredentialsProvider(new UsernamePasswordCredentialsProvider(GH_TOKEN, "")) .call(); git.checkout().setName(beforeBranch).call(); await().pollInterval(3, SECONDS) .timeout(120, SECONDS) .until(ghBranchAppeared(getGhRepo(), branch)); }
Example #22
Source File: GitCredentialsProviderFactoryTests.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Test public void testCreateForAwsDisabled() { this.factory.setAwsCodeCommitEnabled(false); CredentialsProvider provider = this.factory.createFor(AWS_REPO, null, null, null, false); assertThat(provider).isNull(); provider = this.factory.createFor(AWS_REPO, USER, PASSWORD, null, false); assertThat(provider).isNotNull(); assertThat(provider instanceof UsernamePasswordCredentialsProvider).isTrue(); }
Example #23
Source File: GitLabIT.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
private String initGitLabProject(String url, boolean addFeatureBranch) throws GitAPIException, IOException { // Setup git repository Git.init().setDirectory(tmp.getRoot()).call(); Git git = Git.open(tmp.getRoot()); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", url); config.save(); // Setup remote master branch tmp.newFile("test"); git.add().addFilepattern("test"); RevCommit commit = git.commit().setMessage("test").call(); git.push() .setRemote("origin").add("master") .setCredentialsProvider(new UsernamePasswordCredentialsProvider(gitlab.getUsername(), gitlab.getPassword())) .call(); if (addFeatureBranch) { // Setup remote feature branch git.checkout().setName("feature").setCreateBranch(true).call(); tmp.newFile("feature"); commit = git.commit().setMessage("feature").call(); git.push().setRemote("origin").add("feature").setCredentialsProvider(new UsernamePasswordCredentialsProvider(gitlab.getUsername(), gitlab.getPassword())) .call(); } return commit.getName(); }
Example #24
Source File: JGitEnvironmentRepositoryTests.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Test public void usernamePasswordShouldSetCredentials() throws Exception { Git mockGit = mock(Git.class); MockCloneCommand mockCloneCommand = new MockCloneCommand(mockGit); JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository( this.environment, new JGitEnvironmentProperties()); envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand)); envRepository.setUri("git+ssh://git@somegitserver/somegitrepo"); envRepository.setBasedir(new File("./mybasedir")); final String username = "someuser"; final String password = "mypassword"; envRepository.setUsername(username); envRepository.setPassword(password); envRepository.setCloneOnStart(true); envRepository.afterPropertiesSet(); assertTrue(mockCloneCommand .getCredentialsProvider() instanceof UsernamePasswordCredentialsProvider); CredentialsProvider provider = mockCloneCommand.getCredentialsProvider(); CredentialItem.Username usernameCredential = new CredentialItem.Username(); CredentialItem.Password passwordCredential = new CredentialItem.Password(); assertThat(provider.supports(usernameCredential)).isTrue(); assertThat(provider.supports(passwordCredential)).isTrue(); provider.get(new URIish(), usernameCredential); assertThat(username).isEqualTo(usernameCredential.getValue()); provider.get(new URIish(), passwordCredential); assertThat(password).isEqualTo(String.valueOf(passwordCredential.getValue())); }
Example #25
Source File: JGitEnvironmentRepositoryTests.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Test public void gitCredentialsProviderFactoryCreatesUsernamePasswordProvider() throws Exception { Git mockGit = mock(Git.class); MockCloneCommand mockCloneCommand = new MockCloneCommand(mockGit); final String username = "someuser"; final String password = "mypassword"; JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository( this.environment, new JGitEnvironmentProperties()); envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand)); envRepository.setUri("git+ssh://git@somegitserver/somegitrepo"); envRepository.setBasedir(new File("./mybasedir")); envRepository.setUsername(username); envRepository.setPassword(password); envRepository.setCloneOnStart(true); envRepository.afterPropertiesSet(); assertTrue(mockCloneCommand .getCredentialsProvider() instanceof UsernamePasswordCredentialsProvider); CredentialsProvider provider = mockCloneCommand.getCredentialsProvider(); CredentialItem.Username usernameCredential = new CredentialItem.Username(); CredentialItem.Password passwordCredential = new CredentialItem.Password(); assertThat(provider.supports(usernameCredential)).isTrue(); assertThat(provider.supports(passwordCredential)).isTrue(); provider.get(new URIish(), usernameCredential); assertThat(username).isEqualTo(usernameCredential.getValue()); provider.get(new URIish(), passwordCredential); assertThat(password).isEqualTo(String.valueOf(passwordCredential.getValue())); }
Example #26
Source File: GitCredentialsProviderFactoryTests.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Test public void testCreateForFileWithUsername() { CredentialsProvider provider = this.factory.createFor(FILE_REPO, USER, PASSWORD, null, false); assertThat(provider).isNotNull(); assertThat(provider instanceof UsernamePasswordCredentialsProvider).isTrue(); }
Example #27
Source File: TutorialPublishTask.java From aeron with Apache License 2.0 | 5 votes |
@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(); }
Example #28
Source File: GitCredentialsProviderFactoryTests.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Test public void testCreateForSshServerWithSkipSslValidation() { CredentialsProvider provider = this.factory.createFor(SSH_GIT_REPO, USER, PASSWORD, null, true); assertThat(provider).isNotNull(); assertThat(provider instanceof UsernamePasswordCredentialsProvider).isTrue(); }
Example #29
Source File: GitCredentialsProviderFactoryTests.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Test public void testCreateForHttpsServerWithoutSpecifyingSkipSslValidation() { CredentialsProvider provider = this.factory.createFor(HTTPS_GIT_REPO, USER, PASSWORD, null); assertThat(provider).isNotNull(); assertThat(provider instanceof UsernamePasswordCredentialsProvider) .as("deprecated createFor() should not enable ssl validation skipping") .isTrue(); }
Example #30
Source File: GithubApi.java From karamel with Apache License 2.0 | 5 votes |
public synchronized static void removeFile(String owner, String repoName, String fileName) throws KaramelException { File repoDir = getRepoDirectory(repoName); Git git = null; try { git = Git.open(repoDir); new File(repoDir + File.separator + fileName).delete(); git.add().addFilepattern(fileName).call(); git.commit().setAuthor(user, email).setMessage("File removed by Karamel.") .setAll(true).call(); git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)).call(); RepoItem toRemove = null; List<RepoItem> repos = cachedRepos.get(owner); for (RepoItem r : repos) { if (r.getName().compareToIgnoreCase(repoName) == 0) { toRemove = r; } } if (toRemove != null) { repos.remove(toRemove); } } catch (IOException | GitAPIException ex) { throw new KaramelException(ex.getMessage()); } finally { if (git != null) { git.close(); } } }