【python】jiraAPI使用教程 自动创建jira问题单并置状态为OPEN
来源:互联网 发布:wireshark软件下载 编辑:程序博客网 时间:2024/05/22 08:00
环境依赖 : python库 redis jira
安装命令:pip install redis
pip install jira
redis服务安装命令:
$sudo apt-get update
$sudo apt-get install redis-server
启动 Redis
$ redis-server
查看 redis 是否启动?
$ redis-cli
以上命令将打开以下终端:
redis 127.0.0.1:6379>
127.0.0.1 是本机 IP ,6379 是 redis 服务端口。现在我们输入 PING 命令。
redis 127.0.0.1:6379> ping PONG
AutoCreateIssue
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/python
# -*- coding:utf-8 -*-
from
jira
import
JIRA
import
sys, getopt, redis, os
class
JiraTool:
def
__init__(
self
):
self
.server
=
'https:/jira。example.net'
self
.basic_auth
=
(
'username'
,
'password'
)
self
.jiraClinet
=
None
def
login(
self
):
self
.jiraClinet
=
JIRA(server
=
self
.server, basic_auth
=
self
.basic_auth)
if
self
.jiraClinet !
=
None
:
return
True
else
:
return
False
def
findIssueById(
self
, issueId):
if
issueId:
if
self
.jiraClinet
=
=
None
:
self
.login()
return
self
.jiraClinet.issue(issueId)
else
:
return
'Please input your issueId'
def
createIssue(
self
, description, assignee, project, parent, filepath):
issue_dict
=
{
'project'
: {
'key'
: project},
'issuetype'
: {
'name'
:
'Sub-Task'
},
'parent'
: {
'key'
: parent},
'summary'
:
'[xxx]Auto sync file %s from storage-cnn to storage'
%
(filepath),
'description'
: description,
'assignee'
: {
'name'
: assignee},
'customfield_12603'
: {
'value'
:
'xxx'
},
'components'
: [{
'name'
:
'SCM'
}],
'priority'
: {
'name'
:
'Major'
},
}
if
self
.jiraClinet
=
=
None
:
self
.login()
return
self
.jiraClinet.create_issue(issue_dict)
if
__name__
=
=
'__main__'
:
redisTool
=
redis.Redis(host
=
'127.0.0.1'
, port
=
6379
)
jiraTool
=
JiraTool()
jiraTool.login()
description
=
''
assignee
=
''
watchers
=
None
project
=
''
parent
=
''
openIssuekey
=
''
cnnStoragePath
=
'xxxxx'
opts, args
=
getopt.getopt(sys.argv[
1
:],
'd:a:w:p:o:'
)
for
op, value
in
opts:
if
op
=
=
'-d'
:
filepath
=
value
elif
op
=
=
'-a'
:
user
=
jiraTool.jiraClinet.search_users(user
=
value)
if
user:
assignee
=
user[
0
].key
else
:
print
(
'Please make sure that the user email is correct!'
)
sys.exit(
-
1
)
elif
op
=
=
'-p'
:
if
'Austin'
in
value:
project
=
'xxxx'
parent
=
'xxxx'
cnnStoragePath
=
os.path.join(cnnStoragePath,
'xxxx'
)
elif
'Ford'
in
value:
project
=
'xxxxx'
parent
=
'xxxxx'
cnnStoragePath
=
os.path.join(cnnStoragePath,
'xxxxx'
)
else
:
print
(
'Please make sure that the project is correct!'
)
sys.exit(
-
1
)
elif
op
=
=
'-w'
:
watchers
=
value.split(
','
)
elif
op
=
=
'-o'
:
openIssuekey
=
value
if
not
openIssuekey:
print
(
'Please make sure that the openIssuekey is correct!'
)
sys.exit(
-
1
)
break
try
:
if
openIssuekey:
issuekeyTmp
=
redisTool.get(openIssuekey)
issue
=
jiraTool.findIssueById(issuekeyTmp)
print
openIssuekey,
'----'
, issuekeyTmp,
'----'
, issue.fields.status
if
'Screen'
in
str
(issue.fields.status):
print
'Update %s status screen ----> open '
%
(issuekeyTmp)
jiraTool.jiraClinet.transition_issue(issue,
151
)
redisTool.delete(openIssuekey)
else
:
print
'Please make sure the issue status is not screen'
else
:
if
not
filepath:
print
(
'Please make sure that the file path is correct!'
)
sys.exit(
-
1
)
if
not
assignee:
print
(
'Please make sure that the assignee is correct!'
)
sys.exit(
-
1
)
if
not
project:
print
(
'Please make sure that the project is correct!'
)
sys.exit(
-
1
)
print
(
'Creating issue now'
)
cnnStoragePath
=
os.path.join(cnnStoragePath,filepath)
description
=
'[Files to sync]\n'
+
cnnStoragePath
print
"cnnStoragePath: "
+
cnnStoragePath
print
"description: "
+
description
print
"assignee: "
+
assignee
issue
=
jiraTool.createIssue(description, assignee, project, parent,filepath)
issueKey
=
issue.key
redisTool.
set
(filepath, issueKey)
print
(
'issue key is ---->'
, issueKey)
if
watchers:
for
watcherItem
in
watchers:
watcher
=
jiraTool.jiraClinet.search_users(user
=
watcherItem)
if
watcher:
watcherKey
=
watcher[
0
].key
jiraTool.jiraClinet.add_watcher(issue
=
issueKey, watcher
=
watcherKey)
else
:
print
(
'%s user does not exis'
%
(watcherItem))
jiraTool.jiraClinet.add_comment(issue
=
issueKey, body
=
'%s user does not exis'
%
(watcherItem))
except
Exception as e:
print
e
sys.exit(
-
1
)
阅读全文
0 0
- 【python】jiraAPI使用教程 自动创建jira问题单并置状态为OPEN
- ARX创建新图层,设置颜色,并置为当前图层
- 创建并置表,第 1 部分: 使用 Flex 创建 JTable
- jira搭建使用教程
- Jira使用问题记录
- [JIRA] Jira中文乱码问题以及自动备份
- JIRA根据问题状态设置权限
- 如何设置JIRA在创建问题时将当前经办人指定为报告人
- 如何设置JIRA在创建问题时将当前经办人指定为报告人
- 自动链接JIRA问题至Confluence页面
- jira链接子jira单
- 使用python统计处理jira数据
- Python Qt5 Creator 使用创建项目教程
- 使用 JIRA 搭建企业问题跟踪系统
- 使用JIRA搭建企业问题跟踪系统
- 使用JIRA搭建企业问题跟踪系统
- 使用JIRA搭建企业问题跟踪系统
- 使用 JIRA 搭建企业问题跟踪系统
- 【Gerrit】gerrit server搭建
- 目标主体名称不正确,无法生成 SSPI 上下文。
- 【Jenkins】jenkins简单搭建并执行任务
- 【Flask】Flask快速玩框架
- 【Gerrit】Gerrit cmd query (gerrit命令行查询change信息)
- 【python】jiraAPI使用教程 自动创建jira问题单并置状态为OPEN
- 通过页面调用APP【H5与APP互通】
- 【python】Redis介绍及简单使用
- 使用的DockPanel的心得
- CodeForces 243A|The Brand New Function|位运算
- 【python】PIL 批量绘制图片矩形框工具
- 【python】pandas & matplotlib 数据处理 绘制曲面图
- 【Django】Django web项目部署(Nginx+uwsgi)
- 【Django】Django 定时任务实现(django-crontab+command)