classAzureProvider_3.py 1.1 KB

123456789101112131415161718192021222324252627282930
  1. def azure_create_branch(self, from_ref, branch_name):
  2. authorization = str(base64.b64encode(bytes(':' + self.azure_api_token, 'ascii')), 'ascii')
  3. url = f"{self.azure_base_url}/_apis/git/repositories/{self.azure_repo_id}/refs?api-version=6.0"
  4. headers = {
  5. 'Authorization': 'Basic ' + authorization
  6. }
  7. body = [
  8. {
  9. 'name': f"refs/heads/{branch_name}",
  10. 'oldObjectId': '0000000000000000000000000000000000000000',
  11. 'newObjectId': from_ref
  12. }
  13. ]
  14. if globals.debug > 0:
  15. print("DEBUG: perform API Call to ADO: " + url + " : " + json.dumps(body, indent=4, sort_keys=True) + "\n")
  16. r = requests.post(url, json=body, headers=headers)
  17. if r.status_code == 200:
  18. if globals.debug > 0:
  19. print(f"DEBUG: Success creating branch")
  20. print(r.text)
  21. return True
  22. else:
  23. print(f"BD-Scan-Action: ERROR: Failure creating branch: Error {r.status_code}")
  24. print(r.text)
  25. return False