export function compareStars({ currentRepos, previousSnapshot,}: CompareStarsParams): ComparisonResults { // Builds maps of current vs previous star counts // Identifies new repos, removed repos, and deltas // Returns ComparisonResults with per-repo and aggregate metrics}
snapshot.ts - Snapshot management
export function getLastSnapshot(history: History): Snapshot | null;export function addSnapshot({ history, snapshot, maxHistory }: AddSnapshotParams): History;
forecast.ts - Growth prediction
export function computeForecast({ history, topRepoNames,}: ComputeForecastParams): ForecastData | null { // Requires at least 3 snapshots // Applies linear regression and weighted moving average // Forecasts 4 weeks ahead}
stargazers.ts - Stargazer diffing
export function diffStargazers({ current, previousMap,}: DiffStargazersParams): StargazerDiffResult { // Identifies new stargazers per repository // Returns sorted list by starred_at timestamp}
notification.ts - Threshold logic
export function shouldNotify({ totalStars, starsAtLastNotification, threshold,}: ShouldNotifyParams): boolean { // Supports fixed thresholds (N stars) // Supports adaptive thresholds ('auto' mode) // Adaptive: 1% for <1000 stars, 0.5% for 1000-10000, 0.1% for >10000}
export async function fetchAllStargazers({ octokit, repos,}: FetchAllStargazersParams): Promise<RepoStargazers[]> { // Paginates through stargazers endpoint // Returns login, avatar, profile URL, and starred_at timestamp}
git/worktree.ts - Git worktree management
export function initializeDataBranch(dataBranch: string): string { // Configures git user (github-actions[bot]) // Checks if branch exists on remote // Creates orphan branch if needed // Adds worktree in separate directory return dataDir; // e.g., ".star-tracker-data"}export function cleanup(dataDir: string): void { // Removes worktree after operations complete}
Worktrees allow the action to work with two branches simultaneously without affecting the main checkout.
persistence/storage.ts - File operations
export function readHistory(dataDir: string): History;export function writeHistory({ dataDir, history }: WriteHistoryParams): void;export function writeReport({ dataDir, markdown }: WriteReportParams): void;export function writeBadge({ dataDir, svg }: WriteBadgeParams): void;export function writeChart({ dataDir, filename, svg }: WriteChartParams): void;export function writeCsv({ dataDir, csv }: WriteCsvParams): void;export function readStargazers(dataDir: string): StargazerMap;export function writeStargazers({ dataDir, stargazerMap }: WriteStargazersParams): void;
persistence/storage.ts - Git commit and push
export function commitAndPush({ dataDir, dataBranch, message,}: CommitAndPushParams): boolean { // Stages all files with git add -A // Checks for staged changes with git diff --cached --quiet // Commits and pushes to origin/{dataBranch} // Returns true if changes were committed}
notification/email.ts - SMTP delivery
export async function sendEmail({ emailConfig, subject, htmlBody,}: SendEmailParams): Promise<void> { // Uses nodemailer with SMTP transport // Sends HTML report with inline styles}
Application Layer (/src/application)
Orchestrates the entire workflow by coordinating domain logic and infrastructure.tracker.ts - Main entry point
import { getTranslations } from '@i18n';const t = getTranslations(config.locale);const title = t.report.starHistory; // "Star History" or "Historial de Estrellas"
The action is optimized for low overhead and fast execution.
Bundled Dependencies: Zero runtime npm installs. All dependencies are bundled at build time.Git Worktrees: Avoids expensive branch switches and stash operations.Incremental Processing: Only fetches stargazers if track-stargazers: true.Efficient Pagination: Uses GitHub’s REST API with optimal page sizes.Snapshot Rotation: Limits history to max-history snapshots (default: 52) to prevent unbounded growth.