Skip to content

Commit

Permalink
Merge pull request #17 from epimorphics/spike/resolve-rubocop-warnings
Browse files Browse the repository at this point in the history
Task: Release v1.5.2
  • Loading branch information
jonrandahl authored Feb 17, 2025
2 parents 85ead27 + 6c3d279 commit 410b087
Show file tree
Hide file tree
Showing 11 changed files with 283 additions and 130 deletions.
52 changes: 52 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh
# caveat: this script assumes all modifications to a file were staged in the commit
# beware if you are in the habit of committing only partial modifications to a file:
# THIS HOOK WILL ADD ALL MODIFICATIONS TO A FILE TO THE COMMIT IF ANY FILE WAS CHANGED BY LINTING

list="issue spike task"

listRE="^($(printf '%s\n' "$list" | tr ' ' '|'))/"

BRANCH_NAME=$(git branch --show-current | grep -E "$listRE" | sed 's/* //')

printf '\n\033[0;105mChecking "%s"... \033[0m\n', "$BRANCH_NAME"

if echo "$BRANCH_NAME" | grep -q '^(rebase)|(production)*$'; then
printf '\n\033[0;32mNo checks necessary on "%s", pushing now... 🎉\033[0m\n', "$BRANCH_NAME"
exit 0
fi

RUBY_FILES="$(git diff --diff-filter=d --name-only --cached | grep -E '(Gemfile|Rakefile|\.(rb|rake|ru))$')"

PRE_STATUS="$(git status | wc -l)"

WORK_DONE=0

if [ -n "$RUBY_FILES" ]; then
printf '\nRunning Rubocop...'
for file in $RUBY_FILES; do
git show :"$file" | bundle exec rubocop -A --stdin "$file"
done
RUBOCOP_EXIT_CODE=$?
WORK_DONE=1
else
RUBOCOP_EXIT_CODE=0
fi

POST_STATUS="$(git status | wc -l)"

if [ ! $RUBOCOP_EXIT_CODE -eq 0 ]; then
git reset HEAD
printf '\n\033[0;31mLinting has unfixable errors; please fix and restage your commit. 😖\033[0m\n'
exit 1
fi

if [ "$PRE_STATUS" != "$POST_STATUS" ]; then
git add "$RUBY_FILES" "$ESLINT_FILES" "$PRETTIER_FILES"
fi

if [ $WORK_DONE -eq 1 ]; then
printf '\n\033[0;32mLinting completed successfully! 🎉\033[0m\n'
fi

exit 0
46 changes: 46 additions & 0 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh

list="issue spike task"

listRE="^($(printf '%s\n' "$list" | tr ' ' '|'))/"

BRANCH_NAME=$(git branch --show-current | grep -E "$listRE" | sed 's/* //')

printf '\n\033[0;105mChecking "%s"... \033[0m\n', "$BRANCH_NAME"

if echo "$BRANCH_NAME" | grep -q '^(rebase)|(production)*$'; then
printf '\n\033[0;32mNo checks necessary on "%s", pushing now... 🎉\033[0m\n', "$BRANCH_NAME"
exit 0
fi

# Check for existence of "new or modified" test files
TEST_FILES="$(git diff --diff-filter=ACDM --name-only --cached | grep -E '(./test/*)$')"
# Get all test files to run tests
RUBY_FILES="$(git ls-files | grep -i -E '(_test\.rb)$')"

WORK_DONE=0

if [ -z "$TEST_FILES" ]; then
printf 'There are no new tests created in "%s".\n', "$BRANCH_NAME"
printf '\n\033[0;31mContinuing without new tests... 😖\033[0m\n'
fi

if [ -n "$RUBY_FILES" ]; then
printf '\nRunning Unit Tests...'
make test
RUBY_TEST_EXIT_CODE=$?
WORK_DONE=1
else
RUBY_TEST_EXIT_CODE=0
fi

if [ ! $RUBY_TEST_EXIT_CODE -eq 0 ]; then
printf '\n\033[0;31mCannot push, tests are failing. Use --no-verify to force push. 😖\033[0m\n'
exit 1
fi

