Skip to content

Commit 53b2886

Browse files
committed
Add continue to ensure that if condition exits after DFIU skips Renovate-onboarded repo
1 parent 851b05b commit 53b2886

File tree

2 files changed

+36
-50
lines changed

2 files changed

+36
-50
lines changed

dockerfile-image-update/src/main/java/com/salesforce/dockerfileimageupdate/utils/PullRequests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ public void prepareToCreate(final Namespace ns,
3434
//If the repository has been onboarded to renovate enterprise, skip sending the DFIU PR
3535
if(ns.getBoolean(Constants.CHECK_FOR_RENOVATE)
3636
&& (githubAppCheck.isGithubAppEnabledOnRepository(forkWithContentPaths.get().getParent().getFullName()))) {
37-
log.info("The repo {} is onboarded onto Renovate.Hence, skip sending DFIU PRs to this repository.", forkWithContentPaths.get().getParent().getFullName());
37+
log.info("The repo {} is onboarded onto Renovate. Hence, skip sending DFIU PRs to this repository.", forkWithContentPaths.get().getParent().getFullName());
38+
continue;
3839
} else {
3940
dockerfileGitHubUtil.changeDockerfiles(ns,
4041
pathToDockerfilesInParentRepo,
4142
forkWithContentPaths.get(), skippedRepos,
4243
gitForkBranch, rateLimiter);
44+
continue;
4345
}
4446
} catch (IOException | InterruptedException e) {
4547
log.error(String.format("Error changing Dockerfile for %s", forkWithContentPaths.get().getParent().getFullName()), e);

dockerfile-image-update/src/test/java/com/salesforce/dockerfileimageupdate/utils/PullRequestsTest.java

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -115,55 +115,39 @@ public void testPullRequestsPrepareToCreateWhenNoDockerfileFound() throws Except
115115
eq(gitHubContentToProcess), anyList(), eq(gitForkBranch),eq(rateLimiter));
116116
}
117117

