Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 295 monorepo directory structure design proposal #389

Merged
merged 137 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
01fea64
initial directory structure organization
hbraswelrh Nov 12, 2024
ec67718
feat: initial work on config and common options
gvauter Nov 13, 2024
a1984a5
chore: add openssf scorecard workflow (#359)
jpower432 Nov 14, 2024
cc569d5
build(deps): bump compliance-trestle from 3.4.0 to 3.5.0 (#380)
dependabot[bot] Nov 14, 2024
c5b9418
feat: adds logic to load yaml config into click context to set defaut…
gvauter Nov 15, 2024
c6a2569
feat: adds debug logging statements
gvauter Nov 15, 2024
78fd113
feat: add markdown directory creation and call to compliance trestle …
gvauter Nov 15, 2024
6be37e8
feat: simplify directory creation and better error handling for inval…
gvauter Nov 20, 2024
45fc4b8
feat: initial work on autosync
qduanmu Nov 20, 2024
a239482
Initial create command for click cli
hbraswelrh Nov 20, 2024
5931b5c
Initial create command for click cli
hbraswelrh Nov 20, 2024
1ba1010
adding unit test for config module
gvauter Nov 20, 2024
7645fbe
adding unit test for config module
gvauter Nov 20, 2024
268c558
Update autosync command
qduanmu Nov 21, 2024
823e5bc
Update autosync command
qduanmu Nov 21, 2024
000e26e
feat: add ssp index option
gvauter Nov 21, 2024
5aeb27d
feat: add ssp index option
gvauter Nov 21, 2024
362faf1
add unit tests for init command
gvauter Nov 21, 2024
75fd0c1
add unit tests for init command
gvauter Nov 21, 2024
59da2c8
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter Nov 21, 2024
7f266f0
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter Nov 21, 2024
1382cdc
feat: root call create and logging replacement
hbraswelrh Nov 21, 2024
3292aa5
feat: root call create and logging replacement
hbraswelrh Nov 21, 2024
0a12ef9
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Nov 21, 2024
89de0ce
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Nov 21, 2024
d41e017
feat: add upstream commands, fix common options decorators, expand co…
gvauter Nov 24, 2024
b172bcf
feat: add upstream commands, fix common options decorators, expand co…
gvauter Nov 24, 2024
0a1c0cd
Update autosync options and add tests
qduanmu Nov 25, 2024
c4a90a8
Update autosync options and add tests
qduanmu Nov 25, 2024
05cb60a
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Nov 25, 2024
d3b7215
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Nov 25, 2024
3725e7e
docs: adr-001 cli implementation (#347)
gvauter Nov 26, 2024
ed11e85
feat: add logic to make_config for nested upstream model and update r…
gvauter Nov 26, 2024
8f34874
feat: add logic to make_config for nested upstream model and update r…
gvauter Nov 26, 2024
2a3845d
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter Nov 26, 2024
f50c39d
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter Nov 26, 2024
b3ba8de
feat: create command logic for compdef and ssp
hbraswelrh Nov 26, 2024
ffae2e8
feat: create command logic for compdef and ssp
hbraswelrh Nov 26, 2024
3b63750
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Nov 26, 2024
b97d7fa
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Nov 26, 2024
9284ad8
feat: create command updates to prompts and logger messages
hbraswelrh Nov 26, 2024
92092a7
feat: create command updates to prompts and logger messages
hbraswelrh Nov 26, 2024
3c13ad6
feat: add default git info to init prompts and config
gvauter Nov 27, 2024
3a9a7c3
feat: add default git info to init prompts and config
gvauter Nov 27, 2024
a4dbaa6
fix hidden keep file creation
gvauter Nov 27, 2024
7d3b9e3
fix hidden keep file creation
gvauter Nov 27, 2024
1206a16
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter Nov 27, 2024
1b5566e
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter Nov 27, 2024
8fe0747
Add rule-transform command and unit test
qduanmu Nov 27, 2024
4484a56
Add rule-transform command and unit test
qduanmu Nov 27, 2024
74dd43d
feat: create command logic and adding unit tests
hbraswelrh Nov 27, 2024
17d524a
feat: create command logic and adding unit tests
hbraswelrh Nov 27, 2024
c628013
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Nov 27, 2024
cf044da
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Nov 27, 2024
d21f5f6
Fix AttributeError, some misc updates
qduanmu Nov 29, 2024
df0e5d2
Fix AttributeError, some misc updates
qduanmu Nov 29, 2024
aef085f
feat: unit tests added for create command
hbraswelrh Dec 2, 2024
dbf9fa2
feat: unit tests added for create command
hbraswelrh Dec 2, 2024
7bca6cd
refactor sync upstreams and autosync to match existing entrypoint syntax
gvauter Dec 3, 2024
40d6009
refactor sync upstreams and autosync to match existing entrypoint syntax
gvauter Dec 3, 2024
486ad1e
Fix AttributeError, some misc updates
qduanmu Nov 29, 2024
fb36a11
Fix AttributeError, some misc updates
qduanmu Nov 29, 2024
742cef9
feat: unit tests added for create command
hbraswelrh Dec 2, 2024
026657c
feat: unit tests added for create command
hbraswelrh Dec 2, 2024
f9a2bca
fix: docstrings added for create command unit tests
hbraswelrh Dec 3, 2024
ee0feec
fix: docstrings added for create command unit tests
hbraswelrh Dec 3, 2024
8f68749
refactor sync upstreams and autosync to match existing entrypoint syntax
gvauter Dec 3, 2024
39ebbab
refactor sync upstreams and autosync to match existing entrypoint syntax
gvauter Dec 3, 2024
ec2d3f6
refactor sync upstreams and autosync to match existing entrypoint syntax
gvauter Dec 3, 2024
f439a6e
refactor sync upstreams and autosync to match existing entrypoint syntax
gvauter Dec 3, 2024
9164f41
fix: docstrings added for create unit tests
hbraswelrh Dec 3, 2024
fc49a30
fix: docstrings added for create unit tests
hbraswelrh Dec 3, 2024
ef31702
add file pattern filter
gvauter Dec 3, 2024
39ded49
add file pattern filter
gvauter Dec 3, 2024
f352487
fix: updated headers with license and copyright
hbraswelrh Dec 3, 2024
3c094d2
fix: updated headers with license and copyright
hbraswelrh Dec 3, 2024
9fd8c3b
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Dec 3, 2024
d31e2c0
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Dec 3, 2024
170cfbc
fix: updated logger statements
hbraswelrh Dec 3, 2024
afa3f8e
fix: updated logger statements
hbraswelrh Dec 3, 2024
fa13754
fix: logger statements shortened
hbraswelrh Dec 3, 2024
a11615f
fix: logger statements shortened
hbraswelrh Dec 3, 2024
0ca9439
fix: yaml default deletion
hbraswelrh Dec 3, 2024
799b0ec
fix: yaml default deletion
hbraswelrh Dec 3, 2024
99915e4
docs: updates to reference the CLI commands in the README.md
hbraswelrh Dec 3, 2024
a44aa80
docs: updates to reference the CLI commands in the README.md
hbraswelrh Dec 3, 2024
f9feb88
feat: update for required ssp name
hbraswelrh Dec 3, 2024
8dbe4e3
feat: update for required ssp name
hbraswelrh Dec 3, 2024
91d115c
Update trestlebot/cli/commands/init.py
gvauter Dec 3, 2024
d6356c0
Update trestlebot/cli/commands/init.py
gvauter Dec 3, 2024
c6b5560
Update trestlebot/cli/commands/init.py
gvauter Dec 3, 2024
cba3776
Update trestlebot/cli/commands/init.py
gvauter Dec 3, 2024
5f456a8
fix typo in error msg
gvauter Dec 3, 2024
f72483d
fix typo in error msg
gvauter Dec 3, 2024
7bac602
fix help text for sync upstreams
gvauter Dec 3, 2024
f8c12b7
fix help text for sync upstreams
gvauter Dec 3, 2024
fa1466c
fix: update for help text and testing location errors
hbraswelrh Dec 3, 2024
8133f73
fix: update for help text and testing location errors
hbraswelrh Dec 3, 2024
d1cbc0b
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Dec 3, 2024
2df503b
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Dec 3, 2024
be89e66
fix: update for clarity on profile name for trestle workspace
hbraswelrh Dec 4, 2024
4c5a7e2
fix: update for clarity on profile name for trestle workspace
hbraswelrh Dec 4, 2024
f6fcf2d
Fix AssertionError, add missing register
qduanmu Dec 4, 2024
1669ea8
Fix AssertionError, add missing register
qduanmu Dec 4, 2024
e09b455
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Dec 4, 2024
562da56
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
hbraswelrh Dec 4, 2024
80cd9cc
fix: profile name prompting update
hbraswelrh Dec 4, 2024
4226a86
fix: profile name prompting update
hbraswelrh Dec 4, 2024
877ac9a
feat: updating compdef list to required
hbraswelrh Dec 4, 2024
66f55c7
feat: updating compdef list to required
hbraswelrh Dec 4, 2024
db34e53
docs: change of verbiage for readability
hbraswelrh Dec 4, 2024
dfc0aba
docs: change of verbiage for readability
hbraswelrh Dec 4, 2024
5c5a17a
docs: change to indicate trestle-bot as a cli tool
hbraswelrh Dec 4, 2024
230568d
docs: change to indicate trestle-bot as a cli tool
hbraswelrh Dec 4, 2024
0e31aa8
feat: change to help description of create command
hbraswelrh Dec 4, 2024
143b92a
feat: change to help description of create command
hbraswelrh Dec 4, 2024
88da512
docs: added high level folder structure for cli
hbraswelrh Dec 6, 2024
553ad1d
docs: added high level folder structure for cli
hbraswelrh Dec 6, 2024
7711aec
fix: default value returned if no key in dictionary
hbraswelrh Dec 11, 2024
b3b8ebd
fix: default value returned if no key in dictionary
hbraswelrh Dec 11, 2024
826a8f5
feat: align skip-item option to skip-items
qduanmu Dec 13, 2024
5144e10
feat: align skip-item option to skip-items
qduanmu Dec 13, 2024
84c38ba
fix: add missing git options in create command
qduanmu Dec 16, 2024
06e574b
fix: add missing git options in create command
qduanmu Dec 16, 2024
ddff735
fix: refactor testt and remove prompts
gvauter Dec 17, 2024
6e28c41
fix: refactor testt and remove prompts
gvauter Dec 17, 2024
e47dca5
fix: formatting issues and typos
gvauter Dec 17, 2024
f125d5f
fix: formatting issues and typos
gvauter Dec 17, 2024
fd2f738
chore: merge latest from main and fix conflicts
gvauter Dec 17, 2024
3b95d76
chore: merge latest from main and fix conflicts
gvauter Dec 17, 2024
954d38a
chore: update poetry lock with latest dependencies
gvauter Dec 17, 2024
586bfca
chore: update poetry lock with latest dependencies
gvauter Dec 17, 2024
1f6f6c6
fix: do not overwrite config path if set
gvauter Dec 17, 2024
ceb084c
fix: do not overwrite config path if set
gvauter Dec 17, 2024
769d0df
fix: do not overwrite config path if set
gvauter Dec 17, 2024
18eaf09
fix: do not overwrite config path if set
gvauter Dec 17, 2024
32a4132
Merge branch '295-monorepo-directory-structure-design-proposal' of gi…
gvauter Dec 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ flake8-print = "^5.0.0"
pre-commit = "^3.4.0"
mkdocs-material = "^9.5.43"
markdown-include = "^0.8.1"
types-pyyaml = "^6.0.12.20240917"

[tool.poetry.group.tests]
optional = true
Expand Down
90 changes: 90 additions & 0 deletions trestlebot/cli/base.py
qduanmu marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import argparse
import logging
from typing import List

from trestlebot.bot import TrestleBot
from trestlebot.cli.options.common import handle_exceptions
from trestlebot.tasks.assemble_task import AssembleTask
from trestlebot.tasks.authored import types
from trestlebot.tasks.authored.base_authored import AuthoredObjectBase
from trestlebot.tasks.base_task import ModelFilter, TaskBase
from trestlebot.tasks.regenerate_task import RegenerateTask


logger = logging.getLogger(__name__)


def comma_sep_to_list(string: str) -> List[str]:
"""Convert comma-sep string to list of strings and strip."""
string = string.strip() if string else ""
return list(map(str.strip, string.split(","))) if string else []


def run_base(args: argparse.Namespace, pre_tasks: List[TaskBase]) -> None:
qduanmu marked this conversation as resolved.
Show resolved Hide resolved
"""Reusable logic for all commands."""
# from trestlebot.reporter import BotResults, ResultsReporter
# git_provider: Optional[GitProvider] = self.set_git_provider(args)
# results_reporter: ResultsReporter = self.set_reporter()

# Configure and run the bot
bot = TrestleBot(
working_dir=args.working_dir,
branch=args.branch,
commit_name=args.committer_name,
commit_email=args.committer_email,
author_name=args.author_name,
author_email=args.author_email,
# target_branch=args.target_branch,
)
# results: BotResults = bot.run(
bot.run(
pre_tasks=pre_tasks,
patterns=comma_sep_to_list(args.patterns),
commit_message=args.commit_message,
# git_provider=git_provider,
# pull_request_title=args.pull_request_title,
dry_run=args.dry_run,
)

# # Report the results
# results_reporter.report_results(results)


@handle_exceptions
def run(oscal_model: str, args: argparse.Namespace, ssp_index_path: str = "") -> None:
"""Run the autosync for oscal model."""

pre_tasks: List[TaskBase] = []
# Allow any model to be skipped from the args, by default include all
model_filter: ModelFilter = ModelFilter(
skip_patterns=comma_sep_to_list(args.skip_items),
include_patterns=["*"],
)
authored_object: AuthoredObjectBase = types.get_authored_object(
oscal_model, args.working_dir, ssp_index_path
)

# Assuming an edit has occurred assemble would be run before regenerate.
# Adding this to the list first
if not args.skip_assemble:
assemble_task: AssembleTask = AssembleTask(
authored_object=authored_object,
markdown_dir=args.markdown_path,
version=args.version,
model_filter=model_filter,
)
pre_tasks.append(assemble_task)
else:
logger.info("Assemble task skipped.")

if not args.skip_regenerate:
regenerate_task: RegenerateTask = RegenerateTask(
authored_object=authored_object,
markdown_dir=args.markdown_path,
model_filter=model_filter,
)
pre_tasks.append(regenerate_task)
else:
logger.info("Regeneration task skipped.")

run_base(args, pre_tasks)
155 changes: 155 additions & 0 deletions trestlebot/cli/commands/autosync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
""" Autosync command"""

import argparse

import click

from trestlebot.cli.base import comma_sep_to_list, run
from trestlebot.cli.options.common import git_options


@click.group(name="autosync", help="Autosync operations")
qduanmu marked this conversation as resolved.
Show resolved Hide resolved
@click.option(
"--working-dir",
qduanmu marked this conversation as resolved.
Show resolved Hide resolved
help="Working directory wit git repository",
type=click.Path(exists=True),
)
@click.option(
"--dry-run",
help="Run tasks, but do not push to the repository",
is_flag=True,
)
@click.option(
"--markdown-path",
help="Path to Trestle markdown files",
type=click.Path(exists=True), # Should it exist?
)
@click.option(
"--skip-items",
help="Comma-separated list of glob patterns to skip when running tasks",
type=str, # What's the type?
)
@click.option(
"--skip-assemble",
help="Skip assembly task",
is_flag=True,
default=False,
show_default=True,
)
@click.option(
"--skip-regenerate",
help="Skip regenerate task",
is_flag=True,
default=False,
show_default=True,
)
@click.option(
"--version",
help="Version of the OSCAL model to set during assembly into JSON",
type=str,
)
@git_options
@click.pass_context
def autosync_cmd(
ctx: click.Context,
working_dir: str,
markdown_path: str,
dry_run: bool,
skip_items: str,
skip_assemble: bool,
skip_regenerate: bool,
file_patterns: str,
branch: str,
commit_message: str,
committer_name: str,
committer_email: str,
author_name: str,
author_email: str,
version: str,
) -> None:
"""Command to autosync catalog, profile, compdef and ssp."""

need_to_prompt = any(
(
not working_dir,
not markdown_path,
not branch,
not committer_email,
not committer_name,
)
)
if need_to_prompt:
click.echo("\n* Welcome to the Trestle-bot CLI *\n")
click.echo("Please provide the following values to start autosync operations.")
if not working_dir:
working_dir = click.prompt(
"Enter path to working directory wit git repository",
default=".",
type=click.Path(exists=True),
)
if not markdown_path:
markdown_path = click.prompt(
"Enter path to to Trestle markdown files",
type=click.Path(exists=True),
)
if not branch:
branch = click.prompt(
"Enter branch name to push changes to",
)
if not committer_email:
committer_email = click.prompt(
"Enter email for committer",
)
if not committer_name:
committer_name = click.prompt(
"Enter name of committer",
)

ctx.trestle_args = argparse.Namespace(
working_dir=working_dir,
markdown_path=markdown_path,
skip_items=skip_items,
skip_assemble=skip_assemble,
skip_regenerate=skip_regenerate,
version=version,
patterns=comma_sep_to_list(file_patterns),
branch=branch,
commit_message=commit_message,
committer_name=committer_name,
committer_email=committer_email,
author_name=author_name,
author_email=author_email,
# target_branch=target_branch,
# pull_request_title=pull_request_title,
dry_run=dry_run,
)


@autosync_cmd.command("ssp")
@click.pass_context
@click.option("--ssp-index-path", help="Path to ssp index file", type=click.File("r"))
def autosync_ssp_cmd(ctx: click.Context, ssp_index_path: str) -> None:
if not ssp_index_path:
ssp_index_path = click.prompt(
"Enter path to ssp index file",
type=click.Path(exists=True),
)
run("ssp", ctx.parent.trestle_args, ssp_index_path)


@autosync_cmd.command("compdef")
@click.pass_context
def autosync_compdef_cmd(ctx: click.Context) -> None:
run("compdef", ctx.parent.trestle_args)


@autosync_cmd.command("catalog")
@click.pass_context
def autosync_catalog_cmd(ctx: click.Context) -> None:
run("catalog", ctx.parent.trestle_args)


@autosync_cmd.command("profile")
@click.pass_context
def autosync_profile_cmd(ctx: click.Context) -> None:
run("profile", ctx.parent.trestle_args)
Loading