Added git_hash and git_tag to generated cache info.#357
Added git_hash and git_tag to generated cache info.#357mnesarco wants to merge 1 commit intoFreeCAD:devfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends the generated addon catalog cache metadata to include git provenance (git_hash and git_tag) so consumers can distinguish between “official” tagged releases vs. untagged commit states.
Changes:
- Add
git_hash/git_tagfields toAddonCatalogEntryand a helper API to populate them. - Compute git tag (exact match) and HEAD commit hash during cache generation and write them into the cache output.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| AddonCatalogCacheCreator.py | Computes git tag/hash for locally cloned addon repos and stores them into the catalog entries during cache generation. |
| AddonCatalog.py | Extends AddonCatalogEntry with git_hash/git_tag and adds add_git_info_to_entry() to persist those values. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
AddonCatalogCacheCreator.py
Outdated
| def get_git_info( | ||
| self, addon_id: str, index: int, catalog_entry: AddonCatalog.AddonCatalogEntry | ||
| ) -> Tuple[str | None, str | None]: | ||
| commit_hash: str | None = None | ||
| tag: str | None = None | ||
| dirname = self.get_directory_name(addon_id, index, catalog_entry) | ||
| if os.path.exists(os.path.join(self.cwd, dirname, ".git")): | ||
| repo = os.path.join(self.cwd, dirname) | ||
| # Tag | ||
| try: | ||
| result = subprocess.run( | ||
| ["git", "describe", "--tags", "--exact-match"], | ||
| capture_output=True, | ||
| text=True, | ||
| check=True, | ||
| cwd=repo, | ||
| ) | ||
| tag = result.stdout.strip() | ||
| except Exception: | ||
| tag = None | ||
| # Hash | ||
| try: | ||
| result = subprocess.run( | ||
| ["git", "rev-parse", "HEAD"], | ||
| capture_output=True, | ||
| text=True, | ||
| check=True, | ||
| cwd=repo, | ||
| ) | ||
| commit_hash = result.stdout.strip() | ||
| except Exception: | ||
| commit_hash = None | ||
|
|
||
| return commit_hash, tag |
There was a problem hiding this comment.
New behavior is introduced here (calling git to compute git_hash/git_tag and storing it in the catalog), but the existing unit test suite for AddonCatalogCacheCreator doesn’t cover this path. Please add tests for get_git_info (e.g., patch subprocess.run to simulate a tagged vs untagged HEAD and to ensure failures produce None values without invoking real git).
| def add_git_info_to_entry( | ||
| self, addon_id: str, index: int, commit_hash: str | None, tag: str | None | ||
| ) -> None: | ||
| """Adds git commit hash and tag to an AddonCatalogEntry""" | ||
| entries = self._dictionary.get(addon_id) | ||
| if entries is None: | ||
| raise RuntimeError(f"Addon {addon_id} does not exist") | ||
| if index >= len(entries): | ||
| raise RuntimeError(f"Addon {addon_id} index out of range") | ||
| entry = entries[index] | ||
| entry.git_hash = commit_hash | ||
| entry.git_tag = tag | ||
|
|
There was a problem hiding this comment.
add_git_info_to_entry is a new public method on AddonCatalog but there are existing tests for AddonCatalog/AddonCatalogEntry that don’t cover it. Please add unit tests to verify it sets git_hash/git_tag on the correct entry and raises the expected errors for unknown addon IDs / out-of-range indexes.
| from dataclasses import is_dataclass, fields | ||
| from typing import Any, List, Optional, Dict | ||
| from typing import Any, List, Optional, Dict, Tuple | ||
|
|
There was a problem hiding this comment.
typing.List is imported twice in this module (once in the combined import that was updated here, and again later as from typing import List). Please drop the later duplicate import to avoid redundancy and keep imports consistent.
|
I don't know what is going on with Github, but the latest changes are not reflected here. So look at the branch directly: dev...mnesarco:AddonManager:dev-git-info |
f34b88b to
bc55442
Compare
Added git info to cache data, it provides better ways to determine if an addon has changed "officially" by its tag or just by commits.
Note: For some strange reason, Github does not refresh latest changes from the branch:
dev-git-info