python jira模块

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 jira模块的主要内容,如果未能解决你的问题,请参考以下文章

JIRA模块列表过滤

JIRA小工具REST模块不会给予回报

jira中新增模块详解

Python操作Jira

jira插件开发——新增模块SAL控制层

jira插件开发——新增模块SAL控制层