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.
- {gcp_platforms_auto-0.6.4 → gcp_platforms_auto-0.7.0}/PKG-INFO +1 -1
- {gcp_platforms_auto-0.6.4 → gcp_platforms_auto-0.7.0}/gcp_platforms_auto/git.py +29 -2
- {gcp_platforms_auto-0.6.4 → gcp_platforms_auto-0.7.0}/gcp_platforms_auto.egg-info/PKG-INFO +1 -1
- {gcp_platforms_auto-0.6.4 → gcp_platforms_auto-0.7.0}/pyproject.toml +1 -1
- {gcp_platforms_auto-0.6.4 → gcp_platforms_auto-0.7.0}/README.md +0 -0
- {gcp_platforms_auto-0.6.4 → gcp_platforms_auto-0.7.0}/gcp_platforms_auto/__init__.py +0 -0
- {gcp_platforms_auto-0.6.4 → gcp_platforms_auto-0.7.0}/gcp_platforms_auto.egg-info/SOURCES.txt +0 -0
- {gcp_platforms_auto-0.6.4 → gcp_platforms_auto-0.7.0}/gcp_platforms_auto.egg-info/dependency_links.txt +0 -0
- {gcp_platforms_auto-0.6.4 → gcp_platforms_auto-0.7.0}/gcp_platforms_auto.egg-info/requires.txt +0 -0
- {gcp_platforms_auto-0.6.4 → gcp_platforms_auto-0.7.0}/gcp_platforms_auto.egg-info/top_level.txt +0 -0
- {gcp_platforms_auto-0.6.4 → gcp_platforms_auto-0.7.0}/setup.cfg +0 -0
|
@@ -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
|
|
File without changes
|
|
File without changes
|
{gcp_platforms_auto-0.6.4 → gcp_platforms_auto-0.7.0}/gcp_platforms_auto.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{gcp_platforms_auto-0.6.4 → gcp_platforms_auto-0.7.0}/gcp_platforms_auto.egg-info/requires.txt
RENAMED
|
File without changes
|
{gcp_platforms_auto-0.6.4 → gcp_platforms_auto-0.7.0}/gcp_platforms_auto.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|