Guest User

Untitled

a guest
Jan 30th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. # Get user credentials from consule
  2. def get_user_credentials (self):
  3. self.username = raw_input("Github username: ")
  4. self.password = getpass.getpass(prompt='Github password: ')
  5. self.repository_name = raw_input("Repository name: ")
  6. self.release_name = raw_input('Release name: ')
  7.  
  8. # Read details of all releases in a repository
  9. def read_requested_release_detials(self, release, tag_name, sheet, is_release_found):
  10. is_release_found = True
  11. release_body = release.body
  12. lines_in_release_body = (release_body.splitlines(0))
  13. ReadRelease.read_lines_start_with_dash(self, lines_in_release_body, self.sheet, tag_name)
  14.  
  15. # Read all releases names of a repository
  16. def read_all_releases_names(self, repository, release_name, sheet):
  17. is_release_found = False
  18. for release in repository.get_releases():
  19. tag_name = (release.tag_name).encode('utf-8')
  20. name = (release.title).encode('utf-8')
  21. # Filter releases name with give release name
  22. if name == release_name:
  23. is_release_found = True
  24. ReadRelease.read_requested_release_detials(self, release, tag_name, self.sheet, is_release_found)
  25. if not is_release_found:
  26. print "'Release Name' is wrong!, Please try again with correct 'release name'"
  27. else:
  28. print "Releases inserted to the Google sheet."
  29.  
  30. # Insert a line to google sheet file (those issues which are not fixed)
  31. def issue_not_fixed(self, sheet, tag_name, line, row):
  32. sheet.insert_row([tag_name, tag_name, line[7:].encode('utf-8'), 'NO'], row)
  33.  
  34. # Insert a line to google sheet file and set fix the Is fixed? column
  35. def issue_fixed(self, sheet, tag_name, line, row):
  36. sheet.insert_row([tag_name, tag_name, line[7:].encode('utf-8'), 'YES'], row)
  37.  
  38. # Read all lines in ralease body whihc start with '-'
  39. def read_lines_start_with_dash(self, lines_in_release_body, sheet, tag_name):
  40. # Counter for updating rows in google sheet file
  41. row = 2
  42. for line in lines_in_release_body:
  43. if (line[:1]).encode('utf-8') == '-':
  44. if line[1:7].encode('utf-8') == ' [FIX]':
  45. ReadRelease.issue_fixed(self, sheet, tag_name, line, row)
  46. elif line[1:7].encode('utf-8') == '------':
  47. break
  48. else:
  49. ReadRelease.issue_not_fixed(self, sheet, tag_name, line, row)
  50. row += 1
  51.  
  52. # Set google sheet api credentials and open file on google sheet
  53. def set_google_sheet_credentials(self, sheet):
  54. scope = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']
  55. google_credentials = ServiceAccountCredentials.from_json_keyfile_name('test.json', scope)
  56. file = gspread.authorize(google_credentials)
  57. self.sheet = file.open('Copy_of_MOD_Change_Worklog_Tracker.xlsx').sheet1
  58. # Add headers to the sheet
  59. self.sheet.update_acell('A1', 'Client Version')
  60. self.sheet.update_acell('B1', 'Version Reference for Internal Purposes')
  61. self.sheet.update_acell('C1', 'Proposed Change (Expected Functional Behavior)')
  62. self.sheet.update_acell('D1', 'Bug Fix?')
  63.  
  64. # URL Builder method for github repository
  65. def prepare_github_repository_url(self):
  66. return(str('someuseraccount/'+ self.repository_name))
  67.  
  68. # Authunticate user in github
  69. def github_authunticate(self, username, password, url):
  70. github_account = Github(self.username, self.password)
  71. return (github_account.get_repo(url))
  72.  
  73. read_release_obj.get_user_credentials()
  74.  
  75. url = read_release_obj.prepare_github_repository_url()
  76.  
  77. # Check if username and password exist
  78. if read_release_obj.username and read_release_obj.password:
  79. try:
  80. github_repo = read_release_obj.github_authunticate(read_release_obj.username, read_release_obj.password, url)
  81.  
  82. read_release_obj.set_google_sheet_credentials(read_release_obj.sheet)
  83.  
  84. read_release_obj.read_all_releases_names(github_repo, read_release_obj.release_name, read_release_obj.sheet)
  85.  
  86. except BadCredentialsException:
  87. print ('Bad credentials. Try again!')
  88.  
  89. else:
  90. print ('Github credentials are required!')
Add Comment
Please, Sign In to add comment