Skip to content

Commit

Permalink
APPEALS-51866: Added CodeClimate CLI command to custom git actions (#…
Browse files Browse the repository at this point in the history
…22193)

* added command line option to run codeclimate locally

* added code climate option to clean-pr command

* created code climate command to run tests

* added code climate UI output for user.
  • Loading branch information
HunJerBAH authored Jul 17, 2024
1 parent c03619a commit 0e1e4c6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
26 changes: 24 additions & 2 deletions git-commands/git-clean-pr
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
CURRENT_DIR=$(pwd)

# determine if branch param was passed
if [ ! -z "$1" ]; then
if [ ! -z "$1" ] && [ "$1" != "with-codeclimate" ]; then
# get the list of files changed that are eligible for testing
jsxCommits=$(git diff --name-only "$1" | grep -E '.jsx$') # get the list of jsx files
jsCommits=$(git diff --name-only "$1" | grep -E '.js$') # get the list of js files
rbCommits=$(git diff --name-only "$1" | grep -E '.rb$') # get the list of ruby files
scssCommits=$(git diff --name-only "$1" | grep -E '.scss$') # get the list of scss files

allCommits=$(git diff --name-only "$1")
else
# else default to no branch comparison
# get the list of files changed that are eligible for testing
jsxCommits=$(git diff --name-only | grep -E '.jsx$') # get the list of jsx files
jsCommits=$(git diff --name-only | grep -E '.js$') # get the list of js files
rbCommits=$(git diff --name-only | grep -E '.rb$') # get the list of ruby files
scssCommits=$(git diff --name-only | grep -E '.scss$') # get the list of scss files
allCommits=$(git diff --name-only)
fi

# cycle through ruby suite of tests
Expand Down Expand Up @@ -87,4 +88,25 @@ if [[ ! -z "$jsxCommits" || ! -z "$jsCommits" ]]; then
echo "Relevant jest, lint, and prettier tests have been run"; echo "";
fi

# run code climate for all changed files
if [ "$1" == "with-codeclimate" ] || [ "$2" == "with-codeclimate" ]; then
docker pull codeclimate/codeclimate

docker run \
--interactive --tty --rm \
--env CODECLIMATE_CODE="$PWD" \
--volume "$PWD":/code \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume /tmp/cc:/tmp/cc \
codeclimate/codeclimate help

codeclimate engines:install

# analyze each of the commits
for commit in $allCommits; do
echo "running codeClimate CLI for $commit"
codeclimate analyze $commit
done
fi

echo "All tests relevant to current code changes have been run"
27 changes: 27 additions & 0 deletions git-commands/git-codeclimate
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
# git command to run codeclimate on in-flight code changes
# accepts a file path or will run codeclimate on the entire project
file=$1

docker pull codeclimate/codeclimate

docker run \
--interactive --tty --rm \
--env CODECLIMATE_CODE="$PWD" \
--volume "$PWD":/code \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume /tmp/cc:/tmp/cc \
codeclimate/codeclimate help

# install engines in .codeclimate.yml
codeclimate engines:install

# run tests for single file or entire project
if [ ! -z "$1" ]; then
# analyze changes on file
echo "running codeClimate CLI for $file"
codeclimate analyze $file
else
echo "running CodeClimate CLI for entire project"
codeclimate analyze
fi

0 comments on commit 0e1e4c6

Please sign in to comment.