Skip to content

fix: link an installation to a git tag that already exists - #111

Open
turegjorup wants to merge 2 commits into
developfrom
fix/gittagfactory-link-existing-tag
Open

turegjorup wants to merge 2 commits into
developfrom
fix/gittagfactory-link-existing-tag

Conversation

@turegjorup

Copy link
Copy Markdown
Contributor

Link to ticket

https://leantime.itkdev.dk/#/tickets/showTicket/7213

Description

GitTagFactory::setGitCloneData() called $gitTag->addInstallation($installation) only inside the null === $gitTag branch, and GitTag::addInstallation() is the only thing that sets Installation::$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() and findPackageVersionsPerRepoWithAdvisories() inner join GitRepo → gitTags → installations → packageVersions → advisories, so an unlinked installation contributes nothing and drops out of the repo advisories page entirely.

Changes:

  • Move the addInstallation() call out of the if, so the installation is linked whether or not the tag row was just created.
  • Add tests/Service/GitTagFactoryTest.php, the first test in tests/Service/.

The reason this has not been more visible: RemovedRelationsListener deletes any GitTag with 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

  • My code is covered by test cases.
  • My code passes our test (all our tests).
  • My code passes our static analysis suite.
  • My code passes our continuous integration process.

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:

  • There is no unique constraint on git_tag (repo_id, tag) — only an index on repo_id — so concurrent producers can race in duplicate rows and findOneBy then picks one arbitrarily.
  • parseRemoteUrl() assumes a two-segment path and a remote that is either https… or git@…; anything else raises an undefined-key error that the caller's catch (\JsonException) does not cover.

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.
@github-actions

Copy link
Copy Markdown

API Specification - Non-breaking changes

No changelog changes

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 43.09%. Comparing base (c77a06a) to head (e3d8b3a).
⚠️ Report is 4 commits behind head on develop.

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     
Flag Coverage Δ
unittests 43.09% <100.00%> (+2.76%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants