Skip to content

Commit

Permalink
Merge pull request #27 from stakater/add-bitbucket-cloud
Browse files Browse the repository at this point in the history
Add bitbucket cloud
  • Loading branch information
rasheedamir authored Aug 11, 2023
2 parents 7a12706 + b952299 commit dd8f0b8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
52 changes: 28 additions & 24 deletions scripts/python/fetch-params/fetch_params_bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,36 @@ def send_api_request(url, username, password):
print(f"Error occurred during the API request: {e}")
return None

def fetch_params_bitbucket(provider, username, password, hash, workspace, repository):

print(f"provider: {provider} \nusername: {username}\npassword: {password}\nhash: {hash}\nworkspace: {workspace}\nrepository: {repository}")
if provider == "bitbucket":
def fetch_params_bitbucket(provider, username, password, hash, workspace, repository, url):

if provider == "bitbucket-cloud":
url = f"{url}/{workspace}/{repository}/pullrequests"
else:
url = f"https://api.bitbucket.org/2.0/repositories/{workspace}/{repository}/pullrequests"
print(f"provider: {provider} \nusername: {username}\npassword: {password}\nhash: {hash}\nworkspace: {workspace}\nrepository: {repository}")
response = send_api_request(url, username, password)
found = False

response = send_api_request(url, username, password)
found = False
if response:
for pull_request in response['values']:
if found == True:
break
pull_request_id = pull_request['id']
if response:
for pull_request in response['values']:
if found == True:
break
pull_request_id = pull_request['id']
if provider == "bitbucket-cloud":
url = f"{url}/{workspace}/{repository}/pullrequests/{pull_request_id}/commits"
else:
url = f"https://api.bitbucket.org/2.0/repositories/{workspace}/{repository}/pullrequests/{pull_request_id}/commits"
commits = send_api_request(url, username, password)
commits = send_api_request(url, username, password)

if commits:
for commit in commits['values']:
print(f"Commit ID: {commit['hash']}, Author: {commit['author']['raw']}, Message: {commit['message']}")
if commit['hash'] == hash:
print(f"Found hash in PR {pull_request_id}")
found = True
return pull_request_id
break
else:
return None
else:
return None
if commits:
for commit in commits['values']:
print(f"Commit ID: {commit['hash']}, Author: {commit['author']['raw']}, Message: {commit['message']}")
if commit['hash'] == hash:
print(f"Found hash in PR {pull_request_id}")
found = True
return pull_request_id
break
else:
return None
else:
return None
9 changes: 5 additions & 4 deletions scripts/python/fetch-params/find_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from fetch_params_github import fetch_params_github
import argparse

def find_hash(provider, username, password, hash, workspace, repository):
def find_hash(provider, username, password, hash, workspace, repository, url):
pr_number = None
if provider == "bitbucket":
pr_number = fetch_params_bitbucket(provider, username, password, hash, workspace, repository)
if (provider == "bitbucket") or (provider == "bitbucket-cloud") :
pr_number = fetch_params_bitbucket(provider, username, password, hash, workspace, repository, url)
elif provider == "github":
pr_number = fetch_params_github(provider, username, password, hash, workspace, repository)
return pr_number
Expand All @@ -17,6 +17,7 @@ def find_hash(provider, username, password, hash, workspace, repository):
parser.add_argument("hash", help="Hash of the commit that triggered the pipeline")
parser.add_argument("workspace", help="Workspace/Organization")
parser.add_argument("repository", help="Git repository name")
parser.add_argument("url", nargs="?", help="An optional URL argument", default="")
args = parser.parse_args()
pr_number = find_hash(args.provider, args.username, args.password, args.hash, args.workspace, args.repository)
pr_number = find_hash(args.provider, args.username, args.password, args.hash, args.workspace, args.repository, args.url)
print(pr_number)

0 comments on commit dd8f0b8

Please sign in to comment.