Skip to content

Commit 93f8e12

Browse files
committed
refactor: update work report command to improve date handling and enhance documentation
1 parent a03e9c8 commit 93f8e12

3 files changed

Lines changed: 67 additions & 62 deletions

File tree

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# /gitlab.work_report
22

3-
Generate user weekly report based on gitlab issue and commit information
3+
Generate user work report based on GitLab issue and commit information
44

55
## Purpose
66

@@ -10,25 +10,19 @@ Generate user weekly report based on gitlab issue and commit information
1010

1111
## Usage Method
1212

13-
1. Execute the command with date range:
13+
```shell
14+
/gitlab.work_report <date_description>
15+
```
1416

15-
```shell
16-
/gitlab.work_report <start_date> <end_date>
17-
```
17+
Example: `/gitlab.work_report last week`
1818

19-
Example: `/gitlab.work_report 2024-03-01 2024-03-07`
20-
21-
2. Or execute without parameters to generate yesterday's report:
22-
23-
```shell
24-
/gitlab.work_report
25-
```
19+
If no valid date parameters are provided, the system will default to generating a report from yesterday to today.
2620

2721
## Features
2822

2923
- Generates reports based on:
30-
- Issues created/updated within the specified time period
31-
- Commits made within the specified time period
24+
- Issues created within the specified time period
25+
- Commits made within the specified time period by the author
3226
- Uses a customizable template for report formatting
3327
- Supports both English and Chinese documentation
3428
- Automatically detects user's GitLab username and repository information
@@ -40,8 +34,8 @@ The report includes:
4034
- Time period covered
4135
- List of issues worked on
4236
- List of commits made
43-
- Formatted according to the template specified in configuration
37+
- Formatted according to the configured template
4438

4539
## Configuration
4640

47-
The report template can be customized by modifying the `template.md` file in the `~/.chat/scripts/community/gitlab/work_report` directory.
41+
The report template can be customized by modifying the `template.md` file in the script directory. The template file is located at `~/.chat/scripts/community/gitlab/work_report/template.md`.
Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# /gitlab.work_report
22

3-
根据用户 gitlab issue 信息和 commit 信息生成用户周日报
3+
根据用户 GitLab issue 信息和 commit 信息生成用户工作报告
44

55
## 功能目的
66

@@ -10,25 +10,19 @@
1010

1111
## 使用方法
1212

13-
1. 带日期范围执行命令:
13+
```shell
14+
/gitlab.work_report <日期描述>
15+
```
1416

15-
```shell
16-
/gitlab.work_report <开始日期> <结束日期>
17-
```
17+
示例:`/gitlab.work_report 上周`
1818

19-
示例:`/gitlab.work_report 2024-03-01 2024-03-07`
20-
21-
2. 不带参数执行命令(生成昨天的报告):
22-
23-
```shell
24-
/gitlab.work_report
25-
```
19+
如果没有提供有效的日期参数,系统将默认生成从昨天到今天的报告。
2620

2721
## 功能特点
2822

2923
- 报告生成基于:
30-
- 指定时间段内创建/更新的 issues
31-
- 指定时间段内的 commits
24+
- 指定时间段内创建的 issues
25+
- 指定时间段内作者提交的 commits
3226
- 使用可自定义的报告模板
3327
- 支持中英文文档
3428
- 自动检测用户的 GitLab 用户名和仓库信息
@@ -44,4 +38,4 @@
4438

4539
## 配置说明
4640

47-
可以修改 `~/.chat/scripts/community/gitlab/work_report/template.md` 文件来修改报告模板
41+
可以修改脚本目录中的 `template.md` 文件来自定义报告模板。模板文件位于 `~/.chat/scripts/community/gitlab/work_report/template.md`

community/gitlab/work_report/command.py

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import os
22
import sys
3-
from datetime import datetime, timedelta
3+
from datetime import date, datetime, timedelta
44

5-
from devchat.llm import chat
5+
from devchat.llm import chat, chat_json
66

77
from community.gitlab.git_api import (
88
get_commit_author,
@@ -11,25 +11,7 @@
1111
get_repo_issues,
1212
get_username,
1313
)
14-
15-
PROMPT = """
16-
我希望你根据以下信息生成一份从 {start_time} 到 {end_time} 的工作报告。
17-
18-
问题列表:
19-
<issues>
20-
{issues}
21-
</issues>
22-
23-
提交列表:
24-
<commits>
25-
{commits}
26-
</commits>
27-
28-
请参考以下模板内容的格式:
29-
<template>
30-
{template}
31-
</template>
32-
"""
14+
from lib.workflow.decorators import check_input
3315

3416

3517
def get_template():
@@ -54,20 +36,55 @@ def get_commits(start_time, end_time):
5436
return commits
5537

5638

57-
@chat(prompt=PROMPT, stream_out=True)
39+
@chat(
40+
prompt="""
41+
我希望你根据以下信息生成一份从 {start_time} 到 {end_time} 的工作报告。
42+
43+
问题列表:
44+
<issues>
45+
{issues}
46+
</issues>
47+
48+
提交列表:
49+
<commits>
50+
{commits}
51+
</commits>
52+
53+
请参考以下模板内容的格式:
54+
<template>
55+
{template}
56+
</template>
57+
""",
58+
stream_out=True,
59+
)
5860
def generate_work_report(start_time, end_time, issues, commits, template):
5961
pass
6062

6163

62-
def main():
63-
arg = sys.argv[1]
64-
args = arg.split(" ")
65-
if len(args) == 3:
66-
start_time = args[1]
67-
end_time = args[2]
68-
else:
69-
end_time = datetime.now().strftime("%Y-%m-%d")
70-
start_time = (datetime.now() - timedelta(days=1)).strftime("%Y-%m-%d")
64+
@chat_json(
65+
prompt="""
66+
今天是 {today},我希望你根据输入信息获取开始时间和结束时间。如果无法获取,则获取昨天到今天的时间范围。
67+
68+
<input>
69+
{input}
70+
</input>
71+
72+
输出格式为 JSON 格式,如下所示:
73+
{{
74+
"start_time": "2025-05-19",
75+
"end_time": "2025-05-20"
76+
}}
77+
"""
78+
)
79+
def get_date_range(today, input):
80+
pass
81+
82+
83+
@check_input("请输入需要生成工作报告的日期")
84+
def main(input):
85+
result = get_date_range(today=date.today(), input=input)
86+
start_time = result["start_time"]
87+
end_time = result["end_time"]
7188
issues = get_issues(start_time, end_time)
7289
commits = get_commits(start_time, end_time)
7390
template = get_template()

0 commit comments

Comments
 (0)