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

failure case added #26

Merged
merged 5 commits 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
34 changes: 19 additions & 15 deletions scripts/python/fetch-params/fetch_params_bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,30 @@ def send_api_request(url, username, password):

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

print(f"provider: {provider}. \nusername: {username}\n password: {password}\nhash: {hash}\nworkspace: {workspace}\nrepository: {repository}")
print(f"provider: {provider} \nusername: {username}\npassword: {password}\nhash: {hash}\nworkspace: {workspace}\nrepository: {repository}")
if provider == "bitbucket":

url = f"https://api.bitbucket.org/2.0/repositories/{workspace}/{repository}/pullrequests"

response = send_api_request(url, username, password)
found = False
for pull_request in response['values']:
if found == True:
break
pull_request_id = pull_request['id']
url = f"https://api.bitbucket.org/2.0/repositories/{workspace}/{repository}/pullrequests/{pull_request_id}/commits"
commits = send_api_request(url, username, password)
if response:
for pull_request in response['values']:
if found == True:
break
pull_request_id = pull_request['id']
url = f"https://api.bitbucket.org/2.0/repositories/{workspace}/{repository}/pullrequests/{pull_request_id}/commits"
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
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
6 changes: 4 additions & 2 deletions scripts/python/fetch-params/find_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import argparse

def find_hash(provider, username, password, hash, workspace, repository):
pr_number = None
if provider == "bitbucket":
pr_number = fetch_params_bitbucket(provider, username, password, hash, workspace, repository)
elif provider == "github":
pr_number = fetch_params_github(provider, username, password, hash, workspace, repository)

return pr_number
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("provider", help="Name of git provider")
Expand All @@ -17,4 +18,5 @@ def find_hash(provider, username, password, hash, workspace, repository):
parser.add_argument("workspace", help="Workspace/Organization")
parser.add_argument("repository", help="Git repository name")
args = parser.parse_args()
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)
print(pr_number)