-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #275 from yashksaini-coder/yash/fix-162
Add Contributors and Project structure markdown workflows
- Loading branch information
Showing
5 changed files
with
246 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import os | ||
import github | ||
from github import Github | ||
|
||
def get_repo_structure(path='.', prefix=''): | ||
structure = [] | ||
items = sorted(os.listdir(path)) | ||
for i, item in enumerate(items): | ||
if item.startswith('.'): | ||
continue | ||
item_path = os.path.join(path, item) | ||
is_last = i == len(items) - 1 | ||
current_prefix = '└── ' if is_last else '├── ' | ||
structure.append(f"{prefix}{current_prefix}{item}") | ||
if os.path.isdir(item_path): | ||
next_prefix = prefix + (' ' if is_last else '│ ') | ||
structure.extend(get_repo_structure(item_path, next_prefix)) | ||
return structure | ||
|
||
def update_structure_file(structure): | ||
with open('project_structure.txt', 'w') as f: | ||
f.write('\n'.join(structure)) | ||
|
||
def update_readme(structure): | ||
with open('project-structure.md', 'r') as f: # updated file name | ||
content = f.read() | ||
|
||
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:] | ||
) | ||
|
||
with open('project-structure.md', 'w') as f: | ||
f.write(new_content) | ||
print("Repo-structure.md updated with new structure.") | ||
else: | ||
print("Markers not found in Repo-structure.md. Structure not updated.") | ||
|
||
def main(): | ||
g = Github(os.environ['GH_TOKEN']) | ||
repo = g.get_repo(os.environ['GITHUB_REPOSITORY']) | ||
|
||
current_structure = get_repo_structure() | ||
|
||
try: | ||
contents = repo.get_contents("project_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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Update Contributors in README | ||
on: | ||
push: | ||
branches: ["main"] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
contrib-readme-job: | ||
runs-on: ubuntu-latest | ||
name: An action workflow to automate contributors in README | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Update Contributors List | ||
uses: akhilmhdh/contributors-readme-action@v2.3.10 | ||
with: | ||
commit_message: "Updated contributors list" | ||
committer_username: "yashksaini-coder" | ||
committer_email: "115717039+yashksaini-coder@users.noreply.github.com" | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Detect and Update Repo 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 | ||
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 --local user.email ""115717039+yashksaini-coder@users.noreply.github.com"" | ||
git config --local user.name "yashksaini-coder" | ||
git add . | ||
git diff --quiet && git diff --staged --quiet || (git commit -m "Update repo structure" && git push) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!-- START_STRUCTURE --> | ||
``` | ||
├── BuddyTrail | ||
├── Code_of_Conduct.md | ||
├── README.md | ||
├── book.html | ||
├── boy.png | ||
├── chatbot.gif | ||
├── chatbot.html | ||
├── firebase.js | ||
├── icons | ||
│ ├── airplane.svg | ||
│ ├── bed-solid.svg | ||
│ ├── instagram.svg | ||
│ ├── plane-departure-solid.svg | ||
│ ├── route-solid.svg | ||
│ ├── twitter-x.svg | ||
│ ├── twitter.svg | ||
│ └── youtube.svg | ||
├── img | ||
│ ├── banner.png | ||
│ ├── cloud.png | ||
│ ├── contact-mountain.png | ||
│ ├── googleLogo.png | ||
│ ├── landing-page.jpg | ||
│ └── new-york-page.png | ||
├── index.html | ||
├── login.css | ||
├── login.html | ||
├── project-structure.md | ||
├── script.js | ||
├── signUp.css | ||
├── signUp.html | ||
└── style.css | ||
``` | ||
<!-- END_STRUCTURE --> |