Skip to content

Commit

Permalink
Merge pull request #130 from J-B-Mugundh/master
Browse files Browse the repository at this point in the history
Automated project structure updation using github workflows, python scripts and action bot
  • Loading branch information
yuvrajsinghgmx authored Oct 21, 2024
2 parents 8dbb9dd + 7c23107 commit 4a2872d
Show file tree
Hide file tree
Showing 4 changed files with 465 additions and 0 deletions.
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('README.md', 'r') as f:
content = f.read()
except FileNotFoundError:
print("README.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('README.md', 'w') as f:
f.write(new_content)
print("README.md updated with new structure.")
except IOError as e:
print(f"Error writing to README.md: {e}")
else:
print("Markers not found in README.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)
166 changes: 166 additions & 0 deletions Readme.md → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,172 @@ ShopSmart is a user-friendly shopping list app built with Kotlin and Jetpack Com
<!--Line-->
<img src="https://user-images.githubusercontent.com/74038190/212284100-561aa473-3905-4a80-b561-0d28506553ee.gif" width="900">

## Project Structure

<!-- START_STRUCTURE -->
```
├── Assets/
│ ├── Pasted image.png
│ ├── ScreenShot1.jpg
│ ├── ScreenShot2.jpg
│ ├── ScreenShot3.jpg
│ ├── ScreenShot4.jpg
│ ├── ShopSmartLogo.png
│ └── ShopSmartLogo2.png
├── CODE_OF_CONDUCT.md
├── DarkModeToggle
├── LICENSE
├── README.md
├── Screenshot 2024-10-03 202535.png
├── Screenshot 2024-10-03 202631.png
├── app/
│ ├── build.gradle.kts
│ ├── proguard-rules.pro
│ └── src/
│ ├── androidTest/
│ │ └── java/
│ │ └── com/
│ │ └── yuvrajsinghgmx/
│ │ └── shopsmart/
│ │ └── ExampleInstrumentedTest.kt
│ ├── main/
│ │ ├── AndroidManifest.xml
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── yuvrajsinghgmx/
│ │ │ └── shopsmart/
│ │ │ ├── ApiData/
│ │ │ │ ├── Hit.kt
│ │ │ │ └── Pics.kt
│ │ │ ├── MainActivity.kt
│ │ │ ├── MyApp.kt
│ │ │ ├── Repository/
│ │ │ │ └── ImageRepo.kt
│ │ │ ├── api/
│ │ │ │ └── API.kt
│ │ │ ├── datastore/
│ │ │ │ ├── instance.kt
│ │ │ │ └── products.kt
│ │ │ ├── di/
│ │ │ │ └── NetworkModule.kt
│ │ │ ├── navbarpr.kt
│ │ │ ├── navigation/
│ │ │ │ └── Navigation.kt
│ │ │ ├── profilefeatures/
│ │ │ │ └── ImageComponents.kt
│ │ │ ├── screens/
│ │ │ │ ├── ContactUsScreen.kt
│ │ │ │ ├── EmailSignUpScreen.kt
│ │ │ │ ├── FAQScreen.kt
│ │ │ │ ├── HelpS.kt
│ │ │ │ ├── HomeScreen.kt
│ │ │ │ ├── ListScreen.kt
│ │ │ │ ├── MyOrders.kt
│ │ │ │ ├── Profile.kt
│ │ │ │ ├── ShopSmartNavBar.kt
│ │ │ │ ├── Signup.kt
│ │ │ │ ├── TermsCondition.kt
│ │ │ │ └── Upcoming.kt
│ │ │ ├── ui/
│ │ │ │ ├── Authpage.kt.txt
│ │ │ │ └── theme/
│ │ │ │ ├── Color.kt
│ │ │ │ ├── Theme.kt
│ │ │ │ └── Type.kt
│ │ │ ├── utils/
│ │ │ │ ├── ImageHelper.kt
│ │ │ │ └── SharedPrefsHelper.kt
│ │ │ └── viewmodel/
│ │ │ ├── HomeScreenViewModel.kt
│ │ │ └── ShoppingListViewModel.kt
│ │ └── res/
│ │ ├── drawable/
│ │ │ ├── addicon.png
│ │ │ ├── baseline_keyboard_voice_24.xml
│ │ │ ├── baseline_star_24.xml
│ │ │ ├── bell.png
│ │ │ ├── checkout.png
│ │ │ ├── customer_care.xml
│ │ │ ├── edit.png
│ │ │ ├── empty_dark.png
│ │ │ ├── empty_light.png
│ │ │ ├── fb.xml
│ │ │ ├── file__1_.png
│ │ │ ├── gmail.xml
│ │ │ ├── google.xml
│ │ │ ├── help.png
│ │ │ ├── ic_launcher_background.xml
│ │ │ ├── ic_launcher_foreground.xml
│ │ │ ├── instagram.xml
│ │ │ ├── linkedin.xml
│ │ │ ├── logo1.png
│ │ │ ├── logo2.png
│ │ │ ├── profile.png
│ │ │ ├── profilenewone.png
│ │ │ ├── setting.png
│ │ │ ├── shopinterior.jpeg
│ │ │ ├── shoppingbag.png
│ │ │ ├── shopsmart.png
│ │ │ └── whatsapp.xml
│ │ ├── font/
│ │ │ ├── abril_fatface_regular.ttf
│ │ │ ├── lexend_black.ttf
│ │ │ ├── lexend_bold.ttf
│ │ │ ├── lexend_extrabold.ttf
│ │ │ ├── lexend_light.ttf
│ │ │ ├── lexend_medium.ttf
│ │ │ ├── lexend_regular.ttf
│ │ │ ├── lexend_semibold.ttf
│ │ │ ├── lexend_thin.ttf
│ │ │ ├── montserrat_bold.ttf
│ │ │ └── montserrat_regular.ttf
│ │ ├── mipmap-anydpi/
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi/
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ ├── mipmap-mdpi/
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xhdpi/
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xxhdpi/
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xxxhdpi/
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ ├── values/
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ └── themes.xml
│ │ └── xml/
│ │ ├── backup_rules.xml
│ │ ├── data_extraction_rules.xml
│ │ └── file_paths.xml
│ └── test/
│ └── java/
│ └── com/
│ └── yuvrajsinghgmx/
│ └── shopsmart/
│ └── ExampleUnitTest.kt
├── build.gradle.kts
├── contributors.md
├── gradle/
│ ├── libs.versions.toml
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
├── repo_structure.txt
└── settings.gradle.kts
```
<!-- END_STRUCTURE -->

## **🔗 Table of Contents**
1. [Features](#features)
2. [Screenshots](#screenshots)
Expand Down
Loading

0 comments on commit 4a2872d

Please sign in to comment.