From 3a5582c50c3e9d6514032e2c9980826ae3aed02d Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Wed, 4 Oct 2023 07:40:08 +0300 Subject: [PATCH] #93 polish fixed --- steps/polish.sh | 6 +++--- tests/steps/test-polish.sh | 11 ++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/steps/polish.sh b/steps/polish.sh index 28d807ec..ebea6efd 100755 --- a/steps/polish.sh +++ b/steps/polish.sh @@ -32,14 +32,14 @@ fi repos=$(find "${dir}" -maxdepth 2 -mindepth 2 -type d -exec realpath --relative-to="${dir}" {} \;) echo "${repos}" | while IFS= read -r repo; do if [ -z "${repo}" ]; then continue; fi - if grep -Fxq "${repo}" "${TARGET}/repositories.csv"; then + if grep "${repo}," "${TARGET}/repositories.csv"; then echo "Directory of ${repo} is already here" else rm -rf "${dir:?}/${repo}" echo "Directory of ${repo} is obsolete and was deleted" fi done -echo "All $(echo "${repos}" | wc -l | xargs) repo directories inside ${dir} look good" +echo "All $(echo "${repos}" | wc -l | xargs) repo directories inside ${dir} were checked" orgs=$(find "${dir}" -maxdepth 1 -mindepth 1 -type d -exec realpath --relative-to="${dir}" {} \;) echo "${orgs}" | while IFS= read -r org; do @@ -48,5 +48,5 @@ echo "${orgs}" | while IFS= read -r org; do echo "Organization ${org} is empty and was deleted" fi done -echo "All $(echo "${orgs}" | wc -l | xargs) org directories inside ${dir} look good" +echo "All $(echo "${orgs}" | wc -l | xargs) org directories inside ${dir} were checked" diff --git a/tests/steps/test-polish.sh b/tests/steps/test-polish.sh index 78a9ec35..355b5834 100755 --- a/tests/steps/test-polish.sh +++ b/tests/steps/test-polish.sh @@ -23,13 +23,22 @@ set -e set -o pipefail +echo -e 'repo,branch\nfoo/bar,master,44,55' > "${TARGET}/repositories.csv" +rm -rf "${TARGET}/github" +mkdir -p "${TARGET}/github/foo/bar" +msg=$("${LOCAL}/steps/polish.sh") +echo $msg +test -e "${TARGET}/github/foo/bar" +echo "${msg}" | grep -v "foo/bar is already here" >/dev/null +echo "👍🏻 A correct directory was not deleted" + touch "${TARGET}/repositories.csv" rm -rf "${TARGET}/github" mkdir -p "${TARGET}/github/foo/bar" msg=$("${LOCAL}/steps/polish.sh") echo "${msg}" | grep -v "foo/bar is obsolete and was deleted" >/dev/null echo "${msg}" | grep -v "All 1 repo directories" >/dev/null -echo "👍🏻 A more complex filtering ran smoothly" +echo "👍🏻 An obsolete directory was deleted" TARGET=${TARGET}/dir-is-absent msg=$("${LOCAL}/steps/polish.sh")