From fdd87834ff245b8583d4d3b1b57eabc9faca8bbd Mon Sep 17 00:00:00 2001 From: Zimmerberger Markus Date: Tue, 11 Nov 2025 10:49:25 +0100 Subject: [PATCH] BitBucket connector --- BitBucket_connector.py | 4 +-- ListCommits.py | 76 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 ListCommits.py diff --git a/BitBucket_connector.py b/BitBucket_connector.py index 4537283..c4e72e3 100644 --- a/BitBucket_connector.py +++ b/BitBucket_connector.py @@ -9,9 +9,9 @@ pat = "OTAyMTM3MjY0MjE0Ovz6bu0ti1TlEdSegmmiWiJ2wGeD" bitbucket = Bitbucket( url=host, username='zim9003', # Assuming you need authentication - password='3S1punk08_113$', # Use token for authentication + password='3S1punk08_114$', # Use token for authentication ) -repos = bitbucket.repo_list('BAUWB') +repos = bitbucket.repo_list('WRGWR') for repo in repos: print(repo) \ No newline at end of file diff --git a/ListCommits.py b/ListCommits.py new file mode 100644 index 0000000..dc82b23 --- /dev/null +++ b/ListCommits.py @@ -0,0 +1,76 @@ +from atlassian import Bitbucket + +from jira import JIRA + +host = "https://bitbucket.wien.gv.at/" +pat = "OTAyMTM3MjY0MjE0Ovz6bu0ti1TlEdSegmmiWiJ2wGeD" + +# Initialize Bitbucket instance +#TODO Use token for authentication +bitbucket = Bitbucket( + url=host, + username='zim9003', # Assuming you need authentication + password='', # Use token for authentication +) + +# Define repository information +project_key = 'WRGWR' # Bitbucket project key +repository_slug = 'WGWR' # Repository slug +file_path = 'Application/MagWien.Wgwr.Repository/Scripts/10_WGWR_01.04_xxxxxx.01_UPDATES.txt' # Path to the specific file within the repo + +# Function to fetch all commits that touched a specific file +def get_file_commits(bitbucket, project_key, repository_slug, file_path): + commits = [] + start = 0 + limit = 100 # Number of commits to retrieve per API call + hash_newest = 'refs/heads/master' + + while True: + # Fetch a list of commits with pagination + response = bitbucket.get_commits( + project_key=project_key, + repository_slug=repository_slug, + limit=limit, + hash_newest=hash_newest + ) + + print(type(response)) + + # Check if the response is empty or an error occurred + # if not response or 'values' not in response: + # break + + # Filter commits that modified the specific file + for cnt in range(0, limit): + commit = list(response)[cnt] + commit_id = commit['id'] + # Get detailed info about each commit + commit_details = bitbucket.get_commit_changes( + project_key=project_key, + repository_slug=repository_slug, + commit_id=commit_id + ) + # Check if the file path is in the list of modified files + if any(file['path']['toString'] == file_path for file in commit_details['files']): + commit.append({ + 'commit_id': commit_id, + 'message': commit['message'], + 'author': commit['author'], + 'date': commit['authorTimestamp'] + }) + + # Check if we've retrieved all commits + if len(response['values']) < limit: + break + start += limit + + return commits + +# Get and print commits affecting the specified file +commits = get_file_commits(bitbucket, project_key, repository_slug, file_path) +for commit in commits: + print(f"Commit ID: {commit['commit_id']}") + print(f"Message: {commit['message']}") + print(f"Author: {commit['author']}") + print(f"Date: {commit['date']}") + print("--------")