I’m using the Bitbucket API to retrieve the 5 characteristics of Bitbucket projects, but I’m encountering challenges. I couldn’t find the project sizes, instead I retrieved the numbers of the repositories.
Also, I’m unable to retrieve the last access date and the project owners for each project.
from atlassian import Bitbucket
import csv
def get_bitbucket_project_info(url, token):
bitbucket = Bitbucket(url=url, token=token)
projects_info = []
projects = bitbucket.project_list()
for project in projects:
project_key = project['key']
project_info = bitbucket.project(project_key)
project_size = len(list(bitbucket.repo_list(project_key)))
last_access_date = project_info.get('lastActivityMillis', 'N/A')
last_access_date_readable = 'N/A' if last_access_date == 'N/A' else datetime.datetime.fromtimestamp(last_access_date/1000.0).strftime('%Y-%m-%d %H:%M:%S')
project_admins = bitbucket.project_users_with_administrator_permissions(project_key)
admins_display_names = [admin['user']['displayName'] for admin in project_admins if 'user' in admin]
project_data = {
'Name of project': project.get('name', 'N/A'),
'Size of project': project_size,
'How many deposits': project_size,
'Last access date': last_access_date_readable,
'Project owner(s)': ', '.join(admins_display_names) if admins_display_names else 'N/A'
}
projects_info.append(project_data)
with open('bitbucket_projects_info.csv', 'w', newline='', encoding='utf-8') as csvfile:
fieldnames = ['Name of project', 'Size of project', 'How many deposits', 'Last access date', 'Project owner(s)']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for project in projects_info:
writer.writerow(project)
url = ''
token = ''
get_bitbucket_project_info(url, token)
I tried to calculates the size of the project by counting the number of repositories within the project. But i have only the number of deposit.
Also I retrieves the last access date of the project and converts the timestamp into a human-readable date format.But i never have a result excep N/A.
And this is the same for the owner of project, do you have any ideas ?
Guizi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.