Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bitbucket cloud #27

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading