journal

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendEntries

func AppendEntries(project string, entries []Entry) error

AppendEntries appends entries to the project's commits.jsonl, creating parent directories if needed. Entries whose SHA+Ticket pair already exists in the file are skipped.

func AppendEntriesToPath

func AppendEntriesToPath(path string, entries []Entry) error

AppendEntriesToPath appends entries to a specific JSONL path with dedup.

func CountForTicket

func CountForTicket(entries []Entry, ticketID string) int

CountForTicket counts entries for a specific ticket ID.

func ExtractTicketActions

func ExtractTicketActions(message string) map[string]string

ExtractTicketActions parses a commit message and returns a map of ticket ID to action. Bracket refs [ticket-id] produce action "ref". Closes:/Fixes: prefixes followed by bracket refs produce action "close".

func FirstLine

func FirstLine(s string) string

FirstLine returns the first line of s, truncating at the first newline.

func GetDiffStats

func GetDiffStats(repoPath, sha string) (files []string, added, removed int, branch string, err error)

GetDiffStats runs git diff-tree --numstat for a commit and returns changed files, total lines added, total lines removed, and the branch name.

func GetParentCommitTS

func GetParentCommitTS(repoPath, sha string) string

GetParentCommitTS returns the author date of the parent commit (sha^), used as a work_started proxy. Returns empty string on any error.

func GroupByTicket

func GroupByTicket(entries []Entry) map[string][]Entry

GroupByTicket groups entries by ticket ID into a map.

func IsLiveCommit

func IsLiveCommit(ts string) bool

IsLiveCommit returns true if the commit timestamp is within the last 60 seconds.

func JournalPath

func JournalPath(project string) (string, error)

JournalPath returns ~/.ticket/state/<project>/commits.jsonl.

func LoadJournalState

func LoadJournalState(path string) (map[string]struct{}, string, error)

LoadJournalState reads existing SHAs and the last SHA from a journal file.

func ResolveStableBranchName

func ResolveStableBranchName(repoPath, sha string) string

ResolveStableBranchName returns a single stable branch label for a commit. Returns empty string if the commit belongs to zero or multiple branches.

func StatePath

func StatePath(project string) (string, error)

StatePath returns ~/.ticket/state/<project>/.

func WorkDurationSeconds

func WorkDurationSeconds(started, ended string) int

WorkDurationSeconds computes the duration in seconds between two RFC3339 timestamps. Returns 0 if either is empty or unparseable.

Types

type EffortSummary

type EffortSummary struct {
	LinesAdded   int
	LinesRemoved int
	FilesChanged int
	Commits      int
}

EffortSummary holds aggregated diff stats for a set of journal entries.

func Effort

func Effort(entries []Entry) EffortSummary

Effort computes aggregated diff stats from a slice of journal entries.

func (EffortSummary) String

func (e EffortSummary) String() string

String returns a human-readable effort summary, or empty string if no data.

type Entry

type Entry struct {
	SHA          string   `json:"sha"`
	Ticket       string   `json:"ticket"`
	Repo         string   `json:"repo"`
	TS           string   `json:"ts"`
	Msg          string   `json:"msg"`
	Author       string   `json:"author"`
	Action       string   `json:"action"`
	FilesChanged []string `json:"files_changed,omitempty"`
	LinesAdded   int      `json:"lines_added,omitempty"`
	LinesRemoved int      `json:"lines_removed,omitempty"`
	Branch       string   `json:"branch,omitempty"`
	WorkStarted  string   `json:"work_started,omitempty"`
	WorkEnded    string   `json:"work_ended,omitempty"`
	DurationSecs int      `json:"duration_seconds,omitempty"`
}

Entry represents a single commit-to-ticket link in the journal JSONL file.

func FilterByTickets

func FilterByTickets(entries []Entry, ids []string) []Entry

FilterByTickets returns entries whose Ticket is in the given set of IDs.

func LastN

func LastN(entries []Entry, n int) []Entry

LastN returns the last n entries (or all if fewer).

func ReadEntries

func ReadEntries(project string) ([]Entry, error)

ReadEntries loads all commit journal entries for the given project. Malformed lines are silently skipped. Missing file returns empty slice.

func ReadEntriesFromPath

func ReadEntriesFromPath(path string) ([]Entry, error)

ReadEntriesFromPath loads entries from a specific JSONL file path.

type GitCommit

type GitCommit struct {
	SHA    string
	TS     string
	Author string
	Msg    string
}

GitCommit represents a parsed git log entry.

func CollectCommits

func CollectCommits(repoPath, lastSHA, registeredAt string) ([]GitCommit, error)

CollectCommits runs git log and returns commits in chronological order. If lastSHA is provided, returns commits after that SHA. If lastSHA is empty or the SHA range fails (history rewrite), falls back to --since=registeredAt.

type WatchCycleResult

type WatchCycleResult struct {
	Appended int
	Closed   int
	Warnings []string
}

WatchCycleResult holds the outcome of a single watch cycle for a project.

func RunWatchCycle

func RunWatchCycle(projectName string, cfg project.ProjectConfig, store ticket.Store) (WatchCycleResult, error)

RunWatchCycle processes new git commits for a project, extracts ticket references, computes diff stats, appends journal entries, and optionally auto-closes tickets.

Jump to

Keyboard shortcuts

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