Commit 91a98580 authored by clabby's avatar clabby

Improvements

parent 2ebb928a
#!/bin/bash #!/bin/bash
set -uo pipefail
# Flags
FAIL_INVALID_FMT=false
VERBOSE=false
# Github API access token (Optional - necessary for private repositories.) # Github API access token (Optional - necessary for private repositories.)
TOKEN="" GH_API_TOKEN=""
if [[ $TOKEN != "" ]]; then AUTH=""
if [[ $GH_API_TOKEN != "" ]]; then
AUTH="Authorization: token $TOKEN" AUTH="Authorization: token $TOKEN"
fi fi
...@@ -25,11 +32,10 @@ CYAN='\033[0;36m' ...@@ -25,11 +32,10 @@ CYAN='\033[0;36m'
PURPLE='\033[0;35m' PURPLE='\033[0;35m'
NC='\033[0m' # No Color NC='\033[0m' # No Color
# Toggle strict mode; Will fail if any TODOs are found that don't match the expected # Parse flags
# formats: #
# * TODO(<issue_number>): <description> (Default org & repo: "ethereum-optimism/client-pod") # `--strict`: Toggle strict mode; Will fail if any TODOs are found that don't match the expected
# * TODO(repo#<issue_number>): <description> (Default org "ethereum-optimism") # `--verbose`: Toggle verbose mode; Will print out details about each TODO
# * TODO(org/repo#<issue_number>): <description>
for arg in "$@"; do for arg in "$@"; do
case $arg in case $arg in
--strict) --strict)
...@@ -44,14 +50,21 @@ for arg in "$@"; do ...@@ -44,14 +50,21 @@ for arg in "$@"; do
done done
# Use ripgrep to search for the pattern in all files within the repo # Use ripgrep to search for the pattern in all files within the repo
todos=$(rg -o --no-filename --no-line-number -g '!ops/scripts/todo-checker.sh' 'TODO\(([^)]+)\): [^,;]*') todos=$(rg -o --with-filename -n -g '!ops/scripts/todo-checker.sh' 'TODO\(([^)]+)\): [^,;]*')
# Check each TODO comment in the repo # Check each TODO comment in the repo
IFS=$'\n' # Set Internal Field Separator to newline for iteration IFS=$'\n' # Set Internal Field Separator to newline for iteration
for todo in $todos; do for todo in $todos; do
# Extract the text inside the parenthesis # Extract the text inside the parenthesis
FILE=$(echo $todo | awk -F':' '{print $1}')
LINE_NUM=$(echo $todo | awk -F':' '{print $2}')
ISSUE_REFERENCE=$(echo $todo | sed -n 's/.*TODO(\([^)]*\)).*/\1/p') ISSUE_REFERENCE=$(echo $todo | sed -n 's/.*TODO(\([^)]*\)).*/\1/p')
# Parse the format of the TODO comment. There are 3 supported formats:
# * TODO(<issue_number>): <description> (Default org & repo: "ethereum-optimism/client-pod")
# * TODO(repo#<issue_number>): <description> (Default org "ethereum-optimism")
# * TODO(org/repo#<issue_number>): <description>
#
# Check if it's just a number # Check if it's just a number
if [[ $ISSUE_REFERENCE =~ ^[0-9]+$ ]]; then if [[ $ISSUE_REFERENCE =~ ^[0-9]+$ ]]; then
REPO_FULL="$ORG/$REPO" REPO_FULL="$ORG/$REPO"
...@@ -65,9 +78,9 @@ for todo in $todos; do ...@@ -65,9 +78,9 @@ for todo in $todos; do
REPO_FULL="$ORG/${BASH_REMATCH[1]}" REPO_FULL="$ORG/${BASH_REMATCH[1]}"
ISSUE_NUM="${BASH_REMATCH[2]}" ISSUE_NUM="${BASH_REMATCH[2]}"
else else
if [[ $FAIL_INVALID_FMT || $VERBOSE ]]; then if $FAIL_INVALID_FMT || $VERBOSE; then
echo -e "$YELLOW[Warning]:$NC Invalid TODO format: $todo" echo -e "${YELLOW}[Warning]:${NC} Invalid TODO format: $todo"
if [[ $FAIL_INVALID_FMT ]]; then if $FAIL_INVALID_FMT; then
exit 1 exit 1
fi fi
fi fi
...@@ -76,12 +89,13 @@ for todo in $todos; do ...@@ -76,12 +89,13 @@ for todo in $todos; do
fi fi
# Use GitHub API to fetch issue details # Use GitHub API to fetch issue details
RESPONSE=$(curl -sL -H "$AUTH" --request GET "https://api.github.com/repos/$REPO_FULL/issues/$ISSUE_NUM") GH_URL_PATH="$REPO_FULL/issues/$ISSUE_NUM"
RESPONSE=$(curl -sL -H "$AUTH" --request GET "https://api.github.com/repos/$GH_URL_PATH")
# Check if issue was found # Check if issue was found
if echo "$RESPONSE" | rg -q "Not Found"; then if echo "$RESPONSE" | rg -q "Not Found"; then
if [[ $VERBOSE ]]; then if [[ $VERBOSE ]]; then
echo -e "$YELLOW[Warning]:$NC Issue not found: $RED$REPO_FULL/$ISSUE_NUM$NC" echo -e "${YELLOW}[Warning]:${NC} Issue not found: ${RED}$REPO_FULL/$ISSUE_NUM${NC}"
fi fi
((NOT_FOUND_COUNT++)) ((NOT_FOUND_COUNT++))
continue continue
...@@ -91,30 +105,44 @@ for todo in $todos; do ...@@ -91,30 +105,44 @@ for todo in $todos; do
STATE=$(echo "$RESPONSE" | jq -r .state) STATE=$(echo "$RESPONSE" | jq -r .state)
if [[ "$STATE" == "closed" ]]; then if [[ "$STATE" == "closed" ]]; then
echo -e "$RED[Error]:$NC Issue #$issue_num is closed. Please remove the TODO: $todo" echo -e "${RED}[Error]:${NC} Issue #$ISSUE_NUM is closed. Please remove the TODO in ${GREEN}$FILE:$LINE_NUM${NC} referencing ${YELLOW}$ISSUE_REFERENCE${NC} (${CYAN}https://github.com/$GH_URL_PATH${NC})"
exit 1 exit 1
fi fi
((OPEN_COUNT++)) ((OPEN_COUNT++))
TITLE=$(echo "$RESPONSE" | jq -r .title) TITLE=$(echo "$RESPONSE" | jq -r .title)
OPEN_ISSUES+=("$REPO_FULL/issues/$ISSUE_NUM|$TITLE") OPEN_ISSUES+=("$REPO_FULL/issues/$ISSUE_NUM|$TITLE|$FILE:$LINE_NUM")
done done
# Print summary # Print summary
if [[ $NOT_FOUND_COUNT -gt 0 ]]; then if [[ $NOT_FOUND_COUNT -gt 0 ]]; then
echo -e "$YELLOW[Warning]:$NC $NOT_FOUND_COUNT TODOs referred to issues that were not found." echo -e "${YELLOW}[Warning]:${NC} ${CYAN}$NOT_FOUND_COUNT${NC} TODOs referred to issues that were not found."
fi fi
if [[ $MISMATCH_COUNT -gt 0 ]]; then if [[ $MISMATCH_COUNT -gt 0 ]]; then
echo -e "$YELLOW[Warning]:$NC $MISMATCH_COUNT TODOs did not match the expected pattern." echo -e "${YELLOW}[Warning]:${NC} ${CYAN}$MISMATCH_COUNT${NC} TODOs did not match the expected pattern. Run with ${RED}\`--verbose\`${NC} to show details."
fi fi
if [[ $OPEN_COUNT -gt 0 ]]; then if [[ $OPEN_COUNT -gt 0 ]]; then
echo -e "$GREEN[Info]:$NC $OPEN_COUNT TODOs refer to issues that are still open." echo -e "${GREEN}[Info]:${NC} ${CYAN}$OPEN_COUNT${NC} TODOs refer to issues that are still open."
echo -e "$GREEN[Info]:$NC Open issue details:" echo -e "${GREEN}[Info]:${NC} Open issue details:"
printf "\n${PURPLE}%-59s${NC} ${GREY}|${NC} ${GREEN}%-75s${NC}\n" "Repository & Issue" "Title" printf "\n${PURPLE}%-50s${NC} ${GREY}|${NC} ${GREEN}%-55s${NC} ${GREY}|${NC} ${YELLOW}%-30s${NC}\n" "Repository & Issue" "Title" "Location"
echo -e "$GREY------------------------------------------------------------+---------------------------------------------------------------------------$NC" echo -e "$GREY$(printf '%0.s-' {1..51})+$(printf '%0.s-' {1..57})+$(printf '%0.s-' {1..31})$NC"
for issue in "${OPEN_ISSUES[@]}"; do for issue in "${OPEN_ISSUES[@]}"; do
REPO_ISSUE="${issue%|*}" REPO_ISSUE="https://github.com/${issue%%|*}" # up to the first |
TITLE="${issue#*|}" REMAINING="${issue#*|}" # after the first |
printf "${CYAN}%-59s${NC} ${GREY}|${NC} %-75s\n" "https://github.com/$REPO_ISSUE" "$TITLE" TITLE="${REMAINING%%|*}" # up to the second |
LOC="${REMAINING#*|}" # after the second |
# Truncate if necessary
if [ ${#REPO_ISSUE} -gt 47 ]; then
REPO_ISSUE=$(printf "%.47s..." "$REPO_ISSUE")
fi
if [ ${#TITLE} -gt 47 ]; then
TITLE=$(printf "%.52s..." "$TITLE")
fi
if [ ${#LOC} -gt 27 ]; then
LOC=$(printf "%.24s..." "$LOC")
fi
printf "${CYAN}%-50s${NC} ${GREY}|${NC} %-55s ${GREY}|${NC} ${YELLOW}%-30s${NC}\n" "$REPO_ISSUE" "$TITLE" "$LOC"
done done
fi fi
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
"bindings": "nx bindings @eth-optimism/contracts-bedrock", "bindings": "nx bindings @eth-optimism/contracts-bedrock",
"build": "npx nx run-many --target=build", "build": "npx nx run-many --target=build",
"test": "npx nx run-many --target=test", "test": "npx nx run-many --target=test",
"issues": "./ops/scripts/todo-checker.sh",
"lint": "npx nx run-many --target=lint", "lint": "npx nx run-many --target=lint",
"test:coverage": "npx nx run-many --target=test:coverage", "test:coverage": "npx nx run-many --target=test:coverage",
"lint:ts:check": "npx nx run-many --target=lint:ts:check", "lint:ts:check": "npx nx run-many --target=lint:ts:check",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment