From b7bd5ec6a3c12c9f6321167287e2928ee50cb280 Mon Sep 17 00:00:00 2001
From: "Sigmund, Dominik" <dominik.sigmund@br.de>
Date: Mon, 31 Jul 2023 11:20:12 +0000
Subject: [PATCH] Update file script.py

---
 script.py | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

diff --git a/script.py b/script.py
index a9383d8..595e2a2 100644
--- a/script.py
+++ b/script.py
@@ -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
 }
 
-- 
GitLab