简体   繁体   中英

Jira - Get issue rating via REST API

I'm trying to get the ranking of a Jira ID via REST :

This is the GET request which i'm sending:

JIRA-HOST/rest/agile/1.0/issue/MyIssue

I'm getting the key: customfield_10690, which is the rating field, but the value of this field is unreadable and unparseable, the value that i'm getting is: "customfield_10690":"0|i1qu83:"

What can i do?

Is the rating system a series of images? Like stars or something? Maybe jira is trying to send you the image as a text and thats becoming something unprintable.

If this is the case, I think you're only option is to: 1. Change the rating system to a number 2. If the values are consistent, have a mapping so you can map "0|i1qu83:" to a rating that makes sense to your code.

The value you're seeing is a lexorank token .

If you need a numerical ranking (eg rank 15 of 100), you may want to fetch the total list of issues through the JIRA search endpoint using JQL (their limited query language), and enumerate the results or search for the issue you need by key while incrementing or updating some rank number. If your query returns several results, performance matters, and you only require a single issue, you may want to use a more intelligent search like binary search .

Here's a rough example using the node client :

import jiraAPI from 'jira-client'

const jira = new jiraAPI({
  protocol: 'https',
  host: process.env['JIRA_HOST'],
  username: process.env['JIRA_USERNAME'],
  password: process.env['JIRA_PASSWORD'],
  apiVersion: '2',
  strictSSL: true,
  timeout: 30000, // 30s
})

const JQL = 'project = "your-project" AND status IN ("To Do", "In Progress", "Blocked") order by status desc, Rank asc'

const FIELDS = ['key', 'priority', 'status', 'summary', 'labels', 'assignee']

const formatIssue = ({ issue: { key, fields = {} }, rank = 0, total = 0 }) => ({
  key,
  rank,
  total,
  priority: fields.priority.name,
  status: fields.status.name,
  summary: fields.summary,
  assignee: fields.assignee ? fields.assignee.displayName : null,
  labels: fields.labels
})

async function* issueGenerator ({ offset = 0, limit = 100 }) {
  for (let max = 1; offset < max; offset += limit) {
    const { total = 0, maxResults = 0, startAt = 0, issues = [] } = await jira.searchJira(JQL, {
      startAt: offset,
      maxResults: limit,
      fields: FIELDS
    })

    max = total
    limit = maxResults
    offset = startAt

    for (let i = 0, len = issues.length; i < len; i++) {
      yield formatIssue({ issue: issues[i], rank: offset + i + 1, total })
    }
  }
}


async function fetchIssuesWithLabel (label) {
  const issueIterator = issueGenerator({ offset: 0, limit: 100 })
  const teamIssues = []

  for await (const issue of issueIterator) {
    if (issue.labels.includes(label)) {
      teamIssues.push(issue)
    }
  }

  return teamIssues
}

fetchIssuesWithLabel('bug').then(result => console.log(result))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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