Skip to content

Commit

Permalink
chore: updates how entrypoint handles boolean flags
Browse files Browse the repository at this point in the history
Signed-off-by: Jennifer Power <[email protected]>
  • Loading branch information
jpower432 committed Jul 5, 2023
1 parent 1998031 commit 9cd4f19
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
46 changes: 30 additions & 16 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,36 @@ exec 3>&1

trap exec 3>&- EXIT

output=$(python3.8 -m trestlebot \
--markdown-path="${INPUT_MARKDOWN_PATH}" \
--oscal-model="${INPUT_OSCAL_MODEL}" \
--ssp-index-path="${INPUT_SSP_INDEX_PATH}" \
--commit-message="${INPUT_COMMIT_MESSAGE}" \
--branch="${INPUT_BRANCH}" \
--patterns="${INPUT_FILE_PATTERN}" \
--committer-name="${INPUT_COMMIT_USER_NAME}" \
--committer-email="${INPUT_COMMIT_USER_EMAIL}" \
--author-name="${INPUT_COMMIT_AUTHOR_NAME}" \
--author-email="${INPUT_COMMIT_AUTHOR_EMAIL}" \
--skip-assemble="${INPUT_SKIP_ASSEMBLE}" \
--skip-regenerate="${INPUT_SKIP_REGENERATE}" \
--check-only="${INPUT_CHECK_ONLY}" \
--skip-items="${INPUT_SKIP_ITEMS}" \
--working-dir="${INPUT_REPOSITORY}" | tee /dev/fd/3)

# Initialize the command variable
command="python3.8 -m trestlebot \
--markdown-path=${INPUT_MARKDOWN_PATH} \
--oscal-model=${INPUT_OSCAL_MODEL} \
--ssp-index-path=${INPUT_SSP_INDEX_PATH} \
--commit-message=${INPUT_COMMIT_MESSAGE} \
--branch=${INPUT_BRANCH} \
--patterns=${INPUT_FILE_PATTERN} \
--committer-name=${INPUT_COMMIT_USER_NAME} \
--committer-email=${INPUT_COMMIT_USER_EMAIL} \
--author-name=${INPUT_COMMIT_AUTHOR_NAME} \
--author-email=${INPUT_COMMIT_AUTHOR_EMAIL} \
--skip-items=${INPUT_SKIP_ITEMS} \
--working-dir=${INPUT_REPOSITORY}"

# Conditionally include flags
if [[ ${INPUT_SKIP_ASSEMBLE} == true ]]; then
command+=" --skip-assemble"
fi

if [[ ${INPUT_SKIP_REGENERATE} == true ]]; then
command+=" --skip-regenerate"
fi

if [[ ${INPUT_CHECK_ONLY} == true ]]; then
command+=" --check-only"
fi

output=$( eval "$command" | tee /dev/fd/3)

commit=$(echo "$output" | grep "Commit Hash:" | sed 's/.*: //')

Expand Down
2 changes: 1 addition & 1 deletion tests/trestlebot/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def test_run_check_only(tmp_repo: Tuple[str, Repo]) -> None:

with pytest.raises(
bot.RepoException,
match="Check only mode is enable and diff detected. Manual intervention on main is required.",
match="Check only mode is enabled and diff detected. Manual intervention on main is required.",
):
_ = bot.run(
working_dir=repo_path,
Expand Down
2 changes: 1 addition & 1 deletion trestlebot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def run(
if repo.is_dirty(untracked_files=True):
if check_only:
raise RepoException(
"Check only mode is enable and diff detected. "
"Check only mode is enabled and diff detected. "
f"Manual intervention on {branch} is required."
)

Expand Down
14 changes: 8 additions & 6 deletions trestlebot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,19 @@ def _parse_cli_arguments() -> argparse.Namespace:
parser.add_argument(
"--skip-assemble",
required=False,
type=bool,
default=False,
action="store_true",
help="Skip assembly task. Defaults to false",
)
parser.add_argument(
"--skip-regenerate",
required=False,
type=bool,
default=False,
action="store_true",
help="Skip regenerate task. Defaults to false.",
)
parser.add_argument(
"--check-only",
required=False,
type=bool,
default=False,
action="store_true",
help="Runs tasks and exits with an error if there is a diff",
)
parser.add_argument(
Expand Down Expand Up @@ -186,6 +183,8 @@ def run() -> None:
args.ssp_index_path,
)
pre_tasks.append(assemble_task)
else:
logging.info("Assemble task skipped")

if not args.skip_regenerate:
regenerate_task = RegenerateTask(
Expand All @@ -195,6 +194,8 @@ def run() -> None:
args.ssp_index_path,
)
pre_tasks.append(regenerate_task)
else:
logging.info("Regeneration task skipped")

exit_code: int = 0

Expand All @@ -211,6 +212,7 @@ def run() -> None:
author_email=args.author_email,
pre_tasks=pre_tasks,
patterns=args.patterns,
check_only=args.check_only,
)

# Print the full commit sha
Expand Down

0 comments on commit 9cd4f19

Please sign in to comment.