python python jira模块

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python python jira模块相关的知识,希望对你有一定的参考价值。

# install jira
# pipenv install jira 

from jira import JIRA
jira = JIRA(os.getenv("jira_url"),basic_auth=(os.getenv('username'),os.getenv('password')))
from datetime import datetime,timedelta
import os

def create_issues(project,assignee,summary,description,issuetype,**kw):
        issue_dict = {
            "project":{"key":project},
            "assignee":{"name":assignee},
            "summary":summary,
            "description":description,
            "issuetype":{"name":issuetype},
            "customfield_10001": {
                "value": "3 - Medium"
            },
            "customfield_10024": datetime.strftime(datetime.now() + timedelta(days=30),"%Y-%m-%d")
        }
        if kw:
            issue_dict.update(kw)
        
        new_issue = jira.create_issue(fields=issue_dict) # jira is the result of init 
        print(new_issue) # print issue number but it is issue object
    def link_issue(self,inwardIssue):
        res = self.jira.create_issue_link("Related",inwardIssue,self.new_issue)
        print(res) # <Response [201]>
    def close_issue(self):
        res = self.jira.transition_issue(self.new_issue,"2891",fields={"assignee":{"name":"+close_folder"},"resolution":{"name":"Completed"}},comment="close the issue")
        print(res)
    def add_to_current_spring(self):
        res = self.jira.sprints(437)
        #print(dir(res[0]))
        #print(res[0].state)
        for sprint in res:
            if sprint.state == "ACTIVE":
                print(isinstance(sprint.id,int))
                print(self.new_issue.key)
                res = self.jira.add_issues_to_sprint(sprint_id=sprint.id,issue_keys=[self.new_issue.key])
                print(res)
   def attach_file(self,file):
        with open(file, 'rb') as f:
            self.jira.add_attachment(issue=self.new_issue, attachment=f,filename="test")
    

以上是关于python python jira模块的主要内容,如果未能解决你的问题,请参考以下文章

Python操作Jira

jira python 认证

JIRA python篇之展示多人未完成任务列表

python 用于从TestRail和Jira检索信息的Python脚本。需要在jira_testrail_cfg.py中定义凭据

获取问题评论 JIRA python

Python requests jira登录302重定向