Skip to content

Commit

Permalink
Implementet gitops-model list
Browse files Browse the repository at this point in the history
  • Loading branch information
aho-dips committed Jan 23, 2024
1 parent cc7ecc0 commit 0b7a61f
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 60 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@

## Version 1.0.6
- Implementet gitops-model list

## Version 1.0.5
- Changed list function from commit-focus to version-focus

## Version 1.0.4
- Added init functiion with improvements.
- Improved help messages as well
Expand Down
105 changes: 105 additions & 0 deletions smud-cli/functions-gitops.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/usr/bin/env bash

show_gitops_changes()
{
printf "${white}List changes in Gitops model:${normal}\n"
has_changes_command="git log $git_range --max-count=1 --no-merges $git_grep $diff_filter --pretty=format:1 -- $devops_model_filter"
{
if [ "$git_range" ]; then
run_command has-gitops-changes --command-from-var=has_changes_command --return-in-var=has_changes --debug-title='Check if any changes on gitops-model'
fi
} ||
{
has_changes=""
}
if [ ! "$has_changes" ]; then
if [ ! "$is_smud_dev_repo" ] && [ ! "$installed_gitops" ]; then
printf "${gray}No gitops-model changes found.${normal}\n"
return
fi
fi

show_changelog_file "git"
list_gitops_files "git"
}

list_gitops_files()
{
from="$1"
if [ "$from" = "git" ]; then
context="Changed"
if [ "$git_range" ]; then
list_gitops_files_command="git --no-pager log $git_range --name-only --pretty= -- :$devops_model_filter|sort -u"
else
echo "No revisions available to fetch $context GitOps-model files!"
fi
else
context="Current"
list_gitops_files_command="git --no-pager ls-files -- $devops_model_filter"
fi

{
if [ "$list_gitops_files_command" ]; then
run_command list-gitops-files --command-var=list_gitops_files_command --return=changed_files --debug-title='Find all changed gitops-model files files'
fi
} ||
{
return
}

if [ "$changed_files" ]; then
echo "$context GitOps-model files:"
echo $changed_files
else
echo "No $context GitOps-model files found!"
fi

echo ""
}

show_changelog_file()
{
from="$1"
if [ "$from" = "git" ]; then
revisions=$git_range
if [ ! "$revisions" ]; then
echo "No revision"
return
fi
context="Latest"
show_changelog_commit_command="git rev-list $revisions -1 -- :CHANGELOG.md"
{
run_command --show_changelog_commit --command-var show_changelog_commit_command --return changelog_commit
if [ "$changelog_commit" ]; then
show_changelog_command="git show $changelog_commit:CHANGELOG.md"
fi
} || {
show_changelog_command=""
}
else
context="Current"
BASEDIR=$(dirname "$0")
file=$BASEDIR/CHANGELOG.md
if [ -f $file ]; then
show_changelog_command="cat $file"
fi
fi

if [ "$show_changelog_command" ]; then
run_command --show_changelog --command-var show_changelog_command --return changelog_content
fi

if [ "$changelog_content" ]; then
print "$context GitOps-model Changelog:"
echo $changelog_content
IFS=$'\n' read -rd '' -a changelog_commits <<< "$changelog_commits"

for commit in "${changelog_commits[@]}"
do
git show $commit:CHANGELOG.md --no-color
done
else
print "No $context GitOps-model Changelog found!"
fi
echo ""
}
2 changes: 1 addition & 1 deletion smud-cli/functions-list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ list()
fi

if [ ! "$product" ] && [ ! "$installed" ]; then
show_gitopd_changes
show_gitops_changes
return
fi

Expand Down
38 changes: 11 additions & 27 deletions smud-cli/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,41 +114,25 @@ show_date_help()
echo " --$s='1 week ago|5 days ago|1 year ago'"
}

