Skip to content

Commit

Permalink
disable git/gh ops if DEBUG env var is set
Browse files Browse the repository at this point in the history
  • Loading branch information
qododavid committed Jan 27, 2025
1 parent 8cddb2d commit 719f33f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 47 deletions.
45 changes: 25 additions & 20 deletions .github/actions/qodo-cover-pr/scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ REPORT_DIR="/tmp"
REPORT_PATH="$REPORT_DIR/report.txt"
MODIFIED_FILES_JSON="/tmp/modified-files.json"

DEBUG=${DEBUG:-false}

while [[ "$#" -gt 0 ]]; do
case $1 in
--pr-number) PR_NUMBER="$2"; shift ;;
Expand Down Expand Up @@ -46,36 +48,39 @@ if [ "$PROJECT_LANGUAGE" == "python" ]; then
fi
fi

# Set up Git configuration
git config --global user.email "[email protected]"
git config --global user.name "Qodo Cover"

# Download cover-agent-pro if not already downloaded
if [ ! -f "$BINARY_PATH" ]; then
echo "Downloading cover-agent-pro ${ACTION_REF}..."
mkdir -p /tmp/bin
wget -q -P /tmp/bin "https://github.com/qodo-ai/qodo-ci/releases/download/${ACTION_REF}/cover-agent-pro" >/dev/null
chmod +x "$BINARY_PATH"
fi
# Skip git if in debug mode
if ["$DEBUG" = "false"]; then
# Set up Git configuration
git config --global user.email "[email protected]"
git config --global user.name "Qodo Cover"

# Checkout the PR branch
git fetch origin "$PR_REF"
git checkout "$PR_REF"
# Checkout the PR branch
git fetch origin "$PR_REF"
git checkout "$PR_REF"

# Get the repository root
REPO_ROOT=$(git rev-parse --show-toplevel)
# Get the repository root
REPO_ROOT=$(git rev-parse --show-toplevel)

# Generate the modified files JSON using gh pr view, including only added or modified files
echo "Generating modified files list..."
gh pr view "$PR_NUMBER" --json files --jq '.files[].path' | \
jq -R -s 'split("\n")[:-1] | map("'"$REPO_ROOT"'/" + .)' > "$MODIFIED_FILES_JSON"
# Generate the modified files JSON using gh pr view, including only added or modified files
echo "Generating modified files list..."
gh pr view "$PR_NUMBER" --json files --jq '.files[].path' | \
jq -R -s 'split("\n")[:-1] | map("'"$REPO_ROOT"'/" + .)' > "$MODIFIED_FILES_JSON"
fi

# Check if modified-files.json is empty
if [ ! -s "$MODIFIED_FILES_JSON" ]; then
echo "No added or modified files found in the PR. Exiting."
exit 0
fi

# Download cover-agent-pro if not already downloaded
if [ ! -f "$BINARY_PATH" ]; then
echo "Downloading cover-agent-pro ${ACTION_REF}..."
mkdir -p /tmp/bin
wget -q -P /tmp/bin "https://github.com/qodo-ai/qodo-ci/releases/download/${ACTION_REF}/cover-agent-pro" >/dev/null
chmod +x "$BINARY_PATH"
fi

# Run cover-agent-pro in pr mode with the provided arguments
"$BINARY_PATH" \
--mode "pr" \
Expand Down
63 changes: 36 additions & 27 deletions .github/actions/qodo-cover/scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ BINARY_PATH="/tmp/bin/cover-agent-pro"
REPORT_DIR="/tmp"
REPORT_PATH="$REPORT_DIR/report.txt"

DEBUG=${DEBUG:-false}

while [[ "$#" -gt 0 ]]; do
case $1 in
--branch) BRANCH="$2"; shift ;;
Expand Down Expand Up @@ -44,9 +46,16 @@ if [ "$PROJECT_LANGUAGE" == "python" ]; then
fi
fi

# Set up Git configuration
git config --global user.email "[email protected]"
git config --global user.name "Qodo Cover"
# Skip git if in debug mode
if ["$DEBUG" = "false"]; then
# Set up Git configuration
git config --global user.email "[email protected]"
git config --global user.name "Qodo Cover"

# Checkout the specified branch
git fetch origin
git checkout "$BRANCH"
fi

# Download cover-agent-pro if not already downloaded
if [ ! -f "$BINARY_PATH" ]; then
Expand All @@ -56,9 +65,6 @@ if [ ! -f "$BINARY_PATH" ]; then
chmod +x "$BINARY_PATH"
fi

# Checkout the specified branch
git fetch origin
git checkout "$BRANCH"

# Run cover-agent-pro
"$BINARY_PATH" \
Expand All @@ -73,27 +79,30 @@ git checkout "$BRANCH"
--run-each-test-separately "$RUN_EACH_TEST_SEPARATELY" \
--report-dir "$REPORT_DIR"

# If new changes
if [ -n "$(git status --porcelain)" ]; then
TIMESTAMP=$(date +%s)
BRANCH_NAME="qodo-ci-${BRANCH}-${TIMESTAMP}"
# Skip git if in debug mode
if ["$DEBUG" = "false"]; then
# If new changes
if [ -n "$(git status --porcelain)" ]; then
TIMESTAMP=$(date +%s)
BRANCH_NAME="qodo-ci-${BRANCH}-${TIMESTAMP}"

if [ ! -f "$REPORT_PATH" ]; then
echo "Error: Report file not found at $REPORT_PATH"
exit 1
fi
if [ ! -f "$REPORT_PATH" ]; then
echo "Error: Report file not found at $REPORT_PATH"
exit 1
fi

REPORT_TEXT=$(cat "$REPORT_PATH")
PR_BODY=$(jinja2 "$ACTION_PATH/templates/pr_body_template.j2" -D target_branch="$BRANCH" -D report="$REPORT_TEXT")

REPORT_TEXT=$(cat "$REPORT_PATH")
PR_BODY=$(jinja2 "$ACTION_PATH/templates/pr_body_template.j2" -D target_branch="$BRANCH" -D report="$REPORT_TEXT")

git checkout -b "$BRANCH_NAME"
git add .
git commit -m "add tests"
git push origin "$BRANCH_NAME"

gh pr create \
--base "$BRANCH" \
--head "$BRANCH_NAME" \
--title "Qodo Cover Update: ${TIMESTAMP}" \
--body "$PR_BODY"
git checkout -b "$BRANCH_NAME"
git add .
git commit -m "add tests"
git push origin "$BRANCH_NAME"

gh pr create \
--base "$BRANCH" \
--head "$BRANCH_NAME" \
--title "Qodo Cover Update: ${TIMESTAMP}" \
--body "$PR_BODY"
fi
fi

0 comments on commit 719f33f

Please sign in to comment.