一、写在前面
公司每天早晨站立会时,都需要测试人员报告一下目前的bug情况,包括待办、测试中、完成的数量,以及各个开发端:ios、android、api….的情况。
于是测试人员每天早晨到公司后都需要做这样的事:统计一下到今天早晨为止,bug的情况。这样的事做一次还好,如果每天都做,真是一件费时的事……
如果能写一个程序,每天只需要运行一下程序,就能把想要的数据统计好,这样会不会更好些呢?
这次要说的是使用python统计jira上的bug数据
二、程序运行结果
程序运行后出现了我想要的统计结果,如下图所示。
简单介绍一下统计的内容。内容包括了项目的四个部分:ios(APP端)、android(APP端)、api(后端)、shuri(前端),其中30(0-0-15-15-0),表示ios端有30个bug待办,从左到右表示bug等级从Highest、High、Medium、Low、Lowest这五个等级对应的bug的数量
三、jira包下载
使用以下命令安装jira包
pip install jira
四、JQL语句的使用
程序使用JQL对bug数据进行查询和统计
看到这里,各位不要慌额。我弄这个的时候原本以为需要把JQL的相关语法从头到尾的学习一遍呢,其实并不需要
jira中能将你的查询用JQL表示出来,见下图,在图中前面部分的查询条件中填写好你需要查询的条件,然后点击高级,就能将你的查询的语句转化为JQL语句
下图是jira中高级查询的JQL语句,是不是很棒呀
五、编写代码
给出程序源码
#coding=utf-8
from jira import JIRA
jira_server = 'http://jira.com' #jira地址
jira_username = 'username' #用户名
jira_password = 'password' #密码
jira = JIRA(basic_auth=(jira_username, jira_password), options = {'server': jira_server})
#print(jira.user(jira.current_user()))#当前用户
#
done = jira.search_issues('project = "test" AND issuetype = 故障 AND status = Done ',maxResults=100000)
testing = jira.search_issues('project = "test" AND issuetype = 故障 AND status = 测试中 ',maxResults=100000)
toDo = jira.search_issues('project = "test" AND issuetype = 故障 AND status = "To Do" ',maxResults=100000)
#ios
ios_done = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = Done AND text ~ "ios" ',maxResults=100000)
ios_testing = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = 测试中 AND text ~ "ios" ',maxResults=100000)
ios_toDo = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND text ~ "ios" ',maxResults=100000)
ios_Highest = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = Highest AND text ~ "ios" ',maxResults=100000)
ios_High = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = High AND text ~ "ios" ',maxResults=100000)
ios_Medium = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = Medium AND text ~ "ios" ',maxResults=100000)
ios_Low = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = Low AND text ~ "ios" ',maxResults=100000)
ios_Lowest = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = Lowest AND text ~ "ios" ',maxResults=100000)
#android
android_done = jira.search_issues('project = "test" AND issuetype = 故障 AND status = Done AND text ~ "android" ',maxResults=100000)
android_testing = jira.search_issues('project = "test" AND issuetype = 故障 AND status = 测试中 AND text ~ "android" ',maxResults=100000)
android_toDo = jira.search_issues('project = "test" AND issuetype = 故障 AND status = "To Do" AND text ~ "android" ',maxResults=100000)
android_Highest = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = Highest AND text ~ "android" ',maxResults=100000)
android_High = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = High AND text ~ "android" ',maxResults=100000)
android_Medium = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = Medium AND text ~ "android" ',maxResults=100000)
android_Low = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = Low AND text ~ "android" ',maxResults=100000)
android_Lowest = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = Lowest AND text ~ "android" ',maxResults=100000)
#api:
api_done = jira.search_issues('project = "test" AND issuetype = 故障 AND status = Done AND text ~ "api" ',maxResults=100000)
api_testing = jira.search_issues('project = "test" AND issuetype = 故障 AND status = 测试中 AND text ~ "api" ',maxResults=100000)
api_toDo = jira.search_issues('project = "test" AND issuetype = 故障 AND status = "To Do" AND text ~ "api" ',maxResults=100000)
api_Highest = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = Highest AND text ~ "api" ',maxResults=100000)
api_High = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = High AND text ~ "api" ',maxResults=100000)
api_Medium = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = Medium AND text ~ "api" ',maxResults=100000)
api_Low = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = Low AND text ~ "api" ',maxResults=100000)
api_Lowest = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = Lowest AND text ~ "api" ',maxResults=100000)
#shuri
shuri_done = jira.search_issues('project = "test" AND issuetype = 故障 AND status = Done AND text ~ "shuri" ',maxResults=100000)
shuri_testing = jira.search_issues('project = "test" AND issuetype = 故障 AND status = 测试中 AND text ~ "shuri" ',maxResults=100000)
shuri_toDo = jira.search_issues('project = "test" AND issuetype = 故障 AND status = "To Do" AND text ~ "shuri" ',maxResults=100000)
shuri_Highest = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = Highest AND text ~ "shuri" ',maxResults=100000)
shuri_High = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = High AND text ~ "shuri" ',maxResults=100000)
shuri_Medium = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = Medium AND text ~ "shuri" ',maxResults=100000)
shuri_Low = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = Low AND text ~ "shuri" ',maxResults=100000)
shuri_Lowest = jira.search_issues('project = RRPK AND issuetype = 故障 AND status = "To Do" AND priority = Lowest AND text ~ "shuri" ',maxResults=100000)
print ('\n\n 待办 测试中 已完成')
print ('总:'+' '+str(len(toDo))+' '+str(len(testing))+' '+str(len(done)))
print ('ios: '+str(len(ios_toDo))+'('+str(len(ios_Highest))+'-'+str(len(ios_High))+'-'+str(len(ios_Medium))+'-'+str(len(ios_Low))+'-'+str(len(ios_Lowest))+') '+str(len(ios_testing))+' '+str(len(ios_done)))
print ('android: '+str(len(android_toDo))+'('+str(len(android_Highest))+'-'+str(len(android_High))+'-'+str(len(android_Medium))+'-'+str(len(android_Low))+'-'+str(len(android_Lowest))+') '+str(len(android_testing))+' '+str(len(android_done)))
print ('api: '+str(len(api_toDo))+'('+str(len(api_Highest))+'-'+str(len(api_High))+'-'+str(len(api_Medium))+'-'+str(len(api_Low))+'-'+str(len(api_Lowest))+') '+str(len(api_testing))+' '+str(len(api_done)))
print ('shuri: '+str(len(shuri_toDo))+'('+str(len(shuri_Highest))+'-'+str(len(shuri_High))+'-'+str(len(shuri_Medium))+'-'+str(len(shuri_Low))+'-'+str(len(shuri_Lowest))+') '+str(len(shuri_testing))+' '+str(len(shuri_done)))
六、写在最后
这个程序写的不是很好,运行速度也比较慢,总体上来说还可以,毕竟可以使用并且能达到我想要的需求