if [ $WORK_DONE = 1 ]; then
printf '\n\033[0;32mAll tests are green, pushing... 🎉\033[0m\n'
fi

exit 0
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ AllCops:
- db/**
NewCops: enable


Layout/LineLength:
Max: 100
IgnoredPatterns: ['^(\s*#)']
Exclude:
- test/**/*

Expand Down
21 changes: 19 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
# Changelog for DS API rubygem

## 1.5.2 - 2024-10-15

## 1.5.2 - 2025-02

- (Jon) Added pre-commit and pre-push hooks to prevent committing and pushing
code that does not pass the linting and testing checks.
- (Jon) Adjusted the styling and linting rules to ensure the codebase adheres to
the latest best practices.
- (Jon) Refactored test suite and fixed tests for the service class.
- (Jon) Added timing for API requests to log processing time.
- (Jon) Enhanced log messages with more detailed info about requests.
- (Jon) Updated methods to streamline error handling and logging.
- (Jon) Refactored connection creation to include retry logic.
- (Jon) Cleaned up method parameters for better readability.
- (Jon) Updated the `lib/data_services_api/service.rb` to include the `X-Request-Id`
header in the SAPINT requests to match the header received from the apps using
the gem.
- (Jon) Updated the `CHANGELOG.md` to include the new version changes
- (Jon) Updated the `lib/data_services_api/version.rb` to include the new version
number `1.5.2`.
- (Jon) Updated the `lib/data_services_api/service.rb` for ignorable Rubocop warnings.
- (Jon) Implemented the `.github/workflows/publish.yml` workflow to publish the
gem to the Epimorphics GitHub Package Registry.
- (Jon) Updated the `README.md` to include the new workflow and the `Makefile` to
Expand Down
16 changes: 15 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,18 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in data-api.gemspec
gemspec

gem 'simplecov', require: false
# Add development dependencies here though as they are not required to run the gem
group :development, :test do
gem 'bundler', '~> 2.4'
gem 'byebug', '~> 11.1.3'
gem 'excon', '~> 0.90.0'
gem 'json_expressions', '~> 0.9.0'
gem 'minitest', '~> 5.15.0'
gem 'minitest-rg', '~> 5.2.0'
gem 'minitest-vcr', '~> 1.4.0'
gem 'mocha', '~> 1.13.0'
gem 'rake', '~> 13.0.6'
gem 'rubocop', '~> 1.25.0'
gem 'simplecov', '~> 0.21.2', require: false
gem 'webmock', '~> 3.14.0'
end
18 changes: 3 additions & 15 deletions data_services_api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,7 @@ Gem::Specification.new do |spec|

spec.metadata['rubygems_mfa_required'] = 'true'

spec.add_runtime_dependency 'faraday_middleware', '~> 1.2.0'
spec.add_runtime_dependency 'json', '~> 2.6.1'
spec.add_runtime_dependency 'yajl-ruby', '~> 1.4.1'

spec.add_development_dependency 'bundler', '~> 2.4'
spec.add_development_dependency 'byebug', '~> 11.1.3'
spec.add_development_dependency 'excon', '~> 0.90.0'
spec.add_development_dependency 'json_expressions', '~> 0.9.0'
spec.add_development_dependency 'minitest', '~> 5.15.0'
spec.add_development_dependency 'minitest-rg', '~> 5.2.0'
spec.add_development_dependency 'minitest-vcr', '~> 1.4.0'
spec.add_development_dependency 'mocha', '~> 1.13.0'
spec.add_development_dependency 'rake', '~> 13.0.6'
spec.add_development_dependency 'rubocop', '~> 1.25.0'
spec.add_development_dependency 'webmock', '~> 3.14.0'
spec.add_dependency 'faraday_middleware', '~> 1.2.0'
spec.add_dependency 'json', '~> 2.6.1'
spec.add_dependency 'yajl-ruby', '~> 1.4.1'
end
Loading

0 comments on commit 410b087

Please sign in to comment.