Skip to content

Handling reviews#21

Open
plebioda wants to merge 3 commits into
masterfrom
handling-reviews
Open

Handling reviews#21
plebioda wants to merge 3 commits into
masterfrom
handling-reviews

Conversation

@plebioda

Copy link
Copy Markdown
Collaborator

No description provided.

Drop the abandoned PR-comment / user-comment note fields and everything
that fed them into the resolve prompt. `set_pr_comments` was never called
(pure dead code) and `mergai comment` only attached a free-text note.

Removed:
- MergaiNote.pr_comments / user_comment fields and their
  set/has/drop/from_dict/combine/to_dict/uncommitted/all_fields handling
- The resolve-prompt injection blocks and prompt loaders
- pr_comments/user_comment formatters and get_comments_stats
- The `mergai comment` command and its helpers, plus the
  --pr-comments/--user-comment show flags and markdown/text exports
- `context drop pr_comments|user_comment` entries and field plumbing
  in app.py / notes.py
- Asset files: prompts/{pr_comments,user_comment,old_system_prompt}.md
  and templates/{markdown,text}/{pr_comments,user_comment}.jinja2

Kept the unrelated `mergai pr comment` subcommand and the CI-fix
PR-comment machinery (note.ci_comments).

Copilot AI 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.

Pull request overview

Adds a new “review-fix” flow to mergai that fetches GitHub PR review threads, filters actionable ones, builds a dedicated prompt/context for an agent run, commits any resulting changes as a type: review_fix solution, and posts per-thread replies. In parallel, it removes the older PR-comments/user-comment note fields, prompts, templates, and related CLI surfaces.

Changes:

  • Introduce mergai review commands (review list, review fix) plus the underlying review-thread fetching/filtering, prompt context building, agent validation, committing, and reply posting.
  • Add new review-specific prompt templates (system_prompt_review.md, review_context.md) and prompt builder support.
  • Remove legacy PR comments / user comment plumbing from notes, formatters, templates, prompts, and CLI.

Reviewed changes

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

Show a summary per file
File Description
tests/test_review_threads.py Adds unit tests for thread filtering/parsing, review context building, validator behavior, and reply rendering.
src/mergai/utils/formatters.py Removes PR comment/user comment formatting helpers and related summary output.
src/mergai/templates/text/user_comment.jinja2 Deletes legacy user-comment text template.
src/mergai/templates/text/pr_comments.jinja2 Deletes legacy PR-comments text template.
src/mergai/templates/text/commit_summary.jinja2 Removes PR comment/user comment sections from commit summary template.
src/mergai/templates/markdown/user_comment.jinja2 Deletes legacy user-comment markdown template.
src/mergai/templates/markdown/pr_comments.jinja2 Deletes legacy PR-comments markdown template.
src/mergai/templates/markdown/commit_summary.jinja2 Removes PR-comments reference from markdown commit summary template.
src/mergai/solution_types.py Adds REVIEW_FIX = "review_fix" constant.
src/mergai/review/threads.py Implements GraphQL fetch + parsing of review threads and actionable filtering logic.
src/mergai/review/replies.py Adds reply-body rendering and REST reply posting for review threads.
src/mergai/review/handler.py Adds agent execution wrapper + validator for per-thread coverage/classification.
src/mergai/review/context.py Builds the JSON-serializable ReviewContext embedded into the agent prompt.
src/mergai/review/commit.py Commits a review-fix solution and attaches a selective note entry.
src/mergai/review/init.py Introduces the mergai.review package.
src/mergai/prompts/user_comment.md Deletes legacy user-comment prompt.
src/mergai/prompts/system_prompt_review.md Adds the system prompt template for review-fix runs.
src/mergai/prompts/review_context.md Adds the “Review Context” prompt section template.
src/mergai/prompts/pr_comments.md Deletes legacy PR-comments prompt.
src/mergai/prompts/old_system_prompt.md Deletes legacy system prompt file.
src/mergai/prompts/merge_context_for_ci_fix.md Removes references to PR comments/user comment from CI-fix merge-context prompt.
src/mergai/prompts/init.py Adds loaders for review prompts and removes legacy PR-comments/user-comment loaders.
src/mergai/prompt_builder.py Removes PR-comments/user-comment serialization and adds build_review_prompt.
src/mergai/models.py Removes pr_comments/user_comment fields and related helpers from MergaiNote.
src/mergai/main.py Registers the new review command and removes the legacy comment command.
src/mergai/config.py Adds ReviewConfig and a commit-title format for review-fix commits.
src/mergai/commands/util.py Removes --pr-comments/--user-comment show options and deletes the legacy comment subcommand implementation.
src/mergai/commands/review.py Adds the mergai review click group and fix/list subcommands.
src/mergai/commands/notes.py Removes PR-comments/user-comment field listing from note summary formatting.
src/mergai/commands/context.py Removes support for dropping pr_comments/user_comment via context drop.
src/mergai/app.py Removes selective-note handling and note rebuild summaries for pr_comments/user_comment.

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

