首页 > 编程语言 > 详细

python 操作jira接口

时间:2020-06-05 22:29:39      阅读:75      评论:0      收藏:0      [点我收藏+]

文档:

   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 对象,然后可以进行一些你想要的操作 官方文档没看太明白
目前清楚的 支持

myissue.update({json})
myissue.fields.labels.append(utext)
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() + "\n")

# ****_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:])

 

python 操作jira接口

原文:https://www.cnblogs.com/lesten/p/13052336.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!