2

我正在尝试通过 API 导出 JIRA 任务,但由于 JIRA 只允许 1000 个限制,我在 excel 上碰壁了。我可以手动导出到 CSV 并获得 1000 多个结果,并且想知道是否有人对通过 REST API 进行大型 JIRA 导出有任何运气,并且可以帮助我指出正确的方向。

猜测导出到 CSV 然后拉入 excel 进行报告可能有效吗?

谢谢!

4

3 回答 3

2

JIRA 的 REST API 支持分页,以防止 API 的客户端对应用程序施加过多的负载。这意味着您不能仅通过 1 次 REST 调用来提取所有问题数据。

您只能使用分页查询参数startAtmaxResults检索最多 1000 个问题的“页面” 。请参阅此处的分页部分。

如果您运行 JIRA 独立服务器,则可以调整 JIRA 返回的最大结果数,但对于云实例,这是不可能的。有关更多信息,请参阅此知识库文章

于 2017-01-26T12:28:09.407 回答
1

使用 jira-python (根据您的标签)

# search_issues can only return 1000 issues, so if there are more we have to search again, thus startAt=count
issues = []
count = 0
while True:
    tmp_issues = jira_connection.search_issues('', startAt=count, maxResults=count + 999)
    if len(tmp_issues) == 0:
        # Since Python does not offer do-while, we have to break here.
        break
    issues.extend(tmp_issues)
    count += 999
于 2017-02-10T10:17:56.467 回答
0

下面的代码将一次获取结果 200 条记录,直到所有记录都被导出。

您可以通过更新页面大小一次导出最多 1000 条记录,它将递归地获取 1000 条记录,直到所有内容都被导出

变量窗口滑块 = 200

    const request = require('request')
const fs = require('fs')
const chalk = require('chalk')


var windowSlider = 200

var totlExtractedRecords = 0;
fs.writeFileSync('output.txt', '')

const option = {
    url: 'https://jira.yourdomain.com/rest/api/2/search',
    json: true,
    qs: {
        jql: "project in (xyz)",
        maxResults: 200,
        startAt: 0,
    }
}

const callback = (error, response) => {
    const body = response.body

    console.log(response.body)

    const dataArray = body.issues
    const total = body.total


    totlExtractedRecords = dataArray.length + totlExtractedRecords

    if (totlExtractedRecords > 0) {
        option.qs.startAt = windowSlider + option.qs.startAt
    }

    dataArray.forEach(element => {
        fs.appendFileSync('output.txt', element.key + '\n')
    })

    console.log(chalk.red.inverse('Total extracted data : ' + totlExtractedRecords))
    console.log(chalk.red.inverse('Total data: ' + total))

    if (totlExtractedRecords < total) {
        console.log('Re - Running with start as ' + option.qs.startAt)
        console.log('Re - Running with maxResult as ' + option.qs.maxResults)
        request(option, callback).auth('api-reader', 'APITOKEN', true)
    }
}


request(option, callback).auth('api-reader', 'APITOKEN', true)
于 2019-09-05T10:57:45.720 回答