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 project structure updation using github workflows and action bot #248

Merged
merged 6 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
- 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)
112 changes: 112 additions & 0 deletions PROJECT_STRUCTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
## Project Structure ✨

<!-- START_STRUCTURE -->
```
β”œβ”€β”€ Code_of_Conduct.md
β”œβ”€β”€ Contributing.md
β”œβ”€β”€ Image/
β”‚ β”œβ”€β”€ 212284100-561aa473-3905-4a80-b561-0d28506553ee.gif
β”‚ β”œβ”€β”€ 329829127-e79eb6de-81b1-4ffb-b6ed-f018bb977e88.png
β”‚ β”œβ”€β”€ Images
β”‚ └── hacktober.png
β”œβ”€β”€ LICENSE
β”œβ”€β”€ PROJECT_STRUCTURE.md
β”œβ”€β”€ README.md
β”œβ”€β”€ Research-Nexas - Application Architecture.png
β”œβ”€β”€ backend/
β”‚ β”œβ”€β”€ profile.js
β”‚ └── stk_profile.js
β”œβ”€β”€ config/
β”‚ └── mysql_connection.js
β”œβ”€β”€ file_upload/
β”‚ β”œβ”€β”€ form_db.js
β”‚ β”œβ”€β”€ upload.js
β”‚ └── uploads/
β”‚ β”œβ”€β”€ 1728284943729-pebble watch invoice.pdf
β”‚ β”œβ”€β”€ 1728291889782-Essential_documents_for_admission.txt
β”‚ └── 1728962999779-Screenshot from 2024-10-09 10-26-04.png
β”œβ”€β”€ login-system/
β”‚ β”œβ”€β”€ dbServer.js
β”‚ β”œβ”€β”€ login.js
β”‚ β”œβ”€β”€ logout.js
β”‚ β”œβ”€β”€ notification.js
β”‚ └── token.js
β”œβ”€β”€ package-lock.json
β”œβ”€β”€ package.json
β”œβ”€β”€ public/
β”‚ β”œβ”€β”€ allotment.html
β”‚ β”œβ”€β”€ choose-file.html
β”‚ β”œβ”€β”€ choose-signup-file.html
β”‚ β”œβ”€β”€ contact-us.html
β”‚ β”œβ”€β”€ contributor.html
β”‚ β”œβ”€β”€ css/
β”‚ β”‚ β”œβ”€β”€ choosefile.css
β”‚ β”‚ β”œβ”€β”€ contact-us.css
β”‚ β”‚ β”œβ”€β”€ contributor.css
β”‚ β”‚ β”œβ”€β”€ faculty_styling.css
β”‚ β”‚ β”œβ”€β”€ faq_style.css
β”‚ β”‚ β”œβ”€β”€ form.css
β”‚ β”‚ β”œβ”€β”€ login_style.css
β”‚ β”‚ β”œβ”€β”€ main_page_style.css
β”‚ β”‚ β”œβ”€β”€ privacy_style.css
β”‚ β”‚ β”œβ”€β”€ profile.css
β”‚ β”‚ β”œβ”€β”€ stk_mainstyling.css
β”‚ β”‚ β”œβ”€β”€ style.css
β”‚ β”‚ └── uploadfile.css
β”‚ β”œβ”€β”€ dashboard.html
β”‚ β”œβ”€β”€ fac_login.html
β”‚ β”œβ”€β”€ faculty.html
β”‚ β”œβ”€β”€ form_filling.html
β”‚ β”œβ”€β”€ gitContributors.html
β”‚ β”œβ”€β”€ images/
β”‚ β”‚ β”œβ”€β”€ Design 1.webp
β”‚ β”‚ β”œβ”€β”€ badge.webp
β”‚ β”‚ β”œβ”€β”€ badges.webp
β”‚ β”‚ β”œβ”€β”€ boost.webp
β”‚ β”‚ β”œβ”€β”€ calm.jpg
β”‚ β”‚ β”œβ”€β”€ career.webp
β”‚ β”‚ β”œβ”€β”€ career_pic.webp
β”‚ β”‚ β”œβ”€β”€ collaborate.webp
β”‚ β”‚ β”œβ”€β”€ connect.webp
β”‚ β”‚ β”œβ”€β”€ connectpeers.webp
β”‚ β”‚ β”œβ”€β”€ dark_mode.webp
β”‚ β”‚ β”œβ”€β”€ explorepapers.webp
β”‚ β”‚ β”œβ”€β”€ follow.webp
β”‚ β”‚ β”œβ”€β”€ logo.webp
β”‚ β”‚ β”œβ”€β”€ moon.webp
β”‚ β”‚ β”œβ”€β”€ plagiarism.webp
β”‚ β”‚ β”œβ”€β”€ sun.webp
β”‚ β”‚ β”œβ”€β”€ upload-image.webp
β”‚ β”‚ └── wave.webp
β”‚ β”œβ”€β”€ index.html
β”‚ β”œβ”€β”€ login.html
β”‚ β”œβ”€β”€ main_page.html
β”‚ β”œβ”€β”€ password_reset.html
β”‚ β”œβ”€β”€ privacy_policy.html
β”‚ β”œβ”€β”€ script/
β”‚ β”‚ β”œβ”€β”€ approval.js
β”‚ β”‚ β”œβ”€β”€ contributor.js
β”‚ β”‚ β”œβ”€β”€ main-page-script.js
β”‚ β”‚ β”œβ”€β”€ paper_allotment.js
β”‚ β”‚ β”œβ”€β”€ script.js
β”‚ β”‚ β”œβ”€β”€ slider.js
β”‚ β”‚ └── stk_mainpage.js
β”‚ β”œβ”€β”€ signup.html
β”‚ β”œβ”€β”€ stk_dashboard.html
β”‚ β”œβ”€β”€ stk_login.html
β”‚ β”œβ”€β”€ stk_mainpage.html
β”‚ β”œβ”€β”€ stk_signup.html
β”‚ └── upload_file.html
β”œβ”€β”€ pull_request_template.md
β”œβ”€β”€ repo_structure.txt
β”œβ”€β”€ stakeholder/
β”‚ β”œβ”€β”€ allotment.js
β”‚ β”œβ”€β”€ evaluation.js
β”‚ β”œβ”€β”€ faculty.js
β”‚ β”œβ”€β”€ login.js
β”‚ └── stk_approval.js
└── views/
β”œβ”€β”€ fac_signup.ejs
└── stk_papers.ejs
```
<!-- END_STRUCTURE -->
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ With **Research-Nexas**, the future of research collaboration is smarter, faster

