Skip to content

Commit 2f4f946

Browse files
committed
Create PR only when files modified
1 parent e8b92a5 commit 2f4f946

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

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

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

280-
public void modifyOnGithub(GHContent content,
280+
public Boolean modifyOnGithub(GHContent content,
281281
String branch, String img, String tag,
282282
String customMessage, String ignoreImageString) throws IOException {
283+
Boolean modified = false;
283284
try (InputStream stream = content.read();
284285
InputStreamReader streamR = new InputStreamReader(stream);
285286
BufferedReader reader = new BufferedReader(streamR)) {
286-
findImagesAndFix(content, branch, img, tag, customMessage, reader, ignoreImageString);
287+
modified = findImagesAndFix(content, branch, img, tag, customMessage, reader,
288+
ignoreImageString);
287289
}
290+
return modified;
288291
}
289292

290-
protected void findImagesAndFix(GHContent content, String branch, String img,
293+
protected Boolean findImagesAndFix(GHContent content, String branch, String img,
291294
String tag, String customMessage, BufferedReader reader,
292295
String ignoreImageString) throws IOException {
293296
StringBuilder strB = new StringBuilder();
@@ -296,6 +299,7 @@ protected void findImagesAndFix(GHContent content, String branch, String img,
296299
content.update(strB.toString(),
297300
"Fix Docker base image in /" + content.getPath() + "\n\n" + customMessage, branch);
298301
}
302+
return modified;
299303
}
300304

301305
protected boolean rewriteDockerfile(String img, String tag,
@@ -542,9 +546,9 @@ public void changeDockerfiles(Namespace ns,
542546
if (content == null) {
543547
log.info("No Dockerfile found at path: '{}'", pathToDockerfile);
544548
} else {
545-
modifyOnGithub(content, gitForkBranch.getBranchName(), gitForkBranch.getImageName(), gitForkBranch.getImageTag(),
549+
isContentModified = modifyOnGithub(content, gitForkBranch.getBranchName(),
550+
gitForkBranch.getImageName(), gitForkBranch.getImageTag(),
546551
ns.get(Constants.GIT_ADDITIONAL_COMMIT_MESSAGE), ns.get(Constants.IGNORE_IMAGE_STRING));
547-
isContentModified = true;
548552
isRepoSkipped = false;
549553
}
550554
}

0 commit comments

Comments
 (0)