6
6
7
7
from lib .chatmark .step import Step
8
8
9
+ # TODO: 需要替换为实际的值
10
+ USERS = ["xxx" ]
11
+
9
12
GITLAB_TOKEN = "xxx"
10
13
GITLAB_URL = "xx"
11
14
GITLAB_HEADERS = {"Authorization" : f"Bearer { GITLAB_TOKEN } " }
12
- GITLAB_USERS = ["xxx" ]
13
15
14
16
JIRA_TOKEN = "xxx"
15
17
JIRA_USERNAME = "xxx"
16
18
JIRA_URL = "xxx"
17
- JIRA_DEV_USER = "xxx"
18
19
JIRA_API_VERSION = "2"
19
20
20
21
OPENAI_API_URL = "xxx"
21
22
OPENAI_API_KEY = "xxx"
22
23
LLM_MODEL = "xxx"
23
24
25
+ CONFLUENCE_URL = "xxx"
26
+ CONFLUENCE_USERNAME = "xxx"
27
+ CONFLUENCE_TOKEN = "xxx"
28
+
24
29
START_TIME = datetime .datetime .strptime ("2025-06-01 00:00:00" , "%Y-%m-%d %H:%M:%S" )
25
30
END_TIME = datetime .datetime .strptime ("2025-06-11 23:59:59" , "%Y-%m-%d %H:%M:%S" )
26
31
@@ -258,7 +263,7 @@ def get_commits(projects, author_email):
258
263
return commits
259
264
260
265
261
- def get_jira_projects ():
266
+ def get_jira_projects (user ):
262
267
# 获取当前用户信息
263
268
# myself = requests.get(
264
269
# f"{JIRA_URL}/rest/api/{JIRA_API_VERSION}/myself",
@@ -267,7 +272,7 @@ def get_jira_projects():
267
272
268
273
# 获取与当前用户相关的项目
269
274
url = f"{ JIRA_URL } /rest/api/{ JIRA_API_VERSION } /search"
270
- jql = f"assignee = '{ JIRA_DEV_USER } ' OR watcher = '{ JIRA_DEV_USER } '"
275
+ jql = f"assignee = '{ user } ' OR watcher = '{ user } '"
271
276
272
277
response = requests .get (
273
278
url ,
@@ -296,7 +301,7 @@ def get_jira_projects():
296
301
return {"values" : list (projects .values ())}
297
302
298
303
299
- def get_jira_issues (projects ):
304
+ def get_jira_issues (projects , user ):
300
305
"""获取JIRA项目统计信息"""
301
306
url = f"{ JIRA_URL } /rest/api/{ JIRA_API_VERSION } /search"
302
307
result = {}
@@ -343,7 +348,7 @@ def get_jira_issues(projects):
343
348
"jql" : f"""project = { project_id } AND
344
349
updated >= '{ START_TIME .strftime ("%Y-%m-%d %H:%M" )} ' AND
345
350
updated <= '{ END_TIME .strftime ("%Y-%m-%d %H:%M" )} ' AND
346
- assignee = '{ JIRA_USERNAME } '""" ,
351
+ assignee = '{ user } '""" ,
347
352
"startAt" : 0 ,
348
353
"maxResults" : 1000 ,
349
354
"expand" : "changelog" ,
@@ -362,7 +367,7 @@ def get_jira_issues(projects):
362
367
filtered_histories = []
363
368
for history in issue ["changelog" ].get ("histories" , []):
364
369
author = history .get ("author" , {})
365
- if "emailAddress" in author and author ["emailAddress" ] == JIRA_USERNAME :
370
+ if "emailAddress" in author and author ["emailAddress" ] == user :
366
371
author .pop ("avatarUrls" , None )
367
372
filtered_histories .append (history )
368
373
issue ["changelog" ]["histories" ] = filtered_histories
@@ -390,13 +395,15 @@ def get_jira_issues(projects):
390
395
return result , user_updated_issues
391
396
392
397
393
- def gen_report (relations ):
398
+ def gen_report (relations , confluence_pages ):
394
399
prompt = f"""
395
400
你是一个经验丰富的助手,请根据以下数据,分析我的工作情况,并给出我的工作总结。
396
401
数据如下:
397
402
- 数据启始结束时间: { str (START_TIME )} - { str (END_TIME )}
398
403
- 用户相关数据:
399
404
{ json .dumps (relations , indent = 2 , ensure_ascii = False )}
405
+ - confluence 页面数据:
406
+ { json .dumps (confluence_pages , indent = 2 , ensure_ascii = False )}
400
407
401
408
输出有以下要求:
402
409
1. 如果 issue 没有和提交相互关联,需要给出警告
@@ -405,6 +412,7 @@ def gen_report(relations):
405
412
4. 日报需要以 markdown 的形式输出
406
413
5. 日报需要以中文输出
407
414
6. 不要输入额外的解释,直接输出日报
415
+ 7. 日报中包含confluence的数据,比如新增了哪些页面,修改了哪些页面
408
416
409
417
具体输出格式内容如下:
410
418
```report
@@ -596,6 +604,57 @@ def mr_commits_to_issue(project_id, mr, commits, jira_issues):
596
604
return issues_new
597
605
598
606
607
+ def get_confluence_current_user (account_id ):
608
+ url = f"https://{ CONFLUENCE_URL } /wiki/rest/api/user"
609
+ response = requests .get (
610
+ url ,
611
+ auth = HTTPBasicAuth (CONFLUENCE_USERNAME , CONFLUENCE_TOKEN ),
612
+ headers = {"Accept" : "application/json" },
613
+ params = {"accountId" : account_id },
614
+ )
615
+ data = response .json ()
616
+ return data
617
+
618
+
619
+ def get_confluence_page_versions (page_id ):
620
+ url = f"https://{ CONFLUENCE_URL } /wiki/api/v2/pages/{ page_id } /versions"
621
+ response = requests .get (
622
+ url ,
623
+ auth = HTTPBasicAuth (CONFLUENCE_USERNAME , CONFLUENCE_TOKEN ),
624
+ headers = {"Accept" : "application/json" },
625
+ )
626
+ data = response .json ()
627
+ return data ["results" ]
628
+
629
+
630
+ def get_confluence_pages (email ):
631
+ url = f"https://{ CONFLUENCE_URL } /wiki/api/v2/pages"
632
+ response = requests .get (
633
+ url ,
634
+ auth = HTTPBasicAuth (CONFLUENCE_USERNAME , CONFLUENCE_TOKEN ),
635
+ headers = {"Accept" : "application/json" },
636
+ params = {"sort" : "-modified-date" , "limit" : 250 },
637
+ )
638
+ data = response .json ()
639
+ results = data ["results" ]
640
+ ret = []
641
+ for result in results :
642
+ ownerId = result ["ownerId" ]
643
+ user = get_confluence_current_user (ownerId )
644
+ if user ["email" ] == email :
645
+ versions = get_confluence_page_versions (result ["id" ])
646
+ versions_ = []
647
+ for version in versions :
648
+ created_at = datetime .datetime .fromisoformat (version ["createdAt" ])
649
+ created_at = created_at .replace (tzinfo = None )
650
+ if START_TIME <= created_at <= END_TIME :
651
+ versions_ .append (version )
652
+ if versions_ :
653
+ result ["versions" ] = versions_
654
+ ret .append (result )
655
+ return ret
656
+
657
+
599
658
def get_relation (merge_requests , commits , jira_issues ):
600
659
ret = []
601
660
@@ -810,9 +869,9 @@ def update_description_by_commits(relations):
810
869
811
870
def main ():
812
871
print ("------" , flush = True )
813
- for GITLAB_USER in GITLAB_USERS :
814
- with Step (f"正在生成用户{ GITLAB_USER } 的报告..." ):
815
- user_id , projects = get_projects_by_email (GITLAB_USER )
872
+ for user in USERS :
873
+ with Step (f"正在生成用户{ user } 的报告..." ):
874
+ user_id , projects = get_projects_by_email (user )
816
875
print (projects )
817
876
print ("获取到的GITLAB项目数量:" , len (projects ))
818
877
if not projects :
@@ -826,25 +885,32 @@ def main():
826
885
json .dumps (merge_requests , indent = 2 , ensure_ascii = False ),
827
886
flush = True ,
828
887
)
829
- commits = get_commits (projects , GITLAB_USER )
888
+ commits = get_commits (projects , user )
830
889
print (
831
890
"获取到的提交数量:" , sum (len (project ["commits" ]) for project in commits ), flush = True
832
891
)
833
892
print ("提交详情:" , json .dumps (commits , indent = 2 , ensure_ascii = False ), flush = True )
834
- jira_projects = get_jira_projects ()
893
+ jira_projects = get_jira_projects (user )
835
894
print ("获取到的JIRA项目数量:" , len (jira_projects ["values" ]), flush = True )
836
- jira_issues , user_updated_issues = get_jira_issues (jira_projects ["values" ])
895
+ jira_issues , user_updated_issues = get_jira_issues (jira_projects ["values" ], user )
837
896
print (
838
897
"获取到的JIRA ISSUE数量:" ,
839
898
sum (issue ["user_updated_issues_count" ] for issue in jira_issues .values ()),
840
899
flush = True ,
841
900
)
901
+ confluence_pages = get_confluence_pages (user )
902
+ print ("获取到的confluence页面数量:" , len (confluence_pages ), flush = True )
903
+ print (
904
+ "confluence页面详情:" ,
905
+ json .dumps (confluence_pages , indent = 2 , ensure_ascii = False ),
906
+ flush = True ,
907
+ )
842
908
relations = get_relation (merge_requests , commits , user_updated_issues )
843
909
update_description_by_commits (relations )
844
910
print ("获取到的关联关系数量:" , len (relations ), flush = True )
845
911
print ("关联关系详情:" , json .dumps (relations , indent = 2 , ensure_ascii = False ), flush = True )
846
912
print ("生成日报..." , flush = True )
847
- result = gen_report (relations )
913
+ result = gen_report (relations , confluence_pages )
848
914
with open ("result.md" , "a" ) as f :
849
915
f .write (result )
850
916
print ("日报已生成,保存在 result.md 文件中。" )
0 commit comments