Skip to content

feat: expose changed files as {{.Files}} in webhook prompt templates#1565

Open
knechtionscoding wants to merge 1 commit into
kelos-dev:mainfrom
datagravity-ai:worktree-files-template-var
Open

feat: expose changed files as {{.Files}} in webhook prompt templates#1565
knechtionscoding wants to merge 1 commit into
kelos-dev:mainfrom
datagravity-ai:worktree-files-template-var

Conversation

@knechtionscoding

@knechtionscoding knechtionscoding commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it:

Kelos already fetches a pull request's changed-file list for filePatterns filtering (fetchPRChangedFilesWithToken in internal/webhook/github_files.go) and then discards it once matching is done. This PR exposes that list to prompt templates as {{.Files}} via ExtractGitHubWorkItem, so spawners can pass the set of touched files into the task prompt without an extra runtime gh call.

Details:

  • Files is always present in the template var map so {{.Files}} never trips the renderer's missingkey=error.
  • For PR events it is only populated when a matching filter's filePatterns forced the changed-files fetch (fetching is gated on filePatterns); otherwise it renders as an empty list.
  • Push events populate {{.Files}} from the payload regardless.
  • Iterate with {{range .Files}}.

This resolves the "deferred to a follow-up" NOTE previously left on the ChangedFiles field. Scope is intentionally limited to .Files only — .Diff would require fetching per-file patch content (larger payloads, truncation concerns) and is left as a future change, consistent with keeping API surfaces minimal.

Which issue(s) this PR is related to:

N/A

Special notes for your reviewer:

{{.Files}} for PR events depends on filePatterns being set on the matching filter, because that is the only thing that triggers the lazy fetch. This coupling is documented in docs/reference.md. Adding a .Diff variable or fetching files when the prompt references {{.Files}} without filePatterns are possible follow-ups.

Does this PR introduce a user-facing change?

TaskSpawner/SessionSpawner GitHub webhook prompt templates can now reference `{{.Files}}`, the list of changed file paths. It is populated for push events, and for pull request events when the matching filter declares `filePatterns`.

Summary by cubic

Expose changed file paths to webhook prompt templates as {{.Files}} so tasks can include touched files without extra GitHub calls. For PRs, it is populated only when a matching filter’s filePatterns triggered a fetch; push events always provide it from the payload.

  • New Features
    • Add {{.Files}} (list of paths). Always present; may be empty. Iterate with {{range .Files}}.
    • Update docs/reference.md and add tests for rendering and empty behavior.

Written for commit eeb26b7. Summary will update on new commits.

Review in cubic

Kelos already fetches a PR's changed-file list for filePatterns
filtering and then discards it. Expose that list to prompt templates as
{{.Files}} via ExtractGitHubWorkItem. The key is always set so
{{.Files}} never trips missingkey=error; for PR events it is only
populated when a matching filter's filePatterns forced the fetch, while
push events populate it from the payload.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added kind/feature Categorizes issue or PR as related to a new feature needs-triage needs-priority needs-actor needs-release-note Indicates a PR lacks a release-note block release-note and removed needs-release-note Indicates a PR lacks a release-note block labels Jul 24, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 4 files

Re-trigger cubic

@gjkim42 gjkim42 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good, one nit for naming.

// {{.Files}} never trips missingkey=error) but is only populated when a
// filter's filePatterns forced a changed-files fetch; otherwise it is
// empty. See the ChangedFiles field for details.
"Files": eventData.ChangedFiles,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is it better to name it ChangedFiles?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Categorizes issue or PR as related to a new feature needs-actor needs-priority needs-triage release-note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants