@hecom/codearts 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -169
- package/dist/bin/cli.js +39 -52
- package/dist/commands/bug.command.d.ts +7 -0
- package/dist/commands/bug.command.js +158 -0
- package/dist/commands/config.command.d.ts +25 -0
- package/dist/commands/config.command.js +417 -71
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.js +3 -1
- package/dist/services/api.service.d.ts +13 -5
- package/dist/services/api.service.js +28 -9
- package/dist/services/business.service.d.ts +42 -2
- package/dist/services/business.service.js +145 -11
- package/dist/types/index.d.ts +161 -117
- package/dist/types/index.js +56 -0
- package/dist/utils/config-loader.d.ts +28 -9
- package/dist/utils/config-loader.js +195 -31
- package/package.json +5 -6
- package/.env.example +0 -20
- package/dist/utils/global-config.d.ts +0 -24
- package/dist/utils/global-config.js +0 -153
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @hecom/codearts
|
|
2
2
|
|
|
3
|
-
基于华为云 CodeArts API
|
|
3
|
+
基于华为云 CodeArts API 的统计分析工具。
|
|
4
4
|
|
|
5
5
|
## 快速开始
|
|
6
6
|
|
|
@@ -24,16 +24,19 @@ npx @hecom/codearts daily
|
|
|
24
24
|
# 生成当年工时统计
|
|
25
25
|
npx @hecom/codearts work-hour
|
|
26
26
|
|
|
27
|
-
#
|
|
28
|
-
npx @hecom/codearts
|
|
29
|
-
|
|
27
|
+
# 更新全局配置
|
|
28
|
+
npx @hecom/codearts config
|
|
29
|
+
|
|
30
|
+
# 单独更新角色配置
|
|
31
|
+
npx @hecom/codearts config role-id
|
|
32
|
+
```
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
### 3. 升级
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# 更新最新版本
|
|
38
|
+
npx @hecom/codearts@latest
|
|
34
39
|
|
|
35
|
-
# 更新配置
|
|
36
|
-
npx @hecom/codearts config
|
|
37
40
|
```
|
|
38
41
|
|
|
39
42
|
---
|
|
@@ -42,7 +45,7 @@ npx @hecom/codearts config
|
|
|
42
45
|
|
|
43
46
|
### 环境要求
|
|
44
47
|
|
|
45
|
-
- Node.js >=
|
|
48
|
+
- Node.js >= 23.0.0
|
|
46
49
|
- npm >= 7.0.0
|
|
47
50
|
|
|
48
51
|
### 安装依赖
|
|
@@ -51,175 +54,37 @@ npx @hecom/codearts config
|
|
|
51
54
|
npm install
|
|
52
55
|
```
|
|
53
56
|
|
|
54
|
-
###
|
|
57
|
+
### 本地运行
|
|
55
58
|
|
|
56
59
|
```bash
|
|
57
|
-
|
|
58
|
-
npm
|
|
59
|
-
codearts --help
|
|
60
|
-
```
|
|
60
|
+
# 运行命令
|
|
61
|
+
npm run dev
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
```bash
|
|
65
|
-
# 编译 TypeScript
|
|
66
|
-
npm run build
|
|
63
|
+
npm run dev daily
|
|
67
64
|
|
|
68
|
-
|
|
69
|
-
npm test
|
|
65
|
+
npm run dev work-hour
|
|
70
66
|
```
|
|
71
67
|
|
|
72
|
-
###
|
|
73
|
-
|
|
74
|
-
**配置优先级**:命令行参数 > 当前目录 .env > 全局配置 > 默认值
|
|
75
|
-
|
|
76
|
-
#### 项目级配置
|
|
77
|
-
|
|
78
|
-
在项目目录创建 `.env` 文件(优先级高于全局配置):
|
|
68
|
+
### 本地链接 CLI 工具
|
|
79
69
|
|
|
80
70
|
```bash
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
修改 `.env` 文件中的配置:
|
|
85
|
-
|
|
86
|
-
```env
|
|
87
|
-
# 华为云IAM认证端点(根据区域调整)
|
|
88
|
-
HUAWEI_CLOUD_IAM_ENDPOINT=https://iam.cn-north-4.myhuaweicloud.com
|
|
89
|
-
HUAWEI_CLOUD_REGION=cn-north-4
|
|
90
|
-
|
|
91
|
-
# IAM用户凭证
|
|
92
|
-
HUAWEI_CLOUD_USERNAME=your-iam-username
|
|
93
|
-
HUAWEI_CLOUD_PASSWORD=your-iam-password
|
|
94
|
-
HUAWEI_CLOUD_DOMAIN=your-domain-name
|
|
95
|
-
|
|
96
|
-
# 项目配置
|
|
97
|
-
CODEARTS_BASE_URL=https://projectman-ext.cn-north-4.myhuaweicloud.cn
|
|
98
|
-
PROJECT_ID=your-project-id
|
|
99
|
-
ROLE_ID=1,2,3 # 支持逗号分隔的多个角色ID
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
**适用场景**: 团队协作,不同项目使用不同配置
|
|
103
|
-
|
|
104
|
-
#### 环境变量说明
|
|
105
|
-
|
|
106
|
-
| 变量名 | 说明 | 必填 | 默认值 |
|
|
107
|
-
| --------------------------- | ---------------------------------- | ---- | ---------------------------------------------------- |
|
|
108
|
-
| `HUAWEI_CLOUD_IAM_ENDPOINT` | IAM 认证端点 | 否 | `https://iam.cn-north-4.myhuaweicloud.com` |
|
|
109
|
-
| `HUAWEI_CLOUD_REGION` | 华为云区域 | 否 | `cn-north-4` |
|
|
110
|
-
| `HUAWEI_CLOUD_USERNAME` | IAM 用户名 | 是 | - |
|
|
111
|
-
| `HUAWEI_CLOUD_PASSWORD` | IAM 密码 | 是 | - |
|
|
112
|
-
| `HUAWEI_CLOUD_DOMAIN` | 华为云账号名 | 是 | - |
|
|
113
|
-
| `CODEARTS_BASE_URL` | CodeArts API 地址 | 否 | `https://projectman-ext.cn-north-4.myhuaweicloud.cn` |
|
|
114
|
-
| `PROJECT_ID` | 项目 ID | 是 | - |
|
|
115
|
-
| `ROLE_ID` | 角色 ID(支持逗号分隔,如: 1,2,3) | 是 | - |
|
|
116
|
-
| `TARGET_DATE` | 目标日期(YYYY-MM-DD) | 否 | 当天日期 |
|
|
117
|
-
|
|
118
|
-
---
|
|
119
|
-
|
|
120
|
-
## 项目信息
|
|
121
|
-
|
|
122
|
-
### 项目描述
|
|
123
|
-
|
|
124
|
-
这是一个使用 TypeScript/Node.js 构建的工时统计分析项目,通过华为云 CodeArts API 获取 issue、人员、工时等数据,并生成日报和年度工时统计报表。
|
|
125
|
-
|
|
126
|
-
### 技术栈
|
|
127
|
-
|
|
128
|
-
- **语言**: TypeScript
|
|
129
|
-
- **运行环境**: Node.js
|
|
130
|
-
- **HTTP客户端**: Axios
|
|
131
|
-
- **测试框架**: Jest
|
|
132
|
-
|
|
133
|
-
### 项目结构
|
|
134
|
-
|
|
135
|
-
```
|
|
136
|
-
@hecom/codearts/
|
|
137
|
-
├── src/
|
|
138
|
-
│ ├── bin/ # CLI 入口
|
|
139
|
-
│ │ └── cli.ts # Commander.js CLI 定义
|
|
140
|
-
│ ├── commands/ # 命令实现
|
|
141
|
-
│ │ ├── config.command.ts # 配置命令逻辑
|
|
142
|
-
│ │ ├── daily.command.ts # 日报命令逻辑
|
|
143
|
-
│ │ ├── work-hour.command.ts# 工时统计命令逻辑
|
|
144
|
-
│ │ └── index.ts # 命令导出
|
|
145
|
-
│ ├── services/ # API服务类
|
|
146
|
-
│ │ ├── api.service.ts # 华为云基础 API 封装
|
|
147
|
-
│ │ └── business.service.ts # 业务场景 API 封装
|
|
148
|
-
│ ├── utils/ # 工具函数
|
|
149
|
-
│ │ ├── global-config.ts # 全局配置查找
|
|
150
|
-
│ │ └── config-loader.ts # 配置加载器(CLI参数 > 环境变量)
|
|
151
|
-
│ ├── config/ # 配置文件
|
|
152
|
-
│ │ └── holidays.ts # 节假日配置与工作日计算
|
|
153
|
-
│ ├── types/ # TypeScript 类型定义
|
|
154
|
-
│ │ └── index.ts # API 契约与数据结构定义
|
|
155
|
-
│ └── index.ts # 模块导出
|
|
156
|
-
├── bin/
|
|
157
|
-
│ └── codearts # CLI 可执行文件
|
|
158
|
-
├── __tests__/ # 测试文件
|
|
159
|
-
├── dist/ # 编译输出目录
|
|
160
|
-
├── .env # 环境变量配置
|
|
161
|
-
├── .env.example # 环境变量配置模板
|
|
162
|
-
├── tsconfig.json # TypeScript配置
|
|
163
|
-
├── jest.config.js # Jest测试配置
|
|
164
|
-
└── package.json # 项目配置
|
|
71
|
+
npm run build
|
|
72
|
+
npm link
|
|
73
|
+
codearts --help
|
|
165
74
|
```
|
|
166
75
|
|
|
167
|
-
###
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
#### 年度工时统计 (work-hour)
|
|
180
|
-
|
|
181
|
-
生成指定年份的工时统计报表,包括:
|
|
182
|
-
|
|
183
|
-
- 计算年度应计工作日(自动排除法定节假日和周末)
|
|
184
|
-
- 统计实际工时与应计工时的完成率
|
|
185
|
-
- 按人员生成工时明细表
|
|
186
|
-
- 按领域类型(需求、缺陷、任务等)统计工时分布
|
|
187
|
-
- 支持多角色统计(按角色分组,显示小计和总计)
|
|
188
|
-
- 生成 Markdown 格式的统计表格
|
|
189
|
-
|
|
190
|
-
### API服务层
|
|
191
|
-
|
|
192
|
-
#### ApiService (api.service.ts)
|
|
193
|
-
|
|
194
|
-
华为云 CodeArts 基础 API 封装:
|
|
195
|
-
|
|
196
|
-
- IAM Token 认证管理(自动获取和缓存)
|
|
197
|
-
- 项目管理 API(项目列表、成员查询)
|
|
198
|
-
- 迭代管理 API(迭代列表、迭代详情)
|
|
199
|
-
- 工作项 API(Issue 列表、详情、创建、更新)
|
|
200
|
-
- 工时管理 API(工时查询、提交)
|
|
201
|
-
- 请求日志(可选的 curl 风格日志输出)
|
|
202
|
-
- 完善的错误处理
|
|
203
|
-
|
|
204
|
-
#### BusinessService (business.service.ts)
|
|
205
|
-
|
|
206
|
-
面向业务场景的高级 API 封装:
|
|
207
|
-
|
|
208
|
-
- `getMembersByRoleId()`: 通过角色获取人员列表
|
|
209
|
-
- `getActiveIterationsOnDate()`: 查询指定日期的活跃迭代
|
|
210
|
-
- `getWorkloadByIterationsAndUsers()`: 批量查询工作量
|
|
211
|
-
- `getAllIssuesByIteration()`: 查询迭代内所有 Issue(自动分页)
|
|
212
|
-
- `getDailyWorkHourStats()`: 获取日报工时统计
|
|
213
|
-
- `getAllWorkHourStats()`: 获取年度工时统计
|
|
214
|
-
- `addIssueNote()`: 添加工作项备注
|
|
215
|
-
|
|
216
|
-
### 节假日配置 (config/holidays.ts)
|
|
217
|
-
|
|
218
|
-
- 支持中国法定节假日配置
|
|
219
|
-
- 支持调休工作日配置
|
|
220
|
-
- 支持大小周制度
|
|
221
|
-
- 自动计算年度应计工作日
|
|
222
|
-
- 判断指定日期是否为工作日
|
|
76
|
+
### 配置项
|
|
77
|
+
|
|
78
|
+
| 配置项 | 说明 | 必填 |
|
|
79
|
+
| --------------------------- | ---------------------------------- | ---- |
|
|
80
|
+
| `HUAWEI_CLOUD_IAM_ENDPOINT` | IAM 认证端点 | 是 |
|
|
81
|
+
| `HUAWEI_CLOUD_REGION` | 华为云区域 | 是 |
|
|
82
|
+
| `HUAWEI_CLOUD_USERNAME` | IAM 用户名 | 是 |
|
|
83
|
+
| `HUAWEI_CLOUD_PASSWORD` | IAM 密码 | 是 |
|
|
84
|
+
| `HUAWEI_CLOUD_DOMAIN` | 华为云账号名 | 是 |
|
|
85
|
+
| `CODEARTS_BASE_URL` | CodeArts API 地址 | 是 |
|
|
86
|
+
| `PROJECT_ID` | 项目 ID | 是 |
|
|
87
|
+
| `ROLE_ID` | 角色 ID(支持逗号分隔,如: 1,2,3) | 是 |
|
|
223
88
|
|
|
224
89
|
---
|
|
225
90
|
|
package/dist/bin/cli.js
CHANGED
|
@@ -33,45 +33,52 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
return result;
|
|
34
34
|
};
|
|
35
35
|
})();
|
|
36
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
-
};
|
|
39
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
37
|
const commander_1 = require("commander");
|
|
41
38
|
const fs = __importStar(require("fs"));
|
|
42
39
|
const path = __importStar(require("path"));
|
|
43
|
-
const
|
|
44
|
-
const daily_command_1 = require("../commands/daily.command");
|
|
40
|
+
const bug_command_1 = require("../commands/bug.command");
|
|
45
41
|
const config_command_1 = require("../commands/config.command");
|
|
42
|
+
const daily_command_1 = require("../commands/daily.command");
|
|
46
43
|
const work_hour_command_1 = require("../commands/work-hour.command");
|
|
47
|
-
const
|
|
44
|
+
const config_loader_1 = require("../utils/config-loader");
|
|
48
45
|
// 读取 package.json 中的版本号
|
|
49
46
|
const packageJsonPath = path.join(__dirname, '../../package.json');
|
|
50
47
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
51
|
-
const version = packageJson.version
|
|
48
|
+
const version = packageJson.version;
|
|
52
49
|
const program = new commander_1.Command();
|
|
53
|
-
program.name('codearts').description('华为云 CodeArts
|
|
50
|
+
program.name('codearts').description('华为云 CodeArts 统计分析工具').version(version);
|
|
54
51
|
// 全局选项(环境变量覆盖)
|
|
55
|
-
program
|
|
56
|
-
.option('--project-id <id>', '项目 ID')
|
|
57
|
-
.option('--role-id <ids>', '角色 ID(支持逗号分隔,如: 1,2,3)')
|
|
58
|
-
.option('--username <username>', 'IAM 用户名')
|
|
59
|
-
.option('--password <password>', 'IAM 密码(建议使用 .env 文件)')
|
|
60
|
-
.option('--domain <domain>', '华为云账号名')
|
|
61
|
-
.option('--region <region>', '华为云区域')
|
|
62
|
-
.option('--iam-endpoint <url>', 'IAM 认证端点')
|
|
63
|
-
.option('--codearts-url <url>', 'CodeArts API 地址');
|
|
52
|
+
program.option('--role-id <ids>', '角色 ID(支持逗号分隔,如: 1,2,3),优先级高于环境变量 ROLE_ID');
|
|
64
53
|
// config 命令 - 交互式配置向导
|
|
65
|
-
program
|
|
54
|
+
const configCmd = program
|
|
66
55
|
.command('config')
|
|
67
|
-
.description('
|
|
56
|
+
.description('交互式配置向导,引导用户创建或更新全局配置文件\n\n')
|
|
68
57
|
.action(async () => {
|
|
69
58
|
await (0, config_command_1.configCommand)();
|
|
70
59
|
});
|
|
60
|
+
// config show 子命令 - 显示当前配置
|
|
61
|
+
configCmd
|
|
62
|
+
.command('show')
|
|
63
|
+
.description('显示当前配置信息')
|
|
64
|
+
.action(async () => {
|
|
65
|
+
await (0, config_command_1.showConfigCommand)();
|
|
66
|
+
});
|
|
67
|
+
// 为每个项目配置项添加子命令
|
|
68
|
+
const availableConfigs = (0, config_command_1.getAvailableProjectConfigs)();
|
|
69
|
+
availableConfigs.forEach((configItem) => {
|
|
70
|
+
const subCommandName = configItem.key.toLowerCase().replace(/_/g, '-');
|
|
71
|
+
configCmd
|
|
72
|
+
.command(subCommandName)
|
|
73
|
+
.description(`更新${configItem.label}`)
|
|
74
|
+
.action(async () => {
|
|
75
|
+
await (0, config_command_1.updateProjectConfigCommand)(configItem.key);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
71
78
|
// daily 命令
|
|
72
79
|
program
|
|
73
80
|
.command('daily [date]')
|
|
74
|
-
.description('
|
|
81
|
+
.description('生成日报统计')
|
|
75
82
|
.action(async (date) => {
|
|
76
83
|
const opts = program.opts();
|
|
77
84
|
await (0, daily_command_1.dailyCommand)(date, opts);
|
|
@@ -79,47 +86,27 @@ program
|
|
|
79
86
|
// work-hour 命令
|
|
80
87
|
program
|
|
81
88
|
.command('work-hour [year]')
|
|
82
|
-
.description('
|
|
89
|
+
.description('生成年度工时统计')
|
|
83
90
|
.action(async (year) => {
|
|
84
91
|
const opts = program.opts();
|
|
85
92
|
await (0, work_hour_command_1.workHourCommand)(year, opts);
|
|
86
93
|
});
|
|
87
|
-
//
|
|
88
|
-
program
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
HUAWEI_CLOUD_PASSWORD IAM 密码
|
|
96
|
-
HUAWEI_CLOUD_DOMAIN 华为云账号名
|
|
97
|
-
CODEARTS_BASE_URL CodeArts API 地址
|
|
98
|
-
PROJECT_ID 项目 ID
|
|
99
|
-
ROLE_ID 角色 ID(支持逗号分隔)
|
|
100
|
-
|
|
101
|
-
配置优先级:
|
|
102
|
-
命令行参数 > 环境变量 > 默认值
|
|
103
|
-
|
|
104
|
-
快速开始:
|
|
105
|
-
1. 运行配置向导: codearts config
|
|
106
|
-
2. 生成日报: codearts daily
|
|
107
|
-
3. 生成年度工时统计: codearts work-hour
|
|
108
|
-
|
|
109
|
-
更多信息:
|
|
110
|
-
https://github.com/hecom-rn/hecom-codearts
|
|
111
|
-
`);
|
|
94
|
+
// bug-rate 命令
|
|
95
|
+
program
|
|
96
|
+
.command('bug-rate <iterations>')
|
|
97
|
+
.description('按迭代统计产品缺陷率,支持多个迭代(逗号分隔)')
|
|
98
|
+
.action(async (iterations) => {
|
|
99
|
+
const opts = program.opts();
|
|
100
|
+
await (0, bug_command_1.bugCommand)(iterations, opts);
|
|
101
|
+
});
|
|
112
102
|
// 检查配置并自动执行 config 命令
|
|
113
103
|
async function checkConfigAndRun() {
|
|
114
104
|
const args = process.argv.slice(2);
|
|
115
105
|
// 如果没有参数(直接执行 codearts),检测配置
|
|
116
106
|
if (args.length === 0) {
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const hasGlobalConfig = (0, global_config_1.globalConfigExists)();
|
|
121
|
-
const hasEnvConfig = process.env.PROJECT_ID && process.env.ROLE_ID;
|
|
122
|
-
if (!hasGlobalConfig && !hasEnvConfig) {
|
|
107
|
+
// 检查是否有全局配置
|
|
108
|
+
const hasGlobalConfig = (0, config_loader_1.globalConfigExists)();
|
|
109
|
+
if (!hasGlobalConfig) {
|
|
123
110
|
// 没有配置,自动执行 config 命令
|
|
124
111
|
console.log('未检测到配置文件,启动配置向导...\n');
|
|
125
112
|
await (0, config_command_1.configCommand)();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CliOptions } from '../utils/config-loader';
|
|
2
|
+
/**
|
|
3
|
+
* bug 命令入口
|
|
4
|
+
* @param iterationTitlesStr 迭代标题(支持逗号、分号、空格、竖线、顿号等分隔符)
|
|
5
|
+
* @param cliOptions CLI 选项
|
|
6
|
+
*/
|
|
7
|
+
export declare function bugCommand(iterationTitlesStr: string, cliOptions?: CliOptions): Promise<void>;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bugCommand = bugCommand;
|
|
4
|
+
const business_service_1 = require("../services/business.service");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const config_loader_1 = require("../utils/config-loader");
|
|
7
|
+
/**
|
|
8
|
+
* 判断 Bug 是否属于需求变更或产品设计问题
|
|
9
|
+
* @param bug Bug 工作项
|
|
10
|
+
* @returns 是否属于需求变更或产品设计问题
|
|
11
|
+
*/
|
|
12
|
+
function isRequirementOrDesignBug(bug) {
|
|
13
|
+
// 检查 customValueNew(v2 版本的自定义字段,是对象格式)
|
|
14
|
+
const defectAnalysisValue = bug.customValueNew?.custom_field32;
|
|
15
|
+
if (defectAnalysisValue) {
|
|
16
|
+
return (defectAnalysisValue === types_1.DefectAnalysisType.REQUIREMENT_CHANGE ||
|
|
17
|
+
defectAnalysisValue === types_1.DefectAnalysisType.PRODUCT_DESIGN);
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 生成 Bug 统计报告
|
|
23
|
+
*/
|
|
24
|
+
async function generateBugReport(businessService, projectId, roleIds, iterationTitles) {
|
|
25
|
+
console.log(`\n正在统计迭代中的 Bug 数据...`);
|
|
26
|
+
console.log(`目标迭代: ${iterationTitles.join(', ')}`);
|
|
27
|
+
console.log(`角色过滤: ${roleIds.length > 0 ? roleIds.join(', ') : '无(保留所有人)'}`);
|
|
28
|
+
console.log(`统计规则: 统计所有 Bug,同时标记"需求变更问题"和"产品设计问题"`);
|
|
29
|
+
// Step 1: 获取指定角色的成员列表(如果启用了角色过滤)
|
|
30
|
+
const targetMemberIds = new Set();
|
|
31
|
+
if (roleIds.length > 0) {
|
|
32
|
+
for (const roleId of roleIds) {
|
|
33
|
+
const members = await businessService.getMembersByRoleId(projectId, roleId);
|
|
34
|
+
members.forEach((member) => targetMemberIds.add(member.user_num_id));
|
|
35
|
+
}
|
|
36
|
+
console.log(`\n目标角色成员数: ${targetMemberIds.size} 人`);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
console.log(`\n角色过滤: 已禁用,将统计所有人`);
|
|
40
|
+
}
|
|
41
|
+
// Step 2: 获取所有 Story
|
|
42
|
+
const stories = await businessService.getStoriesByIterationTitles(projectId, iterationTitles);
|
|
43
|
+
if (stories.length === 0) {
|
|
44
|
+
console.log('未找到任何 Story');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// Step 3: 过滤出目标角色成员处理的 Story(如果启用了角色过滤)
|
|
48
|
+
const filteredStories = roleIds.length > 0
|
|
49
|
+
? stories.filter((story) => {
|
|
50
|
+
const assignedUserId = story.assigned_user?.id;
|
|
51
|
+
return assignedUserId && targetMemberIds.has(assignedUserId);
|
|
52
|
+
})
|
|
53
|
+
: stories;
|
|
54
|
+
if (filteredStories.length === 0) {
|
|
55
|
+
console.log(roleIds.length > 0 ? '未找到目标角色成员处理的 Story' : '未找到任何 Story');
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (roleIds.length > 0) {
|
|
59
|
+
console.log(`\n找到 ${stories.length} 个 Story,其中 ${filteredStories.length} 个由目标角色成员处理,正在统计 Bug...`);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
console.log(`\n找到 ${filteredStories.length} 个 Story,正在统计 Bug...`);
|
|
63
|
+
}
|
|
64
|
+
// Step 4: 获取每个 Story 的子工作项(Bug)
|
|
65
|
+
const bugStatsMap = new Map();
|
|
66
|
+
for (const story of filteredStories) {
|
|
67
|
+
const childIssues = await businessService.getChildIssues(projectId, String(story.id));
|
|
68
|
+
// 过滤出所有 Bug 类型的子工作项(tracker_id = 3)
|
|
69
|
+
const allBugs = childIssues.filter((issue) => issue.tracker.id === 3);
|
|
70
|
+
if (allBugs.length === 0) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
// 统计产品问题 Bug(需求变更 + 产品设计)
|
|
74
|
+
const productBugs = allBugs.filter((bug) => isRequirementOrDesignBug(bug));
|
|
75
|
+
// Step 3: 按 Story 的处理人统计 Bug
|
|
76
|
+
const assignedUserId = story.assigned_user?.id;
|
|
77
|
+
const assignedUserName = story.assigned_user?.nick_name;
|
|
78
|
+
if (!assignedUserId) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (!bugStatsMap.has(assignedUserId)) {
|
|
82
|
+
bugStatsMap.set(assignedUserId, {
|
|
83
|
+
assignedUser: assignedUserName,
|
|
84
|
+
userId: assignedUserId,
|
|
85
|
+
totalBugCount: 0,
|
|
86
|
+
productBugCount: 0,
|
|
87
|
+
productDefectRate: 0,
|
|
88
|
+
stories: [],
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const userStats = bugStatsMap.get(assignedUserId);
|
|
92
|
+
userStats.totalBugCount += allBugs.length;
|
|
93
|
+
userStats.productBugCount += productBugs.length;
|
|
94
|
+
userStats.stories.push({
|
|
95
|
+
storyName: story.name,
|
|
96
|
+
storyId: story.id,
|
|
97
|
+
totalBugCount: allBugs.length,
|
|
98
|
+
productBugCount: productBugs.length,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
// 计算每个人的产品缺陷率
|
|
102
|
+
bugStatsMap.forEach((stats) => {
|
|
103
|
+
stats.productDefectRate =
|
|
104
|
+
stats.totalBugCount > 0 ? (stats.productBugCount / stats.totalBugCount) * 100 : 0;
|
|
105
|
+
});
|
|
106
|
+
// Step 4: 输出统计结果
|
|
107
|
+
console.log('\n');
|
|
108
|
+
console.log('='.repeat(80));
|
|
109
|
+
console.log(`Bug 统计报告 [${iterationTitles.join(', ')}]`);
|
|
110
|
+
console.log('='.repeat(80));
|
|
111
|
+
console.log('');
|
|
112
|
+
if (bugStatsMap.size === 0) {
|
|
113
|
+
console.log('未找到任何 Bug');
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
// 按总 Bug 数量降序排列
|
|
117
|
+
const sortedStats = Array.from(bugStatsMap.values()).sort((a, b) => b.totalBugCount - a.totalBugCount);
|
|
118
|
+
let totalBugs = 0;
|
|
119
|
+
let totalProductBugs = 0;
|
|
120
|
+
sortedStats.forEach((stats) => {
|
|
121
|
+
console.log(`\x1b[31m${stats.assignedUser}: 总 Bug ${stats.totalBugCount} 个 | 产品问题 ${stats.productBugCount} 个 | 产品缺陷率 ${stats.productDefectRate.toFixed(1)}%\x1b[0m`);
|
|
122
|
+
// 输出该用户的 Story 及其 Bug 数量
|
|
123
|
+
stats.stories.forEach((story) => {
|
|
124
|
+
console.log(` - ${story.storyName} (总 ${story.totalBugCount} 个 Bug,其中产品问题 ${story.productBugCount} 个)`);
|
|
125
|
+
});
|
|
126
|
+
totalBugs += stats.totalBugCount;
|
|
127
|
+
totalProductBugs += stats.productBugCount;
|
|
128
|
+
console.log('');
|
|
129
|
+
});
|
|
130
|
+
const overallProductDefectRate = totalBugs > 0 ? (totalProductBugs / totalBugs) * 100 : 0;
|
|
131
|
+
console.log('='.repeat(80));
|
|
132
|
+
console.log(`总计: ${totalBugs} 个 Bug(产品问题 ${totalProductBugs} 个,产品缺陷率 ${overallProductDefectRate.toFixed(1)}%),涉及 ${sortedStats.length} 位处理人`);
|
|
133
|
+
console.log('='.repeat(80));
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* bug 命令入口
|
|
137
|
+
* @param iterationTitlesStr 迭代标题(支持逗号、分号、空格、竖线、顿号等分隔符)
|
|
138
|
+
* @param cliOptions CLI 选项
|
|
139
|
+
*/
|
|
140
|
+
async function bugCommand(iterationTitlesStr, cliOptions = {}) {
|
|
141
|
+
try {
|
|
142
|
+
if (!iterationTitlesStr || iterationTitlesStr.trim() === '') {
|
|
143
|
+
throw new Error('请指定至少一个迭代标题');
|
|
144
|
+
}
|
|
145
|
+
// 解析迭代标题(支持多种分隔符:逗号、分号、空格、竖线、顿号等)
|
|
146
|
+
const iterationTitles = iterationTitlesStr
|
|
147
|
+
.split(/[,,;;|\s、]+/)
|
|
148
|
+
.map((title) => title.trim())
|
|
149
|
+
.filter((title) => title.length > 0);
|
|
150
|
+
const { projectId, roleIds, config } = (0, config_loader_1.loadConfig)(cliOptions);
|
|
151
|
+
const businessService = new business_service_1.BusinessService(config);
|
|
152
|
+
await generateBugReport(businessService, projectId, roleIds, iterationTitles);
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
console.error('执行过程中发生错误:', error);
|
|
156
|
+
process.exit(1);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -1,5 +1,30 @@
|
|
|
1
|
+
import { BusinessService } from '../services/business.service';
|
|
2
|
+
import { ConfigKey } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* 第三阶段项目配置的配置项定义
|
|
5
|
+
*/
|
|
6
|
+
interface ProjectConfigItem {
|
|
7
|
+
key: ConfigKey;
|
|
8
|
+
label: string;
|
|
9
|
+
configure: (businessService: BusinessService, projectId: string, existingValue?: string) => Promise<string>;
|
|
10
|
+
}
|
|
1
11
|
/**
|
|
2
12
|
* 交互式配置向导命令
|
|
3
13
|
* 引导用户创建或更新全局配置文件
|
|
4
14
|
*/
|
|
5
15
|
export declare function configCommand(): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* 单独更新某个项目配置项
|
|
18
|
+
* @param configKey 配置项的键名(例如 ConfigKey.ROLE_ID)
|
|
19
|
+
*/
|
|
20
|
+
export declare function updateProjectConfigCommand(configKey: ConfigKey): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* 获取所有可用的项目配置项
|
|
23
|
+
*/
|
|
24
|
+
export declare function getAvailableProjectConfigs(): ProjectConfigItem[];
|
|
25
|
+
/**
|
|
26
|
+
* 显示当前配置
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
export declare function showConfigCommand(): Promise<void>;
|
|
30
|
+
export {};
|