安装jira
easy_install jira
导入jira
from jira import JIRA
和jira服务器建立连接
jira = JIRA('http://localhost/jira/',basic_auth=('username', 'password'))
创建issue
issue_dict= {
'project': {'id': 11107},
'summary': 'issue概要',
'description': 'issue描述\n第二行',
'issuetype': {'name': 'Bug'},
'timetracking': {
'originalEstimate': '1h',
'remainingEstimate': '1h',
},
'components':[{'name': '一个模块'}],
'priority': {'name': 'Major'},
'assignee':{'name': 'username'},
'versions':[{'name':'V1.0'}],
}
new_issue = jira.create_issue(fields=issue_dict)
或者
new_issue = jira.create_issue(project='PROJ_key_or_id', summary='New issue from jira-python',
description='Look into this one', issuetype={'name': 'Bug'})
修改issue
issue = jira.issue('JIRA-1')
issue.update(versions=[{"name":'V1.1'}])
issue.update(labels=['Label A','Label B'])
issue.update(components=[{'name': 'Xcomponent'}])
issue.update(summary='new summary', description='A new summary was added')
issue.update(assignee={'name': 'new_user'})
issue_dict= {
'summary': 'issue概要',
'description': 'issue描述\n第二行',
}
issue.update(fields=issue_dict)
获取特定issue
issue = jira.issue('JIRA-1')
issue = jira.issue('JRA-1330', fields='summary,description,comment')
summary = issue.fields.summary
description = issue.fields.description
查询issues
#使用JQL进行查询
issues = jira.search_issues('project=PROJ')
#检索第一个标题中含有‘问题’的issue的所有comment
issues = jira.search_issues(jql_str='project = a_project AND summary ~"问题"', maxResults=1,fields='comment')
查看comment作者
issues[0].fields.comment.comments[0].author.displayName
官方文档