Skip to content

Commit

Permalink
feat: add openvex report production and mail attachment
Browse files Browse the repository at this point in the history
Signed-off-by: r3drun3 <[email protected]>
  • Loading branch information
R3DRUN3 committed Feb 6, 2024
1 parent 4987d6d commit 4305bfa
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions send_mail_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,17 @@
from datetime import datetime
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication

# Get the path to the script directory
script_directory = os.path.dirname(__file__)

# Get the path to the Github Action YAML file
yaml_file_path = os.path.join(os.path.dirname(__file__), '.github/workflows/patch.yaml')

# Read the YAML file to get the patched image list
with open(yaml_file_path, 'r') as yaml_file:
yaml_content = yaml.load(yaml_file, Loader=yaml.FullLoader)
patched_images = yaml_content.get('jobs', {}).get('immunize', {}).get('strategy', {}).get('matrix', {}).get('images', [])

print("Patched images:", patched_images)
current_timestamp = datetime.now().strftime('%Y-%m-%d')
# Prepare the HTML content
current_timestamp = datetime.now().strftime('%Y-%m-%d')
subject = 'IMMUNIZE: OCI Images Patching Report'
html_body = '<h1>Patched Images πŸ’‰ {}</h1><ul>'.format(current_timestamp)
for image in patched_images:
html_body += f'<li>{image}</li>'
html_body = f'<h1>Patched Images πŸ’‰ {current_timestamp}</h1><ul>'


html_body += '</ul><br />'
html_body += 'check the full catalog πŸ“š <a href="https://github.com/R3DRUN3?tab=packages&repo_name=immunize">here</a> !'
html_body += '<br /><br />'
Expand All @@ -39,6 +33,15 @@
message['To'] = ', '.join(recipients)
message['Subject'] = subject
message.attach(MIMEText(html_body, 'html'))
# Get all files named "*-openvex-report" in root of the project folder
report_files = [filename for filename in os.listdir(script_directory) if filename.endswith("-openvex-report")]
# Attach reports to the email
for report_file in report_files:
html_body += f'<li>{report_file}</li>'
with open(os.path.join(script_directory, report_file), 'rb') as file:
part = MIMEApplication(file.read(), Name=os.path.basename(report_file))
part['Content-Disposition'] = f'attachment; filename="{report_file}"'
message.attach(part)

# Connect to the GMAIL SMTP server and send the emails
with smtplib.SMTP('smtp.gmail.com', 587) as server:
Expand Down

0 comments on commit 4305bfa

Please sign in to comment.