show_gitopd_changes()
show_gitops_changes()
{
printf "${white}List changes in Gitops model:${normal}\n"
filter=":applicationsets-staged gitops-engine/argo environments/templates CHANGELOG.md"
has_changes_command="git log $git_range --max-count=1 --no-merges $git_grep $diff_filter --pretty=format:\"%H\" -- $filter"
has_changes_command="git log $git_range --max-count=1 --no-merges $git_grep $diff_filter --pretty=format:1 -- $devops_model_filter"
{
if [ "$git_range" ]; then
run_command has-gitops-changes --command-from-var=has_changes_command --return-in-var=has_changes --debug-title='Check if any changes on gitops-model'
fi
if [ ! "$has_changes" ]; then
if [ ! "$is_smud_dev_repo" ] && [ ! "$installed_gitops" ]; then
printf "${gray}No gitops-model changes found.${normal}\n"
return
fi
fi
} ||
{
return
}
filter=":CHANGELOG.md"
echo ""
changelog_command="git rev-list $git_range $git_grep --reverse $diff_filter -1 -- CHANGELOG.md"
{
if [ "$git_range" ]; then
run_command has-gitops-changelog --command-from-var=changelog_command --return-in-var=changelog_commits --debug-title='Check if any changes on gitops-model'
fi
} ||
{
return
has_changes=""
}
IFS=$'\n' read -rd '' -a changelog_commits <<< "$changelog_commits"
if [ ! "$has_changes" ]; then
if [ ! "$is_smud_dev_repo" ] && [ ! "$installed_gitops" ]; then
printf "${gray}No gitops-model changes found.${normal}\n"
return
fi
fi

for commit in "${changelog_commits[@]}"
do
git --no-pager show $commit:CHANGELOG.md --no-color --
done
return
show_changelog_file "git"
list_gitops_files "git"
}
42 changes: 10 additions & 32 deletions smud-cli/include.sh
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,10 @@ run_command()
declare -A run_command_args

parse_arguments run_command_args "$@"
get_arg command_from_var '--command-from-var,--command-var,-c-var' '' run_command_args
get_arg command_from_var '--command-var,--command-from-var,--command-in-var' '' run_command_args
get_arg debug_title '--debug-title,-dt' '' run_command_args
get_arg return_in_var '--return-in-var,-var' '' run_command_args
get_arg return_in_var '--return,--return-var,--return-in-var' '' run_command_args
get_arg skip_error '--skip-error' '' run_command_args

if [ "$command_from_var" ];then
local -n command=$command_from_var
Expand All @@ -247,46 +248,22 @@ run_command()
print_error "Missing 'command' parameter!"
return 1
fi
if [ "$debug_title" ]; then
if [ "$debug_title" ] && [ "$return_in_var" ]; then
print_debug "$debug_title:\n$command"
fi
{

run_command_result="$(sh -c "$command" 2>&1)"
} || {
print_error "$run_command_result"
if [ ! "$skip_error" ]; then
print_error "$run_command_result"
fi
return 1
}

if [ ! "$return_in_var" ];then
print_error "$run_command_result"
fi

}

can_run_git_log()
{
if [ "$can_do_git" ]; then
check="git ls-files GETTING_STARTED.md README.md gitops-engine/argo/Chart.yaml environments/environments.example.yaml"
if [ "$check" ]; then
echo "$can_do_git"
fi
echo "$run_command_result"
fi

}

get_changelog_file()
{
BASEDIR=$(dirname "$0")
file=$BASEDIR/CHANGELOG.md

if [ ! -f $file ]; then
BASEDIR=$(dirname "$BASEDIR")
file=$BASEDIR/CHANGELOG.md
fi
if [ -f $file ]; then
echo "$file"
fi
}

parse_arguments ARGS $@
Expand Down Expand Up @@ -315,6 +292,7 @@ get_arg to_date '--to-date,-TD'
get_arg grep '--grep'
get_arg no_progress '--no-progress' "$silent"
get_arg skip_files '--skip-files'
get_arg files '--files'

get_arg development '--development,-D,-DEV'
get_arg external_test '--external-test,-ET'
Expand Down Expand Up @@ -475,7 +453,7 @@ else
fi
filter_=$filter
filter=":$filter"

devops_model_filter="GETTING_STARTED.md CHANGELOG.md applicationsets-staged/* environments/* gitops-engine/* repositories/*"
diff_filter=''

if [ $debug ];then
Expand Down
1 change: 1 addition & 0 deletions smud-cli/smud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
. $(dirname "$0")/functions.sh
. $(dirname "$0")/functions-list.sh
. $(dirname "$0")/functions-upgrade.sh
. $(dirname "$0")/functions-gitops.sh
. $(dirname "$0")/functions-init.sh

command=$1
Expand Down

0 comments on commit 0b7a61f

Please sign in to comment.