-
Notifications
You must be signed in to change notification settings - Fork 5
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
1 parent
e09c36d
commit 2026bfc
Showing
3 changed files
with
70 additions
and
2 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,6 +1,7 @@ | ||
__pycache__ | ||
.coverage | ||
.terraform/ | ||
*.csv | ||
*.egg-info | ||
/.cache | ||
/.env | ||
|
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,60 @@ | ||
import csv | ||
import logging | ||
from pathlib import Path | ||
from urllib.parse import urlparse | ||
|
||
import click | ||
from click_help_colors import HelpColorsCommand | ||
|
||
from spacemk import get_tmp_folder, load_normalized_data, save_normalized_data | ||
|
||
|
||
def find_stack_vcs_config(stack_name: str, vcs_config: dict) -> dict | None: | ||
for item in vcs_config: | ||
if item.get("WorkspaceName") == stack_name: | ||
return item | ||
|
||
return None | ||
|
||
|
||
def load_vcs_config(path: str) -> dict: | ||
with Path(path).open("r", encoding="utf-8") as fp: | ||
return list(csv.DictReader(fp)) | ||
|
||
|
||
@click.command( | ||
cls=HelpColorsCommand, | ||
help="Update stacks VCS configuration.", | ||
help_headers_color="yellow", | ||
help_options_color="green", | ||
) | ||
@click.option( | ||
"--path", | ||
"vcs_config_file_path", | ||
default="vcs_config.csv", | ||
help="Path to the CSV file containing the VCS configuration.", | ||
show_default=True, | ||
type=click.Path(exists=True), | ||
) | ||
def update_vcs_config(vcs_config_file_path: str): | ||
data = load_normalized_data() | ||
save_normalized_data(data, Path(get_tmp_folder(), "data.bak.json")) | ||
vcs_config = load_vcs_config(vcs_config_file_path) | ||
|
||
for stack in data.get("stacks"): | ||
stack_vcs_config = find_stack_vcs_config(stack.get("name"), vcs_config) | ||
if not stack_vcs_config: | ||
logging.warning(f"No VCS configuration found for the '{stack.get('name')}' stack. Skipping.") | ||
continue | ||
|
||
stack.vcs.update( | ||
{ | ||
"branch": stack_vcs_config.get("Branch"), | ||
"namespace": urlparse(stack_vcs_config.get("RepoURL")).path.split("/")[1], | ||
"project_root": Path(stack_vcs_config.get("BackendPath")).parent.as_posix() + "/", | ||
"provider": "azure_devops", | ||
"repository": stack_vcs_config.get("RepoName"), | ||
} | ||
) | ||
|
||
save_normalized_data(data) |
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