Comment thread src/mergai/review/threads.py Outdated
Comment thread src/mergai/review/threads.py
Comment thread tests/test_ci_fix_ack.py Fixed
@plebioda plebioda force-pushed the handling-reviews branch 2 times, most recently from 0e4df79 to 08e2589 Compare June 16, 2026 08:22
@plebioda plebioda requested a review from Copilot June 16, 2026 08:30

Copilot AI 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.

Pull request overview

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

Comment thread src/mergai/config.py Outdated
Comment thread src/mergai/commands/review.py
Comment thread src/mergai/prompt_builder.py
@plebioda plebioda force-pushed the handling-reviews branch 2 times, most recently from dc41445 to c0c001a Compare June 16, 2026 10:41
@plebioda plebioda requested a review from Copilot June 16, 2026 10:46

Copilot AI 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.

Pull request overview

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

Comment thread src/mergai/review/threads.py
Comment thread src/mergai/commands/review.py
Comment thread src/mergai/commands/review.py
Comment thread src/mergai/commands/review.py Outdated
An agent-driven flow that addresses code-review feedback on a mergai PR,
mirroring the `mergai ci` architecture. Fully generic and config-driven.

New `review/` package:
- threads.py  - GraphQL fetch of review threads (isResolved/isOutdated are
  GraphQL-only), paginating both the threads and each thread's comments, plus
  pure, network-free filtering of which threads are actionable.
- context.py  - builds the per-thread prompt context keyed by thread id.
- handler.py  - runs the agent via AgentExecutor with a validator that checks
  file changes and that every thread is classified exactly once.
- replies.py  - renders/posts fixed & unfixable replies over REST (no
  auto-resolve) and records the created reply URL for traceability.
- commit.py   - commits the result as a `type: review_fix` solution.

Command `mergai review`:
- `fix` - auto-detects the PR from the current branch (override with
  --pr-number), runs the agent once over all actionable comments, commits one
  review_fix solution, and records a reply per thread (publish with `post`).
  `--ack` posts a one-line outcome summary; `--since` pins the run to the
  comment set as it stood when triggered.
- `post` - publishes the recorded replies.
- `list` - read-only diagnostic listing every thread with its classification.
- `sync` - prunes review metadata whose commit is no longer reachable.

A thread is actionable when it is unresolved, not outdated, carries no
`/mergai skip` token, has not already been addressed by mergai (tracked
durably via the addressed thread-id set on review_fix solutions, not by
inspecting replies), and - unless process_external - was raised by a trusted
author (trusted_associations defaults to OWNER/MEMBER; trusted_logins is an
explicit allowlist). Untrusted replies and comments outside the --since cutoff
are stripped from the agent context so an external account cannot inject
instructions. The review system prompt forbids editing files no comment
refers to.

Wiring: REVIEW_FIX solution type; ReviewConfig; system_prompt_review.md,
review_context.md, and a review-specific merge-context prompt;
build_review_prompt. Tests cover filtering, skip-reason bucketing, GraphQL
parsing, the response validator, reply rendering, and orphan pruning.
…d `fix --ack`

Three related improvements to CI failure handling:

- Skip runs that are not real code failures. A `failure` conclusion is treated
  as actionable only on positive evidence: `cancelled` runs, runs whose
  deployment approval was `rejected`, and runs where no job has a failing step
  (runner death / startup_failure / infra) are skipped with a clear reason.
  Both side-checks fail open so a flaky API call never blocks a genuine fix; a
  `check_failure_kind` flag keeps `ci list` cheap.

- Aggregate CI notifications into a single per-PR comment. `ci comment post`
  groups postable entries by target PR and posts one comment listing each
  check's status, instead of one comment per processed run.

- Add `mergai ci fix --ack`: after fixing, post one short PR comment
  summarising the trigger outcome (how many failing checks were found and
  fixed), even when zero, for the comment-triggered `/mergai ci fix` path.
  Always print the actionable-run count to stdout.

Tests cover run classification/skip reasons, the aggregated comment grouping,
and the --ack feedback.

Copilot AI 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.

Pull request overview

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

Comment thread src/mergai/commands/ci.py
Comment on lines 728 to +732
continue

posted = _create_pr_comment(app, int(target_pr), body, run_id)
app.note.mark_ci_comment_posted(
run_id, posted_at=now, comment_url=getattr(posted, "html_url", None)
)
posted = _create_pr_comment(app, target_pr, body, run_ids[0])
comment_url = getattr(posted, "html_url", None)
for run_id in run_ids:
Comment on lines +236 to +241
msg = (
f"mergai review fix: no team review comments to address; "
f"ignored {ignored} (not processed)."
if ignored
else "mergai review fix: no review comments to address."
)
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.

3 participants