BitBucket connector
This commit is contained in:
@@ -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)
|
||||
@@ -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='<PWD>', # 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("--------")
|
||||
Reference in New Issue
Block a user