使用 python 在 jira 中循环创建票证
Using python to loop through the creation of tickets in jira
我正在考虑使用 JIRA 模块通过 python 在 Jira 中批量创建工单。我正在接受用户输入,将它们插入字典,然后在我的 JIRA 项目中创建票证。这一切都很好,并且按照我的意愿创建了票证。但是,当我尝试循环创建票证直到我指定一个点时,我的问题就出现了?
我基本上希望它接受用户输入,创建票证然后问我是否要创建另一个票证。如果我指定字母 'Y',它会提示用户再次填写输入框并创建另一张票,依此类推,直到我另行指定。
我目前的代码是:
decision = input("Do you want to create a ticket? ")
project = "My project"
if decision == 'Y':
issue_dict = {
'project': {'key':project},
'summary': input("Please provide a summary "),
'description' : input("please describe the issue "),
'issuetype':{'name': 'Story'},
'assignee': {"name": input("Who is this assigned to ")}
}
ticket_id = jira.create_issue(fields=issue_dict)
print("Created, ticket reference: ", ticket_id)
decision = input("Do you want to create another ticket? ")
else:
print("No more tickets")
我使用此代码得到的错误是:
NameError: 名称 'jira' 未定义
第 14 行:
ticket_id = jira.create_issue(字段=issue_dict)
任何帮助将不胜感激,如果这是一个愚蠢的错误,我深表歉意,我对 python 循环没有什么经验!
谢谢:)
编辑:我不明白如何将代码 运行 返回顶部,一旦它通过一次,抱歉!
使用这个:
from jira.client import JIRA
jira_options = {'server': 'MY_jira.com'}
jira = JIRA(options=jira_options, basic_auth=(USERNAME, PASSWORD))
def ask_what_to_do():
decision = input("Do you want to create a ticket? \n")
if decision == 'Y':
issue_dict = {
'project': {'key':project},
'summary': input("Please provide a summary "),
'description' : input("please describe the issue "),
'issuetype':{'name': 'Story'},
'assignee': {"name": input("Who is this assigned to ")}
}
ticket_id = jira.create_issue(fields=issue_dict)
print("Created, ticket reference: ", ticket_id)
ask_what_to_do()
else:
print("No more tickets \n")
显然,为了不出现导入错误,您必须从某个地方导入 jira
。
decision = "Y"
while decision == 'Y':
issue_dict = {
'project': {'key':project},
'summary': input("Please provide a summary "),
'description' : input("please describe the issue "),
'issuetype':{'name': 'Story'},
'assignee': {"name": input("Who is this assigned to ")}
}
ticket_id = jira.create_issue(fields=issue_dict)
print("Created, ticket reference: ", ticket_id)
decision = input("Do you want to create another ticket? ")
我正在考虑使用 JIRA 模块通过 python 在 Jira 中批量创建工单。我正在接受用户输入,将它们插入字典,然后在我的 JIRA 项目中创建票证。这一切都很好,并且按照我的意愿创建了票证。但是,当我尝试循环创建票证直到我指定一个点时,我的问题就出现了?
我基本上希望它接受用户输入,创建票证然后问我是否要创建另一个票证。如果我指定字母 'Y',它会提示用户再次填写输入框并创建另一张票,依此类推,直到我另行指定。
我目前的代码是:
decision = input("Do you want to create a ticket? ")
project = "My project"
if decision == 'Y':
issue_dict = {
'project': {'key':project},
'summary': input("Please provide a summary "),
'description' : input("please describe the issue "),
'issuetype':{'name': 'Story'},
'assignee': {"name": input("Who is this assigned to ")}
}
ticket_id = jira.create_issue(fields=issue_dict)
print("Created, ticket reference: ", ticket_id)
decision = input("Do you want to create another ticket? ")
else:
print("No more tickets")
我使用此代码得到的错误是:
NameError: 名称 'jira' 未定义
第 14 行:
ticket_id = jira.create_issue(字段=issue_dict)
任何帮助将不胜感激,如果这是一个愚蠢的错误,我深表歉意,我对 python 循环没有什么经验!
谢谢:)
编辑:我不明白如何将代码 运行 返回顶部,一旦它通过一次,抱歉!
使用这个:
from jira.client import JIRA
jira_options = {'server': 'MY_jira.com'}
jira = JIRA(options=jira_options, basic_auth=(USERNAME, PASSWORD))
def ask_what_to_do():
decision = input("Do you want to create a ticket? \n")
if decision == 'Y':
issue_dict = {
'project': {'key':project},
'summary': input("Please provide a summary "),
'description' : input("please describe the issue "),
'issuetype':{'name': 'Story'},
'assignee': {"name": input("Who is this assigned to ")}
}
ticket_id = jira.create_issue(fields=issue_dict)
print("Created, ticket reference: ", ticket_id)
ask_what_to_do()
else:
print("No more tickets \n")
显然,为了不出现导入错误,您必须从某个地方导入 jira
。
decision = "Y"
while decision == 'Y':
issue_dict = {
'project': {'key':project},
'summary': input("Please provide a summary "),
'description' : input("please describe the issue "),
'issuetype':{'name': 'Story'},
'assignee': {"name": input("Who is this assigned to ")}
}
ticket_id = jira.create_issue(fields=issue_dict)
print("Created, ticket reference: ", ticket_id)
decision = input("Do you want to create another ticket? ")