state

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const PRStateMarker = "<!-- manque-state:"

PRStateMarker is the HTML comment marker used to store state in PR body

View Source
const SessionMarker = "<!-- manque-session:"

SessionMarker is the HTML comment marker used to store session data in PR body

Variables

This section is empty.

Functions

func ComputeCommentHash

func ComputeCommentHash(file string, startLine, endLine int, content string) string

ComputeCommentHash generates a unique hash for a comment

func CountCommits

func CountCommits(baseBranch, headSHA string) (int, error)

CountCommits counts the number of commits in a PR

func CreateSessionMarker

func CreateSessionMarker(session *Session) string

CreateSessionMarker creates the HTML comment with session data

func CreateStateMarker

func CreateStateMarker(state *ReviewState) string

CreateStateMarker creates the HTML comment with state data

func GetCommitRange

func GetCommitRange(baseSHA, headSHA string) ([]string, error)

GetCommitRange gets the commits between two SHAs

func GetIncrementalDiff

func GetIncrementalDiff(lastReviewedSHA, currentSHA string) (string, error)

GetIncrementalDiff gets the diff between the last reviewed commit and current HEAD

func StripSessionMarker

func StripSessionMarker(body string) string

StripSessionMarker removes the session marker from a PR body

func StripStateMarker

func StripStateMarker(body string) string

StripStateMarker removes the state marker from a PR body

Types

type DismissedIssue

type DismissedIssue struct {
	Hash        string    `json:"hash"` // file:line:content hash
	Reason      string    `json:"reason,omitempty"`
	DismissedAt time.Time `json:"dismissed_at"`
}

DismissedIssue represents an issue the user explicitly dismissed

type Interaction

type Interaction struct {
	Type       string    `json:"type"` // "reply", "resolve", "dismiss", "command"
	CommentID  int64     `json:"comment_id,omitempty"`
	Content    string    `json:"content,omitempty"`
	Timestamp  time.Time `json:"timestamp"`
	BotReponse string    `json:"bot_response,omitempty"`
}

Interaction represents a user interaction with the bot

type ReviewRecord

type ReviewRecord struct {
	SHA           string    `json:"sha"`
	ReviewedAt    time.Time `json:"reviewed_at"`
	CommentHashes []string  `json:"comment_hashes"` // SHA256 of file:line:content
	Score         int       `json:"score"`
	IssueCount    int       `json:"issue_count"`
	Addressed     []string  `json:"addressed,omitempty"` // Hashes of issues fixed in subsequent commits
}

ReviewRecord represents a single review round

type ReviewState

type ReviewState struct {
	PRNumber        int       `json:"pr_number"`
	Repository      string    `json:"repository"`
	LastReviewedSHA string    `json:"last_reviewed_sha"`
	ReviewedAt      time.Time `json:"reviewed_at"`
	CommitCount     int       `json:"commit_count"`
}

ReviewState represents the state of a PR review

func ExtractStateFromBody

func ExtractStateFromBody(body string) *ReviewState

ExtractStateFromBody extracts the review state from a PR body

type Session

type Session struct {
	PRNumber     int              `json:"pr_number"`
	Repository   string           `json:"repository"`
	Reviews      []ReviewRecord   `json:"reviews"`
	Interactions []Interaction    `json:"interactions"`
	Dismissed    []DismissedIssue `json:"dismissed"`
	UpdatedAt    time.Time        `json:"updated_at"`
}

Session represents the accumulated review session data

func ExtractSessionFromBody

func ExtractSessionFromBody(body string) *Session

ExtractSessionFromBody extracts the session from a PR body

func (*Session) AddInteraction

func (s *Session) AddInteraction(interactionType string, commentID int64, content, botResponse string)

AddInteraction records a user interaction

func (*Session) AddReviewRecord

func (s *Session) AddReviewRecord(sha string, commentHashes []string, score, issueCount int)

AddReviewRecord adds a new review record to the session

func (*Session) DismissIssue

func (s *Session) DismissIssue(hash, reason string)

DismissIssue marks an issue as dismissed

func (*Session) GetPreviousCommentHashes

func (s *Session) GetPreviousCommentHashes() map[string]bool

GetPreviousCommentHashes returns all comment hashes from previous reviews

func (*Session) GetSummary

func (s *Session) GetSummary() string

GetSummary returns a human-readable summary of the session

func (*Session) IsDismissed

func (s *Session) IsDismissed(hash string) bool

IsDismissed checks if an issue has been dismissed

func (*Session) MarkAddressed

func (s *Session) MarkAddressed(hashes []string)

MarkAddressed marks issues as addressed in the previous review

func (*Session) TrimSession

func (s *Session) TrimSession(maxReviews int)

TrimSession removes old data to keep the marker size manageable

func (*Session) WasAddressed

func (s *Session) WasAddressed(hash string) bool

WasAddressed checks if an issue was marked as addressed

type SessionManager

type SessionManager struct {
	Repository string
	PRNumber   int
}

SessionManager handles session persistence and retrieval

func NewSessionManager

func NewSessionManager(repository string, prNumber int) *SessionManager

NewSessionManager creates a new session manager

func (*SessionManager) GetOrCreateSession

func (m *SessionManager) GetOrCreateSession(prBody string) *Session

GetOrCreateSession retrieves existing session or creates a new one

type Tracker

type Tracker struct {
	Repository string
	PRNumber   int
}

Tracker manages incremental review state

func NewTracker

func NewTracker(repository string, prNumber int) *Tracker

NewTracker creates a new state tracker

func (*Tracker) CreateNewState

func (t *Tracker) CreateNewState(currentSHA string, commitCount int) *ReviewState

CreateNewState creates a new review state

func (*Tracker) IsIncrementalReview

func (t *Tracker) IsIncrementalReview(prBody, currentSHA string) (bool, *ReviewState)

IsIncrementalReview determines if this is an incremental review

Jump to

Keyboard shortcuts

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