Created
November 28, 2024 14:49
-
-
Save tichopad/f34470f232f947a34e1989b842c8d9eb to your computer and use it in GitHub Desktop.
Lists all TODO/FIXME comments in the current Git branch compared to master
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Colors for output | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
YELLOW='\033[1;33m' | |
NC='\033[0m' # No Color | |
# Get the current branch name | |
current_branch=$(git rev-parse --abbrev-ref HEAD) | |
# Check if we're on a branch other than master | |
if [ "$current_branch" == "master" ]; then | |
echo -e "${RED}Error: You are currently on master branch${NC}" | |
exit 1 | |
fi | |
# Get list of changed files compared to master | |
changed_files=$(git diff --name-only master) | |
if [ -z "$changed_files" ]; then | |
echo -e "${YELLOW}No changed files found compared to master${NC}" | |
exit 0 | |
fi | |
echo -e "${GREEN}Searching for TODO/FIXME comments in changed files...${NC}\n" | |
found_items=0 | |
# Loop through each changed file | |
while IFS= read -r file; do | |
# Check if file exists (hasn't been deleted) | |
if [ -f "$file" ]; then | |
# Search for TODO/FIXME comments and store results | |
results=$(grep -Hin -E "TODO:|todo:|FIXME:|fixme:" "$file" || true) | |
if [ ! -z "$results" ]; then | |
echo -e "${GREEN}${file}:${NC}" | |
echo "$results" | while IFS= read -r line; do | |
echo " $line" | |
done | |
echo "" | |
found_items=1 | |
fi | |
fi | |
done <<< "$changed_files" | |
if [ $found_items -eq 0 ]; then | |
echo -e "${GREEN}No TODO/FIXME comments found in changed files${NC}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment