Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated of project structure updation using GitHub workflows and Python scripts #203

Merged
merged 9 commits into from
Oct 30, 2024
101 changes: 101 additions & 0 deletions .github/scripts/update_structure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import os
import github
from github import Github

# Helper function to recursively build the repo structure and include file extensions
def get_repo_structure(path='.', prefix=''):
structure = []
try:
items = sorted(os.listdir(path))
except FileNotFoundError:
print(f"Path not found: {path}")
return structure

for i, item in enumerate(items):
if item.startswith('.'):
continue # Skip hidden files and directories
item_path = os.path.join(path, item)
is_last = i == len(items) - 1
current_prefix = '└── ' if is_last else '├── '

if os.path.isdir(item_path):
# Directory case
structure.append(f"{prefix}{current_prefix}{item}/")
next_prefix = prefix + (' ' if is_last else '│ ')
structure.extend(get_repo_structure(item_path, next_prefix))
else:
# File case with extension
file_name, file_extension = os.path.splitext(item)
structure.append(f"{prefix}{current_prefix}{file_name}{file_extension}")

return structure

# Function to update the repo_structure.txt file
def update_structure_file(structure):
try:
with open('repo_structure.txt', 'w') as f:
f.write('\n'.join(structure))
print("repo_structure.txt updated successfully.")
except IOError as e:
print(f"Error writing to repo_structure.txt: {e}")

# Function to update the README.md with the new structure
def update_README(structure):
try:
with open('PROJECT_STRUCTURE.md', 'r') as f:
content = f.read()
except FileNotFoundError:
print("PROJECT_STRUCTURE.md not found.")
return

start_marker = '<!-- START_STRUCTURE -->'
end_marker = '<!-- END_STRUCTURE -->'

start_index = content.find(start_marker)
end_index = content.find(end_marker)

if start_index != -1 and end_index != -1:
new_content = (
content[:start_index + len(start_marker)] +
'\n```\n' + '\n'.join(structure) + '\n```\n' +
content[end_index:]
)
try:
with open('PROJECT_STRUCTURE.md', 'w') as f:
f.write(new_content)
print("PROJECT_STRUCTURE.md updated with new structure.")
except IOError as e:
print(f"Error writing to PROJECT_STRUCTURE.md: {e}")
else:
print("Markers not found in PROJECT_STRUCTURE.md. Structure not updated.")

# Main function to compare and update repository structure
def main():
gh_token = os.getenv('GH_TOKEN')
gh_repo = os.getenv('GITHUB_REPOSITORY')

if not gh_token or not gh_repo:
print("Environment variables GH_TOKEN and GITHUB_REPOSITORY must be set.")
return

g = Github(gh_token)
repo = g.get_repo(gh_repo)

current_structure = get_repo_structure()

try:
# Fetch the contents of repo_structure.txt from GitHub
contents = repo.get_contents("repo_structure.txt")
existing_structure = contents.decoded_content.decode().split('\n')
except github.GithubException:
existing_structure = None

if current_structure != existing_structure:
update_structure_file(current_structure)
update_README(current_structure)
print("Repository structure updated.")
else:
print("No changes in repository structure.")

if __name__ == "__main__":
main()
39 changes: 39 additions & 0 deletions .github/workflows/update-readme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Update Repository structure

on:
schedule:
- cron: '0 * * * *' # Run every hour
workflow_dispatch: # Allow manual triggering
push:
branches:
- main

jobs:
detect-and-update-structure:
runs-on: ubuntu-latest
permissions:
contents: write # Permission to the GitHub Bot to access and update the Project Repository
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.12

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install PyGithub
- name: Run update script
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: python .github/scripts/update_structure.py # Run the python script to create/update the repo sturcture

- name: Commit and push if changed # Commit and push changes to the head branch(main)
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git add .
git diff --quiet && git diff --staged --quiet || (git commit -m "Update repo structure" && git push)
69 changes: 0 additions & 69 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,75 +29,6 @@ If you're new to Git and GitHub, no worries! Here are some useful resources:

