zoukankan      html  css  js  c++  java
  • python的jira库调用jira接口

    官方文档:https://jira.readthedocs.io/en/master/

    官方文档:https://docs.atlassian.com/DAC/rest/jira/6.1.html#d2e864

    优秀博客:https://blog.csdn.net/weixin_43790276/article/details/89892699

    优秀博客:https://www.cnblogs.com/superhin/p/11693280.html

    一、先安装jira库,并测试获取所有项目信息

    pip install jira

    from jira import JIRA
    
    jira = JIRA(auth=("username", "pwd"), options={'server': 'https://**.**.**.**'})
    projects = jira.projects()
    print(projects)

    注意:

      jira = JIRA(auth=("username", "pwd"), options={'server': 'https://**.**.**.**'})

      第一行中的参数是auth不是basic_auth,连接方式请参考文首最新的官方文档,其他文章均为basic_auth,导致连不上

    输出:

      是一个数组,每个项目由<>包围,key是关键字,name是项目名

    [<JIRA Project: key='NEW', name='***项目', id='10433'>, <JIRA Project: key='**', name='**', id='10467'>, <JIRA Project: key='***', name='***重构', id='10501'>, <JIRA Project: key='P2020021451', name='**', id='10502'>, <JIRA Project: key='***', name='**工作', id='10481'>, <JIRA Project: key='***', name='**工作', id='10490'>, <JIRA Project: key='**', name='**申请', id='10446'>, <JIRA Project: key='**', name='**', id='10613'>]

    可以和jira页面项目列表对照一下,是完整且正确的。

    二、查询某个项目的bug数据:总数,严重bug数。。。。。

    from jira import JIRA
    
    jira = JIRA(auth=("username", "pwd"), options={'server': 'https://jira.**.net.cn'})
    
    
    # 查询问题,支持JQL语句
    issue = jira.search_issues('project = P2020021451 AND component = **管理模块', maxResults=-1)
    print(len(issue))

    输出:显示77条bug总数

    注意:如果不加maxResults=-1参数,则实际总数大于50时只能查出50条数据。

    实例2:

    查询每个bug的详细信息,需要加上fields参数

    可使用的字段:项目project; 模块名称components; 标题summary; 缺陷类型issuetype; 具体描述内容description; 经办人assignee; 报告人reporter; 解决结果resolution; bug状态status; 优先级priority; 创建时间created; 更新时间updated; 评论comments

    # 查询问题,支持JQL语句,一定要增加json_result参数,会返回bug详细信息,fields为指定显示的字段
    issues = jira.search_issues('project = P2020021451 AND component = 销售管理模块',  fields="summary, priority, status", maxResults=-1, json_result='true')
    
    print(issues)

    输出:

    {
        'expand': 'schema,names',
        'startAt': 0,
        'maxResults': 1000,
        'total': 77,
        'issues': [{
            'expand': 'operations,versionedRepresentations,editmeta,changelog,renderedFields',
            'id': '66559',
            'self': 'https://jira.**.net.cn/rest/api/2/issue/66559',
            'key': 'P2020021451-173',
            'fields': {
                'summary': '***为非必填项',
                'priority': {
                    'self': 'https://jira.**.net.cn/rest/api/2/priority/3',
                    'iconUrl': 'https://jira.**.net.cn/images/icons/priorities/medium.svg',
                    'name': '中',
                    'id': '3'
                },
                'status': {
                    'self': 'https://jira.**.net.cn/rest/api/2/status/10540',
                    'description': '',
                    'iconUrl': 'https://jira.**.net.cn/images/icons/statuses/generic.png',
                    'name': '开发处理中',
                    'id': '10540',
                    'statusCategory': {
                        'self': 'https://jira.**.net.cn/rest/api/2/statuscategory/4',
                        'id': 4,
                        'key': 'indeterminate',
                        'colorName': 'yellow',
                        'name': '处理中'
                    }
                }
            }
        }, {
            'expand': 'operations,versionedRepresentations,editmeta,changelog,renderedFields',
            'id': '57443',
            'self': 'https://jira.**.net.cn/rest/api/2/issue/57443',
            'key': 'P2020021451-4',
            'fields': {
                'summary': '**开发功能',
                'priority': {
                    'self': 'https://jira.**.net.cn/rest/api/2/priority/2',
                    'iconUrl': 'https://jira.**.net.cn/images/icons/priorities/high.svg',
                    'name': '高',
                    'id': '2'
                },
                'status': {
                    'self': 'https://jira.**.net.cn/rest/api/2/status/10332',
                    'description': '',
                    'iconUrl': 'https://jira.**.net.cn/images/icons/statuses/generic.png',
                    'name': '需求完成',
                    'id': '10332',
                    'statusCategory': {
                        'self': 'https://jira.**.net.cn/rest/api/2/statuscategory/3',
                        'id': 3,
                        'key': 'done',
                        'colorName': 'green',
                        'name': '完成'
                    }
                }
            }
        }]
    }

     可以看见返回为json格式,我们指定要返回的fields字段都在json里面

  • 相关阅读:
    绘制QQ圆形图像
    java环境变量设置
    NDK调试
    NDK中android.mk文件的简单介绍和第三方库的调用
    Opencv的使用,NDK的简单使用
    java类成员的访问权限
    一、基础篇--1.2Java集合-HashMap源码解析
    一、基础篇--1.2Java集合-ArrayList和Vector的区别
    一、基础篇--1.2Java集合-Arraylist 与 LinkedList 区别
    一、基础篇--1.2Java集合-List、Set、Map区别
  • 原文地址:https://www.cnblogs.com/gcgc/p/12674341.html
Copyright © 2011-2022 走看看