From 1d4cd136dbe0bdae96b9df26f9c9202771f83ac0 Mon Sep 17 00:00:00 2001 From: Roger Barker Date: Thu, 1 May 2025 11:03:50 -0700 Subject: [PATCH 1/2] feat: dynamically assign user name and filtered teams **Description**: Dynamically injects github user name (based on GITHUB_UNAME env) Dynamically updates team list based on input teams Signed-off-by: Roger Barker --- README.md | 2 ++ src/static_site_generator.py | 16 ++++++++++++---- version2.py | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6eaa63f..86ef5fe 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ The following dependencies are required to run the program: ## 💻 Setup - Authentication through `gh auth login` +- Set the `GITHUB_TOKEN` environment variable: `export GITHUB_TOKEN=$(gh auth token)` +- Set the `GITHUB_UNAME` environment variable: `export GITHUB_UNAME=$(gh auth status | grep "(GITHUB_TOKEN)" | cut -d " " -f9)` - Set the appropriate token permissions: `gh auth refresh --scopes read:project` - Run `make install` inside the repo directory to configure the appropriate versions of dependencies. diff --git a/src/static_site_generator.py b/src/static_site_generator.py index 56bac63..8792eca 100644 --- a/src/static_site_generator.py +++ b/src/static_site_generator.py @@ -1,5 +1,6 @@ from jinja2 import Environment, FileSystemLoader -import logging +import logging +import os class StaticSiteGenerator(): @@ -7,18 +8,25 @@ class StaticSiteGenerator(): def __init__(self): self.GENERATOR_DATA = { 'title': 'Version Two', - 'github_user': 'octocat', - 'team': 'Platform Engineering', + 'github_user': "", + 'team': "", 'tasks': [] } - def generate_site(self, data=None, output_file='./_site/index.html'): + def generate_site(self, data:list=None, teams:list[str]=None,output_file='./_site/index.html'): logging.info("Generating Static Site") env = Environment(loader=FileSystemLoader('templates')) template = env.get_template('kaban_board.html') self.GENERATOR_DATA["tasks"] = data if data is not None else [] + # Set the github user name + self.github_uname = os.getenv("GITHUB_UNAME") if os.getenv("GITHUB_UNAME") else "Not logged in" + self.GENERATOR_DATA["github_user"] = self.github_uname + + # Set the team(s) + self.GENERATOR_DATA["team"] = ' '.join(teams) if teams is not None else "" + # Extract unique statuses from the tasks list unique_statuses = sorted({task["status"] for task in self.GENERATOR_DATA["tasks"]}) diff --git a/version2.py b/version2.py index 0622818..688adda 100644 --- a/version2.py +++ b/version2.py @@ -44,7 +44,7 @@ def main(): with open(output_file, 'r') as f: data = json.load(f) - ss_gen.generate_site(data=data) + ss_gen.generate_site(data=data, teams=filters["include_teams"]) if __name__ == "__main__": main() From 2486ae098a162b7a02f58759857dbebb6d10a508 Mon Sep 17 00:00:00 2001 From: Roger Barker Date: Thu, 1 May 2025 11:07:07 -0700 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Roger Barker --- src/static_site_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/static_site_generator.py b/src/static_site_generator.py index 8792eca..db228ff 100644 --- a/src/static_site_generator.py +++ b/src/static_site_generator.py @@ -13,7 +13,7 @@ def __init__(self): 'tasks': [] } - def generate_site(self, data:list=None, teams:list[str]=None,output_file='./_site/index.html'): + def generate_site(self, data:list=None, teams:list[str]=None, output_file='./_site/index.html'): logging.info("Generating Static Site") env = Environment(loader=FileSystemLoader('templates')) template = env.get_template('kaban_board.html')