Skip to content
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
2 changes: 2 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-reco
default-jdk-headless \
# shellcheck — adapter finds it on PATH, skips the GitHub release download
shellcheck \
# ripgrep — gemini-cli prefers rg over the fallback GrepTool
ripgrep \
# Ruby runtime — rubocop, reek, brakeman, sqlint
ruby \
ruby-dev \
Expand Down
5 changes: 0 additions & 5 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,4 @@ fi
# Fix ownership of the tool-cache volume (mounted as root by Docker)
sudo chown -R node:node /home/node/.codacy 2>/dev/null || true

# Install Gemini extension from pre-baked local clone (--consent skips the prompt)
if [ -n "${GEMINI_API_KEY:-}" ]; then
gemini extensions install /opt/codacy-skills --consent 2>/dev/null || true
fi

exec "$@"
39 changes: 36 additions & 3 deletions docker/local-pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,42 @@ if [ -n "${ANTHROPIC_API_KEY:-}" ]; then

elif [ -n "${GEMINI_API_KEY:-}" ]; then
echo "==> Running configure-codacy-cloud with Gemini..."
echo "/configure-codacy-cloud" | gemini
SKILL_EXIT=$?
RUN_META=""
SKILL_MD="/opt/codacy-skills/skills/configure-codacy-cloud/SKILL.md"
if [[ ! -f "${SKILL_MD}" ]]; then
echo "ERROR: ${SKILL_MD} not found in the container" >&2
exit 1
fi
GEMINI_STREAM_FILE=$(mktemp)
RUN_STARTED_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ)

Comment on lines +58 to +60
gemini -y --skip-trust -m "${GEMINI_MODEL:-gemini-3-flash-preview}" -o stream-json \
-p "Execute the skill instructions provided above." < "${SKILL_MD}" \
| tee "${GEMINI_STREAM_FILE}" \
| jq --unbuffered -rj 'select(.type == "message" and .role == "assistant") | .content'
SKILL_EXIT=${PIPESTATUS[0]}
RUN_FINISHED_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ)
echo
Comment on lines +61 to +67

RUN_META=$(jq -rsc \
--arg startedAt "${RUN_STARTED_AT}" \
--arg finishedAt "${RUN_FINISHED_AT}" '
. as $events |
($events | map(select(.type == "init")) | first | .session_id // "") as $sessionId |
($events | map(select(.type == "init")) | first | .model // "unknown") as $model |
($events | map(select(.type == "result")) | last) as $result |
{
llm: "gemini",
model: $model,
startedAt: $startedAt,
finishedAt: $finishedAt,
tokensIn: ($result.stats.input_tokens // 0),
tokensOut: ($result.stats.output_tokens // 0),
durationMs: ($result.stats.duration_ms // 0),
costUsd: ((($result.stats.input_tokens // 0) * 0.50 + ($result.stats.output_tokens // 0) * 3.00) / 1000000),
Comment on lines +81 to +84

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the Gemini run fails or does not emit a result event, $result will be null. In jq, attempting to index a variable that is null directly (e.g., $result.stats) throws a Cannot index null with string "stats" error, which will cause this jq command to fail and print an error to stderr.

To prevent this, use the pipe operator to safely navigate the potentially null $result object (e.g., ($result | .stats.input_tokens // 0)).

Suggested change
tokensIn: ($result.stats.input_tokens // 0),
tokensOut: ($result.stats.output_tokens // 0),
durationMs: ($result.stats.duration_ms // 0),
costUsd: ((($result.stats.input_tokens // 0) * 0.50 + ($result.stats.output_tokens // 0) * 3.00) / 1000000),
tokensIn: ($result | .stats.input_tokens // 0),
tokensOut: ($result | .stats.output_tokens // 0),
durationMs: ($result | .stats.duration_ms // 0),
costUsd: (((($result | .stats.input_tokens // 0) * 0.50 + ($result | .stats.output_tokens // 0) * 3.00)) / 1000000),

sessionId: $sessionId
}
' "${GEMINI_STREAM_FILE}")
rm -f "${GEMINI_STREAM_FILE}"

else
echo "Error: neither ANTHROPIC_API_KEY nor GEMINI_API_KEY is set." >&2
Expand Down