Skip to content

Commit

Permalink
#93 polish fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Oct 4, 2023
1 parent 2560ba9 commit 3a5582c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions steps/polish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

11 changes: 10 additions & 1 deletion tests/steps/test-polish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 3a5582c

Please sign in to comment.