zoukankan      html  css  js  c++  java
  • 从 Jira page 上获取信息和下载附件

    文档:

       https://jira.readthedocs.io/en/latest/api.html

    jira提供了一系列的接口。包括给python,甚至 curl 来操作它

    原本官方接口有限。但是可以通过一些骚操作来不那么正式的获取一些数据

    #安装pip  mac 自带了 easy_install 

    sudo easy_install pip

    pip install JIRA

    通过 myissue = jac.issue('CT-'+id) 一个issue id 获取一个 issue 对象,然后可以进行一些你想要的操作 官方文档没看太明白

    翻了挺久看到更新、提交、创建、删除等等接口,但是一直没有找到从 jira page 上获取信息和下载附件的接口, 这种很常见的接口不应该不提供吧?找了找,用自己的办法撸了一个 凑活用吧
    目前清楚的 支持

    myissue.update({json})
    myissue.fields.labels.append(u'text')
    myissue.delete()
    
    # 将两个问题关联
    issue = jira.issue('WV-1430')
    issue2 = jira.issue('CC-17')
    jira.add_remote_link(issue, issue2)

    用例 demo:

    #usr/bin/python
    #coding:utf-8
    
    import sys
    reload(sys)
    sys.setdefaultencoding('utf8')
    
    from jira import JIRA
    import time
    
    jac = JIRA('http://xxxxxxxxx:xxx', basic_auth=('username', 'password'))
    
    key_val = {
        "giteeurl":  "customfield_10303",
        "password":  "customfield_10307",
        "emailpwd":  "customfield_10306",
        "giteepwd":  "customfield_10601",
        "username":  "customfield_10619",
        "phonenumber":  "customfield_11800",
        "proxyaddr":  "customfield_10310",
        "attachment":  "attachment",
    } 
    
    import os.path
    def downloadContent(data, filename, fpath):
        filepath = os.path.join(fpath, filename)
        with open(filepath,'wb') as f:
            f.write(data)
            f.close()
    
        if os.path.exists(filepath):
            if os.path.getsize(filepath) > 9 * 1024:
                return 
            else:
                print os.path.getsize(filepath)
        else:
            print "downloadContent failed! no find " + filepath
    
        print "downloadContent  file is too small!  Maybe sth wrong happend!"
    
    def get_issue(id, fname):
        # 获取一个issue issueid or issuekey
        myissue = jac.issue('CT-'+id)
        with open(fname,'w') as fa:
            for key in key_val:
                if key == "attachment":
                    val = myissue.fields().attachment
                    # print dir(val[0])
                    downloadContent(val[0].get(), val[0].filename, os.path.dirname(fname))
                else:
                    var = myissue.fields().__getattribute__(key_val[key])
                    if var:
                        fa.write(key.strip()+"="+var.strip() + "
    ")
    
    # ****_1555.zip 为issue_id
    def handleDir(params):
        rootpath = params[0]
        for gamepath in os.listdir(rootpath):
            if gamepath != "queue" and gamepath != ".DS_Store":
                gameabs_p = os.path.join(rootpath, gamepath)
                if os.path.isdir(gameabs_p):
                    for gamezipf in os.listdir(gameabs_p):
                        if os.path.splitext(gamezipf)[1] == ".zip":
                            start = gamezipf.rfind("_")
                            end = gamezipf.rfind(".zip")
                            if ((start != -1) and (end != -1)):
                                acc = gamezipf[start + 1: end]
                                get_issue(acc, os.path.join(gameabs_p, "gameinfo.txt"))
    
        print "handleDir Succeed!!!"
    
    if __name__=='__main__':
        handleDir(sys.argv[1:])
    
    
    #通过这样可以 获取所有的key
    for key in dir(myissue.fields()):
        var = getattr(myissue.fields(), key)
        print key
        print var
  • 相关阅读:
    18、排序算法-快速排序
    centos7.x 端口映射
    SpringBoot多环境分离resources和lib进行打包
    Java枚举储存的一种索引实现方式
    Maven项目pom文件设置JDK版本
    Java提取URL某个参数的值
    使用正则替换script及其内容
    Oracle设置主键自增
    Maven配置ojdbc14-10.2.0.4.0.jar
    使用maven生成可执行jar包(包含依赖)
  • 原文地址:https://www.cnblogs.com/lesten/p/13052336.html
Copyright © 2011-2022 走看看