Skip to content
Snippets Groups Projects
Commit b7bd5ec6 authored by Sigmund, Dominik's avatar Sigmund, Dominik
Browse files

Update file script.py

parent 902b6fb4
No related branches found
No related tags found
No related merge requests found
......@@ -91,18 +91,6 @@ def get_total_commits_last_month(gl):
return total_commits_last_month
def get_projects_with_no_activity(gl):
# Get projects with no activity in the last month
current_date = datetime.datetime.now()
last_month_start = (current_date.replace(day=1) - datetime.timedelta(days=1)).replace(day=1)
projects_with_no_activity = []
projects = gl.projects.list(all=True)
for project in projects:
commits = project.commits.list(since=last_month_start)
if len(commits) == 0:
projects_with_no_activity.append(project.name)
return projects_with_no_activity
def get_gitlab_version():
# Run 'gitlab-ctl' command to get GitLab version
......@@ -145,9 +133,6 @@ def get_gitlab_info(api_token):
total_commits_last_month = get_total_commits_last_month(gl)
print(f"Total commits last month: {total_commits_last_month}")
# Get projects with no activity
projects_with_no_activity = get_projects_with_no_activity(gl)
print(f"Projects with no activity: {len(projects_with_no_activity)}")
# Get GitLab version
......@@ -155,9 +140,9 @@ def get_gitlab_info(api_token):
print(f"GitLab version: {gitlab_version}")
return num_projects, num_users, admin_users_list, free_space_on_disk, total_commits_last_month, projects_with_no_activity, gitlab_version
return num_projects, num_users, admin_users_list, free_space_on_disk, total_commits_last_month, gitlab_version
def send_email(sender_email, sender_password, recipient_email, subject, body):
def send_email(sender_email, recipient_email, subject, body):
# Create the email body in HTML format
msg = MIMEMultipart('alternative')
msg['From'] = sender_email
......@@ -170,6 +155,7 @@ def send_email(sender_email, sender_password, recipient_email, subject, body):
<head></head>
<body>
<h2>Monthly GitLab Report - {datetime.datetime.now().strftime('%B %Y')}</h2>
<p>{body['gitlab_version']}<</p>
<table border="1" cellpadding="5" style="border-collapse: collapse; width: 50%;">
<tr>
<th>Metrics</th>
......@@ -195,6 +181,10 @@ def send_email(sender_email, sender_password, recipient_email, subject, body):
<td>Free Space on Disk</td>
<td>{body['free_space_on_disk']}</td>
</tr>
<tr>
<td>Total Commits last Month</td>
<td>{body['total_commits_last_month']}</td>
</tr>
</table>
</body>
</html>
......@@ -252,7 +242,7 @@ api_token, confluence_token = load_api_token()
subject = 'Monthly GitLab Report - {month} {year}'.format(month=datetime.datetime.now().strftime('%B'), year=datetime.datetime.now().strftime('%Y'))
# Get GitLab information
num_projects, num_users, admin_users_list, free_space_on_disk, total_commits_last_month, projects_with_no_activity, gitlab_version = get_gitlab_info(api_token)
num_projects, num_users, admin_users_list, free_space_on_disk, total_commits_last_month, gitlab_version = get_gitlab_info(api_token)
# Compose the email body as a dictionary
email_body = {
......@@ -261,7 +251,6 @@ email_body = {
'admin_users_list': admin_users_list,
'free_space_on_disk': free_space_on_disk,
'total_commits_last_month': total_commits_last_month,
'projects_with_no_activity': projects_with_no_activity,
'gitlab_version': gitlab_version
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment