Skip to content

Commit 79f71bd

Browse files
committed
Addressing PR comments
1 parent d20c1fa commit 79f71bd

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,17 +277,21 @@ public GHBlob tryRetrievingBlob(GHRepository repo, String path, String branch)
277277
return gitHubUtil.tryRetrievingBlob(repo, path, branch);
278278
}
279279

280-
public boolean modifyOnGithub(GHContent content,
280+
public void modifyOnGithub(GHContent content,
281281
String branch, String img, String tag,
282282
String customMessage, String ignoreImageString) throws IOException {
283-
boolean modified;
283+
modifyContentOnGithub(content, branch, img, tag, customMessage, ignoreImageString);
284+
}
285+
286+
protected boolean modifyContentOnGithub(GHContent content,
287+
String branch, String img, String tag,
288+
String customMessage, String ignoreImageString) throws IOException {
284289
try (InputStream stream = content.read();
285290
InputStreamReader streamR = new InputStreamReader(stream);
286291
BufferedReader reader = new BufferedReader(streamR)) {
287-
modified = findImagesAndFix(content, branch, img, tag, customMessage, reader,
292+
return findImagesAndFix(content, branch, img, tag, customMessage, reader,
288293
ignoreImageString);
289294
}
290-
return modified;
291295
}
292296

293297
protected boolean findImagesAndFix(GHContent content, String branch, String img,
@@ -546,12 +550,10 @@ public void changeDockerfiles(Namespace ns,
546550
if (content == null) {
547551
log.info("No Dockerfile found at path: '{}'", pathToDockerfile);
548552
} else {
549-
if (modifyOnGithub(content, gitForkBranch.getBranchName(),
553+
isContentModified |= modifyContentOnGithub(content, gitForkBranch.getBranchName(),
550554
gitForkBranch.getImageName(), gitForkBranch.getImageTag(),
551555
ns.get(Constants.GIT_ADDITIONAL_COMMIT_MESSAGE),
552-
ns.get(Constants.IGNORE_IMAGE_STRING))) {
553-
isContentModified = true;
554-
}
556+
ns.get(Constants.IGNORE_IMAGE_STRING));
555557
isRepoSkipped = false;
556558
}
557559
}

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,6 @@ public void testOnePullRequestForMultipleDockerfilesInSameRepo() throws Exceptio
831831
when(parentRepo.getFullName()).thenReturn("repo1");
832832
when(forkedRepo.getParent()).thenReturn(parentRepo);
833833

834-
//GHRepository parent = mock(GHRepository.class);
835834
String defaultBranch = "default";
836835
when(parentRepo.getDefaultBranch()).thenReturn(defaultBranch);
837836
GHBranch parentBranch = mock(GHBranch.class);
@@ -854,13 +853,13 @@ public void testOnePullRequestForMultipleDockerfilesInSameRepo() throws Exceptio
854853
eq("df12"), eq("image-tag"))).thenReturn(forkedRepoContent2);
855854

856855
//Both Dockerfiles modified
857-
doReturn(true).when(dockerfileGitHubUtil).modifyOnGithub(eq(forkedRepoContent1),
856+
doReturn(true).when(dockerfileGitHubUtil).modifyContentOnGithub(eq(forkedRepoContent1),
858857
eq("image-tag"),
859858
eq("image"),
860859
eq("tag"),
861860
eq(null),
862861
eq(null));
863-
doReturn(true).when(dockerfileGitHubUtil).modifyOnGithub(eq(forkedRepoContent2),
862+
doReturn(true).when(dockerfileGitHubUtil).modifyContentOnGithub(eq(forkedRepoContent2),
864863
eq("image-tag"),
865864
eq("image"),
866865
eq("tag"),
@@ -881,7 +880,7 @@ public void testOnePullRequestForMultipleDockerfilesInSameRepo() throws Exceptio
881880

882881
// Both Dockerfiles modified
883882
verify(dockerfileGitHubUtil, times(2))
884-
.modifyOnGithub(any(), eq("image-tag"), eq("image"), eq("tag"), any(), any());
883+
.modifyContentOnGithub(any(), eq("image-tag"), eq("image"), eq("tag"), any(), any());
885884

886885
// Only one PR created on the repo with changes to both Dockerfiles.
887886
verify(dockerfileGitHubUtil).createPullReq(eq(parentRepo),
@@ -907,7 +906,6 @@ public void testPullRequestBlockNotExecutedWhenDockerfileIsNotModified() throws
907906
when(parentRepo.getFullName()).thenReturn("repo");
908907
when(forkedRepo.getParent()).thenReturn(parentRepo);
909908

910-
//GHRepository parent = mock(GHRepository.class);
911909
String defaultBranch = "default";
912910
when(parentRepo.getDefaultBranch()).thenReturn(defaultBranch);
913911
GHBranch parentBranch = mock(GHBranch.class);
@@ -926,7 +924,7 @@ public void testPullRequestBlockNotExecutedWhenDockerfileIsNotModified() throws
926924
eq("df11"), eq("image-tag"))).thenReturn(forkedRepoContent);
927925

928926
//Dockerfile not modified
929-
doReturn(false).when(dockerfileGitHubUtil).modifyOnGithub(eq(forkedRepoContent),
927+
doReturn(false).when(dockerfileGitHubUtil).modifyContentOnGithub(eq(forkedRepoContent),
930928
eq("image-tag"),
931929
eq("image"),
932930
eq("tag"),
@@ -944,10 +942,10 @@ public void testPullRequestBlockNotExecutedWhenDockerfileIsNotModified() throws
944942
eq("df11"), eq("image-tag"));
945943

946944
// Trying to modify Dockerfile
947-
verify(dockerfileGitHubUtil).modifyOnGithub(any(), eq("image-tag"), eq("image"), eq("tag"), any(), any());
945+
verify(dockerfileGitHubUtil).modifyContentOnGithub(any(), eq("image-tag"), eq("image"), eq("tag"), any(), any());
948946

949947
// PR creation block not executed
950-
verify(dockerfileGitHubUtil, times(0)).createPullReq(eq(parentRepo),
948+
verify(dockerfileGitHubUtil, never()).createPullReq(eq(parentRepo),
951949
eq("image-tag"), eq(forkedRepo), any(), eq(rateLimiter));
952950
}
953951

@@ -971,7 +969,6 @@ public void testPullRequestCreatedWhenAnyDockerfileIsModified() throws Exception
971969
when(parentRepo.getFullName()).thenReturn("repo");
972970
when(forkedRepo.getParent()).thenReturn(parentRepo);
973971

974-
//GHRepository parent = mock(GHRepository.class);
975972
String defaultBranch = "default";
976973
when(parentRepo.getDefaultBranch()).thenReturn(defaultBranch);
977974
GHBranch parentBranch = mock(GHBranch.class);
@@ -994,15 +991,15 @@ public void testPullRequestCreatedWhenAnyDockerfileIsModified() throws Exception
994991
eq("df12"), eq("image-tag"))).thenReturn(forkedRepoContent2);
995992

996993
//First dockerfile not modified
997-
doReturn(false).when(dockerfileGitHubUtil).modifyOnGithub(eq(forkedRepoContent),
994+
doReturn(false).when(dockerfileGitHubUtil).modifyContentOnGithub(eq(forkedRepoContent),
998995
eq("image-tag"),
999996
eq("image"),
1000997
eq("tag"),
1001998
eq(null),
1002999
eq(null));
10031000

10041001
//Second dockerfile modified
1005-
doReturn(true).when(dockerfileGitHubUtil).modifyOnGithub(eq(forkedRepoContent2),
1002+
doReturn(true).when(dockerfileGitHubUtil).modifyContentOnGithub(eq(forkedRepoContent2),
10061003
eq("image-tag"),
10071004
eq("image"),
10081005
eq("tag"),
@@ -1022,7 +1019,7 @@ public void testPullRequestCreatedWhenAnyDockerfileIsModified() throws Exception
10221019
eq("df12"), eq("image-tag"));
10231020

10241021
// Trying to modify both Dockerfiles
1025-
verify(dockerfileGitHubUtil, times(2)).modifyOnGithub(any(), eq("image-tag"), eq("image")
1022+
verify(dockerfileGitHubUtil, times(2)).modifyContentOnGithub(any(), eq("image-tag"), eq("image")
10261023
, eq("tag"), any(), any());
10271024

10281025
// PR created

0 commit comments

Comments
 (0)