-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
43 additions
and
11 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,15 +1,30 @@ | ||
import os | ||
import subprocess | ||
|
||
import requests | ||
import yaml | ||
|
||
def generate(storage_path: str) -> None: | ||
repo_path = subprocess.run( | ||
["git", "rev-parse", "--show-toplevel"], capture_output=True | ||
).stdout.decode("utf-8") | ||
storage_path = os.path.abspath(os.path.expanduser(storage_path)) | ||
if not storage_path.startswith(repo_path): | ||
raise ValueError("Storage path is not in the git repository") | ||
|
||
rel_path = os.path.relpath(storage_path, repo_path) | ||
old_storage = "" | ||
new_storage = "" | ||
|
||
def generate(local_storage_path: str) -> tuple[str, str]: | ||
local_repo_path = ( | ||
subprocess.run(["git", "rev-parse", "--show-toplevel"], capture_output=True) | ||
.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}'" | ||
) | ||
|
||
# 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: | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pytest | ||
|
||
from snuba.migrations.autogeneration import generate | ||
|
||
|
||
def test_basic() -> None: | ||
old_storage, new_storage = generate( | ||
"snuba/datasets/configuration/events/storages/errors.yaml" | ||
) | ||
assert old_storage, new_storage | ||
|
||
|
||
def test_error() -> None: | ||
with pytest.raises( | ||
ValueError, match=r"Storage path .* is not in the git repository .*" | ||
): | ||
generate("/Users/bloop/hello") |