Skip to content

Commit

Permalink
Merge pull request #63 from felipealfonsog/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
felipealfonsog authored Mar 27, 2024
2 parents 785ba0f + 019f5f7 commit da0987d
Show file tree
Hide file tree
Showing 4 changed files with 334 additions and 105 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ GitSyncMaster* is a versatile tool designed to simplify the process of updating
- **Cron Integration:**
- Seamlessly integrate GitSyncMaster with cron jobs for scheduled updates at predefined intervals, ensuring your repositories are always up to date.

#### New Features

1. **Colorized Output**: The program now utilizes ANSI escape codes to provide colorized output for better readability. Messages such as success, errors, and prompts are now displayed in different colors, making it easier to distinguish different types of messages.

2. **Interactive Commit Workflow**: When choosing to check repositories requiring actions (option 1), users are presented with an interactive workflow for staging changes, committing them with a custom message, and optionally pushing the changes to the remote repository. This allows for a smoother and more user-friendly commit process directly from the command line.

3. **Enhanced Repository Update**: During repository update (option 2), if a directory requires a commit before updating, the program now displays a bold red message indicating the need for a commit. After attempting to pull changes from the remote repository, successful updates are displayed in bold blue text, while errors are shown in bold red text.

4. **Abort Confirmation**: Prior to initiating any action, the program prompts users with an abort confirmation to ensure they intend to proceed. This prevents accidental actions and provides users with the opportunity to cancel the operation if needed.

5. **Improved User Interface**: The program now offers a cleaner and more intuitive user interface with clear prompts and instructions at each step. Users are guided through the process of checking for repository actions or updating repositories, ensuring a seamless experience.

These new features aim to enhance the usability, functionality, and overall experience of the GitHub Repository Updater tool.

#

#### Screenshots
Expand Down
114 changes: 93 additions & 21 deletions src/aur-dev/git_updater.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os

def welcome():
print("Welcome to GitHub Repository Updater -GitSyncMaster-!")
print("This software was developed by Computer Science Engineer Felipe Alfonso González - Github: github.com/felipealfonsog - Under the BSD 3-clause license.")
print("Developed from Chile with love.")
print("----------------------------------------------------")
print("This software will update all GitHub repositories within the current directory or its subdirectories.")
print("\033[1;32mWelcome to GitHub Repository Updater -GitSyncMaster-!\033[0m")
print("\033[1;32mThis software was developed by Computer Science Engineer Felipe Alfonso González - Github: github.com/felipealfonsog - Under the BSD 3-clause license.\033[0m")
print("\033[1;32mDeveloped from Chile with love.\033[0m")
print("\033[1;32m----------------------------------------------------\033[0m")
print("\033[1;32m\033[1mThis software will update all GitHub repositories within the current directory or its subdirectories.\033[0m")

def update_github_repositories(main_directory, include_aur):
print("\nUpdating GitHub repositories...\n")
Expand All @@ -16,39 +16,111 @@ def update_github_repositories(main_directory, include_aur):
git_dir = os.path.join(root, '.git')
if os.path.isdir(git_dir):
if include_aur or not root.endswith("-aur"):
print(f"Updating repository in {root}")
os.chdir(root)
result = os.system('git pull')
os.chdir(main_directory)
if result == 0:
print("Repository updated successfully.")
changes = os.popen('git status --porcelain').read().strip()
if changes:
print(f"\033[1;31mRepository in {root} requires a commit before updating.\033[0m")
try:
result = os.system('git pull')
if result == 0:
print("Repository updated successfully.")
else:
print("Error updating repository.")
except Exception as e:
print(f"Error updating repository: {e}")
else:
print("Error updating repository.")
print(f"Updating repository in {root}")
try:
result = os.system('git pull')
if result == 0:
print("Repository updated successfully.")
else:
print("Error updating repository.")
except Exception as e:
print(f"Error updating repository: {e}")
os.chdir(main_directory)
if not found_repos:
print("No GitHub repositories found in the current directory or its subdirectories. Exiting.")
exit()

def check_repos(main_directory):
print("\nChecking for repositories requiring actions...\n")
repos_needing_action = []
for root, dirs, _ in os.walk(main_directory):
for dir in dirs:
repo_path = os.path.join(root, dir)
git_dir = os.path.join(repo_path, '.git')
if os.path.isdir(git_dir):
os.chdir(repo_path)
changes = os.popen('git status --porcelain').read().strip()
if changes:
repos_needing_action.append(repo_path)
os.chdir(main_directory)

