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

15 add function to set up precommit #92

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

oadetayo
Copy link
Contributor

@oadetayo oadetayo commented Feb 3, 2025

Brief overview of changes

This PR introduces pre-commit hook functionality to the dfeshiny package. It includes:

  • A new script R/pre_commit.R containing all pre-commit functions.
  • Corresponding test cases in testthat/test_precommit.R.

Why are these changes being made?

  • To ensure automated checks before committing code, improving code quality and consistency.
  • To prevent accidental commits of improperly formatted or untracked files.
  • To introduce structured validation steps, including data validation, analytics key checks, and code styling enforcement.

Detailed description of changes

1. Added pre_commit.R in R/ directory

  • pre_commit_innit(skip_analytics = FALSE)

    • Creates a Git pre-commit hook that runs commit_hooks().
    • Saves the hook in .git/hooks/pre-commit and makes it executable.
  • commit_hooks(skip_analytics = FALSE)

    • Runs a series of checks before commit:
      • data_checker(): Validates .gitignore and tracked files.
      • check_analytics_key(): Ensures no sensitive Google Analytics keys exist (can be skipped).
      • style_code(): Formats R code in the repository.

2. Added unit tests in testthat/test_precommit.R

  • Tests for pre_commit_innit():
    • Ensures the pre-commit hook is created and contains the correct script reference.
  • Tests for commit_hooks():
    • Ensures data validation, analytics checks, and styling enforcement function correctly.

Fixes #15.

@rmbielby rmbielby linked an issue Feb 3, 2025 that may be closed by this pull request
Copy link
Contributor

@rmbielby rmbielby left a comment

Choose a reason for hiding this comment

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

Looks nice, got a few revisions, mainly just to tweak the functionality a little.

@oadetayo oadetayo requested a review from rmbielby February 6, 2025 08:50
Copy link

codecov bot commented Feb 7, 2025

Codecov Report

Attention: Patch coverage is 5.00000% with 133 lines in your changes missing coverage. Please review.

Project coverage is 66.45%. Comparing base (5c3bad0) to head (7249bea).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #92      +/-   ##
==========================================
- Coverage   74.21%   66.45%   -7.76%     
==========================================
  Files          12       13       +1     
  Lines        1109     1249     +140     
==========================================
+ Hits          823      830       +7     
- Misses        286      419     +133     

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5c3bad0...7249bea. Read the comment docs.

Copy link
Contributor

@rmbielby rmbielby left a comment

Choose a reason for hiding this comment

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

Few extra things on this one.

@oadetayo oadetayo requested a review from rmbielby February 17, 2025 10:11
Copy link
Contributor

@rmbielby rmbielby left a comment

Choose a reason for hiding this comment

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

Few more ideas around the data file validation side.

@oadetayo oadetayo requested a review from rmbielby February 19, 2025 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add function to set up / update the commit hooks
2 participants