gcp-platforms-auto 0.6.4__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
@@ -87,7 +87,7 @@ def git_push(repo, commit_message, files_to_push=None, branch="main"):
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.4
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=5eh4xqPwrjdYEDhK3mPM0G6-mQsvm6dhZ2kD80yoxI8,4178
3
- gcp_platforms_auto-0.6.4.dist-info/METADATA,sha256=fe_Amei_SerPTmc6sDwP74LZh3MCoq1lRC-cuojFyg4,494
4
- gcp_platforms_auto-0.6.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
- gcp_platforms_auto-0.6.4.dist-info/top_level.txt,sha256=4q-ofPMmvBaTnIbAzs-Wp_OwheAVxxmJ1fW9vl3-kyE,19
6
- gcp_platforms_auto-0.6.4.dist-info/RECORD,,