post

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package post submits approved review findings back to the upstream hosting service as inline PR review comments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Poster

type Poster struct {
	// Out receives dry-run payloads and the resulting Review URL on submit.
	Out io.Writer
	// Repost, when true, bypasses the pre-post dedup step that skips
	// findings whose (file, line) already has a diffsmith thread on the
	// MR/PR. Use this for the explicit "I know there are duplicates and
	// I want them anyway" path; the default behavior is to skip.
	Repost bool
	// OldPaths maps a finding's post-image path to the pre-rename path
	// produced by the diff parser. Used by submitGitLab to populate
	// position.old_path on inline discussions for renamed-with-hunks
	// files; same-path files don't need an entry. Ignored by the
	// GitHub path (GitHub's addPullRequestReviewThread anchors on the
	// post-image path alone).
	//
	// Kept on Poster (not on each Finding) so the model JSON schema
	// stays post-image-path only and the app layer can populate this
	// once from the parsed diff before calling Submit.
	OldPaths map[string]string
}

Poster submits approved review findings to GitHub as inline PR review comments grouped under a single Review.

func (*Poster) PrintPayload

func (p *Poster) PrintPayload(target review.ReviewTarget, findings []review.Finding) error

PrintPayload writes one JSON document per finding to p.Out — a hermetic preview of what Submit would send. The payload shape is host-specific: GitHub gets the addPullRequestReviewThread input (review ID is a placeholder "<REVIEW_ID>" because the pending review only exists after a real submit); GitLab gets the discussions API body, with the same position fields submitGitLab would marshal.

Routing on target.Host is explicit: an unknown host returns an error rather than silently defaulting to GitHub, so a future provider can't ship a shape mismatch by accident (diffsmith-696). Empty Host (zero-value ReviewTarget) hits the same error path.

func (*Poster) Submit

func (p *Poster) Submit(ctx context.Context, target review.ReviewTarget, findings []review.Finding) error

Submit runs the four-phase GraphQL flow that turns approved findings into a single grouped GitHub Review:

  1. Resolve the PR's GraphQL node ID and current headRefOid; refuse when the head moved since the diff was fetched (threads anchor to the current head — there is no commitOID field — so posting after a push would mis-anchor every comment; diffsmith-cgq).
  2. Begin a pending pull request review.
  3. Add one inline thread per finding, anchored to (path, line) on the PR's current head (== capture-time head, per the guard).
  4. Finalize: submit if ≥1 thread succeeded; otherwise delete the pending review so it doesn't strand on GitHub.

Per-finding addThread failures do NOT abort the batch — every finding is attempted, then a summary is printed and the appropriate finalize call runs. This keeps GitHub state consistent: callers either see a real review URL (with a summary that names any failed findings) or a clean error after the pending review has been swept away.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL