feat: 支持导出分析报告为 JSON 和 Markdown 格式#19
Open
xx9090950 wants to merge 1 commit into
Open
Conversation
响应 issue hellodigua#16 需求,用户可以将分析结果导出为文件,方便分享给其他人 共享各公司的真实工作情况 新增: - `-e, --export <format>` 选项支持 json 和 markdown 两种导出格式 - `-o, --output <path>` 选项指定导出文件路径 - `src/utils/exporter.ts` 导出工具模块,包含数据序列化和格式转换 - 单仓库和多仓库模式均支持导出 - 导出内容包含核心结果、工作时间、加班分析、时间分布、月度趋势、团队分析
Reviewer's GuideAdds a generic report export subsystem that can output single- and multi-repo analysis results as JSON or Markdown, wires it into the analyze/multi CLI commands via new -e/--export and -o/--output options, and threads trend and team analysis results into the export payloads. Sequence diagram for CLI report export flow (single-repo analyze)sequenceDiagram
actor Developer
participant CLIManager
participant AnalyzeExecutor
participant TrendAnalyzer
participant GitTeamAnalyzer
participant Exporter as exportReport
Developer->>CLIManager: run code996 analyze -e json -o report.json
CLIManager->>AnalyzeExecutor: execute(path, AnalyzeOptions{export,output,...})
activate AnalyzeExecutor
AnalyzeExecutor->>TrendAnalyzer: analyzeTrend(path, effectiveSince, effectiveUntil, options)
TrendAnalyzer-->>AnalyzeExecutor: trendResult
AnalyzeExecutor->>GitTeamAnalyzer: analyzeTeam(collectOptions, index996, minCommits, maxUsers, false)
GitTeamAnalyzer-->>AnalyzeExecutor: teamResult
alt export option is set
AnalyzeExecutor->>Exporter: exportReport(ExportData{result,parsedData,rawData,trendResult,teamAnalysis}, format, outputPath)
Exporter-->>AnalyzeExecutor: write file
end
AnalyzeExecutor-->>CLIManager: finish
CLIManager-->>Developer: print summary and export success
Class diagram for new exporter data structures and functionsclassDiagram
class Exporter {
+exportReport(data, format, outputPath) void
-exportToJson(data) string
-exportToMarkdown(data) string
-serializeSingleData(data) Record
-serializeMultiData(data) Record
-serializeTeamAnalysis(team) Record
-buildSingleMarkdown(data) string
-buildMultiMarkdown(data) string
-formatHour(hour) string
-getMaxCount(data) number
-trendLabel(trend) string
}
class ExportData {
+string repoName
+string repoPath
+string generatedAt
+Record~string,unknown~ options
+Result996 result
+ParsedGitData parsedData
+GitLogData rawData
+ProjectClassificationResult classification
+TrendAnalysisResult trendResult
+TeamAnalysis teamAnalysis
}
class MultiExportData {
+string generatedAt
+Record~string,unknown~ options
+ExportData[] repos
+Result996 mergedResult
+ParsedGitData mergedParsedData
+GitLogData mergedRawData
+RepoAnalysisRecord[] repoRecords
+TrendAnalysisResult trendResult
+TeamAnalysis teamAnalysis
}
class Result996 {
+number index996
+string index996Str
+number overTimeRadio
}
class ParsedGitData {
+any detectedWorkTime
+any[] hourData
+any[] dayData
+any[] workHourPl
+any[] workWeekPl
+any weekdayOvertime
+any weekendOvertime
+any lateNightAnalysis
}
class GitLogData {
+number totalCommits
+number contributors
+string firstCommitDate
+string lastCommitDate
}
class TrendAnalysisResult {
+any summary
+any[] monthlyData
}
class TeamAnalysis {
+number totalContributors
+number totalAnalyzed
+number baselineEndHour
+any distribution
+any statistics
+any healthAssessment
+any[] coreContributors
}
class RepoAnalysisRecord {
+string status
+any repo
+GitLogData data
+Result996 result
+any classification
}
class ProjectClassificationResult {
+string projectType
+number confidence
}
Exporter --> ExportData : uses
Exporter --> MultiExportData : uses
ExportData --> Result996 : contains
ExportData --> ParsedGitData : contains
ExportData --> GitLogData : contains
ExportData --> ProjectClassificationResult : optional
ExportData --> TrendAnalysisResult : optional
ExportData --> TeamAnalysis : optional
MultiExportData --> ExportData : contains
MultiExportData --> Result996 : contains
MultiExportData --> ParsedGitData : contains
MultiExportData --> GitLogData : contains
MultiExportData --> RepoAnalysisRecord : contains
MultiExportData --> TrendAnalysisResult : optional
MultiExportData --> TeamAnalysis : optional
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- 在 Markdown 导出中有多处直接插入可选字段(例如 classification.confidence、trendResult、weekendOvertime 等),当前逻辑会在缺失时输出
undefined或空结构,建议在生成表格行前做存在性判断或提供合理的 fallback 文本,避免导出的报告出现undefined。 - 多仓库 Markdown 报告的“各仓库对比”表格里所有仓库状态都写死为
✓,同时完全忽略了 repoRecords 中失败或跳过的仓库,建议利用 repoRecords 的 status 字段真实反映成功/失败/跳过,并在表格或单独一节列出未成功分析的仓库。 - 在 multi 模式导出时,会对每个成功仓库重新调用 GitParser.parseGitData 进行解析,这在大仓库/多仓库场景下可能带来明显的额外开销,建议复用 repoRecords 中已有的解析结果(如果存在)或在分析阶段缓存以避免重复计算。
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- 在 Markdown 导出中有多处直接插入可选字段(例如 classification.confidence、trendResult、weekendOvertime 等),当前逻辑会在缺失时输出 `undefined` 或空结构,建议在生成表格行前做存在性判断或提供合理的 fallback 文本,避免导出的报告出现 `undefined`。
- 多仓库 Markdown 报告的“各仓库对比”表格里所有仓库状态都写死为 `✓`,同时完全忽略了 repoRecords 中失败或跳过的仓库,建议利用 repoRecords 的 status 字段真实反映成功/失败/跳过,并在表格或单独一节列出未成功分析的仓库。
- 在 multi 模式导出时,会对每个成功仓库重新调用 GitParser.parseGitData 进行解析,这在大仓库/多仓库场景下可能带来明显的额外开销,建议复用 repoRecords 中已有的解析结果(如果存在)或在分析阶段缓存以避免重复计算。Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Owner
|
hi 可以修复一下AI提出的问题吗,另外目前已支持英文版,要是能一并兼容就好了 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
总结
-e, --export <format>选项(json / markdown)-o, --output <path>指定导出路径测试
已通过 TypeScript 类型检查,JSON 和 Markdown 导出均在真实仓库上验证通过。
Summary by Sourcery
Add report export capability for single and multi-repository analyses, supporting JSON and Markdown outputs from the CLI.
New Features:
Enhancements: