UNPKG

glu-cli

Version:

Git stacked branch management with GitHub integration

52 lines 2.25 kB
import { CommitService } from "../services/commit-service.js"; import { GitAdapter } from "../infrastructure/git-adapter.js"; import { GluGraphService } from "../services/glu-graph-service.js"; import { FileSystemGraphStorage } from "../infrastructure/graph-storage-adapter.js"; import { extractGluId } from "../utils/glu-id.js"; export class ListUseCase { commitService; gluGraphService; constructor(commitService, gluGraphService) { this.commitService = commitService; this.gluGraphService = gluGraphService; } static default() { const git = new GitAdapter(); const graphStorage = new FileSystemGraphStorage(); const commitService = new CommitService(git); const gluGraphService = new GluGraphService(graphStorage); return new ListUseCase(commitService, gluGraphService); } async execute() { const currentBranch = await this.commitService.getCurrentBranch(); const upstreamBranch = await this.commitService.getUpstreamBranch(currentBranch); const unpushedCommits = await this.commitService.getUnpushedCommits(); const comparison = await this.commitService.getAheadBehindStatus(); const enrichedCommits = await this.enrichCommitsWithBranches(unpushedCommits); return { ahead: comparison.ahead, behind: comparison.behind, currentBranch, originBranch: upstreamBranch, unpushedCommits: enrichedCommits, }; } async enrichCommitsWithBranches(commits) { return Promise.all(commits.map(async (commit) => { const gluId = extractGluId(commit.body); if (!gluId) { return { ...commit, trackedBranches: [] }; } const branches = await this.gluGraphService.getBranchesForGluId(gluId); const currentBranch = await this.commitService.getCurrentBranch(); const reviewBranches = branches .filter((b) => b.branch !== currentBranch) .map((b) => b.branch); return { ...commit, trackedBranches: reviewBranches, }; })); } } //# sourceMappingURL=list-use-case.js.map