Skip to content

feat: consistent sha/branch/repo in all git event emitters#139

Open
NeuralEmpowerment wants to merge 2 commits into
mainfrom
feat/consistent-git-event-metadata
Open

feat: consistent sha/branch/repo in all git event emitters#139
NeuralEmpowerment wants to merge 2 commits into
mainfrom
feat/consistent-git-event-metadata

Conversation

@NeuralEmpowerment
Copy link
Copy Markdown
Contributor

Summary

  • All git observability hooks (pre-push, post-merge, post-rewrite) now capture SHA, branch, and repo name consistently, matching post-commit and post-checkout
  • Emitter methods (git_push, git_merge, git_rewrite, git_checkout) accept sha/branch/repo as named params and store them in the context dict, not **metadata
  • Fixes downstream dashboard showing incomplete git sub-headers (missing SHA/repo on push, merge, rewrite events)

Test plan

  • Run a workflow that triggers push, merge, rewrite operations
  • Verify all git events in the dashboard show SHA, branch, and repo consistently

All git observability hooks now consistently capture SHA, branch, and
repo name. Previously only post-commit and post-checkout included all
three fields - pre-push, post-merge, and post-rewrite were missing some.

Emitter methods (git_push, git_merge, git_rewrite, git_checkout) now
accept sha/branch/repo as named context fields instead of relying on
**metadata passthrough, which stored them outside the context dict
where the dashboard resolver couldn't find them.
Copilot AI review requested due to automatic review settings April 12, 2026 01:10
Copy link
Copy Markdown

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

This PR aims to make git observability events emit sha, branch, and repo consistently across additional git hooks (pre-push, post-merge, post-rewrite), and updates the EventEmitter git methods to accept these fields as explicit parameters and place them into the event context.

Changes:

  • Capture and emit sha + repo in the pre-push hook, and sha/branch/repo in the post-rewrite hook.
  • Capture and emit repo in the post-merge hook.
  • Update EventEmitter git emitters (git_push, git_merge, git_rewrite, git_checkout) to accept repo (and sha where applicable) and include them in context.

Reviewed changes

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

File Description
plugins/observability/hooks/git/pre-push Adds HEAD SHA + repo name capture and sends them with git_push events.
plugins/observability/hooks/git/post-rewrite Adds a local run() helper and captures SHA/branch/repo for git_rewrite events.
plugins/observability/hooks/git/post-merge Captures repo name and includes it in git_merge events.
lib/python/agentic_events/agentic_events/emitter.py Extends git emitter APIs to accept sha/repo (where relevant) and place them into context.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +470 to +476
context: dict[str, Any] = {"operation": "push", "remote": remote}
if branch:
context["branch"] = branch
if sha:
context["sha"] = sha
if repo:
context["repo"] = repo
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

git_push() no longer includes branch in context when it is an empty string. This breaks the existing contract/tests that expect context['branch'] == '' for default calls (see TestGitPushEmitter.test_push_defaults). Consider always setting context['branch'] = branch (and optionally defaulting sha/repo keys similarly) to keep the event schema stable, or update the tests/consumers if the schema change is intentional.

Suggested change
context: dict[str, Any] = {"operation": "push", "remote": remote}
if branch:
context["branch"] = branch
if sha:
context["sha"] = sha
if repo:
context["repo"] = repo
context: dict[str, Any] = {
"operation": "push",
"remote": remote,
"branch": branch,
"sha": sha,
"repo": repo,
}

Copilot uses AI. Check for mistakes.
Comment on lines +36 to +38
# Get repo name from remote
origin = run(["git", "remote", "get-url", "origin"])
repo = origin.rstrip("/").rsplit("/", 1)[-1].replace(".git", "") if origin else ""
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

The repo name is derived from origin regardless of which remote is actually being pushed (remote/remote_url from argv). If a user pushes to a non-origin remote (or passes a different URL), this will emit an incorrect repo. Consider preferring remote_url (argv[2]) when present, otherwise git remote get-url <remote>, with origin only as a fallback.

Suggested change
# Get repo name from remote
origin = run(["git", "remote", "get-url", "origin"])
repo = origin.rstrip("/").rsplit("/", 1)[-1].replace(".git", "") if origin else ""
# Get repo name from the actual push target
repo_source_url = remote_url or run(["git", "remote", "get-url", remote]) or run(["git", "remote", "get-url", "origin"])
repo = repo_source_url.rstrip("/").rsplit("/", 1)[-1].replace(".git", "") if repo_source_url else ""

Copilot uses AI. Check for mistakes.
Comment on lines 33 to +35
branch = run(["git", "rev-parse", "--abbrev-ref", "HEAD"])
sha = run(["git", "rev-parse", "HEAD"])

Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

sha is already computed via git rev-parse HEAD, but later the hook shells out again to git rev-parse HEAD when building commit_range. Reusing the existing sha value would avoid an extra subprocess call on every push.

Copilot uses AI. Check for mistakes.
Comment on lines 506 to 512
def git_merge(
self,
branch: str = "",
merge_sha: str = "",
repo: str = "",
**metadata: Any,
) -> dict[str, Any]:
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

PR description says git emitter methods accept sha/branch/repo as named params, but git_merge still uses merge_sha (while storing it under context['sha']). Either update the PR description to reflect the actual API, or consider adding a sha alias (keeping merge_sha for backward compatibility) so callers can pass a consistent sha= keyword across git emitters.

Copilot uses AI. Check for mistakes.
Add frozen dataclasses for each git event type (commit, push, checkout,
branch_changed, merge, rewrite) with to_dict() that strips empty values.
Emitter methods now build typed payloads and namespace git data under
context.git - enabling end-to-end type safety through the pipeline.
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