-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed to local head instead of remote
- Loading branch information
Showing
2 changed files
with
38 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,49 @@ | ||
import os | ||
import subprocess | ||
|
||
import requests | ||
import yaml | ||
|
||
|
||
def generate(local_storage_path: str) -> tuple[str, str]: | ||
local_repo_path = ( | ||
subprocess.run( | ||
["git", "rev-parse", "--show-toplevel"], capture_output=True, check=True | ||
def generate(storage_path: str) -> tuple[str, str]: | ||
storage_path = os.path.abspath(os.path.expanduser(storage_path)) | ||
|
||
# get the version of the storage at HEAD | ||
try: | ||
repo_path = ( | ||
subprocess.run( | ||
[ | ||
"git", | ||
"rev-parse", | ||
"--show-toplevel", | ||
], | ||
cwd=os.path.dirname(storage_path), | ||
capture_output=True, | ||
check=True, | ||
) | ||
.stdout.decode("utf-8") | ||
.strip() | ||
) | ||
.stdout.decode("utf-8") | ||
.strip() | ||
) | ||
local_storage_path = os.path.abspath(os.path.expanduser(local_storage_path)) | ||
if not local_storage_path.startswith(local_repo_path): | ||
raise ValueError( | ||
f"Storage path '{local_storage_path}' is not in the git repository '{local_repo_path}'" | ||
if not repo_path.endswith("snuba"): | ||
raise ValueError( | ||
"expected git repo to end with 'snuba' but got: " + repo_path | ||
) | ||
assert storage_path.startswith(repo_path) # should always hold | ||
rel_storage_path = storage_path[len(repo_path) + 1 :] | ||
old_storage = ( | ||
subprocess.run( | ||
["git", "show", f"HEAD:{rel_storage_path}"], | ||
capture_output=True, | ||
check=True, | ||
) | ||
.stdout.decode("utf-8") | ||
.strip() | ||
) | ||
except subprocess.CalledProcessError as e: | ||
raise ValueError(e.stderr.decode("utf-8")) from e | ||
old_storage = yaml.safe_load(old_storage) | ||
|
||
# get local storage | ||
rel_storage_path = os.path.relpath(local_storage_path, local_repo_path) | ||
with open(os.path.join(local_repo_path, rel_storage_path), "r") as f: | ||
# get the user-provided (modified) storage | ||
with open(storage_path, "r") as f: | ||
new_storage = yaml.safe_load(f) | ||
|
||
# get remote storage | ||
REMOTE_SNUBA_REPO = "https://raw.githubusercontent.com/getsentry/snuba/master" | ||
res = requests.get(f"{REMOTE_SNUBA_REPO}/{rel_storage_path}") | ||
old_storage = yaml.safe_load(res.text) | ||
|
||
return old_storage, new_storage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters