fix: correct pushed image logging for latest tag …#4511
Conversation
Replace image reference string formatting with toStringWithQualifier() for tagged images and avoid duplicate untagged entries in the success message. Add a test covering latest and additional tags in build success logs.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request updates JibBuildRunner to prevent duplicate tag entries in the build success message when a tag matches the target image's qualifier, and adds a corresponding unit test. Feedback on these changes highlights that the new test will fail because the default 'latest' qualifier is skipped in the loop, meaning the success message will contain 'repo/container' instead of 'repo/container:latest'. Additionally, it is recommended to fix a minor indentation issue and reverse the equality check to prevent a potential NullPointerException if additionalTags contains null values.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| Assert.assertTrue(successMessage.contains("repo/container:latest")); | ||
| Assert.assertTrue(successMessage.contains("repo/container:1.0.0-SNAPSHOT")); | ||
| Assert.assertTrue(successMessage.contains("repo/container:branch")); | ||
| long occurrences = successMessage.split("repo/container", -1).length - 1L; | ||
| Assert.assertEquals(3, occurrences); |
There was a problem hiding this comment.
The assertion Assert.assertTrue(successMessage.contains("repo/container:latest")); will fail.
Why it fails:
targetImageReferenceis parsed from"repo/container", which defaults to the"latest"tag. ItstoString()representation is"repo/container"(without the:latestsuffix).- In
JibBuildRunner.java, the loop skips the"latest"tag becausetag.equals(targetImageReference.getQualifier())evaluates totrue(both are"latest"). - As a result, the success message is built as
"Built and pushed image as repo/container, repo/container:1.0.0-SNAPSHOT, repo/container:branch". - This string contains
"repo/container"but does not contain"repo/container:latest".
To fix this, we should assert that "repo/container" is present, but "repo/container:latest" is not.
Assert.assertTrue(successMessage.contains("repo/container"));
Assert.assertFalse(successMessage.contains("repo/container:latest"));
Assert.assertTrue(successMessage.contains("repo/container:1.0.0-SNAPSHOT"));
Assert.assertTrue(successMessage.contains("repo/container:branch"));
long occurrences = successMessage.split("repo/container", -1).length - 1L;
Assert.assertEquals(3, occurrences);| for (String tag : additionalTags) { | ||
| if (tag.equals(targetImageReference.getQualifier())) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
There is a minor indentation issue on line 77 (3 spaces instead of 4). Additionally, to prevent a potential NullPointerException if any element in additionalTags is null, it is safer to use targetImageReference.getQualifier().equals(tag) instead of tag.equals(...) since getQualifier() is guaranteed to return a non-null string.
| for (String tag : additionalTags) { | |
| if (tag.equals(targetImageReference.getQualifier())) { | |
| continue; | |
| } | |
| for (String tag : additionalTags) { | |
| if (targetImageReference.getQualifier().equals(tag)) { | |
| continue; | |
| } |
Use toStringWithQualifier() for the base image reference so the ':latest' tag is shown explicitly in the success message, reverse null-safe equality check for additional tag deduplication, and fix indentation on the for loop.
… ─╯
Replace image reference string formatting with toStringWithQualifier() for tagged images and avoid duplicate untagged entries in the success message.
Add a test covering latest and additional tags in build success logs.
Thank you for your interest in contributing! For general guidelines, please refer to
the contributing guide.
Please follow the guidelines below before opening an issue or a PR:
Fixes #4510 🛠️