elastic / elastic/ai-github-actions
[refactor-opportunist] Consolidate add-comment limitations into a shared safe-output fragment
- Dominant language
- Python
- Stars
- 11
- Forks
- 16
- Avg merge
- 22h 9m
- Merged PRs (30d)
- 31
Description
## 🏗️ Refactor Proposal
**Summary:** Centralize duplicated `add-comment` limitation guidance into one reusable fragment and keep channel-specific behavior in thin wrapper fragments.
## Problem
The same policy text is duplicated across multiple safe-output fragments, which increases maintenance cost and inconsistency risk:
- `.github/workflows/gh-aw-fragments/safe-output-add-comment-issue.md:10-19`
- `.github/workflows/gh-aw-fragments/safe-output-add-comment-issue-or-pr.md:1-10`
- (before PoC) `.github/workflows/gh-aw-fragments/safe-output-add-comment-pr.md:11-20`
- (before PoC) `.github/workflows/gh-aw-fragments/safe-output-add-comment-pr-hide-older.md:12-21`
This duplicated block is consumed broadly: 17 workflow sources currently import one of these fragments (verified via `rg` over `.github/workflows/gh-aw-*.md`).
The structure is harder to evolve because policy prose and channel-specific safe-output settings are mixed in each fragment.
## Proposed Approach
Create one shared fragment containing the common `add-comment` limitation prose, and have channel-specific fragments import it.
- Keep per-channel `safe-outputs` config (`issues`, `pull-requests`, `hide-older-comments`, `target`) in wrapper fragments.
- Move shared prose into `gh-aw-fragments/safe-output-add-comment-limitations.md`.
- Keep issue-specific bot-trigger exception text in issue-targeting wrappers where needed.
This aligns with documented import behavior in `gh-agent-workflows/DEVELOPING.md:109-112` (2-level imports supported; `safe-outputs` composition behavior documented).
## Proof of Concept
I partially implemented this refactor on one representative slice to verify viability.
**Files changed:**
- `.github/workflows/gh-aw-fragments/safe-output-add-comment-limitations.md` (new)
- `.github/workflows/gh-aw-fragments/safe-output-add-comment-pr.md`
- `.github/workflows/gh-aw-fragments/safe-output-add-comment-pr-hide-older.md`
- Recompiled lock files affected by those imports (e.g. `gh-aw-pr-actions-fixer.lock.yml`, `gh-aw-pr-actions-detective.lock.yml`)
**Before → After (key change):**
Before (`safe-output-add-comment-pr.md`):
- Included full `## add-comment Limitations` section inline.
After (`safe-output-add-comment-pr.md:1-12`):
- Keeps only PR-specific `safe-outputs` config.
- Adds:
- `imports:`
- `- gh-aw-fragments/safe-output-add-comment-limitations.md`
Shared prose now lives in:
- `.github/workflows/gh-aw-fragments/safe-output-add-comment-limitations.md:1-10`
**Verification:**
- Baseline: `make compile` ✅, `make lint` ✅
- After PoC: `make compile` ✅, `make lint` ✅
- Existing validation remained green; no compiler/linter failures introduced.
## Incremental Rollout Plan
This refactor can be completed incrementally:
1. ✅ Proven: extract shared limitations and migrate PR-oriented fragments (`safe-output-add-comment-pr*`).
2. Migrate issue-oriented wrappers (`safe-output-add-comment-issue.md`, `safe-output-add-comment-issue-or-pr.md`) while preserving the “unless referencing triggering issue” exception text in those wrappers.
3. Recompile and review lock deltas, then add a short note in `gh-agent-workflows/DEVELOPING.md` recommending shared policy fragments for safe-output text blocks.
## Risks and Mitigations
- **Risk:** Import ordering can produce noisy lock-file prompt block movement.
- **Mitigation:** Validate with `make compile` and review lock diffs for semantic equivalence.
- **Risk:** Issue-targeted bot-trigger exception text could be accidentally generalized.
- **Mitigation:** Keep exception sentence in issue wrappers and only centralize truly common lines.
## Evidence
- Duplication in source fragments:
- `.github/workflows/gh-aw-fragments/safe-output-add-comment-issue.md:10-19`
- `.github/workflows/gh-aw-fragments/safe-output-add-comment-issue-or-pr.md:1-10`
- `.github/workflows/gh-aw-fragments/safe-output-add-comment-pr.md` (pre-PoC inline block)
- `.github/workflows/gh-aw-fragments/safe-output-add-comment-pr-hide-older.md` (pre-PoC inline block)
- Broad usage: 17 importing workflows in `.github/workflows/gh-aw-*.md`.
- PoC compile/lint verification executed successfully after migration slice.
---
[What is this?](https://ela.st/github-ai-tools) | [From workflow: Trigger Refactor Opportunist](https://github.com/elastic/ai-github-actions/actions/runs/23148992561)
Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.
Contributor guide
Assessment
This issue has not been assessed yet.