if repos_needing_action:
print("The following repositories require actions:")
for repo in repos_needing_action:
print(repo)
return repos_needing_action
else:
print("No repositories require actions.")
return []

def main():
welcome()
current_directory = os.getcwd()
if not any('.git' in root for root, _, _ in os.walk(current_directory)):
print("You need to be inside a directory with GitHub repositories to update them.")
exit()
main_directory = input("Do you want to update repositories here? (Press Enter for Yes, No for cancel, default is Yes): ")
if main_directory.lower() == '' or main_directory.lower() == 'y':
abort_choice = input("Do you want to abort the process? (Press Enter for No, Y for Yes default is No): ").lower()

choice = input("Choose an option:\n1. Check repositories requiring actions.\n2. Update repositories.\nEnter option number (default is 2): ").strip() or '2'
if choice == '1':
repos = check_repos(current_directory)
if repos:
proceed = input("Do you want to proceed with the action? (Y/n): ").lower()
if proceed not in ['', 'y']:
print("Action aborted.")
exit()

for repo_path in repos:
os.chdir(repo_path)
changes = os.popen('git status --porcelain').read().strip()
print(f"Repository: {repo_path}\nChanges:\n{changes}")
stage_choice = input("Do you want to stage these changes for commit? (Y/n): ").lower()
if stage_choice in ['', 'y']:
os.system('git add .')
commit_message = input("Enter commit message: ")
os.system(f'git commit -m "{commit_message}"')
push_choice = input("Do you want to push these changes? (Y/n): ").lower()
if push_choice in ['', 'y']:
os.system('git push')
else:
print("Push aborted.")
else:
print("Staging aborted.")
os.chdir(current_directory)
else:
print("No repositories require actions.")
elif choice == '2':
abort_choice = input("Do you want to abort the process? (Press Enter for No, Y for Yes default is No): ").lower() or 'n'
if abort_choice == 'y':
print("Operation aborted.")
exit()

main_directory = input("Do you want to update repositories here? (Press Enter for Yes, No for cancel, default is Yes): ")
if main_directory.lower() == '' or main_directory.lower() == 'y':
exclude_choice = input("Do you want to exclude directories with the '-aur' suffix? (Press Enter for Yes, N for No, default is Yes): ").lower() or 'y'
if exclude_choice == 'y':
include_aur = False
else:
include_aur = True
update_github_repositories(current_directory, include_aur)
else:
print("You need to be inside a directory with GitHub repositories to update them.")
exit()
else:
print("You need to be inside a directory with GitHub repositories to update them.")
print("Invalid option. Exiting.")
exit()
exclude_choice = input("Do you want to exclude directories with the '-aur' suffix? (Press Enter for Yes, N for No, default is Yes): ").lower()
if exclude_choice == '' or exclude_choice == 'y':
include_aur = False
else:
include_aur = True
update_github_repositories(current_directory, include_aur)

if __name__ == "__main__":
main()
114 changes: 93 additions & 21 deletions src/macos-linux-dev/git_update_linux.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os

def welcome():
print("Welcome to GitHub Repository Updater -GitSyncMaster-!")
print("This software was developed by Computer Science Engineer Felipe Alfonso González - Github: github.com/felipealfonsog - Under the BSD 3-clause license.")
print("Developed from Chile with love.")
print("----------------------------------------------------")
print("This software will update all GitHub repositories within the current directory or its subdirectories.")
print("\033[1;32mWelcome to GitHub Repository Updater -GitSyncMaster-!\033[0m")
print("\033[1;32mThis software was developed by Computer Science Engineer Felipe Alfonso González - Github: github.com/felipealfonsog - Under the BSD 3-clause license.\033[0m")
print("\033[1;32mDeveloped from Chile with love.\033[0m")
print("\033[1;32m----------------------------------------------------\033[0m")
print("\033[1;32m\033[1mThis software will update all GitHub repositories within the current directory or its subdirectories.\033[0m")

