简体   繁体   English

是否可以使用 python-jira 更改 jira 问题状态?

[英]Is it possible to change jira issue status with python-jira?

I want to change jira issue status with python-jira.The python-jira API is http://jira-python.readthedocs.org/en/latest/ .I can't find any way to do this.我想用 python-jira 更改 jira 问题状态。python-jira API 是http://jira-python.readthedocs.org/en/latest/ 。我找不到任何方法来做到这一点。 I was trying to use issue.update(status="Closed") .But it didn't work.I found Issue status and workflow in https://developer.atlassian.com/display/JIRADEV/Issue+status+and+workflow .But I still don't know what to do.Can anyone help me out?我试图使用issue.update(status="Closed") 。但它没有用。我在https://developer.atlassian.com/display/JIRADEV/Issue+status+and+ 中找到了问题状态和工作流程工作流程。但我仍然不知道该怎么做。有人可以帮我吗?

I ran into this as well, and unfortunately JIRA's incredible flexibility also makes it a PITA sometimes.我也遇到了这个问题,不幸的是 JIRA 令人难以置信的灵活性有时也使它成为 PITA。

To change the status on a ticket, you need to make a transition , which moves it from one status to the next.要更改工单的状态,您需要进行转换,将其从一种状态移动到下一种状态。

You need to find your transition IDs, then use it like so:您需要找到您的过渡 ID,然后像这样使用它:

if issue.fields.status in ('open', 'reopened'):
    # Move the ticket from opened to closed.
    jira.transition_issue(ticket, transition='131')

jira-python documents discovering and making transitionshere . jira-python 文档在这里发现和进行转换。

jira.transition_issue is documented here . jira.transition_issue记录在此处 You can actually use the name (ex: 'Closed' ) of the transition instead of the ID, but the ID is more reliable as it will not change.您实际上可以使用过渡的名称(例如: 'Closed' )而不是 ID,但 ID 更可靠,因为它不会改变。

To change status, you need to do transaction above the issue.要更改状态,您需要在问题上方进行交易。 Transition is just operation that is defined in 'workflow', and transit issue from one status to another.过渡只是在“工作流程”中定义的操作,以及从一种状态到另一种状态的过渡问题。 From current status you can perform just limited set of transition, that depends on 'workflow'.从当前状态,您只能执行有限的一组转换,这取决于“工作流程”。 Try to use following functions: Current issue status:尝试使用以下功能: 当前问题状态:

issue = jira.issue('PROJECT-1')
issue.fields.status

JIRA Status: name='Fix submitted', id='10827' JIRA 状态:name='修复提交',id='10827'

Possible transitions for current status of the issue:问题当前状态的可能转变:

jira.transitions(issue)

[{'id': '181', 'name': 'Fix Failed', 'to': ..........}}}, {'id': '261', 'name': 'Fix Verfied', 'to': {'self':.....}}}] [{'id': '181', 'name': 'Fix Failed', 'to': ..........}}}, {'id': '261', 'name': 'Fix Verfied', 'to': {'self':.....}}}]

So then you can perform two transitions:那么你可以执行两个转换:

jira.transition_issue(issue, transition='Fix Failed')

or或者

jira.transition_issue(issue, 261)

Then you can verify that your issue changed status on the server:然后您可以验证您的问题在服务器上更改了状态:

issue = jira.issue('PROJECT-1')
issue.fields.status

JIRA Status: name='Fix failed', id='10830' JIRA 状态:name='修复失败',id='10830'

So, in answer of your question, you need to perform more transition to transfer issue from one state to another if states are not connected by transition.因此,在回答您的问题时,如果状态未通过转换连接,您需要执行更多转换以将问题从一种状态转移到另一种状态。 eg.: Consider workflow from this url and your issue current state is " RESOLVED ", and let say you want to achieve status " IN PROGRESS ".例如.:考虑的工作流程,从这个网址与您的问题当前状态为“已解决”,让说你想要达到的状态“进行中”。 Similar code can be used:可以使用类似的代码:

jira.transition_issue(issue, transition='Reopen Issue')
jira.transition_issue(issue, transition='Start Progress')

My use case was only to change status of ticket.我的用例只是更改票证的状态。
All you need to change in your previous attempt is do not explicitly mention the word transitionId=您在之前的尝试中需要更改的只是不要明确提及transitionId=这个词

This worked for me.这对我有用。

jira.transition_issue(issue, '31')

Here is the code for updating the status of Jira issue via Python:以下是通过 Python 更新 Jira 问题状态的代码:

from jira import JIRA
JIRA_SERVER = "https://issues.your-company.com/"
jira_user_name = "your_user_name"
jira_password = "your_jira_password"
jira_connection = JIRA(basic_auth=(jira_user_name, jira_password), 
server=JIRA_SERVER)
jira_connection.transition_issue("PR-1309", "Start Progress")

Here PR-1309 is the ID of your JIRA Issue.这里 PR-1309 是您的 JIRA 问题的 ID。 Start Progress is the action that needs to be taken for this issue. Start Progress 是需要针对此问题采取的操作。 The list of actions can be different for different customers of JIRA. JIRA 的不同客户的操作列表可能不同。 Therefore, open your JIRA Portal and see the available transition options for your JIRA issues.因此,打开您的 JIRA 门户并查看 JIRA 问题的可用转换选项。 Some transition actions can be:-一些过渡动作可以是:-

  1. Prepared准备好了
  2. Done完毕
  3. Reject拒绝
  4. In Progress进行中
  5. To Do去做
  6. Review审查
  7. Abort中止

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM