oborudko

approve

Jul 23rd, 2021
939
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/local/bin/python3
  2.  
  3. from atlassian import Jira
  4. from atlassian import Bitbucket
  5. from config.config import Config
  6. from pprint import pprint
  7. import requests
  8.  
  9. jira = Jira(url=Config().jiraUrl,username=Config().jiraUser,password=Config().jiraPassword)
  10. bitbucket = Bitbucket(url=Config().bitbucketUrl,username=Config().bitbucketUser,password=Config().bitbucketPassword)
  11.  
  12. JQL = 'project = SWOOG AND status = "Code Review" AND assignee in (EMPTY, currentUser())'
  13. data = jira.jql(JQL)
  14.  
  15. # data = request.get_json()
  16.  
  17. if data and 'issues' in data:
  18.     for issue in data['issues']:
  19.         issueId = issue['id']
  20.         print('issue -> %s' %(issueId))
  21.         dev = jira.get('/rest/dev-status/1.0/issue/detail?issueId=%s&applicationType=bitbucket&dataType=repository' %(issue['id']))
  22.         if dev:
  23.             detail = dev['detail'][-1]
  24.             repo = detail['repositories'][-1]
  25.             for commit in repo['commits']:
  26.                 commitId = commit['id']
  27.                 try:
  28.                     r = bitbucket.post('/2.0/repositories/swoogo/www.swoogo.com/commit/%s/approve' %(commitId), {
  29.                         "hasComments": False
  30.                     })
  31.                     print("\tapprove %s " %(commit['id']))
  32.                 except requests.exceptions.HTTPError as err:
  33.                     pass
  34.         jira.set_issue_status(issueId, 'QA')
  35.         jira.assign_issue(issueId)
RAW Paste Data