Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. JIRA-HOST/rest/agile/1.0/issue/MyIssue
  2.  
  3. import jiraAPI from 'jira-client'
  4.  
  5. const jira = new jiraAPI({
  6. protocol: 'https',
  7. host: process.env['JIRA_HOST'],
  8. username: process.env['JIRA_USERNAME'],
  9. password: process.env['JIRA_PASSWORD'],
  10. apiVersion: '2',
  11. strictSSL: true,
  12. timeout: 30000, // 30s
  13. })
  14.  
  15. const JQL = 'project = "your-project" AND status IN ("To Do", "In Progress", "Blocked") order by status desc, Rank asc'
  16.  
  17. const FIELDS = ['key', 'priority', 'status', 'summary', 'labels', 'assignee']
  18.  
  19. const formatIssue = ({ issue: { key, fields = {} }, rank = 0, total = 0 }) => ({
  20. key,
  21. rank,
  22. total,
  23. priority: fields.priority.name,
  24. status: fields.status.name,
  25. summary: fields.summary,
  26. assignee: fields.assignee ? fields.assignee.displayName : null,
  27. labels: fields.labels
  28. })
  29.  
  30. async function* issueGenerator ({ offset = 0, limit = 100 }) {
  31. for (let max = 1; offset < max; offset += limit) {
  32. const { total = 0, maxResults = 0, startAt = 0, issues = [] } = await jira.searchJira(JQL, {
  33. startAt: offset,
  34. maxResults: limit,
  35. fields: FIELDS
  36. })
  37.  
  38. max = total
  39. limit = maxResults
  40. offset = startAt
  41.  
  42. for (let i = 0, len = issues.length; i < len; i++) {
  43. yield formatIssue({ issue: issues[i], rank: offset + i + 1, total })
  44. }
  45. }
  46. }
  47.  
  48.  
  49. async function fetchIssuesWithLabel (label) {
  50. const issueIterator = issueGenerator({ offset: 0, limit: 100 })
  51. const teamIssues = []
  52.  
  53. for await (const issue of issueIterator) {
  54. if (issue.labels.includes(label)) {
  55. teamIssues.push(issue)
  56. }
  57. }
  58.  
  59. return teamIssues
  60. }
  61.  
  62. fetchIssuesWithLabel('bug').then(result => console.log(result))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement