ForkableRepoValidator { protected boolean hasNoChanges(GHContent content, GitForkBranch gitForkBranch) { try (InputStream stream = content.read(); InputStreamReader streamR = new InputStreamReader(stream); BufferedReader reader = new BufferedReader(streamR)) { String line; while ( (line = reader.readLine()) != null ) { if (FromInstruction.isFromInstructionWithThisImageAndOlderTag(line, gitForkBranch.getImageName(), gitForkBranch.getImageTag())) { return false; } } } catch (IOException exception) { log.warn("Failed while checking if there are changes in {}. Skipping... exception: {}", content.getPath(), exception.getMessage()); } return true; } ForkableRepoValidator(DockerfileGitHubUtil dockerfileGitHubUtil); ShouldForkResult shouldFork(GHRepository parentRepo,
                                       GHContent searchResultContent,
                                       GitForkBranch gitForkBranch); static final String REPO_IS_FORK; static final String REPO_IS_ARCHIVED; static final String REPO_IS_OWNED_BY_THIS_USER; static final String COULD_NOT_CHECK_THIS_USER; static final String CONTENT_PATH_NOT_IN_DEFAULT_BRANCH_TEMPLATE; static final String COULD_NOT_FIND_IMAGE_TO_UPDATE_TEMPLATE; }
@Test(dataProvider = "hasNoChangesData") public void testHasNoChanges(String contentText, String imageName, String imageTag, boolean expectedResult) throws IOException { DockerfileGitHubUtil dockerfileGitHubUtil = mock(DockerfileGitHubUtil.class); GHRepository repo = mock(GHRepository.class); ForkableRepoValidator validator = new ForkableRepoValidator(dockerfileGitHubUtil); GHContent content = mock(GHContent.class); InputStream inputStream = new ByteArrayInputStream(contentText.getBytes()); GitForkBranch gitForkBranch = new GitForkBranch(imageName, imageTag, null); when(content.read()).thenReturn(inputStream); when(repo.isArchived()).thenReturn(false); assertEquals(validator.hasNoChanges(content, gitForkBranch), expectedResult); }
@Test public void testHasNoChangesIfExceptionThrownDuringRead() throws IOException { DockerfileGitHubUtil dockerfileGitHubUtil = mock(DockerfileGitHubUtil.class); GHRepository repo = mock(GHRepository.class); ForkableRepoValidator validator = new ForkableRepoValidator(dockerfileGitHubUtil); GHContent content = mock(GHContent.class); GitForkBranch gitForkBranch = new GitForkBranch("name", "tag", null); when(content.read()).thenThrow(new IOException("failed on IO")); assertTrue(validator.hasNoChanges(content, gitForkBranch)); }