118-
// @Test
119-
// public void testPullRequestsPrepareSkipsSendingPRIfRepoOnboardedToRenovate() throws Exception {
120-
// Map<String, Object> nsMap = ImmutableMap.of(
121-
// Constants.IMG, "image",
122-
// Constants.TAG, "tag",
123-
// Constants.STORE,"store",
124-
// Constants.SKIP_PR_CREATION,false,
125-
// Constants.CHECK_FOR_RENOVATE, false);
126-
//
127-
//
128-
// Namespace ns = new Namespace(nsMap);
129-
// PullRequests pullRequests = new PullRequests();
130-
// GitHubPullRequestSender pullRequestSender = mock(GitHubPullRequestSender.class);
131-
// PagedSearchIterable<GHContent> contentsFoundWithImage = mock(PagedSearchIterable.class);
132-
// GitForkBranch gitForkBranch = mock(GitForkBranch.class);
133-
// DockerfileGitHubUtil dockerfileGitHubUtil = mock(DockerfileGitHubUtil.class);
134-
// RenovateUtil renovateUtil = mock(RenovateUtil.class);
135-
// RateLimiter rateLimiter = Mockito.spy(new RateLimiter());
136-
// Multimap<String, GitHubContentToProcess> pathToDockerfilesInParentRepo = ArrayListMultimap.create();
137-
// GitHubContentToProcess gitHubContentToProcess = mock(GitHubContentToProcess.class);
138-
// pathToDockerfilesInParentRepo.put("repo1", gitHubContentToProcess);
139-
// pathToDockerfilesInParentRepo.put("repo2", gitHubContentToProcess);
140-
// pathToDockerfilesInParentRepo.put("repo3", gitHubContentToProcess);
141-
// GHContent content = mock(GHContent.class);
142-
// InputStream inputStream1 = new ByteArrayInputStream("{someKey:someValue}".getBytes());
143-
// InputStream inputStream2 = new ByteArrayInputStream("{enabled:false}".getBytes());
144-
// GHRepository ghRepository = mock(GHRepository.class);
145-
//
146-
// when(pullRequestSender.forkRepositoriesFoundAndGetPathToDockerfiles(contentsFoundWithImage, gitForkBranch)).thenReturn(pathToDockerfilesInParentRepo);
147-
// when(gitHubContentToProcess.getParent()).thenReturn(ghRepository);
148-
// //Fetch the content of the renovate.json file for the 3 repos.
149-
// // The first one returns a file with regular json content.
150-
// // The second one returns a file with the key 'enabled' set to 'false' to replicate a repo that has been onboarded to renovate but has it disabled
151-
// // The third repo does not have the renovate.json file
152-
//// when(ghRepository.getFileContent(anyString())).thenReturn(content).thenReturn(content).thenThrow(new FileNotFoundException());
153-
//// when(ghRepository.getFullName()).thenReturn("org/repo");
154-
//// when(content.read()).thenReturn(inputStream1).thenReturn(inputStream2);
155-
//
156-
// when(renovateUtil.isRenovateEnabledOnRepository(anyString())).thenReturn(true).thenReturn(false).thenReturn(false);
157-
//
158-
// pullRequests.prepareToCreate(ns, pullRequestSender, contentsFoundWithImage,
159-
// gitForkBranch, dockerfileGitHubUtil, rateLimiter);
160-
//
161-
// //Verify that the DFIU PR is skipped for the first repo, but is sent to the other two repos
162-
// verify(dockerfileGitHubUtil, times(2)).changeDockerfiles(eq(ns),
163-
// eq(pathToDockerfilesInParentRepo),
164-
// eq(gitHubContentToProcess), anyList(), eq(gitForkBranch),
165-
// eq(rateLimiter));
166-
// }
118+
// @Test
119+
// public void testPullRequestsPrepareSkipsSendingPRIfRepoOnboardedToRenovate() throws Exception {
120+
// Map<String, Object> nsMap = ImmutableMap.of(Constants.IMG,
121+
// "image", Constants.TAG,
122+
// "tag", Constants.STORE,
123+
// "store", Constants.SKIP_PR_CREATION,
124+
// false, Constants.CHECK_FOR_RENOVATE, true);
125+
// Namespace ns = new Namespace(nsMap);
126+
// PullRequests pullRequests = new PullRequests();
127+
// GitHubPullRequestSender pullRequestSender = mock(GitHubPullRequestSender.class);
128+
// PagedSearchIterable<GHContent> contentsFoundWithImage = mock(PagedSearchIterable.class);
129+
// GitForkBranch gitForkBranch = mock(GitForkBranch.class);
130+
// DockerfileGitHubUtil dockerfileGitHubUtil = mock(DockerfileGitHubUtil.class);
131+
// GithubAppCheck githubAppCheck = mock(GithubAppCheck.class);
132+
// RateLimiter rateLimiter = Mockito.spy(new RateLimiter());
133+
// Multimap<String, GitHubContentToProcess> pathToDockerfilesInParentRepo = ArrayListMultimap.create();
134+
// GitHubContentToProcess gitHubContentToProcess = mock(GitHubContentToProcess.class);
135+
// GHRepository ghRepository = mock(GHRepository.class);
136+
// pathToDockerfilesInParentRepo.put("repo1", gitHubContentToProcess);
137+
138+
// when(pullRequestSender.forkRepositoriesFoundAndGetPathToDockerfiles(contentsFoundWithImage, gitForkBranch)).thenReturn(pathToDockerfilesInParentRepo);
139+
// when(gitHubContentToProcess.getParent()).thenReturn(ghRepository);
140+
// when(ghRepository.getFullName()).thenReturn("repo");
141+
// when(githubAppCheck.isGithubAppEnabledOnRepository(anyString())).thenReturn(true);
142+
143+
// pullRequests.prepareToCreate(ns, pullRequestSender, contentsFoundWithImage,
144+
// gitForkBranch, dockerfileGitHubUtil, rateLimiter);
145+
146+
// verify(dockerfileGitHubUtil, times(0)).changeDockerfiles(eq(ns),
147+
// eq(pathToDockerfilesInParentRepo),
148+
// eq(gitHubContentToProcess), anyList(), eq(gitForkBranch),
149+
// eq(rateLimiter));
150+
// }
167151

168152
@Test
169153
public void testisRenovateEnabledReturnsFalseIfRenovateConfigFileNotFound() throws IOException {

0 commit comments

Comments
 (0)