diff --git a/scripts/python/fetch-params/fetch_params_bitbucket.py b/scripts/python/fetch-params/fetch_params_bitbucket.py index 4df9503..b7ed5d5 100644 --- a/scripts/python/fetch-params/fetch_params_bitbucket.py +++ b/scripts/python/fetch-params/fetch_params_bitbucket.py @@ -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 \ No newline at end of file + 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 \ No newline at end of file diff --git a/scripts/python/fetch-params/find_hash.py b/scripts/python/fetch-params/find_hash.py index 221b444..08f4754 100644 --- a/scripts/python/fetch-params/find_hash.py +++ b/scripts/python/fetch-params/find_hash.py @@ -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 @@ -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) \ No newline at end of file