<img src="https://raw.githubusercontent.com/alo7lika/Research-Nexas/refs/heads/main/Image/212284100-561aa473-3905-4a80-b561-0d28506553ee.gif" width="900">

## Project Structure ✨

Check the project structure here [Project Structure](PROJECT_STRUCTURE.md)

## πŸ“š Table of Contents

Expand Down
106 changes: 106 additions & 0 deletions repo_structure.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
β”œβ”€β”€ Code_of_Conduct.md
β”œβ”€β”€ Contributing.md
β”œβ”€β”€ Image/
β”‚ β”œβ”€β”€ 212284100-561aa473-3905-4a80-b561-0d28506553ee.gif
β”‚ β”œβ”€β”€ 329829127-e79eb6de-81b1-4ffb-b6ed-f018bb977e88.png
β”‚ β”œβ”€β”€ Images
β”‚ └── hacktober.png
β”œβ”€β”€ LICENSE
β”œβ”€β”€ PROJECT_STRUCTURE.md
β”œβ”€β”€ README.md
β”œβ”€β”€ Research-Nexas - Application Architecture.png
β”œβ”€β”€ backend/
β”‚ β”œβ”€β”€ profile.js
β”‚ └── stk_profile.js
β”œβ”€β”€ config/
β”‚ └── mysql_connection.js
β”œβ”€β”€ file_upload/
β”‚ β”œβ”€β”€ form_db.js
β”‚ β”œβ”€β”€ upload.js
β”‚ └── uploads/
β”‚ β”œβ”€β”€ 1728284943729-pebble watch invoice.pdf
β”‚ β”œβ”€β”€ 1728291889782-Essential_documents_for_admission.txt
β”‚ └── 1728962999779-Screenshot from 2024-10-09 10-26-04.png
β”œβ”€β”€ login-system/
β”‚ β”œβ”€β”€ dbServer.js
β”‚ β”œβ”€β”€ login.js
β”‚ β”œβ”€β”€ logout.js
β”‚ β”œβ”€β”€ notification.js
β”‚ └── token.js
β”œβ”€β”€ package-lock.json
β”œβ”€β”€ package.json
β”œβ”€β”€ public/
β”‚ β”œβ”€β”€ allotment.html
β”‚ β”œβ”€β”€ choose-file.html
β”‚ β”œβ”€β”€ choose-signup-file.html
β”‚ β”œβ”€β”€ contact-us.html
β”‚ β”œβ”€β”€ contributor.html
β”‚ β”œβ”€β”€ css/
β”‚ β”‚ β”œβ”€β”€ choosefile.css
β”‚ β”‚ β”œβ”€β”€ contact-us.css
β”‚ β”‚ β”œβ”€β”€ contributor.css
β”‚ β”‚ β”œβ”€β”€ faculty_styling.css
β”‚ β”‚ β”œβ”€β”€ faq_style.css
β”‚ β”‚ β”œβ”€β”€ form.css
β”‚ β”‚ β”œβ”€β”€ login_style.css
β”‚ β”‚ β”œβ”€β”€ main_page_style.css
β”‚ β”‚ β”œβ”€β”€ privacy_style.css
β”‚ β”‚ β”œβ”€β”€ profile.css
β”‚ β”‚ β”œβ”€β”€ stk_mainstyling.css
β”‚ β”‚ β”œβ”€β”€ style.css
β”‚ β”‚ └── uploadfile.css
β”‚ β”œβ”€β”€ dashboard.html
β”‚ β”œβ”€β”€ fac_login.html
β”‚ β”œβ”€β”€ faculty.html
β”‚ β”œβ”€β”€ form_filling.html
β”‚ β”œβ”€β”€ gitContributors.html
β”‚ β”œβ”€β”€ images/
β”‚ β”‚ β”œβ”€β”€ Design 1.webp
β”‚ β”‚ β”œβ”€β”€ badge.webp
β”‚ β”‚ β”œβ”€β”€ badges.webp
β”‚ β”‚ β”œβ”€β”€ boost.webp
β”‚ β”‚ β”œβ”€β”€ calm.jpg
β”‚ β”‚ β”œβ”€β”€ career.webp
β”‚ β”‚ β”œβ”€β”€ career_pic.webp
β”‚ β”‚ β”œβ”€β”€ collaborate.webp
β”‚ β”‚ β”œβ”€β”€ connect.webp
β”‚ β”‚ β”œβ”€β”€ connectpeers.webp
β”‚ β”‚ β”œβ”€β”€ dark_mode.webp
β”‚ β”‚ β”œβ”€β”€ explorepapers.webp
β”‚ β”‚ β”œβ”€β”€ follow.webp
β”‚ β”‚ β”œβ”€β”€ logo.webp
β”‚ β”‚ β”œβ”€β”€ moon.webp
β”‚ β”‚ β”œβ”€β”€ plagiarism.webp
β”‚ β”‚ β”œβ”€β”€ sun.webp
β”‚ β”‚ β”œβ”€β”€ upload-image.webp
β”‚ β”‚ └── wave.webp
β”‚ β”œβ”€β”€ index.html
β”‚ β”œβ”€β”€ login.html
β”‚ β”œβ”€β”€ main_page.html
β”‚ β”œβ”€β”€ password_reset.html
β”‚ β”œβ”€β”€ privacy_policy.html
β”‚ β”œβ”€β”€ script/
β”‚ β”‚ β”œβ”€β”€ approval.js
β”‚ β”‚ β”œβ”€β”€ contributor.js
β”‚ β”‚ β”œβ”€β”€ main-page-script.js
β”‚ β”‚ β”œβ”€β”€ paper_allotment.js
β”‚ β”‚ β”œβ”€β”€ script.js
β”‚ β”‚ β”œβ”€β”€ slider.js
β”‚ β”‚ └── stk_mainpage.js
β”‚ β”œβ”€β”€ signup.html
β”‚ β”œβ”€β”€ stk_dashboard.html
β”‚ β”œβ”€β”€ stk_login.html
β”‚ β”œβ”€β”€ stk_mainpage.html
β”‚ β”œβ”€β”€ stk_signup.html
β”‚ └── upload_file.html
β”œβ”€β”€ pull_request_template.md
β”œβ”€β”€ repo_structure.txt
β”œβ”€β”€ stakeholder/
β”‚ β”œβ”€β”€ allotment.js
β”‚ β”œβ”€β”€ evaluation.js
β”‚ β”œβ”€β”€ faculty.js
β”‚ β”œβ”€β”€ login.js
β”‚ └── stk_approval.js
└── views/
β”œβ”€β”€ fac_signup.ejs
└── stk_papers.ejs