-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
2,366 additions
and
152 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,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() |
This file was deleted.
Oops, something went wrong.
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,46 @@ | ||
name: "Auto Greeting for Issues and PRs" | ||
|
||
on: | ||
issues: | ||
types: [opened] | ||
pull_request_target: | ||
types: [opened] | ||
|
||
permissions: | ||
issues: write | ||
pull-requests: write | ||
|
||
jobs: | ||
greeting: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Greet first-time contributors | ||
id: greet | ||
uses: actions/first-interaction@v1 | ||
with: | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
issue-message: | | ||
๐ Hey @${{ github.actor }}! Thanks for stepping into the chaos and opening an issue in the ChaosWeb project. We embrace disorder, and your contribution adds to the delightful mess! ๐ | ||
Welcome to the wild side of web design. Expect the unexpected! ๐๐ | ||
pr-message: | | ||
๐ Welcome, @${{ github.actor }}! Thank you for your first pull request to ChaosWeb! Weโre excited to see how youโve contributed to the madness. ๐ Our team will review your chaotic creation soon. Keep the disorder coming! ๐ | ||
- name: Assign issue or pull request to a team member | ||
if: github.event_name == 'issues' || github.event_name == 'pull_request_target' | ||
run: | | ||
ISSUE_NUMBER=${{ github.event.issue.number || github.event.pull_request.number }} | ||
curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
-d '{"assignees":["team-member-username"]}' \ | ||
"https://api.github.com/repos/${{ github.repository }}/issues/${ISSUE_NUMBER}" | ||
- name: Welcome message for community contributors | ||
if: github.event_name == 'issues' || github.event_name == 'pull_request_target' | ||
uses: EddieHubCommunity/gh-action-community/src/welcome@main | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
issue-message: "๐ Hey @${{ github.actor }}! Thanks for opening an issue in the ChaosWeb project. Weโre excited to see how youโve contributed to the delightful mess. Our team will review it soon. Stay chaotic! ๐ฏ" | ||
pr-message: "๐ Thanks @${{ github.actor }}! Your pull request has added more chaos to ChaosWeb. Weโll review it shortly. Keep breaking the rules! ๐" |
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,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) |
Oops, something went wrong.