【问题标题】:How can I find the status of a JIRA issue via the REST API?如何通过 REST API 找到 JIRA 问题的状态?
【发布时间】:2014-09-04 14:20:25
【问题描述】:

我正在编写一个脚本(如果重要的话,在 Powershell 中)来部署 SQL 代码。我希望脚本中的部分逻辑是让它在部署之前检查与脚本关联的 JIRA 问题是否处于正确状态(例如,在我的情况下,问题状态是“QE 认证”。

我正在尝试使用 JIRA REST API,但到目前为止,我无法找到一种方法来告诉我问题的当前状态。我发现的最接近的方法是查看可用于该问题的转换:

https://docs.atlassian.com/jira/REST/5.2/#id251679

这不会给我当前的状态,但我可以从可用的转换中弄清楚。这对我来说似乎有点笨拙。

我希望有像 /rest/api/2/issue/{issueIdOrKey}/status 这样的东西可以告诉我问题的当前状态。

通过 REST API 获取问题状态的最佳方式是什么?

谢谢

【问题讨论】:

    标签: rest jira


    【解决方案1】:

    您可以使用/rest/api/2/issue/{issueIdOrKey} 并设置fields-parameter 将返回的数据限制为状态字段。

    所以你的要求是:

    /rest/api/2/issue/{issueIdOrKey}?fields=status
    

    【讨论】:

    • 非常感谢,您为有需要的人节省了宝贵的时间。
    【解决方案2】:

    可以通过curl命令实现。

    语法:

    curl -u username:password -X GET -H "Content-Type: application/json" 
         https://server-url/rest/api/2/issue/JRA-1?fields=status
    

    【讨论】:

      【解决方案3】:

      这里是示例请求:

      /rest/api/2/issue/HTP-55
      

      HTP-55 是问题 ID。

      这是回复中可能对您有用的部分。

      "status": {
        "self": "rest/api/2/status/3",
        "description": "This issue is being actively worked on at the moment by the assignee.",
        "iconUrl": "images/icons/statuses/inprogress.png",
        **"name": "In Progress",
        "id": "3"**
      },
      

      【讨论】:

        【解决方案4】:

        如果您更喜欢使用更高版本的 Jira REST Java Client API(例如 4.0),以下是示例代码。

        private static final String JIRA_SERVER = "http://jiralab";
        
        public static void main(String[] args) {
            try {
                JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
                URI uri = new URI(JIRA_SERVER);
                JiraRestClient client = factory.createWithBasicHttpAuthentication(uri, "admin", "admin");
                getIssue(client, "ISSUE-1");
            }
            catch (Exception ex) {
            }
        }
        
        private static void getIssue(JiraRestClient client, String key) throws Exception {
            Promise<Issue> promise = client.getIssueClient().getIssue(key);
            Issue issue = promise.claim();
            System.out.println("Summary = " + issue.getSummary() + ", Status = " + (issue.getStatus() != null ? issue.getStatus().getName() : "N/A"));
        }
        

        【讨论】:

          【解决方案5】:

          线程晚了,但仍然有用。该命令利用了 jql 的强大功能。

          返回项目中所有项目的 id、key 和 status 字段。如果您想进行一些报告,尤其是基于状态的报告,这很有用。

          curl -u username:passwoorod -X GET -H "Content-Type: application/json" 'https://www.url.com/rest/api/2/search?jql=project=PROJ&fields=id,key,status'
          

          参考:https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/#request-18

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-12-21
            • 1970-01-01
            • 1970-01-01
            • 2016-07-12
            相关资源
            最近更新 更多