<br>

# Project Structure 📂

```bash
ChaosWeb/
├── .github/ # GitHub-related configurations such as workflows, issue templates, etc
├── assets/ # Some images
├── chaosweb-v@2/ # Contains index.html and also some core components of the project
├── css/ # Contains stylesheet files
├── js/ # Contains javascript files
├── node_modules/ # Contains the integrity files
├── sfx/ # Contains sound effects
├── .gitignore
├── 3d-effect-hypnosis-spiral-vector-7844424.jpg
├── chaos.html
├── CODE_OF_CONDUCT.md # Some rules for contributors
├──
├── ContactUs.html # Contains the contact us page
├──
├── CONTRIBUTING.md # Instructions for the contributors
├──
├── emojiland.html
├──
├── hypnotic.html
├──
├── IMG_20241015_121622.jpg
├──
├── index.html # The main .html page
├──
├── LICENSE # A permission to do something
├──
├── maze.html
├──
├── night_time.html
├──
├── package-lock.json
├──
├── preloader.js
├──
├── preloaderStyle.css
├──
├── README.md # Some instructions related to the contributions
├──
├── SECURITY.md
├──
├── signup.html
├──
├── Simongame.html
├──
├── style1.css
├──
├── testing.html
├──
├── Timeline.html
├──
├── yarn.lock
```

<br>

# First Pull Request ✨

1. **Star this repository**
Expand Down
177 changes: 177 additions & 0 deletions PROJECT_STRUCTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
## Project Structure ✨

