Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. import jira.client
  2. from jira.client import JIRA
  3. from jira import JIRA
  4. import pandas as pd
  5. import numpy as np
  6.  
  7. options = {'server':'your server URL here'}
  8. jira = JIRA(options, basic_auth=('your user name here','your password here'))
  9.  
  10.  
  11. #extracting number of issues loop because of Jira limitation.
  12. block_size=100
  13. block_num=0
  14. allissues = []
  15. while True:
  16. start_idx = block_num*block_size
  17. issues = jira.search_issues('project=your project name here', start_idx, block_size)
  18. if len(issues) == 0:
  19. break
  20. block_num += 1
  21. for issue in issues:
  22. allissues.append(issue)
  23.  
  24.  
  25. #Create a dataframe and assign issues one by one.
  26.  
  27. issuesdf=pd.DataFrame()
  28. for issue in allissues:
  29.  
  30. issue = jira.issue(issue.key, expand='changelog')
  31. changelog = issue.changelog
  32.  
  33. for history in changelog.histories:
  34. for item in history.items:
  35. if item.field == 'status':
  36. if "Blocked" in item.toString or "Blocked" in item.fromString:
  37. d={
  38. 'Key' : issue.key,
  39. 'Assignee': issue.fields.assignee,
  40. 'Components': issue.fields.components,
  41. 'Summary': issue.fields.summary,
  42. 'Issuetype': issue.fields.issuetype.name,
  43. 'Priority': issue.fields.priority.name,
  44. 'Current Status': issue.fields.status.name,
  45. 'Date': history.created,
  46. 'Transition': item.fromString+' - '+item.toString,
  47.  
  48.  
  49. }
  50.  
  51.  
  52. issuesdf=issuesdf.append(d,ignore_index=True)
  53.  
  54.  
  55.  
  56. issuesdf['Date']=pd.to_datetime(issuesdf['Date'])
  57. issuesdf['Date']=issuesdf['Date'].dt.normalize()
  58.  
  59. blockeddf = issuesdf[issuesdf['Transition'].str.match('In Progress - Blocked')]
  60. blockeddf['Counter']=blockeddf.groupby((blockeddf['Key'] != blockeddf['Key'].shift(1)).cumsum()).cumcount()+1
  61. resolveddf = issuesdf[issuesdf['Transition'].str.match('Blocked - ')]
  62. resolveddf['Counter']=resolveddf.groupby((resolveddf['Key'] != resolveddf['Key'].shift(1)).cumsum()).cumcount()+1
  63. newdf = pd.merge(blockeddf,resolveddf,how='left', on=['Key','Counter'])
  64. newdf['Number of Days'] = newdf['Date_y'] - newdf['Date_x']
  65. newdf['Number of Days'] = newdf['Number of Days']/np.timedelta64(1,'D')
  66.  
  67. newdf.to_csv(r'your csv path here')
  68.  
  69.  
  70. print(issuesdf)
  71. issuesdf.to_csv(r'your csv path here')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement