forked from Gitlink/gitlink-cli
253 lines
19 KiB
JavaScript
253 lines
19 KiB
JavaScript
const fs = require('fs');
|
||
const { Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell,
|
||
Header, Footer, AlignmentType, HeadingLevel, BorderStyle, WidthType,
|
||
ShadingType, PageNumber, PageBreak, LevelFormat } = require('docx');
|
||
|
||
const border = { style: BorderStyle.SINGLE, size: 1, color: 'BBBBBB' };
|
||
const borders = { top: border, bottom: border, left: border, right: border };
|
||
|
||
function makeHeaderRow(cells) {
|
||
return new TableRow({
|
||
children: cells.map(c => new TableCell({
|
||
borders, width: { size: c.w, type: WidthType.DXA },
|
||
shading: { fill: '1E3A5F', type: ShadingType.CLEAR },
|
||
margins: { top: 60, bottom: 60, left: 100, right: 100 },
|
||
children: [new Paragraph({ children: [new TextRun({ text: c.t, bold: true, color: 'FFFFFF', font: 'Microsoft YaHei', size: 20 })] })]
|
||
}))
|
||
});
|
||
}
|
||
function makeRow(cells) {
|
||
return new TableRow({
|
||
children: cells.map(c => new TableCell({
|
||
borders, width: { size: c.w, type: WidthType.DXA },
|
||
margins: { top: 60, bottom: 60, left: 100, right: 100 },
|
||
children: [new Paragraph({ children: [new TextRun({ text: c.t, font: 'Microsoft YaHei', size: 20 })] })]
|
||
}))
|
||
});
|
||
}
|
||
|
||
function p(text, opts) {
|
||
const size = (opts && opts.size) || 22;
|
||
return new Paragraph({ spacing: { after: 100 }, ...opts,
|
||
children: [new TextRun({ text, font: 'Microsoft YaHei', size })]
|
||
});
|
||
}
|
||
function bullet(text) {
|
||
return new Paragraph({
|
||
numbering: { reference: 'bullets', level: 0 },
|
||
children: [new TextRun({ text, font: 'Microsoft YaHei', size: 22 })]
|
||
});
|
||
}
|
||
|
||
const sharedStyles = {
|
||
default: { document: { run: { font: 'Microsoft YaHei', size: 24 } } },
|
||
paragraphStyles: [
|
||
{ id: 'Heading1', name: 'Heading 1', basedOn: 'Normal', next: 'Normal', quickFormat: true,
|
||
run: { size: 32, bold: true, font: 'Microsoft YaHei', color: '1E3A5F' },
|
||
paragraph: { spacing: { before: 360, after: 200 }, outlineLevel: 0 } },
|
||
{ id: 'Heading2', name: 'Heading 2', basedOn: 'Normal', next: 'Normal', quickFormat: true,
|
||
run: { size: 28, bold: true, font: 'Microsoft YaHei', color: '2B579A' },
|
||
paragraph: { spacing: { before: 280, after: 160 }, outlineLevel: 1 } },
|
||
{ id: 'Heading3', name: 'Heading 3', basedOn: 'Normal', next: 'Normal', quickFormat: true,
|
||
run: { size: 24, bold: true, font: 'Microsoft YaHei' },
|
||
paragraph: { spacing: { before: 200, after: 120 }, outlineLevel: 2 } },
|
||
]
|
||
};
|
||
const sharedNum = { config: [{ reference: 'bullets', levels: [{ level: 0, format: LevelFormat.BULLET, text: '•', alignment: AlignmentType.LEFT, style: { paragraph: { indent: { left: 720, hanging: 360 } } } }] }] };
|
||
|
||
// ========== 报告1:新需求构思报告 ==========
|
||
function buildReport1() {
|
||
return new Document({
|
||
styles: sharedStyles,
|
||
numbering: sharedNum,
|
||
sections: [{
|
||
properties: { page: { size: { width: 11906, height: 16838 }, margin: { top: 1440, right: 1440, bottom: 1440, left: 1440 } } },
|
||
headers: { default: new Header({ children: [new Paragraph({
|
||
alignment: AlignmentType.RIGHT,
|
||
border: { bottom: { style: BorderStyle.SINGLE, size: 4, color: '1E3A5F', space: 4 } },
|
||
children: [new TextRun({ text: '新需求构思报告 · GitLink CLI', size: 16, color: '94A3B8', font: 'Microsoft YaHei' })]
|
||
})] }) },
|
||
footers: { default: new Footer({ children: [new Paragraph({ alignment: AlignmentType.CENTER, children: [
|
||
new TextRun({ text: '第 ', size: 18, color: '94A3B8' }),
|
||
new TextRun({ children: [PageNumber.CURRENT], size: 18, color: '94A3B8' }),
|
||
new TextRun({ text: ' 页', size: 18, color: '94A3B8' })
|
||
] })] }) },
|
||
children: [
|
||
// 封面
|
||
new Paragraph({ spacing: { before: 2500 }, children: [] }),
|
||
new Paragraph({ alignment: AlignmentType.CENTER, spacing: { after: 200 },
|
||
children: [new TextRun({ text: '《软件演化与运维》', size: 36, color: '1E3A5F', bold: true, font: 'Microsoft YaHei' })] }),
|
||
new Paragraph({ alignment: AlignmentType.CENTER, spacing: { after: 600 },
|
||
children: [new TextRun({ text: 'GitLink 智能化能力提升项目', size: 28, color: '2B579A', font: 'Microsoft YaHei' })] }),
|
||
new Paragraph({ alignment: AlignmentType.CENTER, spacing: { before: 600, after: 200 },
|
||
children: [new TextRun({ text: '新需求构思报告', size: 44, bold: true, font: 'Microsoft YaHei', color: '1E3A5F' })] }),
|
||
new Paragraph({ spacing: { before: 2000 }, children: [] }),
|
||
new Table({
|
||
width: { size: 7000, type: WidthType.DXA },
|
||
columnWidths: [2500, 4500],
|
||
rows: [
|
||
makeRow([{t:'项目名称',w:2500},{t:'GitLink 智能化能力提升项目',w:4500}]),
|
||
makeRow([{t:'项目成员',w:2500},{t:'刘焱、赵昌(wqer)、曾蔚然(z2_cc)',w:4500}]),
|
||
makeRow([{t:'完成日期',w:2500},{t:'2026-06-30',w:4500}]),
|
||
]
|
||
}),
|
||
|
||
// 正文
|
||
new Paragraph({ children: [new PageBreak()] }),
|
||
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun('第1章 需求背景')] }),
|
||
p('GitLink 推出了官方命令行工具 gitlink-cli(Go 语言),内置 AI Agent Skills,覆盖仓库管理、Issue 跟踪、PR 协作、CI/CD 等核心场景。本项目围绕 gitlink-cli 及其 Skills 生态,兼顾开发者场景与科研场景,探索 GitLink 平台的智能化服务能力。'),
|
||
p('项目成员包括刘焱(CLI 架构、命令组、REPL、测试)、赵昌(Webhook/Wiki/Snippet 命令、单测、Skills)、z2_cc(DevOps 流水线、审查 Skills、代码合并)和 wqer(工作流编排、科研模块、报告文档),四人协作完成全部四个子任务。'),
|
||
|
||
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun('第2章 需求详述')] }),
|
||
|
||
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun('2.1 子任务一:CLI 能力扩展')] }),
|
||
p('为 gitlink-cli 增加新功能或优化现有功能,包括新增 Shortcut 命令、优化参数设计和输出格式、增加批量操作能力、提升跨平台兼容性和安装体验、补齐 Raw API 封装。'),
|
||
p('最终交付 31 个命令组、181+ 个子命令、20 个单元测试文件。新增的命令组包括:webhook/wiki/snippet/collaborator/dataset/template/attachment 等。同时新增 REPL 交互模式、跨平台包管理(npm/brew/scoop/choco)和 DevOps CI/CD 流水线。'),
|
||
|
||
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun('2.2 子任务二:AI Agent Skills')] }),
|
||
p('基于 gitlink-cli 开发新的 AI Agent Skill,遵循 skills/README.md 规范,兼容 Claude Code 等主流 Agent 平台。'),
|
||
p('共交付 11 个 Claude Code Skills,包括:issue-triage(自动分拣)、newcomer-guide(新人引导)、project-health(健康度报告)、release-auto(自动发布)、code-review/pr-deep-review(审查)、duplicate-detector(重复检测)、compliance(合规检查)、commit-quality(提交质量)、insight(Sprint 报告)等。'),
|
||
|
||
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun('2.3 子任务三:端到端工作流')] }),
|
||
p('组合 ≥3 个 CLI 命令或 Skill 调用,构建可复现的自动化场景。'),
|
||
p('场景 A(社区运营自动化):三阶段流水线——Issue 自动分拣 → 社区周报生成 → Release Notes 发布。提供 4 个 Bash 脚本 + 2 个 JS 分析引擎。'),
|
||
p('场景 B(代码质量看门人):四阶段门禁——PR 采集 → 深度审查 → CI 检查 → 质量评分决策。评分模型:CodeReview×40% + CI×30% + 设计一致性×30%,门槛 ≥70 分。'),
|
||
|
||
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun('2.4 子任务四:科研辅助')] }),
|
||
p('利用 gitlink-cli 数据获取与 AI Agent 能力,面向科研工作者提供服务。'),
|
||
p('模块 C(科研项目洞悉):8 维数据采集(repo/commit/issue/pr/collaborator/topics/languages),4 维度评分(成熟度×25% + 文档×20% + 贡献×30% + 社区×25%)。'),
|
||
p('模块 D(热点追踪与知识图谱):多关键词搜索 → 数据丰富 → 实体关系提取 → 交互式 HTML 知识图谱。'),
|
||
|
||
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun('第3章 技术方案')] }),
|
||
p('整体架构采用四层设计:CLI 层(Go + Cobra 提供 31 个命令组)→ Skills 层(Markdown 知识库为 AI Agent 提供调用指南)→ 工作流层(Bash + Node.js 实现自动化编排)→ 可视化层(HTML + Mermaid 交互式展示)。'),
|
||
p('安全策略方面,所有写操作默认 DRY_RUN=true,CLI 版本自动检测与回退,测试输出隔离到 _output/ 目录。'),
|
||
|
||
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun('第4章 预期效果与风险评估')] }),
|
||
p('预期效果:Issue 分拣时间从 5-10 分钟降至 <1 分钟(提升 80%+),周报生成从 30-60 分钟降至 <5 分钟(提升 90%+),Release Notes 生成从 15-30 分钟降至 <3 分钟(提升 90%+)。'),
|
||
p('主要风险包括 API 不兼容(概率低,通过 CLI 封装隔离)、Token 过期(运行前检测)、CLI 版本差异(自动检测脚本应对)、跨平台兼容性(MSYS 路径处理)。'),
|
||
|
||
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun('第5章 成员工作量')] }),
|
||
new Table({
|
||
width: { size: 9026, type: WidthType.DXA },
|
||
columnWidths: [2000, 2000, 2200, 2826],
|
||
rows: [
|
||
makeHeaderRow([{t:'成员',w:2000},{t:'提交数',w:2000},{t:'主要子任务',w:2200},{t:'核心贡献',w:2826}]),
|
||
makeRow([{t:'刘焱',w:2000},{t:'78 次',w:2000},{t:'子任务一、二',w:2200},{t:'CLI 架构、23 组 Shortcut、REPL、测试、Skills',w:2826}]),
|
||
makeRow([{t:'赵昌',w:2000},{t:'39 次',w:2000},{t:'子任务一、二',w:2200},{t:'Webhook/Wiki/Snippet 命令、单测、Skills',w:2826}]),
|
||
makeRow([{t:'z2_cc',w:2000},{t:'9 次',w:2000},{t:'子任务一、二',w:2200},{t:'DevOps、审查 Skills、代码合并',w:2826}]),
|
||
makeRow([{t:'wqer',w:2000},{t:'7 次',w:2000},{t:'子任务三、四',w:2200},{t:'工作流编排、科研模块、报告文档',w:2826}]),
|
||
]
|
||
}),
|
||
|
||
new Paragraph({ spacing: { before: 400 }, alignment: AlignmentType.CENTER,
|
||
children: [new TextRun({ text: '— 报告完 —', size: 22, color: '94A3B8', font: 'Microsoft YaHei' })] }),
|
||
]
|
||
}]
|
||
});
|
||
}
|
||
|
||
// ========== 报告2:变更影响分析及测试报告 ==========
|
||
function buildReport2() {
|
||
return new Document({
|
||
styles: sharedStyles,
|
||
numbering: sharedNum,
|
||
sections: [{
|
||
properties: { page: { size: { width: 11906, height: 16838 }, margin: { top: 1440, right: 1440, bottom: 1440, left: 1440 } } },
|
||
headers: { default: new Header({ children: [new Paragraph({
|
||
alignment: AlignmentType.RIGHT,
|
||
border: { bottom: { style: BorderStyle.SINGLE, size: 4, color: '1E3A5F', space: 4 } },
|
||
children: [new TextRun({ text: '变更影响分析及测试报告 · GitLink CLI', size: 16, color: '94A3B8', font: 'Microsoft YaHei' })]
|
||
})] }) },
|
||
footers: { default: new Footer({ children: [new Paragraph({ alignment: AlignmentType.CENTER, children: [
|
||
new TextRun({ text: '第 ', size: 18, color: '94A3B8' }),
|
||
new TextRun({ children: [PageNumber.CURRENT], size: 18, color: '94A3B8' }),
|
||
new TextRun({ text: ' 页', size: 18, color: '94A3B8' })
|
||
] })] }) },
|
||
children: [
|
||
// 封面
|
||
new Paragraph({ spacing: { before: 2500 }, children: [] }),
|
||
new Paragraph({ alignment: AlignmentType.CENTER, spacing: { after: 200 },
|
||
children: [new TextRun({ text: '《软件演化与运维》', size: 36, color: '1E3A5F', bold: true, font: 'Microsoft YaHei' })] }),
|
||
new Paragraph({ alignment: AlignmentType.CENTER, spacing: { after: 600 },
|
||
children: [new TextRun({ text: 'GitLink 智能化能力提升项目', size: 28, color: '2B579A', font: 'Microsoft YaHei' })] }),
|
||
new Paragraph({ alignment: AlignmentType.CENTER, spacing: { before: 600, after: 200 },
|
||
children: [new TextRun({ text: '变更影响分析及测试报告', size: 44, bold: true, font: 'Microsoft YaHei', color: '1E3A5F' })] }),
|
||
new Paragraph({ spacing: { before: 2000 }, children: [] }),
|
||
new Table({ width: { size: 7000, type: WidthType.DXA }, columnWidths: [2500, 4500],
|
||
rows: [
|
||
makeRow([{t:'项目名称',w:2500},{t:'GitLink 智能化能力提升项目',w:4500}]),
|
||
makeRow([{t:'项目成员',w:2500},{t:'刘焱、赵昌(wqer)、曾蔚然(z2_cc)',w:4500}]),
|
||
makeRow([{t:'完成日期',w:2500},{t:'2026-06-30',w:4500}]),
|
||
]
|
||
}),
|
||
|
||
// 正文
|
||
new Paragraph({ children: [new PageBreak()] }),
|
||
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun('第1章 变更范围')] }),
|
||
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun('1.1 子任务一:CLI 能力扩展')] }),
|
||
p('新增 23 个 Shortcut 命令组(181+ 子命令),包括 repo/issue/pr/user/branch/ci/release/org/search/file/commit/label/milestone/tag/sshkey/util/dataset/template/attachment/webhook/wiki/snippet/collaborator。新增 REPL 交互模式、输出格式优化、20 个单元测试文件、DevOps/GitHub Actions CI/CD、npm/Homebrew/Scoop/Chocolatey 包管理。'),
|
||
|
||
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun('1.2 子任务二:Skills 开发')] }),
|
||
p('新增 11 个 Claude Code Skills:issue-triage、newcomer-guide、project-health、release-auto、code-review、pr-deep-review、duplicate-detector、compliance、commit-quality、insight、snippet/webhook/wiki。'),
|
||
|
||
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun('1.3 子任务三:工作流自动化')] }),
|
||
p('社区运营自动化(4 脚本 + 2 分析引擎):skills/gitlink-community-ops/。代码质量门禁(5 脚本):skills/gitlink-quality-gate/。新增 2 条 DevOps 流水线。'),
|
||
|
||
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun('1.4 子任务四:科研辅助')] }),
|
||
p('科研项目洞悉(3 脚本 + analyze.js):skills/gitlink-research-insight/。热点追踪与知识图谱(3 脚本 + hotspot-analyze.js + kg-to-html.js):skills/gitlink-research-hotspot/。'),
|
||
|
||
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun('第2章 受影响模块分析')] }),
|
||
p('全部变更向后兼容,无破坏性变更。shortcuts/ 新增命令组不影响已有命令;cmd/ 新增 REPL 为独立模块;skills/ 和 .claude/skills/ 新增 Skill 为独立目录;.devops/ 和 .github/workflows/ 新增流水线为独立配置。'),
|
||
|
||
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun('第3章 测试结果')] }),
|
||
|
||
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun('3.1 单元测试')] }),
|
||
p('20 个单元测试文件全部通过,覆盖 issue/pr/repo/branch/collaborator/snippet/webhook/wiki/tag/user/output/REPL 等模块。'),
|
||
|
||
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun('3.2 Skills 验证')] }),
|
||
p('所有 11 个 Claude Code Skills 在 Claude Code 平台完成端到端实测验证,含真实仓库写入验证。'),
|
||
|
||
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun('3.3 脚本验证')] }),
|
||
p('15 个 Bash 脚本通过 bash -n 静态检查,6 个 JS 引擎通过 Node.js 语法检查。全流程端到端验证:社区运营三阶段通过、科研数据 8 维采集通过、热点搜索 33 仓库通过、HTML 可视化正常渲染。'),
|
||
|
||
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun('3.4 测试结果汇总')] }),
|
||
new Table({
|
||
width: { size: 9026, type: WidthType.DXA },
|
||
columnWidths: [3500, 2800, 2726],
|
||
rows: [
|
||
makeHeaderRow([{t:'测试项',w:3500},{t:'方法',w:2800},{t:'结果',w:2726}]),
|
||
makeRow([{t:'CLI 命令可用性(31 命令组)',w:3500},{t:'--help 验证',w:2800},{t:'✅',w:2726}]),
|
||
makeRow([{t:'社区运营全流程',w:3500},{t:'dry-run 端到端',w:2800},{t:'✅',w:2726}]),
|
||
makeRow([{t:'Release Notes 生成',w:3500},{t:'100 提交分类验证',w:2800},{t:'✅',w:2726}]),
|
||
makeRow([{t:'科研数据采集',w:3500},{t:'8 维数据完整性',w:2800},{t:'✅',w:2726}]),
|
||
makeRow([{t:'热点搜索',w:3500},{t:'33 仓库/19 主题',w:2800},{t:'✅',w:2726}]),
|
||
makeRow([{t:'HTML 可视化',w:3500},{t:'交互式图谱渲染',w:2800},{t:'✅',w:2726}]),
|
||
makeRow([{t:'CLI 版本检测',w:3500},{t:'本地/系统自动回退',w:2800},{t:'✅',w:2726}]),
|
||
makeRow([{t:'API 后备',w:3500},{t:'非 git 目录 Release',w:2800},{t:'✅',w:2726}]),
|
||
]
|
||
}),
|
||
|
||
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun('第4章 结论')] }),
|
||
p('子任务一(CLI 能力扩展)完成,子任务二(Skills 开发)完成,子任务三(端到端工作流)完成,子任务四(科研辅助)完成。整体交付可发布部署。'),
|
||
|
||
new Paragraph({ spacing: { before: 400 }, alignment: AlignmentType.CENTER,
|
||
children: [new TextRun({ text: '— 报告完 —', size: 22, color: '94A3B8', font: 'Microsoft YaHei' })] }),
|
||
]
|
||
}]
|
||
});
|
||
}
|
||
|
||
// ========== 生成全部 ==========
|
||
const base = 'e:/gitlink-cli/gitlink-cli/doc/';
|
||
const tmp = 'e:/gitlink-cli/gitlink-cli/tmp_docx/';
|
||
if (!fs.existsSync(tmp)) fs.mkdirSync(tmp);
|
||
|
||
Packer.toBuffer(buildReport1()).then(buf => {
|
||
fs.writeFileSync(tmp + '新需求构思报告.docx', buf);
|
||
console.log('Done: 新需求构思报告.docx -> tmp');
|
||
return Packer.toBuffer(buildReport2());
|
||
}).then(buf => {
|
||
fs.writeFileSync(tmp + '变更影响分析及测试报告.docx', buf);
|
||
console.log('Done: 变更影响分析及测试报告.docx -> tmp');
|
||
});
|