赞
踩
JIRA 的 JQL 语法由以下几个元素组成:
语法示例如下:
其中field可用接口中获取:
序号 | 搜索需求 | JQL语句 |
---|---|---|
1 | 分配给我的待处理任务 | assignee = currentUser() AND resolution is EMPTY |
2 | 我报告的并且没处理完成的任务 | reporter = currentUser() AND resolution is EMPTY |
3 | 某项目中已经过期的任务 | project = “XXX” AND due < now() |
4 | 某项目中3天后要过期的任务 | project = “XXX” AND due <= endOfDay(3d) |
5 | 某项目中待办和处理中状态上的任务 | project = “XXX” AND status in (待办, 处理中) |
6 | 某项目中48小时内没变化过的任务 | project = “XXX” AND updated <= -48h ORDER BY updated DESC |
7 | 某项目中没上传附件的Bug | project = “XXX” and type= Bug and attachments is EMPTY |
8 | 某项目中测试组用户处理完成的任务 | project = “XXX” and assignee in membersOf(“testers”) and status = 已完成 |
9 | 某项目中最近30天解决的任务 | project = “XXX” and resolved >= startOfDay(-30d) |
10 | 某项目上即将发布的版本中还没解决的任务 | project = “XXX” and fixVersion = earliestUnreleasedVersion() and resolution is EMPTY |
11 | 某项目中重新打开的Bug | project = “XXX” and type = Bug and resolution changed from fixed to empty |
12 | 某项目中标题包含“服务器异常”的Bug | project = “XXX” and type = Bug and summary ~ “服务器异常” |
13 | 某项目上当前进行的Sprint中被标记的任务 | project = “XXX” and Sprint in openSprints() and Flagged = Impediment |
14 | 昨天我将状态从待办改为处理中的任务 | status changed FROM 待办 TO 处理中 BY currentUser() AFTER startOfDay(-1d) |
15 | 用户User1在2019年修改过的Issue | issue in updatedBy(User1, 2019-1-1, 2019-12-31) |
16 | 某项目中已发布版本中包含的任务 | project = “XXX” and fixVersion in releasedVersions() |
17 | 上周发生状态变化的Issue | status changed DURING (startOfWeek(-1), endOfWeek(-1)) |
18 | 以"is duplicated by"关系链接到某个Issue的任务 | issue in linkedIssues(PRO-1,“is duplicated by”) |
19 | 3天以来关闭的Issue | status = Closed and status was not Closed ON startOfDay(-3) |
pip3 install jira
JIRA都有访问限制,在访问Jira项目时首先要进行认证,Jira Python库提供了3种认证方式:
from jira import JIRA
# 通过jira域名和账户密码登录
jira = JIRA('https://jira.xxx.xxx/', basic_auth=('username', 'password'))
创建JIRA对象需要server处传入公司JIRA服务器的IP,basic_auth里传入登入用户名和密码
from jira import JIRA
jira = JIRA('https://jira.xxx.xxx', basic_auth=('username', 'password'))
# 查询project信息
print(jira.projects()) #获取所有的projets
project = jira.project('KKQA') #获取projet为KKQA的信息
print(project.key) # 获取项目key
print(project.name) # 获取项目名称
print(project.lead) # 获取项目负责人
print(project.description) # 项目描述
print(project.components) # 获取项目组件
print(project.raw) # 获取项目的原始API数据
可以查询到信息有:
from jira import JIRA jira = JIRA('https://jira.xxx.xxx', basic_auth=('username', 'password')) issue = jira.issue('KKQA-57857') print(issue) # jiraID print(issue.id) # internalID print(issue.fields.project) # 所属项目 print('-----------------------------------') print(issue.fields.issuetype) # 问题类型 print(issue.fields.status) # 问题状态 print(issue.fields.timetracking) # 时间跟踪 print(issue.fields.issuelinks) # 链接的问题 print('-----------------------------------') print(issue.fields.creator) # 创建人 print(issue.fields.reporter) # 报告人 print(issue.fields.assignee) # 经办人 print(issue.fields.customfield_10202) # 缺陷类型(自定义字段) print(issue.fields.labels) # 标签 print(issue.fields.created) # 创建时间 print(issue.fields.updated) # 修改时间 print(issue.fields.lastViewed) # 最后查看时间 print(issue.fields.summary) # 主题 print(issue.fields.description) # 描述 print(issue.fields.attachment) # 附件 print(issue.fields.comment.comments) # 备注 print('-----------------------------------') print(issue.fields.issuetype.avatarId) # 类型ID print(issue.fields.components) # 模块 print(issue.fields.priority) # 优先级 print(issue.fields.versions) # 影响版本 print(issue.fields.fixVersions) # 解决版本 print(issue.fields.resolution) # 解决结果 print(issue.fields.resolutiondate) # 解决时间 print(issue.fields.environment) # 环境
Jira有一套专门的搜索语言,称为JQL(Jira Query Language),Jira的Python库便是基于JQL语法进行搜索的,返回的是搜索到的问题列表。使用语句为:
jira.search_issues('JQL语句')
默认最大结果数为1000,可以通过maxResults参数配置,参数为-1时不限制数量,返回所有搜索结果。
from jira import JIRA
jira = JIRA('https://jira.xxx.xxx', basic_auth=('username', 'password'))
jql = 'status in (等待修复, 修复中, 自测中) AND affectedVersion = A7.60.0'
issues = jira.search_issues(jql, 0, 9999, 1, '', '', '')
print(issues)
for issue in issues:
print(f'经办人: {issue.fields.assignee}, {issue.fields.summary}')
参考文档:
https://doc.devpod.cn/jira/jql-3244098.html
https://blog.csdn.net/alice_tl/article/details/101784046
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。