From 9de3cde95fb6aae5efb775c6c8252f3e460fde32 Mon Sep 17 00:00:00 2001 From: Rajdeep Chakraborty Date: Sun, 27 Oct 2024 12:47:39 +0530 Subject: [PATCH 1/9] Added: Stucture file to showcase update --- PROJECT_STRUCTURE.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 PROJECT_STRUCTURE.md diff --git a/PROJECT_STRUCTURE.md b/PROJECT_STRUCTURE.md new file mode 100644 index 0000000..bf13ee0 --- /dev/null +++ b/PROJECT_STRUCTURE.md @@ -0,0 +1,3 @@ +## Project Structure ✨ + + \ No newline at end of file From 0b734180571449d14439a792dfd3e8d9a11974ab Mon Sep 17 00:00:00 2001 From: Rajdeep Chakraborty Date: Sun, 27 Oct 2024 12:50:43 +0530 Subject: [PATCH 2/9] Added: Project Strucuture showcase section --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 8c1348c..a7e3ee8 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,10 @@ I often encounter key concepts that are essential in web development but easy to - Keep track of best practices and techniques. - Ensure I'm up to date with the latest web standards. +## ✨ Project Structure + +Check the project structure here [Project Structure](PROJECT_STRUCTURE.md) + ## 🔍 How to Use Each topic is broken down into simple explanations along with comments with practical code examples where applicable. Feel free to browse the files, and revise your concepts too! From e18758b5d9732a3a1be706ee969ff470e4360fd9 Mon Sep 17 00:00:00 2001 From: Rajdeep Chakraborty Date: Sun, 27 Oct 2024 12:51:12 +0530 Subject: [PATCH 3/9] Added: Script and Workflow file --- .github/scripts/update_structure.py | 101 ++++++++++++++++++++++++++++ .github/workflows/update-readme.yml | 38 +++++++++++ 2 files changed, 139 insertions(+) create mode 100644 .github/scripts/update_structure.py create mode 100644 .github/workflows/update-readme.yml diff --git a/.github/scripts/update_structure.py b/.github/scripts/update_structure.py new file mode 100644 index 0000000..087a077 --- /dev/null +++ b/.github/scripts/update_structure.py @@ -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 = '' + end_marker = '' + + 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() \ No newline at end of file diff --git a/.github/workflows/update-readme.yml b/.github/workflows/update-readme.yml new file mode 100644 index 0000000..3171efb --- /dev/null +++ b/.github/workflows/update-readme.yml @@ -0,0 +1,38 @@ +name: Update Repository structure + +on: + schedule: + - cron: '0 * * * *' # Run every hour + workflow_dispatch: # Allow manual triggering + push: + branches: + - main + - master + +jobs: + detect-and-update-structure: + runs-on: ubuntu-latest + 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 + + - name: Commit and push if changed + 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) \ No newline at end of file From 2c5183d7d2291bf7387e54c4eb80efe5af58f770 Mon Sep 17 00:00:00 2001 From: Rajdeep Chakraborty Date: Sun, 27 Oct 2024 12:51:43 +0530 Subject: [PATCH 4/9] Added: Support file for tracking progress of Structure --- repo_structure.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 repo_structure.txt diff --git a/repo_structure.txt b/repo_structure.txt new file mode 100644 index 0000000..e69de29 From 0e0004c6035cd233ce8c52fa13ee187b8f448fef Mon Sep 17 00:00:00 2001 From: Rajdeep Chakraborty Date: Sun, 27 Oct 2024 12:59:15 +0530 Subject: [PATCH 5/9] Updated: Branch to struct for testing --- .github/workflows/update-readme.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update-readme.yml b/.github/workflows/update-readme.yml index 3171efb..26f9ee1 100644 --- a/.github/workflows/update-readme.yml +++ b/.github/workflows/update-readme.yml @@ -6,8 +6,9 @@ on: workflow_dispatch: # Allow manual triggering push: branches: - - main - - master + # - main + # - master + - struct jobs: detect-and-update-structure: From 25e283bb913d045c8e3c421311c90ad36b6e8326 Mon Sep 17 00:00:00 2001 From: Rajdeep Chakraborty Date: Sun, 27 Oct 2024 13:35:37 +0530 Subject: [PATCH 6/9] Updated: Initial project strucutre --- PROJECT_STRUCTURE.md | 19 ++++++++++++++++++- repo_structure.txt | 14 ++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/PROJECT_STRUCTURE.md b/PROJECT_STRUCTURE.md index bf13ee0..5a40df4 100644 --- a/PROJECT_STRUCTURE.md +++ b/PROJECT_STRUCTURE.md @@ -1,3 +1,20 @@ ## Project Structure ✨ - \ No newline at end of file + +``` +├── .github/ +│ ├── scripts/ +│ │ └── update_structure.py +│ └── workflows/ +│ └── update-readme.yml +├── CSS/ +│ └── style.css +├── HTML/ +│ └── index.html +├── JS/ +│ └── script.js +├── PROJECT_STRUCTURE.md +├── README.md +└── repo_structure.txt +``` + \ No newline at end of file diff --git a/repo_structure.txt b/repo_structure.txt index e69de29..adb1b94 100644 --- a/repo_structure.txt +++ b/repo_structure.txt @@ -0,0 +1,14 @@ +├── .github/ +│ ├── scripts/ +│ │ └── update_structure.py +│ └── workflows/ +│ └── update-readme.yml +├── CSS/ +│ └── style.css +├── HTML/ +│ └── index.html +├── JS/ +│ └── script.js +├── PROJECT_STRUCTURE.md +├── README.md +└── repo_structure.txt \ No newline at end of file From b344ae1837c1fadbb25708c3850201b4ed0883e5 Mon Sep 17 00:00:00 2001 From: Rajdeep Chakraborty Date: Sun, 27 Oct 2024 13:42:03 +0530 Subject: [PATCH 7/9] Provided write permissions --- .github/workflows/update-readme.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/update-readme.yml b/.github/workflows/update-readme.yml index 26f9ee1..d9f142c 100644 --- a/.github/workflows/update-readme.yml +++ b/.github/workflows/update-readme.yml @@ -13,6 +13,8 @@ on: jobs: detect-and-update-structure: runs-on: ubuntu-latest + permissions: + contents: write steps: - name: Checkout repository uses: actions/checkout@v2 From 2f951a66dae797251d85aa2f99c13691d3fe0400 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 27 Oct 2024 08:12:27 +0000 Subject: [PATCH 8/9] Update repo structure --- PROJECT_STRUCTURE.md | 5 ----- repo_structure.txt | 5 ----- 2 files changed, 10 deletions(-) diff --git a/PROJECT_STRUCTURE.md b/PROJECT_STRUCTURE.md index 5a40df4..e6b1090 100644 --- a/PROJECT_STRUCTURE.md +++ b/PROJECT_STRUCTURE.md @@ -2,11 +2,6 @@ ``` -├── .github/ -│ ├── scripts/ -│ │ └── update_structure.py -│ └── workflows/ -│ └── update-readme.yml ├── CSS/ │ └── style.css ├── HTML/ diff --git a/repo_structure.txt b/repo_structure.txt index adb1b94..aa86699 100644 --- a/repo_structure.txt +++ b/repo_structure.txt @@ -1,8 +1,3 @@ -├── .github/ -│ ├── scripts/ -│ │ └── update_structure.py -│ └── workflows/ -│ └── update-readme.yml ├── CSS/ │ └── style.css ├── HTML/ From 720400a23cdcc36276b07f6cfa68bdd0a38cb055 Mon Sep 17 00:00:00 2001 From: Rajdeep Chakraborty Date: Sun, 27 Oct 2024 14:44:55 +0530 Subject: [PATCH 9/9] Reverted: Branch to master/main --- .github/workflows/update-readme.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/update-readme.yml b/.github/workflows/update-readme.yml index d9f142c..cfa769f 100644 --- a/.github/workflows/update-readme.yml +++ b/.github/workflows/update-readme.yml @@ -6,9 +6,8 @@ on: workflow_dispatch: # Allow manual triggering push: branches: - # - main - # - master - - struct + - main + - master jobs: detect-and-update-structure: