TenzinGayche commited on
Commit
5a50431
·
verified ·
1 Parent(s): af9e5f0

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +11 -5
handler.py CHANGED
@@ -69,10 +69,14 @@ def create_github_repo(repo_path: Path, repo_name: str, version: str, realign: b
69
  # Initialize a Git repository
70
  subprocess.run(f"git init".split(), cwd=str(repo_path))
71
 
72
- # Commit the changes
73
  subprocess.run("git add .".split(), cwd=str(repo_path))
74
- commit_message = "Initial commit" if not realign else f"Commit for version {version}"
75
- subprocess.run(f"git commit -m".split() + [commit_message], cwd=str(repo_path))
 
 
 
 
76
 
77
  # Check if realigning
78
  if realign:
@@ -83,6 +87,10 @@ def create_github_repo(repo_path: Path, repo_name: str, version: str, realign: b
83
  logging.error("Version not specified for realignment.")
84
  return
85
  else:
 
 
 
 
86
  # Create a new repository on GitHub
87
  response = requests.post(
88
  GITHUB_API_ENDPOINT,
@@ -93,7 +101,6 @@ def create_github_repo(repo_path: Path, repo_name: str, version: str, realign: b
93
  auth=(GITHUB_USERNAME, GITHUB_ACCESS_TOKEN),
94
  )
95
  response.raise_for_status()
96
-
97
  time.sleep(3)
98
 
99
  # Add the GitHub remote to the local Git repository
@@ -107,7 +114,6 @@ def create_github_repo(repo_path: Path, repo_name: str, version: str, realign: b
107
  subprocess.run(f"git push -u origin {branch_name}".split(), cwd=str(repo_path))
108
 
109
  return f"Branch '{branch_name}' updated in {repo_name}" if realign else response.json()["html_url"]
110
-
111
  def convert_raw_align_to_tm(align_fn: Path, tm_path: Path):
112
  if DEBUG:
113
  logging.debug("[INFO] Conerting raw alignment to TM repo...")
 
69
  # Initialize a Git repository
70
  subprocess.run(f"git init".split(), cwd=str(repo_path))
71
 
72
+ # Add files and check if there are changes to commit
73
  subprocess.run("git add .".split(), cwd=str(repo_path))
74
+ status_result = subprocess.run("git status --porcelain".split(), cwd=str(repo_path), capture_output=True)
75
+ if status_result.stdout:
76
+ commit_message = "Initial commit" if not realign else f"Commit for version {version}"
77
+ subprocess.run(f"git commit -m".split() + [commit_message], cwd=str(repo_path))
78
+ else:
79
+ logging.info("No changes to commit.")
80
 
81
  # Check if realigning
82
  if realign:
 
87
  logging.error("Version not specified for realignment.")
88
  return
89
  else:
90
+ # Create and checkout main branch if it doesn't exist
91
+ subprocess.run("git branch -m main".split(), cwd=str(repo_path))
92
+ subprocess.run("git checkout main".split(), cwd=str(repo_path))
93
+
94
  # Create a new repository on GitHub
95
  response = requests.post(
96
  GITHUB_API_ENDPOINT,
 
101
  auth=(GITHUB_USERNAME, GITHUB_ACCESS_TOKEN),
102
  )
103
  response.raise_for_status()
 
104
  time.sleep(3)
105
 
106
  # Add the GitHub remote to the local Git repository
 
114
  subprocess.run(f"git push -u origin {branch_name}".split(), cwd=str(repo_path))
115
 
116
  return f"Branch '{branch_name}' updated in {repo_name}" if realign else response.json()["html_url"]
 
117
  def convert_raw_align_to_tm(align_fn: Path, tm_path: Path):
118
  if DEBUG:
119
  logging.debug("[INFO] Conerting raw alignment to TM repo...")