Add local git metadata collection in EnvironmentDetector#106
Merged
Conversation
Codecov Report❌ Patch coverage is
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds local Git repository detection to EnvironmentDetector so that, when running outside a CI provider, the SDK can enrich EnvironmentInfo.CustomProperties with Git-derived context (branch, SHA, actor, etc.) and expose whether execution occurred inside a Git repo.
Changes:
- Add Git repository detection and (non-CI) local Git metadata collection to
EnvironmentDetector. - Add xUnit tests covering inside/outside Git repo, detached HEAD, packed-refs SHA resolution, and CI env-var precedence.
- Add small test utilities for temporary directories and working-directory restoration.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Xping.Sdk.Core/Services/Environment/Internals/EnvironmentDetector.cs | Adds .git discovery plus local Git metadata parsing and new custom properties. |
| tests/Xping.Sdk.Core.Tests/Services/Environment/EnvironmentDetectorTests.cs | Adds unit tests and helpers validating new Git metadata behaviors. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Introduce functionality to detect if the application runs inside a git repository and collect relevant local git metadata, enhancing environment detection capabilities for local developer runs.
Changes
CurrentDirectorylooking for.git(directory or file), including worktree/submodule support viagitdir:pointer resolutionIsCIEnvironment = false):Git.Branch— current branch name (omitted on detached HEAD or non-branch symbolic refs)Git.SHA— resolved commit SHA from loose ref orpacked-refsfallbackGit.Actor— author name from.git/config [user] name, opt-in only viaXpingConfiguration.CollectLocalGitAuthor(defaults tofalseto avoid unintentional PII collection)IsInsideGitRepositorycustom property:"true"/"false"IsDetachedHeadcustom property: set only when HEAD contains a raw SHA (truly detached); non-branch symbolic refs (e.g.ref: refs/tags/...) are handled separately and do not set this flagHasStagedChangescustom property: heuristic based on.git/indexmtime vs last-commit ref mtime. Detects staged-but-not-committed changes only (not unstaged working-tree edits). Falls back topacked-refsmtime when no loose ref file exists. Omitted when the check cannot be performed.Tests
Added 11 new unit tests covering: inside/outside git repo, detached HEAD, non-branch symbolic ref, packed-refs SHA resolution, worktree
.gitfile,HasStagedChangestrue/false/absent, actor opt-in/opt-out, and CI env-var precedence.