22import subprocess
33
44def print_header ():
5- print ("""
5+ print (r """
66 ==========================================================
77
88 .__ __
@@ -40,8 +40,10 @@ def print_credits():
4040 print ("-" * 50 )
4141 print ("_" * 50 )
4242
43+
4344def check_repositories (base_path ):
4445 for root , dirs , _ in os .walk (base_path ):
46+ # Se eliminó el filtro basado en el sufijo
4547 for d in dirs :
4648 repo_path = os .path .join (root , d )
4749 if os .path .isdir (os .path .join (repo_path , ".git" )):
@@ -68,6 +70,7 @@ def check_repositories(base_path):
6870 else :
6971 pass # No changes detected, skip output
7072
73+
7174def update_repositories (base_path ):
7275 for root , dirs , _ in os .walk (base_path ):
7376 for d in dirs :
@@ -84,6 +87,9 @@ def update_repositories(base_path):
8487 else :
8588 print (f"Failed to update repository. Error: { process .stderr } \n " )
8689
90+
91+
92+
8793def find_and_create_pr (base_path ):
8894 pr_created = False # Flag to track if a PR was created
8995 pr_number = None # Store the PR number to merge it later
@@ -209,31 +215,61 @@ def find_and_create_pr(base_path):
209215 break # Exit after the first failed attempt
210216 except subprocess .CalledProcessError as e :
211217 print (f"Error while creating pull request in { repo_path } : { e } " )
212- continue
218+ break # Exit after the first failed attempt
219+ else :
220+ print (f"No new commits detected for { repo_path } between { current_branch } and origin/{ default_branch } . Skipping PR creation." )
221+
222+ # Handle repos that require a commit before PR
223+ if not diff_result .stdout .strip ():
224+ repos_missing_commits .append (repo_path )
225+
226+ # Output missing commit repositories
227+ if repos_missing_commits :
228+ print ("\n The following repositories require commits before creating a PR:" )
229+ for repo in repos_missing_commits :
230+ print (f"- { repo } " )
231+
232+ if not pr_created :
233+ print ("\n No pull requests were created. Check the repository status for possible issues." )
234+ else :
235+ print ("\n Pull request was created and attempted to merge successfully." )
236+
237+
238+
213239
214240def main ():
215241 print_header ()
216- print ("Welcome to the GitSync tool!\n " )
217-
218- base_path = input ("Enter the base path to check repositories: " )
219-
242+ base_path = os .getcwd ()
243+
220244 while True :
221- print ("\n Choose an option:" )
222- print ("1. Check repositories for changes" )
223- print ("2. Update all repositories" )
224- print ("3. Find repositories and create PR" )
225- print ("4. Exit" )
226-
227- option = input ("Enter your choice: " ).strip ()
245+ print ("\n Options:" )
246+ print ("1. Check repositories and push changes" )
247+ print ("2. Update repositories" )
248+ print ("3. Find and create pull requests" )
249+ print ("4. Show credits" )
250+ print ("5. Exit" )
251+
252+ option = input ("Enter option number (default is 2): " ).strip () or "2"
228253
229254 if option == "1" :
230255 check_repositories (base_path )
256+
231257 elif option == "2" :
232258 update_repositories (base_path )
259+
233260 elif option == "3" :
234261 find_and_create_pr (base_path )
262+
235263 elif option == "4" :
236- print ("Goodbye!" )
264+ print_credits ()
265+
266+ elif option == "5" :
267+ print ("Exiting program. Goodbye!" )
237268 break
269+
238270 else :
239271 print ("Invalid option. Please try again." )
272+
273+ if __name__ == "__main__" :
274+ main ()
275+
0 commit comments