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

Create a script to collect all bufmod TODOs #2708

Merged
merged 5 commits into from
Jan 18, 2024
Merged
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
4 changes: 4 additions & 0 deletions make/buf/all.mk
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,7 @@ endif
$(SED_I) "s/golang:1\.[0-9][0-9]*\.[0-9][0-9]*/golang:$(GOVERSION)/g" $(shell git-ls-files-unstaged | grep Dockerfile)
$(SED_I) "s/golang:1\.[0-9][0-9]*\.[0-9][0-9]*/golang:$(GOVERSION)/g" $(shell git-ls-files-unstaged | grep \.mk$)
$(SED_I) "s/go-version: 1\.[0-9][0-9]*\.[0-9][0-9]*/go-version: $(GOVERSION)/g" $(shell git-ls-files-unstaged | grep \.github\/workflows | grep -v previous.yaml)

.PHONY: newtodos
newtodos:
bash make/buf/scripts/newtodos.bash
32 changes: 32 additions & 0 deletions make/buf/scripts/newtodos.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

set -eo pipefail

DIR="$(CDPATH= cd "$(dirname "${0}")/../../.." && pwd)"
cd "${DIR}"

if [ -z "${BASE_BRANCH}" ]; then
BASE_BRANCH="main"
fi

TODOS="$(git diff "${BASE_BRANCH}" | awk '
/^diff / {f="?"; next}
f=="?" {if (/^\+\+\+ /) f=substr($0, 7)"\n"; next}
/^@@/ {n=$3; sub(/,.*/,"",n); n=0+$3; next}
/^\+.*TODO/ {print f n ":" substr($0,2); f=""}
substr($0,1,1)~/[ +]/ {n++}')"

FILENAME=""
while read -r line; do
if [[ "${line}" =~ [a-z,A-Z,0-9]+\.[a-z]{2,3}$ ]]; then
FILENAME="${line}"
elif [[ "${line}" == *"make/buf/scripts/newtodos.bash"* ]]; then
FILENAME="no print"
else
if [[ "${FILENAME}" != "no print" ]]; then
LINENUMBER="${line%%:*}"
TODO="${line#*:}"
echo "${FILENAME}":"${LINENUMBER}":"${TODO#"${TODO%%[![:space:]]*}"}"
fi
fi
done <<< "${TODOS}"
Loading