Commit 72e5dc99 authored by clabby's avatar clabby

Update to use CI PAT token

parent 95cf06ba
...@@ -7,10 +7,10 @@ FAIL_INVALID_FMT=false ...@@ -7,10 +7,10 @@ FAIL_INVALID_FMT=false
VERBOSE=false VERBOSE=false
# Github API access token (Optional - necessary for private repositories.) # Github API access token (Optional - necessary for private repositories.)
GH_API_TOKEN="" GH_API_TOKEN="${CI_TODO_CHECKER_PAT:-""}"
AUTH="" AUTH=""
if [[ $GH_API_TOKEN != "" ]]; then if [[ $GH_API_TOKEN != "" ]]; then
AUTH="Authorization: token $TOKEN" AUTH="Authorization: token $GH_API_TOKEN"
fi fi
# Default org and repo # Default org and repo
...@@ -49,128 +49,102 @@ for arg in "$@"; do ...@@ -49,128 +49,102 @@ for arg in "$@"; do
esac esac
done done
spinner() { # Use ripgrep to search for the pattern in all files within the repo
local pid=$1 todos=$(rg -o --with-filename -n -g '!ops/scripts/todo-checker.sh' 'TODO\(([^)]+)\): [^,;]*')
local delay=0.05
local spinstr='|/-\' # Check each TODO comment in the repo
echo -n "Loading TODOs... " IFS=$'\n' # Set Internal Field Separator to newline for iteration
while [ "$(ps a | awk '{print $1}' | rg $pid)" ]; do for todo in $todos; do
local temp=${spinstr#?} # Extract the text inside the parenthesis
printf " [${GREEN}%c${NC}] " "$spinstr" FILE=$(echo $todo | awk -F':' '{print $1}')
local spinstr=$temp${spinstr%"$temp"} LINE_NUM=$(echo $todo | awk -F':' '{print $2}')
sleep $delay ISSUE_REFERENCE=$(echo $todo | sed -n 's/.*TODO(\([^)]*\)).*/\1/p')
printf "\b\b\b\b\b\b"
done # Parse the format of the TODO comment. There are 3 supported formats:
} # * TODO(<issue_number>): <description> (Default org & repo: "ethereum-optimism/monorepo")
# * TODO(repo#<issue_number>): <description> (Default org "ethereum-optimism")
{ # * TODO(org/repo#<issue_number>): <description>
# Use ripgrep to search for the pattern in all files within the repo #
todos=$(rg -o --with-filename -n -g '!ops/scripts/todo-checker.sh' 'TODO\(([^)]+)\): [^,;]*') # Check if it's just a number
if [[ $ISSUE_REFERENCE =~ ^[0-9]+$ ]]; then
# Print a newline REPO_FULL="$ORG/$REPO"
echo "" ISSUE_NUM="$ISSUE_REFERENCE"
# Check for org_name/repo_name#number format
# Check each TODO comment in the repo elif [[ $ISSUE_REFERENCE =~ ^([^/]+)/([^#]+)#([0-9]+)$ ]]; then
IFS=$'\n' # Set Internal Field Separator to newline for iteration REPO_FULL="${BASH_REMATCH[1]}/${BASH_REMATCH[2]}"
for todo in $todos; do ISSUE_NUM="${BASH_REMATCH[3]}"
# Extract the text inside the parenthesis # Check for repo_name#number format
FILE=$(echo $todo | awk -F':' '{print $1}') elif [[ $ISSUE_REFERENCE =~ ^([^#]+)#([0-9]+)$ ]]; then
LINE_NUM=$(echo $todo | awk -F':' '{print $2}') REPO_FULL="$ORG/${BASH_REMATCH[1]}"
ISSUE_REFERENCE=$(echo $todo | sed -n 's/.*TODO(\([^)]*\)).*/\1/p') ISSUE_NUM="${BASH_REMATCH[2]}"
else
# Parse the format of the TODO comment. There are 3 supported formats: if $FAIL_INVALID_FMT || $VERBOSE; then
# * TODO(<issue_number>): <description> (Default org & repo: "ethereum-optimism/monorepo") echo -e "${YELLOW}[Warning]:${NC} Invalid TODO format: $todo"
# * TODO(repo#<issue_number>): <description> (Default org "ethereum-optimism") if $FAIL_INVALID_FMT; then
# * TODO(org/repo#<issue_number>): <description> exit 1
#
# Check if it's just a number
if [[ $ISSUE_REFERENCE =~ ^[0-9]+$ ]]; then
REPO_FULL="$ORG/$REPO"
ISSUE_NUM="$ISSUE_REFERENCE"
# Check for org_name/repo_name#number format
elif [[ $ISSUE_REFERENCE =~ ^([^/]+)/([^#]+)#([0-9]+)$ ]]; then
REPO_FULL="${BASH_REMATCH[1]}/${BASH_REMATCH[2]}"
ISSUE_NUM="${BASH_REMATCH[3]}"
# Check for repo_name#number format
elif [[ $ISSUE_REFERENCE =~ ^([^#]+)#([0-9]+)$ ]]; then
REPO_FULL="$ORG/${BASH_REMATCH[1]}"
ISSUE_NUM="${BASH_REMATCH[2]}"
else
if $FAIL_INVALID_FMT || $VERBOSE; then
echo -e "${YELLOW}[Warning]:${NC} Invalid TODO format: $todo"
if $FAIL_INVALID_FMT; then
exit 1
fi
fi
((MISMATCH_COUNT++))
continue
fi
# Use GitHub API to fetch issue details
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
if echo "$RESPONSE" | rg -q "Not Found"; then
if [[ $VERBOSE ]]; then
echo -e "${YELLOW}[Warning]:${NC} Issue not found: ${RED}$REPO_FULL/$ISSUE_NUM${NC}"
fi fi
((NOT_FOUND_COUNT++))
continue
fi fi
((MISMATCH_COUNT++))
continue
fi
# Check issue state # Use GitHub API to fetch issue details
STATE=$(echo "$RESPONSE" | jq -r .state) GH_URL_PATH="$REPO_FULL/issues/$ISSUE_NUM"
RESPONSE=$(curl -sL -H "$AUTH" --request GET "https://api.github.com/repos/$GH_URL_PATH")
if [[ "$STATE" == "closed" ]]; then # Check if issue was found
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})" if echo "$RESPONSE" | rg -q "Not Found"; then
exit 1 if [[ $VERBOSE ]]; then
echo -e "${YELLOW}[Warning]:${NC} Issue not found: ${RED}$REPO_FULL/$ISSUE_NUM${NC}"
fi fi
((NOT_FOUND_COUNT++))
continue
fi
((OPEN_COUNT++)) # Check issue state
TITLE=$(echo "$RESPONSE" | jq -r .title) STATE=$(echo "$RESPONSE" | jq -r .state)
OPEN_ISSUES+=("$REPO_FULL/issues/$ISSUE_NUM|$TITLE|$FILE:$LINE_NUM")
done
# Print summary if [[ "$STATE" == "closed" ]]; then
if [[ $NOT_FOUND_COUNT -gt 0 ]]; then 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})"
echo -e "${YELLOW}[Warning]:${NC} ${CYAN}$NOT_FOUND_COUNT${NC} TODOs referred to issues that were not found." exit 1
fi
if [[ $MISMATCH_COUNT -gt 0 ]]; then
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
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:"
printf "\n${PURPLE}%-50s${NC} ${GREY}|${NC} ${GREEN}%-55s${NC} ${GREY}|${NC} ${YELLOW}%-30s${NC}\n" "Repository & Issue" "Title" "Location"
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
REPO_ISSUE="https://github.com/${issue%%|*}" # up to the first |
REMAINING="${issue#*|}" # after the first |
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" ((OPEN_COUNT++))
done TITLE=$(echo "$RESPONSE" | jq -r .title)
fi OPEN_ISSUES+=("$REPO_FULL/issues/$ISSUE_NUM|$TITLE|$FILE:$LINE_NUM")
} & done
# Save the Process ID of the job you started in the background # Print summary
PID=$! if [[ $NOT_FOUND_COUNT -gt 0 ]]; then
echo -e "${YELLOW}[Warning]:${NC} ${CYAN}$NOT_FOUND_COUNT${NC} TODOs referred to issues that were not found."
fi
if [[ $MISMATCH_COUNT -gt 0 ]]; then
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
if [[ $OPEN_COUNT -gt 0 ]]; then
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:"
printf "\n${PURPLE}%-50s${NC} ${GREY}|${NC} ${GREEN}%-55s${NC} ${GREY}|${NC} ${YELLOW}%-30s${NC}\n" "Repository & Issue" "Title" "Location"
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
REPO_ISSUE="https://github.com/${issue%%|*}" # up to the first |
REMAINING="${issue#*|}" # after the first |
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
# Start the spinner with the background job's Process ID printf "${CYAN}%-50s${NC} ${GREY}|${NC} %-55s ${GREY}|${NC} ${YELLOW}%-30s${NC}\n" "$REPO_ISSUE" "$TITLE" "$LOC"
spinner $PID done
fi
# Wait for the background job to finish echo -e "${GREEN}[Info]:${NC} Done checking issues."
wait $PID
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