Skip to content

Instantly share code, notes, and snippets.

@MauricioRobayo
Last active May 9, 2020 03:46
Show Gist options
  • Save MauricioRobayo/af148451f54283b1dff5e394782ea569 to your computer and use it in GitHub Desktop.
Save MauricioRobayo/af148451f54283b1dff5e394782ea569 to your computer and use it in GitHub Desktop.
Microverse code review workflow on steroids
cr_wf () {
user="$(echo $1 | sed 's|https://github.com/\([^/]*\)/\([^/]*\)/pull.*$|\1|')"
repo="$(echo $1 | sed 's|https://github.com/\([^/]*\)/\([^/]*\)/pull.*$|\2|')"
pull="$(echo $1 | sed 's|https://github.com/.*/pull/\([0-9]\+\).*$|\1|')"
workspace="/tmp/mv-tse-cr-${user}/${repo}"
api_pr="https://api.github.com/repos/${user}/${repo}/pulls/${pull}')"
branch="$(curl -s -H 'Accept: application/vnd.github.v3+json' "${api_pr}" | jq --raw-output '.head.ref')"
echo "USER=${user}"
echo "REPO=${repo}"
echo "PULL=${pull}"
echo "BRANCH=${branch}"
echo "WORKSPACE=${workspace}"
mkdir -vp "${workspace}"
cd "${workspace}" || exit
if git rev-parse --is-inside-work-tree > /dev/null 2>&1;then
git fetch --quiet origin "${branch}"
git checkout -- .
git clean -f
if [ "$(git rev-parse --abbrev-ref HEAD)" == "${branch}" ];then
git reset --hard "origin/${branch}"
else
# git branch "${branch}" FETCH_HEAD
git checkout -b "${branch}" FETCH_HEAD
fi
else
git clone --quiet --single-branch --branch "${branch}" "https://github.com/${user}/${repo}" .
fi
git log --oneline -1
git status --short
}
cr_css ()
{
properties=("padding" "margin" "height" "width" "flex-direction" "justify-content" "align-items");
for property in "${properties[@]}";
do
echo -n "$property: ";
grep --color=auto -i "$property" "$@" | wc -l;
done
}
cr_html ()
{
tags=("h1" "h2" "h3" "header" "nav" "main" "footer" "article" "section" "aside")
for html in *.html;
do
echo -n "$html => ";
if html5validator "$html" > /dev/null 2>&1; then
echo valid;
else
echo invalid;
fi;
for tag in "${tags[@]}";
do
echo " $tag => $(grep -ic "</$tag>" "$html")";
done;
echo;
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment