Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Pre-commit Error Handling #31

Draft
wants to merge 4 commits into
base: gh-pages
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ python-resize-image = "*"
[dev-packages]

[requires]
python_version = "3.5"
python_version = "3.10"
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from pathlib import Path
from resizeimage import resizeimage

raise Exception("Test")

# File constants
pat = r"[\n\r].*path:\s*([^\n\r]*)"
types = ('*.md', '*.markdown')
Expand Down
25 changes: 11 additions & 14 deletions utilities/pre-commit
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
----------------------------------------

ALRIGHT LISTEN UP HERE

Move this file into your .git/hooks/ directory, then remove this notice, up till and
including the horizontal line just above the shebang. This file even has the right
hook name already aren't I so kind

----------------------------------------
#!/bin/bash

# Pre-commit Git hook. This currently just calls utilities/optimize_thumbnail.py
# Pre-commit Git hook. This currently just calls utilities/optimise_thumbnail.py
# which makes a smaller copy of the header image for all articles.
# To use: run `cp utilities/pre-commit .git/hooks`
CYAN="\e[36m"
RED="\e[31m"
GREEN="\e[92m"
CLEAR="\e[39m"

# Run optimize_thumbnail.py and print out files that need to be thumbnailised to a
# Run optimise_thumbnail.py and print out files that need to be thumbnailised to a
# temporary file
# NOTE: This script runs through all articles. So if there are past articles without
# a thumbnail, a thumbnail will be created and the old article will be edited and
Expand All @@ -31,11 +24,15 @@ run_optimise_thumbnail_script() {
echo -e "${CYAN}Optimising thumbnails...${CLEAR}"
# Check if pipenv is a global or a user install in the your machine
if hash pipenv 2>/dev/null; then
pipenv run python3 "${root}/utilities/optimize_thumbnail.py" $root > $temp
pipenv run --three python3 "${root}/utilities/optimise_thumbnail.py" $root > $temp
else
python3 -m pipenv run python3 "${root}/utilities/optimize_thumbnail.py" \
python3 -m pipenv run --three "${root}/utilities/optimise_thumbnail.py" \
$root > $temp
fi
if [[ $? -gt 0 ]]; then
echo -e "${RED}There was a problem running the optimiser. Please try again.${CLEAR}"
exit 1
fi
echo -e "${GREEN}Thumbnail creation complete! Staging these new changes...\
${CLEAR}"
# Read each line from the temp file to stage the thumbnailised files to commit
Expand Down Expand Up @@ -66,4 +63,4 @@ if [[ ! -z $this_is_the_question ]]; then
echo $this_is_the_question
echo -e "${CYAN}Running thumbnail creation script...${CLEAR}"
run_optimise_thumbnail_script
fi
fi