@hecom/codearts 0.2.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 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 daily 2026-01-15
29
- npx @hecom/codearts work-hour 2025
27
+ # 更新全局配置
28
+ npx @hecom/codearts config
29
+
30
+ # 单独更新角色配置
31
+ npx @hecom/codearts config role-id
32
+ ```
30
33
 
31
- # 使用命令行参数覆盖配置
32
- npx @hecom/codearts daily 2026-01-15 --project-id abc123 --role-id 1,2
33
- npx @hecom/codearts work-hour 2025 --role-id 1,2,3
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 >= 16.0.0
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
- ### 本地链接 CLI 工具
57
+ ### 本地运行
55
58
 
56
59
  ```bash
57
- npm run build
58
- npm link
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
- cp .env.example .env
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
- #### 日报统计 (daily)
170
-
171
- 生成指定日期的工时日报,包括:
172
-
173
- - 按人员统计当日工时
174
- - 统计 Bug 修复工时(自动合并同一 Bug 的多人工时)
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,19 +33,15 @@ 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
- const dotenv_1 = __importDefault(require("dotenv"));
42
38
  const fs = __importStar(require("fs"));
43
39
  const path = __importStar(require("path"));
44
40
  const bug_command_1 = require("../commands/bug.command");
45
41
  const config_command_1 = require("../commands/config.command");
46
42
  const daily_command_1 = require("../commands/daily.command");
47
43
  const work_hour_command_1 = require("../commands/work-hour.command");
48
- const global_config_1 = require("../utils/global-config");
44
+ const config_loader_1 = require("../utils/config-loader");
49
45
  // 读取 package.json 中的版本号
50
46
  const packageJsonPath = path.join(__dirname, '../../package.json');
51
47
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
@@ -55,16 +51,34 @@ program.name('codearts').description('华为云 CodeArts 统计分析工具').ve
55
51
  // 全局选项(环境变量覆盖)
56
52
  program.option('--role-id <ids>', '角色 ID(支持逗号分隔,如: 1,2,3),优先级高于环境变量 ROLE_ID');
57
53
  // config 命令 - 交互式配置向导
58
- program
54
+ const configCmd = program
59
55
  .command('config')
60
56
  .description('交互式配置向导,引导用户创建或更新全局配置文件\n\n')
61
57
  .action(async () => {
62
58
  await (0, config_command_1.configCommand)();
63
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
+ });
64
78
  // daily 命令
65
79
  program
66
80
  .command('daily [date]')
67
- .description('生成日报统计\n\n示例:\n $ codearts daily\n $ codearts daily 2026-01-15\n')
81
+ .description('生成日报统计')
68
82
  .action(async (date) => {
69
83
  const opts = program.opts();
70
84
  await (0, daily_command_1.dailyCommand)(date, opts);
@@ -72,7 +86,7 @@ program
72
86
  // work-hour 命令
73
87
  program
74
88
  .command('work-hour [year]')
75
- .description('生成年度工时统计\n\n示例:\n $ codearts work-hour\n $ codearts work-hour 2025\n')
89
+ .description('生成年度工时统计')
76
90
  .action(async (year) => {
77
91
  const opts = program.opts();
78
92
  await (0, work_hour_command_1.workHourCommand)(year, opts);
@@ -80,7 +94,7 @@ program
80
94
  // bug-rate 命令
81
95
  program
82
96
  .command('bug-rate <iterations>')
83
- .description('按迭代统计产品缺陷率,支持多个迭代(逗号分隔)\n\n示例:\n $ codearts bug-rate "迭代1,迭代2"\n')
97
+ .description('按迭代统计产品缺陷率,支持多个迭代(逗号分隔)')
84
98
  .action(async (iterations) => {
85
99
  const opts = program.opts();
86
100
  await (0, bug_command_1.bugCommand)(iterations, opts);
@@ -90,12 +104,9 @@ async function checkConfigAndRun() {
90
104
  const args = process.argv.slice(2);
91
105
  // 如果没有参数(直接执行 codearts),检测配置
92
106
  if (args.length === 0) {
93
- // 加载当前目录 .env 文件
94
- dotenv_1.default.config();
95
- // 检查是否有配置(全局配置或环境变量)
96
- const hasGlobalConfig = (0, global_config_1.globalConfigExists)();
97
- const hasEnvConfig = process.env.PROJECT_ID && process.env.ROLE_ID;
98
- if (!hasGlobalConfig && !hasEnvConfig) {
107
+ // 检查是否有全局配置
108
+ const hasGlobalConfig = (0, config_loader_1.globalConfigExists)();
109
+ if (!hasGlobalConfig) {
99
110
  // 没有配置,自动执行 config 命令
100
111
  console.log('未检测到配置文件,启动配置向导...\n');
101
112
  await (0, config_command_1.configCommand)();
@@ -140,7 +140,7 @@ async function generateBugReport(businessService, projectId, roleIds, iterationT
140
140
  async function bugCommand(iterationTitlesStr, cliOptions = {}) {
141
141
  try {
142
142
  if (!iterationTitlesStr || iterationTitlesStr.trim() === '') {
143
- throw new Error('请指定至少一个迭代标题\n示例: codearts bug "迭代1,迭代2" 或 "迭代1 迭代2" 或 "迭代1;迭代2"');
143
+ throw new Error('请指定至少一个迭代标题');
144
144
  }
145
145
  // 解析迭代标题(支持多种分隔符:逗号、分号、空格、竖线、顿号等)
146
146
  const iterationTitles = iterationTitlesStr
@@ -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 {};