fix: link an installation to a git tag that already exists - #111
Open
turegjorup wants to merge 2 commits into
Open
turegjorup wants to merge 2 commits into
turegjorup wants to merge 2 commits into
Conversation
addInstallation() was called only when the tag row was created, and it is the only thing that sets Installation::gitTag. A redeployment, or the same release on a second server, therefore left the installation pointing at its previous tag or at nothing - which also dropped it out of the repo advisory rollups, since those inner join GitRepo through gitTags to installations.
API Specification - Non-breaking changesNo changelog changes |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #111 +/- ##
=============================================
+ Coverage 40.32% 43.09% +2.76%
Complexity 1132 1132
=============================================
Files 150 150
Lines 3576 3576
=============================================
+ Hits 1442 1541 +99
+ Misses 2134 2035 -99
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to ticket
https://leantime.itkdev.dk/#/tickets/showTicket/7213
Description
GitTagFactory::setGitCloneData()called$gitTag->addInstallation($installation)only inside thenull === $gitTagbranch, andGitTag::addInstallation()is the only thing that setsInstallation::$gitTag. So the installation was linked only when the tag row happened to be created by that same call.Whenever the
(repo, tag)row already existed — a redeployment of the same release, or the same release deployed to a second server — the installation silently kept its previous tag, or none at all.That is not only a display problem:
GitRepoRepository::findReposWithAdvisoryCount()andfindPackageVersionsPerRepoWithAdvisories()inner joinGitRepo → gitTags → installations → packageVersions → advisories, so an unlinked installation contributes nothing and drops out of the repo advisories page entirely.Changes:
addInstallation()call out of theif, so the installation is linked whether or not the tag row was just created.tests/Service/GitTagFactoryTest.php, the first test intests/Service/.The reason this has not been more visible:
RemovedRelationsListenerdeletes anyGitTagwith no installation on every flush, so in practice a tag usually has exactly the installations pointing at it and the "already exists" branch is rarely taken. It is taken when two installations legitimately share a(repo, tag).This is a prerequisite for reporting Woodpecker deploys, where every deploy of an already-known tag would otherwise link nothing — but it is a bug on the harvester path today and stands on its own.
Screenshot of the result
N/A — no user interface change.
Checklist
Verified that the new test fails against the old code (
Failed asserting that null is identical to an object of class "App\Entity\GitTag") and passes with the fix. Full suite: 79 tests, 197 assertions. PHPStan level 6 clean, php-cs-fixer clean.Additional comments or questions
Two adjacent things found while in here, both left alone deliberately:
git_tag (repo_id, tag)— only an index onrepo_id— so concurrent producers can race in duplicate rows andfindOneBythen picks one arbitrarily.parseRemoteUrl()assumes a two-segment path and a remote that is eitherhttps…orgit@…; anything else raises an undefined-key error that the caller'scatch (\JsonException)does not cover.