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

Update 2 files

- /.env
- /script.py
parent 43fea6da
No related branches found
No related tags found
No related merge requests found
GITLAB_API_TOKEN=your_gitlab_api_token_here
CONFLUENCE_API_TOKEN=your_confluence_api_token_here
\ No newline at end of file
......@@ -10,12 +10,8 @@ from dotenv import load_dotenv
gitlab_url = 'https://gitlab.ard.de'
confluence_url = 'YOUR_CONFLUENCE_URL'
api_token = 'YOUR_API_TOKEN'
sender_email = 'your_email@example.com'
sender_password = 'your_email_password'
recipient_email = 'recipient@example.com'
sender_email = 'gitlab-report@br.de'
recipient_email = 'dominik.sigmund@br.de'
def check_binaries():
required_binaries = ['df', 'gitlab-ctl']
......@@ -31,10 +27,16 @@ def load_api_token():
api_token = os.getenv('GITLAB_API_TOKEN')
if not api_token:
print("Error: API token not found in .env file.")
print("Error: Gitlab API token not found in .env file.")
exit(1)
confluence_token = os.getenv('CONFLUENCE_API_TOKEN')
if not confluence_token:
print("Error: Confluence API token not found in .env file.")
exit(1)
return api_token
return api_token, confluence_token
def get_disk_space():
# Run the df command to get disk space information
......@@ -169,12 +171,8 @@ def send_email(sender_email, sender_password, recipient_email, subject, body):
# Attach the HTML content to the email
msg.attach(MIMEText(html_table, 'html'))
# Send the email
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(sender_email, sender_password)
server.sendmail(sender_email, recipient_email, msg.as_string())
server.quit()
with smtplib.SMTP('localhost') as server:
server.sendmail(sender_email, recipient_email, msg.as_string())
def create_blog_post(confluence_url, api_token, blog_post_content):
headers = {
......@@ -216,7 +214,7 @@ def create_blog_post(confluence_url, api_token, blog_post_content):
# Check if required binaries are available
check_binaries()
api_token = load_api_token()
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'))
......@@ -236,7 +234,7 @@ email_body = {
}
# Send the email
send_email(sender_email, sender_password, recipient_email, subject, email_body)
send_email(sender_email, recipient_email, subject, email_body)
# create blog post
blog_post_id = create_blog_post(confluence_url, api_token, email_body)
\ No newline at end of file
# blog_post_id = create_blog_post(confluence_url, api_token, email_body)
\ No newline at end of file
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