-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
789e251
commit fd81b58
Showing
23 changed files
with
519 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
{ | ||
"jira": { | ||
"url": "https://jira.xxxx.com", | ||
"url_browse": "https://jira.xxxx.com/browse/", | ||
"username": "", | ||
"password": "" | ||
}, | ||
"feishu": { | ||
"webhook": "https://open.feishu.cn/open-apis/bot/v2/hook/xxxx", | ||
"secret":"xxxx" | ||
} | ||
} | ||
"jira": { | ||
"url": "https://jira.xxxx.com", | ||
"url_browse": "https://jira.xxxx.com/browse/", | ||
"username": "你的jira账号", | ||
"password": "你的jira密码" | ||
}, | ||
"feishu": { | ||
"webhook": "https://open.feishu.cn/open-apis/bot/v2/hook/xxxx", | ||
"secret": "xxxx" | ||
}, | ||
"timing_task": { | ||
"week": "1-5", | ||
"hour": 9, | ||
"minute": 30 | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
2022-03-11 16:12:08,755 - src.api.log - INFO - {'Extra': None, 'StatusCode': 0, 'StatusMessage': 'success'} | ||
2022-03-11 16:12:08,756 - src.api.log - INFO - 姓名:李银池 | ||
2022-03-11 16:12:08,756 - src.api.log - INFO - open bug:10 | ||
2022-03-11 16:12:08,756 - src.api.log - INFO - resolved bug:0 | ||
2022-03-11 16:12:09,140 - src.api.log - INFO - {'Extra': None, 'StatusCode': 0, 'StatusMessage': 'success'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
2022-03-11 16:12:07,015 - src.api.log - INFO - resolved bug:11 | ||
2022-03-11 16:12:07,417 - src.api.log - INFO - {'Extra': None, 'StatusCode': 0, 'StatusMessage': 'success'} | ||
2022-03-11 16:12:07,418 - src.api.log - INFO - 姓名:王俊奇 | ||
2022-03-11 16:12:07,418 - src.api.log - INFO - open bug:0 | ||
2022-03-11 16:12:07,418 - src.api.log - INFO - resolved bug:0 | ||
2022-03-11 16:12:07,832 - src.api.log - INFO - {'Extra': None, 'StatusCode': 0, 'StatusMessage': 'success'} | ||
2022-03-11 16:12:07,832 - src.api.log - INFO - 姓名:许冰艳 | ||
2022-03-11 16:12:07,832 - src.api.log - INFO - open bug:14 | ||
2022-03-11 16:12:07,832 - src.api.log - INFO - resolved bug:2 | ||
2022-03-11 16:12:08,218 - src.api.log - INFO - {'Extra': None, 'StatusCode': 0, 'StatusMessage': 'success'} | ||
2022-03-11 16:12:08,218 - src.api.log - INFO - 姓名:康丽婷 | ||
2022-03-11 16:12:08,219 - src.api.log - INFO - open bug:4 | ||
2022-03-11 16:12:08,219 - src.api.log - INFO - resolved bug:2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
2022-03-11 16:12:05,655 - src.api.log - INFO - 姓名:王美玲 | ||
2022-03-11 16:12:05,656 - src.api.log - INFO - open bug:23 | ||
2022-03-11 16:12:05,656 - src.api.log - INFO - resolved bug:16 | ||
2022-03-11 16:12:06,055 - src.api.log - INFO - {'Extra': None, 'StatusCode': 0, 'StatusMessage': 'success'} | ||
2022-03-11 16:12:06,056 - src.api.log - INFO - 姓名:陈耀杰 | ||
2022-03-11 16:12:06,056 - src.api.log - INFO - open bug:19 | ||
2022-03-11 16:12:06,056 - src.api.log - INFO - resolved bug:0 | ||
2022-03-11 16:12:06,498 - src.api.log - INFO - {'Extra': None, 'StatusCode': 0, 'StatusMessage': 'success'} | ||
2022-03-11 16:12:06,499 - src.api.log - INFO - 姓名:练春木 | ||
2022-03-11 16:12:06,499 - src.api.log - INFO - open bug:21 | ||
2022-03-11 16:12:06,499 - src.api.log - INFO - resolved bug:7 | ||
2022-03-11 16:12:07,014 - src.api.log - INFO - {'Extra': None, 'StatusCode': 0, 'StatusMessage': 'success'} | ||
2022-03-11 16:12:07,014 - src.api.log - INFO - 姓名:林志祥 | ||
2022-03-11 16:12:07,015 - src.api.log - INFO - open bug:33 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
#!/usr/bin/python3 | ||
# -*- coding: UTF-8 -*- | ||
from datetime import datetime | ||
from apscheduler.schedulers.blocking import BlockingScheduler | ||
from src.api.feishu_sign import sign | ||
import sys | ||
import os | ||
from util.get_json import config | ||
from asyncio.log import logger | ||
import datetime | ||
from jira import JIRA | ||
from datetime import datetime as dt | ||
import time | ||
from src.api.log import log # 封装日志引入 | ||
from src.api.feishu_robot_push import feishu_robot # 飞书机器人引入 | ||
from src.api.feishu_sign import sign # 飞书签名 | ||
|
||
# 日志实例化 | ||
logger = log().logger() | ||
# 读取配置文件 | ||
Config = config("{}/config/config.json".format(os.getcwd()) | ||
).get_config_from_json() | ||
UserInfo = config("{}/config/userInfo.json".format(os.getcwd()) | ||
).get_config_from_json() | ||
# jira初始化 | ||
jira = JIRA(auth=(Config["jira"]["username"], Config["jira"] | ||
["password"]), options={'server': Config["jira"]["url"]}) | ||
# 飞书签名 | ||
timestamp = str(round(time.time())) | ||
secret = Config["feishu"]["secret"] | ||
sign = sign(timestamp, secret).gen_sign() | ||
|
||
|
||
""" | ||
@Time :2022/02/11 | ||
@Author :liyinchi | ||
@File :main.py | ||
@Ddescription: 定时任务 | ||
""" | ||
def job(): | ||
# 存放jira bug list | ||
result = [] | ||
# 读取人员名单 | ||
workers = UserInfo["userInfo"] | ||
# 初始化迭代 | ||
i = 0 | ||
k = 0 | ||
# 遍历人员名单 | ||
for worker in workers: | ||
# 注意:如果不加maxResults=-1参数,则实际总数大于50时只能查出50条数据。 | ||
open_issues = jira.search_issues( | ||
'status = 激活 AND creator in ("'+worker["username"]+'") ORDER BY priority DESC, updated DESC', maxResults=-1) | ||
# 日志输出 | ||
logger.info('【{}】{}'.format(worker["username"], open_issues)) | ||
# 放入第一层数据 | ||
result.append([ | ||
{"username": worker["username"]}, | ||
{"name": worker["name"]}, | ||
{"open": []}, # 激活状态bug list | ||
{"resolved": []} # 已解决状态bug list | ||
]) | ||
""" | ||
result的数据格式: | ||
[[{"username":"zhanggsan"},{"name":"张三"},{"open":[{"key":xxx,"id":xxx},{"key":xxx,"id":xxx}],"resolved":[{"key":xxx,"id":xxx},{"key":xxx,"id":xxx}]}], | ||
[{"username":"lisi"},{"name":"李四"},{"open":[{"key":xxx,"id":xxx},{"key":xxx,"id":xxx}],"resolved":[{"key":xxx,"id":xxx},{"key":xxx,"id":xxx}]}], | ||
[{"username":"wangwu"},{"name":"王五"},{"open":[{"key":xxx,"id":xxx},{"key":xxx,"id":xxx}],"resolved":[{"key":xxx,"id":xxx},{"key":xxx,"id":xxx}]}]] | ||
""" | ||
# 放入第一层数据open节点中 | ||
for index in range(len(open_issues)): | ||
print("result[{}]][2]".format(i), result[i][2]) | ||
(result[i][2])['open'].append({ | ||
"key": open_issues[index].key, | ||
"id": open_issues[index].id, | ||
"url": Config["jira"]["url_browse"]+open_issues[index].key, | ||
}) | ||
resolved_issues = jira.search_issues( | ||
'status = 已解决 AND creator in ("'+worker["username"]+'") ORDER BY priority DESC, updated DESC', maxResults=-1) | ||
# 日志输出 | ||
logger.info('【{}】{}'.format(worker["username"], resolved_issues)) | ||
# 放入第一层数据resolved节点中 | ||
for index in range(len(resolved_issues)): | ||
print("result[{}][3]".format(i), result[i][3]) | ||
(result[i][3])['resolved'].append({ | ||
"key": resolved_issues[index].key, | ||
"id": resolved_issues[index].id, | ||
"url": Config["jira"]["url_browse"]+resolved_issues[index].key, | ||
}) | ||
i += 1 | ||
logger.info('result' + str(result)) | ||
|
||
""" | ||
result的数据格式: | ||
[[{"username":"zhanggsan"},{"name":"张三"},{"open":[{"key":xxx,"id":xxx},{"key":xxx,"id":xxx}],"resolved":[{"key":xxx,"id":xxx},{"key":xxx,"id":xxx}]}], | ||
[{"username":"lisi"},{"name":"李四"},{"open":[{"key":xxx,"id":xxx},{"key":xxx,"id":xxx}],"resolved":[{"key":xxx,"id":xxx},{"key":xxx,"id":xxx}]}], | ||
[{"username":"王五"},{"name":"王五"},{"open":[{"key":xxx,"id":xxx},{"key":xxx,"id":xxx}],"resolved":[{"key":xxx,"id":xxx},{"key":xxx,"id":xxx}]}]] | ||
""" | ||
# 遍历result 依次调用飞书机器人发送结果 | ||
i = 0 | ||
for j in result: | ||
# | ||
# logger.info("j数据类型:"+ str(type(j))) # <class 'list'> | ||
# 姓名 | ||
logger.info("姓名:" + j[1]['name']) | ||
logger.info("open bug:" + str(len(j[2]["open"])-1)) | ||
logger.info("resolved bug:" + str(len(j[3]["resolved"])-1)) | ||
|
||
message_body = { | ||
"timestamp": timestamp, | ||
"sign": sign, | ||
"msg_type": "post", # 消息类型 包括:text、post、image、file、audio、media、sticker、interactive、share_chat、share_user等,类型定义请参考发送消息content说明:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/im-v1/message/create_json | ||
"content": | ||
{ | ||
"post": { | ||
"zh_cn": { | ||
"title": "JIRA bug 日常提醒【{}】【{}】".format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), j[1]['name']), | ||
"content": [ | ||
[{ | ||
"tag": "text", | ||
"text": "未处理:{}".format(len(j[2]["open"])-1), | ||
}, | ||
{ | ||
"tag": "a", | ||
"href": "https://jira.homeking365.com/browse/S5A-1924?filter=10818&jql=status = {} AND assignee in ({}) ORDER BY priority DESC, updated DESC".format("激活", j[0]['username']), | ||
"text": "点击查看" | ||
}], | ||
[{ | ||
"tag": "text", | ||
"text": "已解决:{}".format(len(j[3]["resolved"])-1), | ||
}, | ||
{ | ||
"tag": "a", | ||
"href": "https://jira.homeking365.com/browse/S5A-1924?filter=10818&jql=status = {} AND assignee in ({}) ORDER BY priority DESC, updated DESC".format("已解决", j[0]['username']), | ||
"text": "点击查看" | ||
}], | ||
# [{ | ||
# "tag": "text", | ||
# "text": "已关闭:{}".format(len(j)-1), | ||
# }, | ||
# { | ||
# "tag": "a", | ||
# "href": "https://jira.homeking365.com/browse/S5A-1924?filter=10818&jql=status = {} AND assignee in ({}) ORDER BY priority DESC, updated DESC".format("已关闭", j[0]['username']), | ||
# "text": "点击查看" | ||
# }], | ||
# [ | ||
# { | ||
# "tag": "at", | ||
# "user_id": "all", | ||
# "user_name": " 所有人 " | ||
# } | ||
# ], | ||
# [{ | ||
# "tag": "img", | ||
# "image_key": "img_7ea74629-9191-4176-998c-2e603c9c5e8g", | ||
# "width": 100, | ||
# "height": 100 | ||
# }] | ||
] | ||
}, | ||
}} | ||
} | ||
i += 1 | ||
# 发送飞书机器人 | ||
response_message = feishu_robot( | ||
Config["feishu"]["webhook"], message_body).push() | ||
logger.info(response_message) | ||
|
||
|
||
# BlockingScheduler | ||
scheduler = BlockingScheduler() | ||
# 创建定时器 | ||
scheduler.add_job(job, 'cron', day_of_week=Config["timing_task"]["week"], hour=Config["timing_task"] | ||
["hour"], minute=Config["timing_task"]["minute"]) # 每周1-5 上午9点30分执行 | ||
# 启动 | ||
scheduler.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,5 @@ websockets==10.1 | |
XlsxWriter==3.0.2 | ||
xlwt==1.3.0 | ||
jira==3.1.1 | ||
bunch==1.0.1 | ||
bunch==1.0.1 | ||
APScheduler==3.9.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/python3 | ||
# -*- coding: UTF-8 -*- | ||
|
||
|
||
if __name__=="__main__": | ||
print("主程序入口") | ||
else : | ||
print("初始化/非主程/被引入或单元测试") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/python3 | ||
# -*- coding: UTF-8 -*- | ||
|
||
|
||
if __name__=="__main__": | ||
print("主程序入口") | ||
else : | ||
print("初始化/非主程/被引入或单元测试") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.