Scott's Blog

学则不固, 知则不惑

0%

Auto Assign Ticket With Jira Python Api

再也不用担心jira工单超时了 🤟

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import time
import os
from collections import Counter
from jira import JIRA
from datetime import datetime

# The notifier function
def run_once(f):
def wrapper(*args, **kwargs):
if not wrapper.has_run:
wrapper.has_run = True
return f(*args, **kwargs)
wrapper.has_run = False
return wrapper


def notify(title, subtitle, message):
t = '-title {!r}'.format(title)
s = '-subtitle {!r}'.format(subtitle)
m = '-message {!r}'.format(message)
v = '-sound glass'
os.system('terminal-notifier {}'.format(' '.join([m, t, s, v])))

def timer(n):
print("初始化")
print("开始监测工单...")
jira = JIRA('你的jira服务器地址',basic_auth=('用户名', '密码'))
while True:
tickets = jira.search_issues('The JQL for search jira ticket,搜索工单的jql')
for issue in tickets:
# jira.assign_issue(issue, '需要assign的用户名')
print('{},{},{},{},{}'.format(issue.key,issue.fields.creator,issue.fields.summary,str(issue.fields.customfield_10208),issue.fields.priority.name))
notify(title = 'JIRA',
subtitle = issue.key,
message = issue.fields.summary)
jira.assign_issue(issue, '需要assign的用户名')
time.sleep(n)
timer(120)

  • 使用之前,需要先安装相关的包(主要是jira),使用pip安装即可
  • 在Mac OS上运行,将会有通知提示,提示音都可以自定义,如果在windows上运行,将* The notifier function*函数和相关语句删除即可
  • timer(120),每隔120S请求一次数据,可以自定义
  • 可以自定义一个userlist,实现多个assigner自动、随机分配