<!-- START_STRUCTURE -->
```
├── 3d-effect-hypnosis-spiral-vector-7844424.jpg
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── ConnectFour.html
├── ContactUs.html
├── IMG_20241015_121622.jpg
├── LICENSE
├── LightsOut.html
├── PROJECT_STRUCTURE.md
├── README.md
├── SECURITY.md
├── Simongame.html
├── Timeline.html
├── WordGuessingGame.html
├── assets/
│ ├── Order And Chaos.png
│ ├── colourfulbg.png
│ ├── crayonbg.png
│ ├── logo/
│ │ ├── ChaosWeb.jpg
│ │ ├── ChaosWeb.png
│ │ ├── ChaosWeb.svg
│ │ ├── ChaosWeb.tiff
│ │ ├── ChaosWeb.webp
│ │ ├── chaosweb_topborder-removebg.png
│ │ ├── favicon.ico
│ │ └── logo2.png
│ ├── mazeIcon.png
│ ├── moon1.png
│ └── moon2.png
├── chaos.html
├── chaosweb-v@2/
│ ├── README.md
│ ├── eslint.config.js
│ ├── index.html
│ ├── package-lock.json
│ ├── package.json
│ ├── postcss.config.js
│ ├── public/
│ │ ├── assets/
│ │ │ ├── js/
│ │ │ │ ├── night_time.js
│ │ │ │ ├── script.js
│ │ │ │ └── sound.js
│ │ │ ├── logo/
│ │ │ │ ├── ChaosWeb.jpg
│ │ │ │ ├── ChaosWeb.png
│ │ │ │ ├── ChaosWeb.svg
│ │ │ │ ├── ChaosWeb.tiff
│ │ │ │ ├── ChaosWeb.webp
│ │ │ │ └── favicon.ico
│ │ │ └── react.svg
│ │ └── logo.png
│ ├── src/
│ │ ├── App.css
│ │ ├── App.jsx
│ │ ├── assets/
│ │ │ ├── boy1.jpeg
│ │ │ ├── boy2.jpeg
│ │ │ ├── boy3.jpeg
│ │ │ ├── creepyImg/
│ │ │ │ ├── jump-scare-2.jpg
│ │ │ │ ├── jump-scare-3.jpg
│ │ │ │ ├── jump-scare-4.jpg
│ │ │ │ ├── jump-scare-5.jpg
│ │ │ │ └── jump-scare.jpg
│ │ │ ├── girl1.jpeg
│ │ │ ├── girl2.jpeg
│ │ │ ├── hamsterSound.mp3
│ │ │ ├── logo/
│ │ │ │ ├── ChaosWeb.jpg
│ │ │ │ ├── ChaosWeb.png
│ │ │ │ ├── ChaosWeb.svg
│ │ │ │ ├── ChaosWeb.tiff
│ │ │ │ ├── ChaosWeb.webp
│ │ │ │ ├── boy2.jpeg
│ │ │ │ ├── favicon.ico
│ │ │ │ └── logo.png
│ │ │ ├── monkey.jpg
│ │ │ ├── react.svg
│ │ │ └── snowstruct.png
│ │ ├── components/
│ │ │ ├── FireRain.css
│ │ │ ├── FireRain.jsx
│ │ │ ├── Firework.css
│ │ │ ├── Firework.jsx
│ │ │ ├── FloatingRain.css
│ │ │ ├── FloatingRain.jsx
│ │ │ ├── InvertColorToggle.jsx
│ │ │ ├── JumpScareEffect.css
│ │ │ ├── JumpScareEffect.jsx
│ │ │ ├── MazeGame.css
│ │ │ ├── MazeGame.jsx
│ │ │ ├── Snowfall.css
│ │ │ ├── Snowfall.jsx
│ │ │ ├── Starfield.css
│ │ │ ├── Starfield.jsx
│ │ │ ├── navbar.css
│ │ │ ├── navbar.jsx
│ │ │ └── popup.jsx
│ │ ├── index.css
│ │ ├── main.jsx
│ │ ├── pages/
│ │ │ ├── BarrelRoll.css
│ │ │ ├── BarrelRoll.jsx
│ │ │ ├── BouncingDiv.jsx
│ │ │ ├── ButtonCollection.css
│ │ │ ├── ButtonCollection.jsx
│ │ │ ├── ChaosMania.css
│ │ │ ├── ChaosMania.jsx
│ │ │ ├── Contributors.css
│ │ │ ├── Contributors.jsx
│ │ │ ├── HypnoticChaos.jsx
│ │ │ ├── Review.jsx
│ │ │ ├── Timeline.css
│ │ │ ├── contact.css
│ │ │ ├── contact.jsx
│ │ │ ├── home.jsx
│ │ │ ├── review.css
│ │ │ └── timeline.jsx
│ │ └── utils/
│ │ └── pages.js
│ ├── style.css
│ ├── tailwind.config.js
│ └── vite.config.js
├── css/
│ ├── contactus.css
│ ├── style.css
│ └── styles.css
├── emojiland.html
├── hypnotic.html
├── index.html
├── js/
│ ├── night_time.js
│ ├── script.js
│ ├── script1.js
│ ├── searchbar.js
│ └── sound.js
├── maze.html
├── night_time.html
├── node_modules/
├── package-lock.json
├── preloader.js
├── preloaderStyle.css
├── repo_structure.txt
├── sfx/
│ ├── Emoji-Land/
│ │ ├── digital-chaos.mp3
│ │ ├── drammatic-cinematic-glitch.mp3
│ │ ├── electric-wasps.mp3
│ │ ├── glitch-sound.mp3
│ │ ├── hurricane.mp3
│ │ └── intro-music-black-box-dirty-glitch.mp3
│ ├── bird.mp3
│ ├── buffalo.mp3
│ ├── cat1.mp3
│ ├── cat2.mp3
│ ├── eagle-squawking-type-2-235997.mp3
│ ├── elephant1.mp3
│ ├── elephant2.mp3
│ ├── mixkit-annoyed-big-dog-barking-51.wav
│ ├── mixkit-scared-horse-neighing-85.wav
│ ├── mixkit-sweet-kitty-meow-93.wav
│ ├── penguin.mp3
│ ├── rooster.mp3
│ ├── source.md
│ └── tiger.mp3
├── signup.html
├── style1.css
├── testing.html
└── yarn.lock
```
<!-- END_STRUCTURE -->
Loading
Loading