changes

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

@index Git diff 기반 변경 감지 및 리스크 점수 산출. 변경된 함수의 영향 범위를 분석한다.

Index

Constants

View Source
const (
	DefaultGitCommandTimeout = 30 * time.Second
	MaxGitOutputSize         = 100 * 1024 * 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecGitClient

type ExecGitClient struct{}

ExecGitClient shells out to git for change detection. @intent provide GitClient behavior using the local git executable

func NewExecGitClient

func NewExecGitClient() *ExecGitClient

NewExecGitClient creates an exec-backed git client. @intent construct a GitClient that reads diffs from the local repository

func (*ExecGitClient) ChangedFiles

func (g *ExecGitClient) ChangedFiles(ctx context.Context, repoDir, baseRef string) ([]string, error)

ChangedFiles lists files changed from the given base ref. @intent identify which repository paths changed since a base revision @param repoDir repository root where git commands are executed @param baseRef git revision used as the diff baseline @return changed file paths reported by git diff --name-only @sideEffect executes git diff in the target repository @requires repoDir points to a valid git working tree @ensures returned file paths are trimmed and exclude blank lines

func (*ExecGitClient) DiffHunks

func (g *ExecGitClient) DiffHunks(ctx context.Context, repoDir, baseRef string, paths []string) ([]Hunk, error)

DiffHunks extracts changed line ranges for the given paths. @intent map git diff output into file-level hunk ranges for overlap analysis @param repoDir repository root where git commands are executed @param baseRef git revision used as the diff baseline @param paths repository-relative paths to limit hunk extraction @return unified diff hunks with inclusive line ranges in new files @sideEffect executes git diff with zero-context output @requires repoDir points to a valid git working tree @ensures each returned hunk has a file path and inclusive start/end lines

type GitClient

type GitClient interface {
	ChangedFiles(ctx context.Context, repoDir, baseRef string) ([]string, error)
	DiffHunks(ctx context.Context, repoDir, baseRef string, paths []string) ([]Hunk, error)
}

GitClient provides git diff data needed for change analysis. @intent abstract git operations so risk analysis can consume changed files and hunks

type Hunk

type Hunk struct {
	FilePath  string
	StartLine int
	EndLine   int
}

Hunk describes a changed line range within one file. @intent represent a diff segment that can be matched against graph nodes

type Result

type Result struct {
	Items      []RiskEntry
	Pagination paging.Page
}

Result carries one bounded page of risk entries plus pagination metadata. @intent expose paged change-risk results while keeping legacy callers working with []RiskEntry.

type RiskEntry

type RiskEntry struct {
	Node      model.Node
	HunkCount int
	RiskScore float64
}

RiskEntry captures risk metrics for one changed node. @intent return the changed node together with overlap count and computed risk

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service coordinates git-based change detection and graph-backed scoring. @intent identify changed nodes and score how risky they are to modify

func New

func New(db *gorm.DB, git GitClient) *Service

New creates a change analysis service. @intent wire database and git dependencies into a reusable analyzer

func (*Service) Analyze

func (s *Service) Analyze(ctx context.Context, repoDir, baseRef string) ([]RiskEntry, error)

Analyze detects changed functions and calculates risk scores. Called from review_changes and pre_merge_check MCP prompts.

@param repoDir git repository root path @param baseRef git base reference for diff comparison @return risk entries with hunk count and risk score per changed function @intent identify high-risk code changes before merge @domainRule risk score equals hunk count multiplied by outgoing edge count plus one @sideEffect executes git diff via GitClient @see impact.Analyzer.ImpactRadius

func (*Service) AnalyzePage

func (s *Service) AnalyzePage(ctx context.Context, repoDir, baseRef string, req paging.Request) (Result, error)

AnalyzePage detects changed functions and returns one bounded page of risk entries. @intent bound handler response allocation while preserving the same sorted risk window that legacy Analyze would expose. @domainRule pagination limits returned items, but compute cost still scales with scoring every changed node to preserve legacy ordering. @domainRule entries are sorted by descending risk_score, then file_path, then qualified_name for stable ordering.

func (*Service) ChangedNodeIDs

func (s *Service) ChangedNodeIDs(ctx context.Context, repoDir, baseRef string) ([]uint, error)

ChangedNodeIDs returns the unique graph node IDs touched by the current diff. @intent let downstream analyzers reuse change detection without paying risk-score or AnalyzePage pagination-loop costs. @sideEffect executes git diff via GitClient. @ensures returned IDs are deterministic by file path, start line, qualified name, then node ID.

Jump to

Keyboard shortcuts

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