@Test public void should_push_changes_to_current_branch_using_root_credentials() throws Exception { StubRunnerOptions options = new StubRunnerOptionsBuilder() .withStubRepositoryRoot("file: .withStubsMode(StubRunnerProperties.StubsMode.REMOTE).withUsername("foo").withPassword("bar").build(); ContractProjectUpdater updater = new ContractProjectUpdater(options); File stubs = new File(GitRepoTests.class.getResource("/git_samples/sample_stubs").toURI()); updater.updateContractProject("hello-world", stubs.toPath()); try (Git git = openGitProject(this.project)) { RevCommit revCommit = git.log().call().iterator().next(); then(revCommit.getShortMessage()).isEqualTo("Updating project [hello-world] with stubs"); git.reset().setMode(ResetCommand.ResetType.HARD).call(); } BDDAssertions.then(new File(this.project, "META-INF/com.example/hello-world/0.0.2/mappings/someMapping.json")) .exists(); BDDAssertions.then(this.outputCapture.toString()) .contains("Passed username and password - will set a custom credentials provider"); }
public void updateContractProject(String projectName, Path rootStubsFolder) { File clonedRepo = this.gitContractsRepo.clonedRepo(this.stubRunnerOptions.stubRepositoryRoot); GitStubDownloaderProperties properties = new GitStubDownloaderProperties( this.stubRunnerOptions.stubRepositoryRoot, this.stubRunnerOptions); copyStubs(projectName, rootStubsFolder, clonedRepo); GitRepo gitRepo = new GitRepo(clonedRepo, properties); String msg = StubRunnerPropertyUtils.getProperty(this.stubRunnerOptions.getProperties(), GIT_COMMIT_MESSAGE); GitRepo.CommitResult commit = gitRepo.commit(clonedRepo, commitMessage(projectName, msg)); if (commit == GitRepo.CommitResult.EMPTY) { log.info("There were no changes to commit. Won't push the changes"); return; } String attempts = StubRunnerPropertyUtils.getProperty(this.stubRunnerOptions.getProperties(), GIT_ATTEMPTS_NO_PROP); int intAttempts = StringUtils.hasText(attempts) ? Integer.parseInt(attempts) : DEFAULT_ATTEMPTS_NO; String wait = StubRunnerPropertyUtils.getProperty(this.stubRunnerOptions.getProperties(), GIT_WAIT_BETWEEN_ATTEMPTS); long longWait = StringUtils.hasText(wait) ? Long.parseLong(wait) : DEFAULT_WAIT_BETWEEN_ATTEMPTS; tryToPushCurrentBranch(clonedRepo, gitRepo, intAttempts, longWait); }
ContractProjectUpdater { public void updateContractProject(String projectName, Path rootStubsFolder) { File clonedRepo = this.gitContractsRepo.clonedRepo(this.stubRunnerOptions.stubRepositoryRoot); GitStubDownloaderProperties properties = new GitStubDownloaderProperties( this.stubRunnerOptions.stubRepositoryRoot, this.stubRunnerOptions); copyStubs(projectName, rootStubsFolder, clonedRepo); GitRepo gitRepo = new GitRepo(clonedRepo, properties); String msg = StubRunnerPropertyUtils.getProperty(this.stubRunnerOptions.getProperties(), GIT_COMMIT_MESSAGE); GitRepo.CommitResult commit = gitRepo.commit(clonedRepo, commitMessage(projectName, msg)); if (commit == GitRepo.CommitResult.EMPTY) { log.info("There were no changes to commit. Won't push the changes"); return; } String attempts = StubRunnerPropertyUtils.getProperty(this.stubRunnerOptions.getProperties(), GIT_ATTEMPTS_NO_PROP); int intAttempts = StringUtils.hasText(attempts) ? Integer.parseInt(attempts) : DEFAULT_ATTEMPTS_NO; String wait = StubRunnerPropertyUtils.getProperty(this.stubRunnerOptions.getProperties(), GIT_WAIT_BETWEEN_ATTEMPTS); long longWait = StringUtils.hasText(wait) ? Long.parseLong(wait) : DEFAULT_WAIT_BETWEEN_ATTEMPTS; tryToPushCurrentBranch(clonedRepo, gitRepo, intAttempts, longWait); } }
ContractProjectUpdater { public void updateContractProject(String projectName, Path rootStubsFolder) { File clonedRepo = this.gitContractsRepo.clonedRepo(this.stubRunnerOptions.stubRepositoryRoot); GitStubDownloaderProperties properties = new GitStubDownloaderProperties( this.stubRunnerOptions.stubRepositoryRoot, this.stubRunnerOptions); copyStubs(projectName, rootStubsFolder, clonedRepo); GitRepo gitRepo = new GitRepo(clonedRepo, properties); String msg = StubRunnerPropertyUtils.getProperty(this.stubRunnerOptions.getProperties(), GIT_COMMIT_MESSAGE); GitRepo.CommitResult commit = gitRepo.commit(clonedRepo, commitMessage(projectName, msg)); if (commit == GitRepo.CommitResult.EMPTY) { log.info("There were no changes to commit. Won't push the changes"); return; } String attempts = StubRunnerPropertyUtils.getProperty(this.stubRunnerOptions.getProperties(), GIT_ATTEMPTS_NO_PROP); int intAttempts = StringUtils.hasText(attempts) ? Integer.parseInt(attempts) : DEFAULT_ATTEMPTS_NO; String wait = StubRunnerPropertyUtils.getProperty(this.stubRunnerOptions.getProperties(), GIT_WAIT_BETWEEN_ATTEMPTS); long longWait = StringUtils.hasText(wait) ? Long.parseLong(wait) : DEFAULT_WAIT_BETWEEN_ATTEMPTS; tryToPushCurrentBranch(clonedRepo, gitRepo, intAttempts, longWait); } ContractProjectUpdater(StubRunnerOptions stubRunnerOptions); }
ContractProjectUpdater { public void updateContractProject(String projectName, Path rootStubsFolder) { File clonedRepo = this.gitContractsRepo.clonedRepo(this.stubRunnerOptions.stubRepositoryRoot); GitStubDownloaderProperties properties = new GitStubDownloaderProperties( this.stubRunnerOptions.stubRepositoryRoot, this.stubRunnerOptions); copyStubs(projectName, rootStubsFolder, clonedRepo); GitRepo gitRepo = new GitRepo(clonedRepo, properties); String msg = StubRunnerPropertyUtils.getProperty(this.stubRunnerOptions.getProperties(), GIT_COMMIT_MESSAGE); GitRepo.CommitResult commit = gitRepo.commit(clonedRepo, commitMessage(projectName, msg)); if (commit == GitRepo.CommitResult.EMPTY) { log.info("There were no changes to commit. Won't push the changes"); return; } String attempts = StubRunnerPropertyUtils.getProperty(this.stubRunnerOptions.getProperties(), GIT_ATTEMPTS_NO_PROP); int intAttempts = StringUtils.hasText(attempts) ? Integer.parseInt(attempts) : DEFAULT_ATTEMPTS_NO; String wait = StubRunnerPropertyUtils.getProperty(this.stubRunnerOptions.getProperties(), GIT_WAIT_BETWEEN_ATTEMPTS); long longWait = StringUtils.hasText(wait) ? Long.parseLong(wait) : DEFAULT_WAIT_BETWEEN_ATTEMPTS; tryToPushCurrentBranch(clonedRepo, gitRepo, intAttempts, longWait); } ContractProjectUpdater(StubRunnerOptions stubRunnerOptions); void updateContractProject(String projectName, Path rootStubsFolder); }
ContractProjectUpdater { public void updateContractProject(String projectName, Path rootStubsFolder) { File clonedRepo = this.gitContractsRepo.clonedRepo(this.stubRunnerOptions.stubRepositoryRoot); GitStubDownloaderProperties properties = new GitStubDownloaderProperties( this.stubRunnerOptions.stubRepositoryRoot, this.stubRunnerOptions); copyStubs(projectName, rootStubsFolder, clonedRepo); GitRepo gitRepo = new GitRepo(clonedRepo, properties); String msg = StubRunnerPropertyUtils.getProperty(this.stubRunnerOptions.getProperties(), GIT_COMMIT_MESSAGE); GitRepo.CommitResult commit = gitRepo.commit(clonedRepo, commitMessage(projectName, msg)); if (commit == GitRepo.CommitResult.EMPTY) { log.info("There were no changes to commit. Won't push the changes"); return; } String attempts = StubRunnerPropertyUtils.getProperty(this.stubRunnerOptions.getProperties(), GIT_ATTEMPTS_NO_PROP); int intAttempts = StringUtils.hasText(attempts) ? Integer.parseInt(attempts) : DEFAULT_ATTEMPTS_NO; String wait = StubRunnerPropertyUtils.getProperty(this.stubRunnerOptions.getProperties(), GIT_WAIT_BETWEEN_ATTEMPTS); long longWait = StringUtils.hasText(wait) ? Long.parseLong(wait) : DEFAULT_WAIT_BETWEEN_ATTEMPTS; tryToPushCurrentBranch(clonedRepo, gitRepo, intAttempts, longWait); } ContractProjectUpdater(StubRunnerOptions stubRunnerOptions); void updateContractProject(String projectName, Path rootStubsFolder);  }