gcp-platforms-auto 0.6.3__py3-none-any.whl → 0.6.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
gcp_platforms_auto/git.py CHANGED
@@ -63,7 +63,7 @@ def get_repo(path_of_git_repo, branch="main", path_to_local_repo="/tmp/repo"):
63
63
  raise e
64
64
 
65
65
 
66
- def git_push(repo, commit_message, files_to_push=None):
66
+ def git_push(repo, commit_message, files_to_push=None, branch="main"):
67
67
  try:
68
68
  logger.info(f"Attempting to push changes to Git with commit message: '{commit_message}'")
69
69
  if files_to_push:
@@ -74,20 +74,20 @@ def git_push(repo, commit_message, files_to_push=None):
74
74
  repo.git.add(all=True)
75
75
  logger.info(f"Committing changes with message: '{commit_message}'")
76
76
  repo.index.commit(commit_message)
77
- logger.info("Pushing changes to remote 'origin'")
78
- push_info = repo.remote(name="origin").push()
77
+ logger.info(f"Pushing changes to remote 'origin', branch '{branch}'")
78
+ push_info = repo.remote(name="origin").push(refspec=f"{branch}:{branch}")
79
79
  for info in push_info:
80
- if info.flags >0:
81
- logger.info(f"Git push info: {info.summary}")
82
- if info.flags == 0:
83
- logger.info(f"Git push info: No update {info.summary}")
80
+ if info.flags > 0:
81
+ logger.info(f"Git push info: {info.summary}")
82
+ elif info.flags == 0:
83
+ logger.info(f"Git push info: No update {info.summary}")
84
84
 
85
85
  logger.info("Successfully pushed changes to Git.")
86
86
  except Exception as e:
87
87
  logger.exception(f"Error pushing to Git: {str(e)}")
88
88
  raise e
89
89
 
90
- def create_repo(org, repo, token, github_enterprise="github.com"):
90
+ def create_repo(org, repo, token, github_enterprise="github.com", branches=None):
91
91
  try:
92
92
  logger.info("Creating repository...")
93
93
  is_github_cloud = github_enterprise is "github.com"
@@ -115,6 +115,25 @@ def create_repo(org, repo, token, github_enterprise="github.com"):
115
115
  logger.error(f"Failed to create repository: {res.status_code} {res.text}")
116
116
  res.raise_for_status()
117
117
 
118
+ if branches:
119
+ main_ref_url = f"{api_base}/repos/{org}/{repo}/git/refs/heads/main"
120
+ res = requests.get(main_ref_url, headers=headers)
121
+ res.raise_for_status()
122
+ sha = res.json()["object"]["sha"]
123
+
124
+ for br in branches:
125
+ if br == "main":
126
+ continue
127
+ ref_url = f"{api_base}/repos/{org}/{repo}/git/refs"
128
+ data = {"ref": f"refs/heads/{br}", "sha": sha}
129
+ r = requests.post(ref_url, headers=headers, json=data)
130
+ if r.status_code == 201:
131
+ logger.info(f"Created branch {br}")
132
+ elif r.status_code == 422 and "Reference already exists" in r.text:
133
+ logger.warning(f"Branch {br} already exists, skipping")
134
+ else:
135
+ logger.error(f"Failed to create branch {br}: {r.status_code} {r.text}")
136
+
118
137
  except Exception as e:
119
138
  logger.exception(f"Error creating repository: {str(e)}")
120
139
  raise e
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gcp_platforms_auto
3
- Version: 0.6.3
3
+ Version: 0.6.5
4
4
  Summary: A brief description of your package
5
5
  Author-email: ofir4858 <ofirshasha10@gmail.com>
6
6
  License: MIT
@@ -0,0 +1,6 @@
1
+ gcp_platforms_auto/__init__.py,sha256=7CmPCQxUqAvZTHKCREhL2b4MKD8Pn7FnKZUcMxYC09g,92
2
+ gcp_platforms_auto/git.py,sha256=9gn4voiUtxGbFXKlICR80jWt5L1x7V0N6vntqs_x3Jw,5106
3
+ gcp_platforms_auto-0.6.5.dist-info/METADATA,sha256=7fl0_0Lje7E7_G_f8BxJEPc-ya7OQbDkwygPIkXt2S0,494
4
+ gcp_platforms_auto-0.6.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
+ gcp_platforms_auto-0.6.5.dist-info/top_level.txt,sha256=4q-ofPMmvBaTnIbAzs-Wp_OwheAVxxmJ1fW9vl3-kyE,19
6
+ gcp_platforms_auto-0.6.5.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- gcp_platforms_auto/__init__.py,sha256=7CmPCQxUqAvZTHKCREhL2b4MKD8Pn7FnKZUcMxYC09g,92
2
- gcp_platforms_auto/git.py,sha256=5slBDPEis29kHisdAaQy9rbV9petduB2sZwgQuD8z0E,4100
3
- gcp_platforms_auto-0.6.3.dist-info/METADATA,sha256=-g0eLryWuNtlWedUbjYJyOXVjpTbil1FuVZPwmEvtY0,494
4
- gcp_platforms_auto-0.6.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
- gcp_platforms_auto-0.6.3.dist-info/top_level.txt,sha256=4q-ofPMmvBaTnIbAzs-Wp_OwheAVxxmJ1fW9vl3-kyE,19
6
- gcp_platforms_auto-0.6.3.dist-info/RECORD,,