Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gitlab-report
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tools
gitlab-report
Commits
b7bd5ec6
Commit
b7bd5ec6
authored
1 year ago
by
Sigmund, Dominik
Browse files
Options
Downloads
Patches
Plain Diff
Update file script.py
parent
902b6fb4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
script.py
+8
-19
8 additions, 19 deletions
script.py
with
8 additions
and
19 deletions
script.py
+
8
−
19
View file @
b7bd5ec6
...
...
@@ -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
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment