Skip to content

Commit

Permalink
update commit parser for test
Browse files Browse the repository at this point in the history
  • Loading branch information
classicrocker883 committed May 8, 2024
1 parent 40923d7 commit 8cb4e91
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 38 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/commit-parser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Generate HTML from Recent Commits

on:
workflow_dispatch:
schedule:
- cron: '0 12 1 * *' # Run 1st day of the month every 30 days

jobs:
generate_html:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Checkout Wiki
uses: actions/checkout@v4
with:
repository: classicrocker883/Marlin.wiki
path: wiki
token: ${{ secrets.GITHUB_TOKEN }}
sparse-checkout: |
"What's-New-in-this-Release.md"
sparse-checkout-cone-mode: false

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install dependencies
run:
pip install requests && pip install emoji

- name: Generate Commits and merge with HTML
run: |
python buildroot/share/scripts/generate_html.py
while [ ! -f buildroot/share/scripts/output_HTML_commits.txt ]; do
sleep 1
done
python buildroot/share/scripts/commit_to_wiki.py
- name: Commit and Push Changes
run: |
git config user.name "Andrew"
git config user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com"
git remote add wiki https://github.com/classicrocker883/Marlin.wiki.git
git add "wiki/What's-New-in-this-Release.md"
git commit -m "⛙ Merge new commits into wiki"
git push wiki master
36 changes: 0 additions & 36 deletions .github/workflows/commit_parser.yml

This file was deleted.

58 changes: 58 additions & 0 deletions buildroot/share/scripts/commit_to_wiki.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python3

import os

# Define the path to output_HTML_commits.txt within the workspace directory
output_commits_path = os.path.join(os.getenv('GITHUB_WORKSPACE'), 'buildroot', 'share', 'scripts', 'output_HTML_commits.txt')

# Check if output_HTML_commits.txt exists
if not os.path.exists(output_commits_path):
print(f"Error: output_HTML_commits.txt not found at {output_commits_path}")
print("Falling back to default path...")
output_commits_path = 'buildroot/share/scripts/output_HTML_commits.txt'

if not os.path.exists(output_commits_path):
print(f"Error: output_HTML_commits.txt not found at buildroot/share/scripts")
exit(1)

# Read the contents of output_HTML_commits.txt
with open(output_commits_path, 'r') as file1:
file1_content = file1.readlines()

# Define the path to What's-New-in-this-Release.md within the workspace directory
release_notes_path = os.path.join(os.getenv('GITHUB_WORKSPACE'), "wiki", "What's-New-in-this-Release.md")

# Check if What's-New-in-this-Release.md exists
if not os.path.exists(release_notes_path):
print(f"Error: What's-New-in-this-Release.md not found at {release_notes_path}")
print("Falling back to default path...")
release_notes_path = "wiki/What's-New-in-this-Release.md"

if not os.path.exists(release_notes_path):
print(f"Error: What's-New-in-this-Release.md not found at wiki")
exit(1)
# with open("https://raw.githubusercontent.com/wiki/classicrocker883/MRiscoCProUI/What's-New-in-this-Release.md", 'r') as file2:
# file2_content = file2.readlines()

# Read the content of What's-New-in-this-Release.md
with open(release_notes_path, 'r') as file2:
file2_content = file2.readlines()

# Find the position of <ul> in What's-New-in-this-Release.md
ul_index = next((i for i, line in enumerate(file2_content) if '<ul>' in line), None)

# Extract existing commits from What's-New-in-this-Release.md
existing_commits = [line.strip() for line in file2_content if '<li>' in line]

# Merge the contents of output_HTML_commits.txt with What's-New-in-this-Release.md, omitting duplicates
new_commits = [line for line in file1_content if '<li>' in line and line.strip() not in existing_commits]

# Insert the new content after <ul> in the correct order and without duplicates
if ul_index is not None:
merged_content = file2_content[:ul_index + 1] + new_commits + file2_content[ul_index + 1:]
else:
merged_content = file2_content + new_commits # If <ul> is not found, append at the end

# Write the merged content back to What's-New-in-this-Release.md
with open(release_notes_path, 'w') as file2:
file2.writelines(merged_content)
7 changes: 5 additions & 2 deletions generate_html.py → buildroot/share/scripts/generate_html.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env python3
#

import requests
import re
from datetime import datetime, timedelta
Expand Down Expand Up @@ -28,7 +31,7 @@ def fetch_commits(url, params):
return commits

url = 'https://api.github.com/repos/MarlinFirmware/Marlin/commits'
params = {'per_page': 100, 'since': (datetime.now() - timedelta(days=30)).isoformat()} # Increase per_page to fetch more commits per request
params = {'per_page': 100, 'since': (datetime.now() - timedelta(days=31)).isoformat()} # Increase per_page to fetch more commits per request
commits = fetch_commits(url, params)

with open('output_HTML_commits.txt', 'w') as file:
Expand All @@ -37,7 +40,7 @@ def fetch_commits(url, params):
commit_date_str = commit.get('commit', {}).get('author', {}).get('date')
if commit_date_str:
commit_date = datetime.strptime(commit_date_str, '%Y-%m-%dT%H:%M:%SZ')
if commit_date >= (datetime.now() - timedelta(days=250)) and not commit.get('commit', {}).get('message', '').startswith('[cron]'):
if commit_date >= (datetime.now() - timedelta(days=31)) and not commit.get('commit', {}).get('message', '').startswith('[cron]'):
message = commit['commit']['message'].split('\n')[0] # Extract the first line as description
emojis = emoji.emoji_list(message) # Use emoji_list to get only distinct emojis
emojis_list = [emoji_data['emoji'] for emoji_data in emojis] # Extract emojis from the list of emoji data
Expand Down
Empty file removed output_HTML.txt
Empty file.

0 comments on commit 8cb4e91

Please sign in to comment.