gcp-platforms-auto 0.6.4__tar.gz → 0.7.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gcp_platforms_auto
3
- Version: 0.6.4
3
+ Version: 0.7.0
4
4
  Summary: A brief description of your package
5
5
  Author-email: ofir4858 <ofirshasha10@gmail.com>
6
6
  License: MIT
@@ -2,7 +2,7 @@ import logging
2
2
  import time
3
3
  import jwt
4
4
  import google.cloud.logging
5
- from git import Repo, NoSuchPathError
5
+ from git import Repo, NoSuchPathError, GitCommandError
6
6
  from pathlib import Path
7
7
  import requests
8
8
 
@@ -58,6 +58,10 @@ def get_repo(path_of_git_repo, branch="main", path_to_local_repo="/tmp/repo"):
58
58
  except NoSuchPathError:
59
59
  logger.error("Repository path does not exist. Cloning fresh repository.")
60
60
  return Repo.clone_from(path_of_git_repo, str(path_to_local_repo), branch=branch)
61
+ except GitCommandError as e:
62
+ logger.error(f"Error pulling repo (command error), trying again")
63
+ time.sleep(5)
64
+ get_repo(path_of_git_repo, branch, path_to_local_repo)
61
65
  except Exception as e:
62
66
  logger.exception(f"Error accessing repo: {str(e)}")
63
67
  raise e
@@ -83,11 +87,15 @@ def git_push(repo, commit_message, files_to_push=None, branch="main"):
83
87
  logger.info(f"Git push info: No update {info.summary}")
84
88
 
85
89
  logger.info("Successfully pushed changes to Git.")
90
+ except GitCommandError as e:
91
+ logger.error(f"Error pushing to Git (command error), trying again")
92
+ time.sleep(5)
93
+ git_push(repo, commit_message, files_to_push, branch)
86
94
  except Exception as e:
87
95
  logger.exception(f"Error pushing to Git: {str(e)}")
88
96
  raise e
89
97
 
90
- def create_repo(org, repo, token, github_enterprise="github.com"):
98
+ def create_repo(org, repo, token, github_enterprise="github.com", branches=None):
91
99
  try:
92
100
  logger.info("Creating repository...")
93
101
  is_github_cloud = github_enterprise is "github.com"
@@ -115,6 +123,25 @@ def create_repo(org, repo, token, github_enterprise="github.com"):
115
123
  logger.error(f"Failed to create repository: {res.status_code} {res.text}")
116
124
  res.raise_for_status()
117
125
 
126
+ if branches:
127
+ main_ref_url = f"{api_base}/repos/{org}/{repo}/git/refs/heads/main"
128
+ res = requests.get(main_ref_url, headers=headers)
129
+ res.raise_for_status()
130
+ sha = res.json()["object"]["sha"]
131
+
132
+ for br in branches:
133
+ if br == "main":
134
+ continue
135
+ ref_url = f"{api_base}/repos/{org}/{repo}/git/refs"
136
+ data = {"ref": f"refs/heads/{br}", "sha": sha}
137
+ r = requests.post(ref_url, headers=headers, json=data)
138
+ if r.status_code == 201:
139
+ logger.info(f"Created branch {br}")
140
+ elif r.status_code == 422 and "Reference already exists" in r.text:
141
+ logger.warning(f"Branch {br} already exists, skipping")
142
+ else:
143
+ logger.error(f"Failed to create branch {br}: {r.status_code} {r.text}")
144
+
118
145
  except Exception as e:
119
146
  logger.exception(f"Error creating repository: {str(e)}")
120
147
  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.7.0
4
4
  Summary: A brief description of your package
5
5
  Author-email: ofir4858 <ofirshasha10@gmail.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "gcp_platforms_auto"
7
- version = "0.6.4"
7
+ version = "0.7.0"
8
8
  description = "A brief description of your package"
9
9
  readme = "README.md"
10
10
  authors = [