Skip to content

Commit

Permalink
Merge pull request #26 from Start-Out/feature/env-enhancements
Browse files Browse the repository at this point in the history
FEATURE: Env Enhancements
  • Loading branch information
trentonyo authored Sep 19, 2024
2 parents defff9b + 2523d32 commit 272b2d2
Show file tree
Hide file tree
Showing 34 changed files with 1,534 additions and 640 deletions.
20 changes: 12 additions & 8 deletions .github/workflows/test-suite.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Test with PyTest, coverage with Coveralls

on:
Expand Down Expand Up @@ -56,3 +48,15 @@ jobs:
uses: coverallsapp/github-action@v2.2.3
with:
file: cov.lcov
parallel: true
flag-name: run-${{ matrix.os }}-${{ matrix.python-version }}

finish:
needs: test_suite
if: ${{ success() }}
runs-on: ubuntu-latest
steps:
- name: Close parallel build
uses: coverallsapp/github-action@v2.2.3
with:
parallel-finished: true
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "startout"
version = "0.4.3"
version = "0.5.1"
description = "Draft version of the StartOut CLI'"
authors = ["Trenton Yo <askstartout@gmail.com>", "Jake Gehrke <askstartout@gmail.com>"]
readme = "README.md"
Expand Down
47 changes: 47 additions & 0 deletions startout/env_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os

from typing import Tuple

from startout.util import is_potentially_sensitive_key_value


class EnvironmentVariableManager:
def __init__(self):
self.initial_vars = {k: v for k, v in os.environ.items()}

self.final_vars = {}

def capture_final_env(self):
current_vars = {key: value for key, value in os.environ.items()}
new_vars = {
key: value
for key, value in current_vars.items()
if key not in self.initial_vars
}
self.final_vars.update(new_vars)

return self.final_vars

def get_captured_vars(self) -> Tuple[dict, dict]:
"""
Returns two dictionaries: one containing the not potentially sensitive variables and their values, and the other
containing the potentially sensitive variables and their values.
**Returns:**
- `not_potentially_sensitive` (dict): A dictionary containing the not potentially sensitive variables and their values.
- `potentially_sensitive` (dict): A dictionary containing the potentially sensitive variables and their values.
"""

potentially_sensitive = {
key: value
for key, value in self.final_vars.items()
if is_potentially_sensitive_key_value(key, value)
}
not_potentially_sensitive = {
key: value
for key, value in self.final_vars.items()
if not is_potentially_sensitive_key_value(key, value)
}
return not_potentially_sensitive, potentially_sensitive
85 changes: 57 additions & 28 deletions startout/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
from rich.theme import Theme
from rich.progress import Progress, SpinnerColumn, TextColumn

custom_theme = Theme({
"input_prompt": "bold cyan",
"announcement": "bold yellow",
"success": "bold green",
"error": "bold red",
"bold": "bold",
})
custom_theme = Theme(
{
"input_prompt": "bold cyan",
"announcement": "bold yellow",
"success": "bold green",
"error": "bold red",
"bold": "bold",
}
)

console = Console(theme=custom_theme)


def create_repo_from_temp(
owner: str, repo_name: str, template: str, public: bool = False
owner: str, repo_name: str, template: str, public: bool = False
):
"""
Create a GitHub repo from a provided template.
Expand All @@ -39,33 +41,47 @@ def create_repo_from_temp(
else:
cmd.append("--private")

result = ''
result = ""

with Progress(SpinnerColumn(), TextColumn("[progress.description]{task.description}")) as progress:
with Progress(
SpinnerColumn(), TextColumn("[progress.description]{task.description}")
) as progress:
task = progress.add_task(f"Fetching and cloning {template}", total=None)

result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

if result.returncode == 0:
progress.update(task, description=f"Success: {template} has been cloned.", completed=True)
progress.update(
task,
description=f"Success: {template} has been cloned.",
completed=True,
)
progress.refresh()
progress.stop()
console.print(f"{result.stdout.decode()}", style='success')
console.print(f"{result.stdout.decode()}", style="success")
return os.path.join(os.getcwd(), repo_name)
else:
progress.update(task, description=f"Failure: {template} has not been cloned.", completed=True)
progress.update(
task,
description=f"Failure: {template} has not been cloned.",
completed=True,
)
progress.refresh()
progress.stop()
console.file = sys.stderr # Set console output to stderr
console.print(f"ERROR: {result.stdout.decode()}", style='error')
console.print(f"ERROR: {result.stdout.decode()}", style="error")
return False


def check_repo_custom_property(template_owner: str, template_name: str, custom_properties: dict) -> bool:
def check_repo_custom_property(
template_owner: str, template_name: str, custom_properties: dict
) -> bool:
cmd_string = f"gh api /repos/{template_owner}/{template_name}/properties/values"
cmd = shlex.split(cmd_string)

with Progress(SpinnerColumn(), TextColumn("[progress.description]{task.description}")) as progress:
with Progress(
SpinnerColumn(), TextColumn("[progress.description]{task.description}")
) as progress:
task = progress.add_task(f"Checking properties of {template_name}", total=None)

result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
Expand All @@ -80,35 +96,48 @@ def check_repo_custom_property(template_owner: str, template_name: str, custom_p
repo_properties[_property["property_name"]] = _property["value"]

except ValueError:
progress.update(task,
description=f"Failure: Failed to check properties of {template_name} "
f"(response {response_str}).",
completed=True)
progress.update(
task,
description=f"Failure: Failed to check properties of {template_name} "
f"(response {response_str}).",
completed=True,
)
progress.refresh()
progress.stop()
return False

progress.update(task, description=f"Success: Received custom properties of {template_name}.",
completed=True)
progress.update(
task,
description=f"Success: Received custom properties of {template_name}.",
completed=True,
)
progress.refresh()

if custom_properties != repo_properties:
progress.update(task, description=f"Expected: {custom_properties}")
progress.update(task, description=f"Received: {repo_properties}")
progress.update(task, description=f"Failure: Mismatch in properties of {template_name}.",
completed=True)
progress.update(
task,
description=f"Failure: Mismatch in properties of {template_name}.",
completed=True,
)
progress.refresh()
progress.stop()
return False

progress.stop()
console.print(f"Validated all custom properties for {template_name}", style='success')
console.print(
f"Validated all custom properties for {template_name}", style="success"
)
return True
else:
progress.update(task, description=f"Failure: Could not check properties of {template_name}.",
completed=True)
progress.update(
task,
description=f"Failure: Could not check properties of {template_name}.",
completed=True,
)
progress.refresh()
progress.stop()
console.file = sys.stderr # Set console output to stderr
console.print(f"ERROR: {result.stdout.decode()}", style='error')
console.print(f"ERROR: {result.stdout.decode()}", style="error")
return False
Loading

0 comments on commit 272b2d2

Please # to comment.