Skip to content

Add local git metadata collection in EnvironmentDetector#106

Merged
xping-admin merged 7 commits into
mainfrom
feat/local-git-metadata-collection
May 12, 2026
Merged

Add local git metadata collection in EnvironmentDetector#106
xping-admin merged 7 commits into
mainfrom
feat/local-git-metadata-collection

Conversation

@xping-admin
Copy link
Copy Markdown
Collaborator

@xping-admin xping-admin commented May 12, 2026

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

  • Git repository detection: walks up from CurrentDirectory looking for .git (directory or file), including worktree/submodule support via gitdir: pointer resolution
  • Local git metadata (populated only when IsCIEnvironment = false):
    • Git.Branch — current branch name (omitted on detached HEAD or non-branch symbolic refs)
    • Git.SHA — resolved commit SHA from loose ref or packed-refs fallback
    • Git.Actor — author name from .git/config [user] name, opt-in only via XpingConfiguration.CollectLocalGitAuthor (defaults to false to avoid unintentional PII collection)
  • IsInsideGitRepository custom property: "true" / "false"
  • IsDetachedHead custom 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 flag
  • HasStagedChanges custom property: heuristic based on .git/index mtime vs last-commit ref mtime. Detects staged-but-not-committed changes only (not unstaged working-tree edits). Falls back to packed-refs mtime 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 .git file, HasStagedChanges true/false/absent, actor opt-in/opt-out, and CI env-var precedence.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 75.40984% with 30 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...vices/Environment/Internals/EnvironmentDetector.cs 74.35% 19 Missing and 11 partials ⚠️
Files with missing lines Coverage Δ
...Xping.Sdk.Core/Configuration/XpingConfiguration.cs 100.00% <100.00%> (ø)
...ore/Extensions/XpingServiceCollectionExtensions.cs 96.63% <100.00%> (+0.05%) ⬆️
...vices/Environment/Internals/EnvironmentDetector.cs 50.00% <74.35%> (+9.10%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/Xping.Sdk.Core/Services/Environment/Internals/EnvironmentDetector.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

Comment thread src/Xping.Sdk.Core/Services/Environment/Internals/EnvironmentDetector.cs Outdated
Comment thread src/Xping.Sdk.Core/Services/Environment/Internals/EnvironmentDetector.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread src/Xping.Sdk.Core/Configuration/XpingConfiguration.cs
Comment thread src/Xping.Sdk.Core/Services/Environment/Internals/EnvironmentDetector.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread src/Xping.Sdk.Core/Services/Environment/Internals/EnvironmentDetector.cs Outdated
xping-admin and others added 2 commits May 12, 2026 21:53
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@xping-admin xping-admin merged commit f4ac851 into main May 12, 2026
3 checks passed
@xping-admin xping-admin deleted the feat/local-git-metadata-collection branch May 12, 2026 21:48
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