Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- JIRA-HOST/rest/agile/1.0/issue/MyIssue
- 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))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement