JIRA REST API 在转换问题时是否需要提交转换 ID? [英] Does the JIRA REST API require submitting a transition ID when transitioning an issue?

查看:48
本文介绍了JIRA REST API 在转换问题时是否需要提交转换 ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我发布这样的问题转换:

If I POST an issue transition like this:

{
    "fields" : {
        "resolution" : {
            "name" : "Fixed"
        }
    }
}

...我收到此错误:

{
    "errorMessages" : ["Missing 'transition' identifier"],
    "errors" : {}
}

这似乎意味着我需要在更改字段列表中包含转换 ID.https://stackoverflow.com/a/14642966/565869 似乎也是如此.很好.

This seems to imply that I need to include a transition ID along with my list of changed fields. https://stackoverflow.com/a/14642966/565869 seems to say the same. Fine.

但是,过渡 ID 似乎是全局的.仅查找此问题的最高转换 ID 并递增它是不够的;这样的 ID 可能在其他地方使用.付出一些代价,我可以获得系统中任何地方使用的最高事务 ID;此时可能是 68,000.但是,如果我当时使用事务 ID 68,001,那么 GUI 用户很有可能会尝试自己转换并在我之前使用此 ID.

However, transition IDs appear to be global. It's not enough to look up the highest transition ID for this issue and increment it; such an ID is probably in use elsewhere. At some expense, I could get the highest transaction ID used anywhere in the system; this might be 68,000 at this moment. But if I were then to use transaction ID 68,001 there's a real chance that a GUI user would attempt a transition of their own and use this ID before I could.

我可以使用 1,000,001 及以上范围内的事务 ID,但如果 JIRA Web GUI 在生成新 ID 时使用先前使用的最高事务 ID,我将只在此范围内而不是 68,000 范围内发生冲突.我可以使用 69,000,并且相信在获得最高事务 ID 所需的时间长度内不会有上千次转换.

I could use transaction IDs in the range of 1,000,001 and up, but if the JIRA web GUI uses the highest previously used transaction ID when generating new IDs I'll just collide in this range instead of the 68,000 range. I could use 69,000 and trust that there won't be a thousand transitions in the length of time it takes to get the highest transaction ID.

然而,这两个看起来都非常笨拙.有没有办法发布一个过渡并让 JIRA 生成自己的唯一 ID?我不需要检索生成的 ID,我只想更新问题的状态和解决方案.

These both seem terribly clumsy, however. Is there no way to post a transition and let JIRA generate its own unique ID? I don't need to retrieve the generated IDs, I just want to update issues' statuses and resolutions.

推荐答案

你有点搞混了.所以让我看看我能不能给你解释得更好.

You're getting mixed up a bit. So lets see if I can explain it better for you.

要转换 JIRA 问题,您可以使用转换 ID 来确定要应用于该问题的转换.您没有为事务指定 ID 或转换 ID 来标识转换发生,JIRA 会为您处理.

To transition a JIRA Issue, you use the Transition ID to identify what transition to apply to the issue. You aren't specifying an ID for a transaction or a transition ID to identify that the transition occurred, JIRA takes care of this for you.

理解它的最简单方法是看到它.

The easiest way to understand it is to see it.

因此,首先您可以通过对 API 调用执行 GET 来查看对问题可用的转换:

So first you can look at what transitions are available to an Issue by doing a GET to the API Call:

/rest/api/2/issue/${issueIdOrKey}/transitions

示例:

/rest/api/2/issue/ABC-123/transitions

将显示如下内容:

{
    "expand": "transitions",
    "transitions": [
        {
            "id": "161",
            "name": "Resolve",
            "to": {
                "description": "A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.",
                "iconUrl": "https://localhost:8080/images/icons/statuses/resolved.png",
                "id": "5",
                "name": "Resolved",
                "self": "https://localhost:8080/rest/api/2/status/5"
            }
        }
    ]
}

因此您可以看到问题 ABC-123 只有 1 个转换可用,并且它的 ID 为 161.

So you can see only 1 transition is available for issue ABC-123 and it has an ID of 161.

如果您要通过 GUI 浏览到该 JIRA 问题,您将只看到 1 个可用的转换,并且它将匹配 API 调用.事实上,如果您检查了该元素,您应该会看到它有一个 a 标记,并且在 href 中类似于 action=161

If you were to browse to that JIRA Issue through the GUI, you would see only 1 Transition available and it would match the API Call. In fact if you inspected the element you should see it having an a tag and in the href something like action=161

因此,如果您想转移此问题,则需要对以下 URL 执行 POST:

So should you want to transition this issue, you'll need to do a POST to the following URL:

/rest/api/2/issue/ABC-123/transitions

像这样的 JSON:

{
    "update": {
        "comment": [
            {
                "add": {
                    "body": "Bug has been fixed."
                }
            }
        ]
    },
    "fields": {
        "assignee": {
            "name": "bob"
        },
        "resolution": {
            "name": "Fixed"
        }
    },
    "transition": {
        "id": "161"
    }
}

使用从显示所有转换的调用中找到的转换 ID.我也同时更新决议和受让人并添加评论.

Which uses the transition ID found from the call that shows all transitions. I also update the resolution and assignee and add comments at the same time.

这样更有意义吗?

这篇关于JIRA REST API 在转换问题时是否需要提交转换 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