def update_github_repositories(main_directory, include_aur):
print("\nUpdating GitHub repositories...\n")
Expand All @@ -16,39 +16,111 @@ def update_github_repositories(main_directory, include_aur):
git_dir = os.path.join(root, '.git')
if os.path.isdir(git_dir):
if include_aur or not root.endswith("-aur"):
print(f"Updating repository in {root}")
os.chdir(root)
result = os.system('git pull')
os.chdir(main_directory)
if result == 0:
print("Repository updated successfully.")
changes = os.popen('git status --porcelain').read().strip()
if changes:
print(f"\033[1;31mRepository in {root} requires a commit before updating.\033[0m")
try:
result = os.system('git pull')
if result == 0:
print("Repository updated successfully.")
else:
print("Error updating repository.")
except Exception as e:
print(f"Error updating repository: {e}")
else:
print("Error updating repository.")
print(f"Updating repository in {root}")
try:
result = os.system('git pull')
if result == 0:
print("Repository updated successfully.")
else:
print("Error updating repository.")
except Exception as e:
print(f"Error updating repository: {e}")
os.chdir(main_directory)
if not found_repos:
print("No GitHub repositories found in the current directory or its subdirectories. Exiting.")
exit()

def check_repos(main_directory):
print("\nChecking for repositories requiring actions...\n")
repos_needing_action = []
for root, dirs, _ in os.walk(main_directory):
for dir in dirs:
repo_path = os.path.join(root, dir)
git_dir = os.path.join(repo_path, '.git')
if os.path.isdir(git_dir):
os.chdir(repo_path)
changes = os.popen('git status --porcelain').read().strip()
if changes:
repos_needing_action.append(repo_path)
os.chdir(main_directory)

if repos_needing_action:
print("The following repositories require actions:")
for repo in repos_needing_action:
print(repo)
return repos_needing_action
else:
print("No repositories require actions.")
return []

def main():
welcome()
current_directory = os.getcwd()
if not any('.git' in root for root, _, _ in os.walk(current_directory)):
print("You need to be inside a directory with GitHub repositories to update them.")
exit()
main_directory = input("Do you want to update repositories here? (Press Enter for Yes, No for cancel, default is Yes): ")
if main_directory.lower() == '' or main_directory.lower() == 'y':
abort_choice = input("Do you want to abort the process? (Press Enter for No, Y for Yes default is No): ").lower()

choice = input("Choose an option:\n1. Check repositories requiring actions.\n2. Update repositories.\nEnter option number (default is 2): ").strip() or '2'
if choice == '1':
repos = check_repos(current_directory)
if repos:
proceed = input("Do you want to proceed with the action? (Y/n): ").lower()
if proceed not in ['', 'y']:
print("Action aborted.")
exit()

for repo_path in repos:
os.chdir(repo_path)
changes = os.popen('git status --porcelain').read().strip()
print(f"Repository: {repo_path}\nChanges:\n{changes}")
stage_choice = input("Do you want to stage these changes for commit? (Y/n): ").lower()
if stage_choice in ['', 'y']:
os.system('git add .')
commit_message = input("Enter commit message: ")
os.system(f'git commit -m "{commit_message}"')
push_choice = input("Do you want to push these changes? (Y/n): ").lower()
if push_choice in ['', 'y']:
os.system('git push')
else:
print("Push aborted.")
else:
print("Staging aborted.")
os.chdir(current_directory)
else:
print("No repositories require actions.")
elif choice == '2':
abort_choice = input("Do you want to abort the process? (Press Enter for No, Y for Yes default is No): ").lower() or 'n'
if abort_choice == 'y':
print("Operation aborted.")
exit()

main_directory = input("Do you want to update repositories here? (Press Enter for Yes, No for cancel, default is Yes): ")
if main_directory.lower() == '' or main_directory.lower() == 'y':
exclude_choice = input("Do you want to exclude directories with the '-aur' suffix? (Press Enter for Yes, N for No, default is Yes): ").lower() or 'y'
if exclude_choice == 'y':
include_aur = False
else:
include_aur = True
update_github_repositories(current_directory, include_aur)
else:
print("You need to be inside a directory with GitHub repositories to update them.")
exit()
else:
print("You need to be inside a directory with GitHub repositories to update them.")
print("Invalid option. Exiting.")
exit()
exclude_choice = input("Do you want to exclude directories with the '-aur' suffix? (Press Enter for Yes, N for No, default is Yes): ").lower()
if exclude_choice == '' or exclude_choice == 'y':
include_aur = False
else:
include_aur = True
update_github_repositories(current_directory, include_aur)

if __name__ == "__main__":
main()
Loading

0 comments on commit da0987d

Please sign in to comment.