diff --git a/.env b/.env index 7d626ea5ca27a10b2c5e01946351f99e08e520fe..09e7d682388014c756f04fb3207e7c843d946f46 100644 --- a/.env +++ b/.env @@ -1 +1,2 @@ GITLAB_API_TOKEN=your_gitlab_api_token_here +CONFLUENCE_API_TOKEN=your_confluence_api_token_here \ No newline at end of file diff --git a/script.py b/script.py index b93525f82cc6ef67170fe5ee2142009be69350d2..af2b87978e10d9cdabfe39a34b3f96c70b3b3cf6 100644 --- a/script.py +++ b/script.py @@ -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