Skip to content

feat(git): implement automation event handling and related tests - #700

Merged
pikann merged 4 commits into
masterfrom
feature/implement-git-automation-event-handling
Nov 4, 2026
Merged

pikann merged 4 commits into
masterfrom
feature/implement-git-automation-event-handling

Conversation

@pikann

@pikann pikann commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Automations built on the GitHub plugin's own nodes (for example Pull Request State Changed → state is merged → set Done) silently stopped firing when the plugins became Git providers: the plugins no longer declare any automation nodes, so nothing emitted github.pr_state_changed and the other github.* nodes were gone too.

Core now owns the Git automation nodes under a git.* namespace, so every Git platform (GitHub, GitLab, …) drives the same triggers, condition and actions. The provider only has to deliver normalized webhook events.

Changes

Triggers (emitted by core after a webhook is ingested or a task is linked)

  • git.pr_linked, git.pr_state_changed (only on a real transition, not a redelivery or a push), git.branch_linked.
  • git.pr_ready_for_review, git.pr_review_submitted, git.pr_comment_created, git.pr_ci_completed (Paca's own run status is excluded; bot comments and reviews never trigger, so an automation that comments cannot start itself).
  • git.issue_created: an issue belongs to no task, so the run has none. A new issue is recognised as the created comment on an issue that has no comment id, so the GitHub and GitLab plugins need no change.

Conditions (read the task's newest linked pull/merge request)

  • git.pr_state, git.pr_ci_status (read live from the provider), git.pr_draft, git.pr_base_branch, git.has_pr.

Actions

  • git.merge_pr and git.comment_pr (these replace the old github.* ones), plus git.close_pr, git.reopen_pr, git.mark_pr_ready, git.add_labels, git.request_reviewers. Each is idempotent: a retried run of an action that is already satisfied counts as done.

Engine and wiring

  • gitsvc.AutomationRuntime wraps the plugin runtime, so the engine, node validation and the palette see the git.* nodes next to plugin nodes. The web UI renders them from their config schema, so it needs no changes.
  • Trigger payload fields reach the graph as {{event.<field>}} placeholders (for example {{event.title}} on an issue) and survive a paused run.
  • Trigger manifests get an optional taskless flag, read through the resolver, so a trigger whose events carry no task cannot be connected to a node that needs one.
  • Store: LinkTaskToChangeRequest / LinkTaskBranch report whether the link is new; new ListChangeRequestTasks.
  • Migration 000080 renames stored github.* nodes to git.*, so existing automations keep working without being rebuilt.

Live refresh

  • Core publishes git.task.updated when a task's pull requests or branches change, and the task Git panel refreshes on it. The dead github. routing rules in the API permission rules and the realtime service are removed.

Notes for reviewers

  • Existing automations are only migrated if their nodes use the six old github.* types. A plugin that declares its own differently named nodes is unaffected.
  • git.issue_created can only reach call_api, trigger_ai_agent and wait nodes (there is no task); graph validation rejects other edges.
  • Review approved / changes requested is not a trigger: the normalized review event carries no decision, so it would need a provider-contract change.
  • Unlinking a pull request or branch does not refresh other open task pages (the user who unlinks already refetches).

Testing

  • go test ./... and go vet for services/api; realtime tests; web tsc -b and the realtime hook test.
  • New unit tests for the triggers (including that redeliveries and bot events do not fire), conditions, actions, the runtime wrapper, event variables and the taskless validation.
  • New e2e spec git-automation-nodes.spec.ts (13 tests, passing on Chromium against the e2e stack): node catalog, graph validation, and graphs running end to end from a queued event (merged pull request moves the task, a closed one does not, a new pull request, an opened issue). The e2e stack has no Git provider, so these put the linked pull request in the database and the event on the trigger stream. The existing automation, Git task-link, webhook and realtime specs still pass.
  • Not covered: a real GitHub or GitLab webhook, and mobile-chrome.

- Added automation tests for Git webhook events, ensuring correct triggers on PR state changes and issue creations.
- Enhanced the Service to handle automation events, linking tasks to change requests and branches.
- Updated router logic to recognize opened issue bodies as comments.
- Introduced event variable handling for plugin trigger events, allowing dynamic template variable substitution.
- Migrated existing GitHub automation nodes to the new git.* namespace for consistency across platforms.
- Improved permissions handling for task-scoped events in the real-time service.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary

This PR moves the Git automation nodes from the GitHub plugin into core under a git.* namespace. The approach is clean and the implementation is thorough — the runtime delegation, event emission, condition/action logic, and migration all hold up to scrutiny.

I reviewed the core logic in automation.go, automation_runtime.go, the event emission paths in service.go, the worker consumer changes, the migration, and the E2E/unit tests. I found no blocking issues.

Strengths

  • Clean delegation architecture. AutomationRuntime wrapping the plugin runtime via an AutomationOwner check keeps core Git logic separate from plugin logic while preserving the existing interface. The gitNodes index and isGit* helpers make ownership checks cheap and clear.
  • Correct event semantics. isIssueBody correctly distinguishes an issue's opening text from later comments (no comment ID), bot comments/reviews are excluded so automations cannot trigger themselves, and Paca's own run status is filtered out of git.pr_ci_completed.
  • Idempotent actions. Merging an already-merged PR returns applied: false, error: nil, and automationSetState treats an already-in-target-state PR as done rather than an error. The worker's RunStepSkipped handling for !applied is the right integration.
  • Safe, scoped migration. 000080 only renames the six known github.* types and is idempotent by construction (the WHERE clause excludes already-renamed rows).
  • Good test coverage. The E2E spec exercises the node catalog, validation edges, and end-to-end runs from a queued event. Unit tests cover redelivery/bot filtering, idempotency, live-head merge behavior, and the taskless trigger validation.

Minor observations (non-blocking)

  1. isIssueBody heuristic relies on an empty Location.CommentID. The comment in the code explains this well, but it's an implicit provider contract. Consider documenting it in the provider SPI so future Git providers know to leave the comment ID empty on the opening issue text.
  2. automationMerge reads the live request first. This is the right call for correctness (retries and stale caches), but it adds an extra GetChangeRequest per merge action. Worth keeping an eye on if action-heavy graphs become common.
  3. git.issue_created only reaches call_api, trigger_ai_agent, and wait. This is documented and validated, but the E2E test only covers the wait path. A unit test for the trigger_ai_agent taskless path would close the loop.

Verification

I ran go build ./..., go test ./internal/service/git/, go test ./internal/service/automation/, go test ./internal/events/, and go test ./internal/worker/ for the changed packages — all passed. I did not run the E2E suite or the web tests in this environment.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — one minor suggestion inline.

Reviewed changes

Reviewed the delta pushed since the last Pullfrog review (b4c418e), i.e. commits d9b11cd0 and defc3927, focused on the new behavior rather than re-reading the whole PR.

  • Previous state read by the upsert — UpsertChangeRequest now reports the state it replaced through a FOR UPDATE CTE, and saveChangeRequest uses that instead of a separate pre-read, so git.pr_state_changed still fires only on a genuine transition when deliveries race or are redelivered.
  • Best-effort state emission — emitStateChange logs and returns instead of failing the webhook; since the row is already persisted, a retry could not re-observe the transition anyway.
  • Paca-footer suppression — comments and reviews whose text carries Paca's footer no longer emit the comment/review triggers, closing the self-trigger loop for agents acting through a user identity.
  • Taskless edge coverage — the E2E spec now asserts that call_api and trigger_ai_agent are reachable from git.issue_created, alongside wait.
  • Docs — the provider SPI and workflow docs now spell out the empty-comment_id issue-body contract and list the git.* node surface in §6.4.
  • Web realtime — the task Git panel hook now matches the git. event prefix and invalidates the git-prefixed query key; PluginNodeType gained the optional taskless flag.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The one open review thread (comment footers treated as Paca's) is addressed, and this push adds no new issues.

Reviewed changes

Reviewed the delta since the prior review (defc392), i.e. commit d093c03, which touches only comment filtering, one test case, and the CI timeout.

  • Comment-footer detection tightened — postedByPaca now requires the trimmed text to end with </sub> and the trailing Posted by block to be a single line, so a person replying to a Paca comment with a quote keeps git.pr_comment_created / git.pr_review_submitted.
  • Regression test for quoted footers — the trigger table now asserts a reply quoting a Paca footer still emits git.pr_comment_created.
  • API CI race-test budget raised — the -race step's -timeout moves from 120s to 300s to match a suite that has grown past the old budget, with a comment explaining why.
  • Prior thread resolved — the inline note on automation.go is addressed by the new footer check and the corresponding test.

go test ./internal/service/git/ passes on the updated branch.

@pikann
pikann merged commit 8561eef into master Nov 4, 2026
9 checks passed
@pikann
pikann deleted the feature/implement-git-automation-event-handling branch November 4, 2026 15:45
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.

1 participant