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

Fix/setup #180

Merged
merged 2 commits into from
Sep 27, 2024
Merged

Fix/setup #180

merged 2 commits into from
Sep 27, 2024

Conversation

Paras-Wednesday
Copy link
Collaborator

@Paras-Wednesday Paras-Wednesday commented Sep 26, 2024

Ticket Link


Related Links


Description


  • fixes the Dockerfile
  • Setup issues
  • Linting errors

Steps to Reproduce / Test


Request


Response


Summary by CodeRabbit

  • New Features

    • Improved Docker build process for better caching and efficiency.
    • Added installation command for go-commitlinter to enhance commit message consistency.
  • Bug Fixes

    • Enhanced error message formatting across various components for improved clarity.
  • Documentation

    • Updated README.MD for better readability and clearer instructions.
  • Chores

    • Updated dependencies in go.mod for better compatibility and performance.
    • Modified import paths to reflect updated package versions.

Copy link

coderabbitai bot commented Sep 26, 2024

Walkthrough

The changes encompass updates to the Dockerfile for optimizing the build process of a Go application, modifications to the README for improved formatting, and adjustments to the go.mod file to specify versions of dependencies. Additionally, several test files have been updated to ensure consistent error message formatting and to replace the redis package with redigo. A new installation command for a commit linter has been added in a setup script, and the import path for the sqlboiler package has been updated.

Changes

Files Change Summary
Dockerfile Optimized build process by separating go.mod and go.sum file copying from application code and consolidating build commands into a single RUN command.
README.MD Formatting adjustments for readability, including removal of line breaks and standardization of code block formatting.
go.mod Updated Go version to 1.22.0, updated github.com/volatiletech/strmangle from v0.0.4 to v0.0.6, and removed github.com/volatiletech/sqlboiler v3.7.1+incompatible.
pkg/utl/rediscache/*.go Changed usage from redis to redigo in test files, updating function signatures and error message formatting for consistency.
pkg/utl/resultwrapper/*.go Modified error handling in multiple functions to format error messages consistently using fmt.Errorf("%s", ...).
pkg/utl/zaplog/zaplog_test.go Updated error message formatting in TestInitLogger to use fmt.Errorf("%s", ...).
resolver/auth_mutations.resolvers_test.go Updated error message formatting in various test cases to use fmt.Errorf("%s", ...).
scripts/setup-pre-commit.sh Added installation command for go-commitlinter and modified .git/hooks/commit-msg file.
tools.go Updated import path for sqlboiler from github.com/volatiletech/sqlboiler to github.com/volatiletech/sqlboiler/v4.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Git
    participant CI/CD
    participant Docker

    Developer->>Git: Commit changes
    Git->>CI/CD: Push changes
    CI/CD->>Docker: Build Docker image
    Docker->>Docker: Optimize build process
    Docker->>CI/CD: Return built image
    CI/CD->>Git: Notify success
Loading

🐰 "In the code, we hop and play,
With changes brightening our day.
Errors formatted, tests align,
Our build process now divine!
Commit linter, oh what a treat,
With every change, we bounce to our beat!" 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

This comment has been minimized.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (5)
scripts/setup-pre-commit.sh (3)

16-16: LGTM! Consider using the latest version.

The addition of go-commitlinter is a good practice for enforcing commit message conventions.

Consider using @latest instead of a specific version to ensure you always have the most up-to-date features and bug fixes. However, if version 0.1.0 is required for compatibility reasons, please disregard this suggestion.


Line range hint 18-20: Prevent duplicate entries in commit-msg hook

The current implementation appends "go-commitlinter" to the commit-msg hook file every time the script is run, which could lead to duplicate entries.

Consider modifying the script to check if the entry already exists before appending. Here's a suggested improvement:

- touch  .git/hooks/commit-msg
- echo "go-commitlinter" >> .git/hooks/commit-msg
+ if [ ! -f .git/hooks/commit-msg ] || ! grep -q "go-commitlinter" .git/hooks/commit-msg; then
+     echo "go-commitlinter" >> .git/hooks/commit-msg
+ fi
  chmod 755 .git/hooks/commit-msg

This change ensures that "go-commitlinter" is only added once to the commit-msg hook file.


Line range hint 21-26: Improve error handling for more accurate feedback

The current error checking might not accurately reflect the status of all commands in the script.

Consider using a trap to catch errors and provide more detailed feedback. Here's a suggested improvement:

 #!/usr/bin/env bash
 # Install pre-commit and required dependencies.
-set -e
+set -eo pipefail
+
+# Initialize error flag
+error_occurred=false
+
+# Trap function to handle errors
+trap 'error_occurred=true' ERR
+
+# Function to run a command and handle errors
+run_command() {
+    if ! "$@"; then
+        echo "Error occurred while running: $*"
+        error_occurred=true
+    fi
+}

 echo "--Installing pre-commit & dependencies---"
-brew install pre-commit
-brew install golangci-lint
-pre-commit install
-go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
+run_command brew install pre-commit
+run_command brew install golangci-lint
+run_command pre-commit install
+run_command go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
 # ... (apply run_command to other installation commands)

 if [ ! -f .git/hooks/commit-msg ] || ! grep -q "go-commitlinter" .git/hooks/commit-msg; then
-    echo "go-commitlinter" >> .git/hooks/commit-msg
+    run_command echo "go-commitlinter" >> .git/hooks/commit-msg
 fi
-chmod 755 .git/hooks/commit-msg
+run_command chmod 755 .git/hooks/commit-msg

-# shellcheck disable=SC2181
-if [ "$?" = "0" ]; then
+if [ "$error_occurred" = false ]; then
     echo "--- setup successful ---"
 else
     echo "--- setup failed ---"
+    exit 1
 fi

This change provides more granular error handling and gives a more accurate success/failure status for the entire script.

pkg/utl/rediscache/redis_test.go (1)

102-108: LGTM with a minor suggestion for error message

The function signature on line 102 has been correctly updated to use redigo.DialOption and redigo.Conn, maintaining consistency with the previous changes and ensuring compatibility with the redigo package.

The error message formatting on line 108 has been improved. However, since ErrMsgMarshal is likely a constant error message, we can simplify it further:

Consider simplifying the error message on line 108:

-					return nil, fmt.Errorf("%s", ErrMsgMarshal)
+					return nil, fmt.Errorf(ErrMsgMarshal)

This change removes the unnecessary string formatting while maintaining the same functionality.

pkg/utl/rediscache/service_test.go (1)

Line range hint 1-564: Overall LGTM with minor consistency improvements needed

The changes in this file significantly improve consistency and clarity:

  1. Successful migration from redis to redigo package.
  2. Consistent updates to function signatures using *gomonkey.Patches.
  3. Standardized error message formatting with fmt.Errorf.

To further enhance consistency:

  1. Update remaining ApplyFunc calls to gomonkey.ApplyFunc (lines 245 and 458).

These changes collectively improve the maintainability and readability of the test file.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2d0538b and 5aba242.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (11)
  • Dockerfile (2 hunks)
  • README.MD (8 hunks)
  • go.mod (2 hunks)
  • pkg/utl/rediscache/redis_test.go (3 hunks)
  • pkg/utl/rediscache/service_test.go (22 hunks)
  • pkg/utl/resultwrapper/error.go (3 hunks)
  • pkg/utl/resultwrapper/error_test.go (12 hunks)
  • pkg/utl/zaplog/zaplog_test.go (1 hunks)
  • resolver/auth_mutations.resolvers_test.go (15 hunks)
  • scripts/setup-pre-commit.sh (2 hunks)
  • tools.go (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • resolver/auth_mutations.resolvers_test.go
  • tools.go
🧰 Additional context used
📓 Learnings (1)
pkg/utl/zaplog/zaplog_test.go (1)
Learnt from: Paras-Wednesday
PR: wednesday-solutions/go-template#179
File: pkg/utl/zaplog/zaplog_test.go:134-134
Timestamp: 2024-09-26T12:32:34.297Z
Learning: Using `fmt.Errorf()` without format specifiers (e.g., `fmt.Errorf(ErrMsgProduction)`) will cause `golangci-lint` to fail in this repository, so we should use `fmt.Errorf("%s", ErrMsgProduction)` instead.
🪛 LanguageTool
README.MD

[style] ~97-~97: Consider shortening or rephrasing this to strengthen your wording.
Context: ... the using docker-compose everytime you make changes to it # Setting up database (postgres) -...

(MAKE_CHANGES)


[grammar] ~251-~251: Did you mean “be generated”?
Context: ...kg/api/api.go) ## Schema - Schema can generated or altered manually Take a look at t...

(WILL_BASED_ON)

🔇 Additional comments (35)
scripts/setup-pre-commit.sh (1)

Line range hint 1-26: Overall assessment: Good additions with room for improvement

The changes to this script, particularly the addition of go-commitlinter, are positive improvements to the project's setup process. They enhance the commit message quality control, which is crucial for maintaining a clean and informative git history.

However, there are a few areas where the script could be made more robust:

  1. Preventing duplicate entries in the commit-msg hook file.
  2. Improving error handling and providing more detailed feedback.
  3. Considering the use of the latest version for go-commitlinter.

Implementing the suggested changes will make the script more resilient and user-friendly. Great job on continuously improving the project setup!

Dockerfile (3)

5-9: Excellent optimization of dependency management!

The separation of go.mod and go.sum copying, followed by go mod download, is a best practice for Docker builds. This approach:

  1. Improves build caching for dependencies.
  2. Speeds up subsequent builds when only application code changes.
  3. Reduces build times in CI/CD pipelines.

Great job implementing this optimization!


11-12: Proper sequencing of project copy

Copying the entire project after dependency resolution is the correct approach. This ensures that changes to application code don't invalidate the dependency cache, maintaining the build optimization introduced earlier. The comment also clearly explains the purpose of this step, which aids in code maintainability.


Line range hint 1-62: Overall improvement in Dockerfile structure and efficiency

The changes made to this Dockerfile significantly improve the build process for the Go application:

  1. The new two-step copying process for dependencies optimizes caching and speeds up builds.
  2. Consolidating build commands reduces the number of layers in the final image.

These improvements align with Docker best practices and should result in faster, more efficient builds and smaller images. The only point of concern is the execution of the seeder during the build process, which has been addressed in a previous comment.

Great work on optimizing the Dockerfile! These changes will likely improve your development and deployment workflows.

pkg/utl/zaplog/zaplog_test.go (1)

134-134: Excellent modification to comply with linting rules!

This change correctly modifies the error formatting to use fmt.Errorf("%s", ErrMsgProduction) instead of fmt.Errorf(ErrMsgProduction). This adjustment ensures compatibility with golangci-lint rules and improves code quality.

The modification aligns with the project's coding standards and prevents potential linting errors. Great attention to detail!

pkg/utl/rediscache/redis_test.go (5)

40-42: LGTM: Correct update to use redigo package

The function signature has been correctly updated to use redigo.DialOption and redigo.Conn, which is consistent with the migration from the redis package to the redigo package. This change ensures compatibility with the new package and maintains the functionality of the test.


44-46: LGTM: Consistent update to use redigo package

The function signature has been correctly updated to use redigo.DialOption and redigo.Conn, maintaining consistency with the previous change and ensuring compatibility with the redigo package throughout the test function.


94-96: LGTM: Consistent update to use redigo package in TestSetKeyValue

The function signature has been correctly updated to use redigo.DialOption and redigo.Conn, maintaining consistency with the previous changes and ensuring compatibility with the redigo package in the TestSetKeyValue function.


152-154: LGTM: Consistent update to use redigo package in TestGetKeyValue

The function signature has been correctly updated to use redigo.DialOption and redigo.Conn, maintaining consistency with the previous changes and ensuring compatibility with the redigo package in the TestGetKeyValue function.


Line range hint 1-172: Summary: Successful migration to redigo package with minor suggestion

The changes in this file consistently update the usage from the redis package to the redigo package across all test functions. The updates maintain the functionality of the tests while ensuring compatibility with the new package.

A minor suggestion was made to simplify an error message in the TestSetKeyValue function.

To ensure the completeness of the migration, please run the following command to check for any remaining references to the old redis package:

If this command returns any results, those occurrences should be reviewed and updated to use the redigo package as well.

go.mod (3)

33-33: Dependency update: github.com/volatiletech/strmangle

The github.com/volatiletech/strmangle package has been updated from v0.0.4 to v0.0.6. This is a minor version update, which should maintain backwards compatibility. It's good practice to keep dependencies up-to-date for bug fixes and improvements.

To verify the usage of this package and ensure no breaking changes, run the following script:

#!/bin/bash
# Description: Check for usage of github.com/volatiletech/strmangle in the project

# Test: Look for imports and usage of strmangle package
echo "Checking for imports of strmangle:"
rg --type go -n "github.com/volatiletech/strmangle"

echo -e "\nChecking for usage of strmangle functions:"
rg --type go -n "strmangle\."

Line range hint 1-33: Verify removal of github.com/volatiletech/sqlboiler

The dependency github.com/volatiletech/sqlboiler v3.7.1+incompatible has been removed from the go.mod file. Please ensure that this removal is intentional and that no part of the codebase still depends on this package.

To verify the removal and check for any remaining usage, run the following script:

If any usage is found, please update the code to remove dependencies on this package or consider re-adding it if it's still needed.


1-3: Go version specification updated

The Go version has been updated from 1.22 to 1.22.0. This change provides a more precise version specification, which is good practice. However, ensure that all development environments and CI/CD pipelines are updated to use Go 1.22.0.

To verify the Go version across the project, run the following script:

pkg/utl/resultwrapper/error.go (4)

81-81: Improved error message formatting

The change from fmt.Errorf(errMessage) to fmt.Errorf("%s", errMessage) is a good practice. It ensures that the error message is explicitly treated as a string, preventing any potential formatting issues if errMessage contains format specifiers. This change improves the robustness of the error handling.


155-155: Consistent error formatting in GraphQL errors

The change from gqlerror.Errorf(errMsg) to gqlerror.Errorf("%s", errMsg) is consistent with the previous modification in the WrapperFromMessage function. This change ensures that GraphQL error messages are also explicitly treated as strings, preventing potential formatting issues and improving the overall consistency of error handling in the application.


199-199: Consistent error formatting across wrapper functions

The change from fmt.Errorf(errMessage) to fmt.Errorf("%s", errMessage) in the ResolverWrapperFromMessage function maintains consistency with the similar modifications in WrapperFromMessage and HandleGraphQLError. This consistent approach to error formatting across different wrapper functions improves the overall reliability and maintainability of the error handling in the application.


Line range hint 1-199: Overall improvement in error handling consistency

The changes made to this file consistently improve the error handling by explicitly formatting error messages as strings. This approach prevents potential issues with format specifiers in error messages and enhances the robustness of the error handling across different functions. The modifications are well-implemented and maintain a uniform style throughout the file.

pkg/utl/resultwrapper/error_test.go (9)

124-124: LGTM: Consistent error formatting.

The change to use fmt.Errorf("%s", ErrMsgJSON) aligns with the overall pattern of modifications in this file, ensuring consistent error formatting across the codebase.


135-135: LGTM: Consistent error formatting maintained.

The change to use fmt.Errorf("%s", ErrMsgJSON) is consistent with the previous modification, maintaining a standardized approach to error creation throughout the test cases.


165-165: LGTM: Consistent error formatting across test cases.

The change to use fmt.Errorf("%s", ErrMsg) in the TestInternalServerError function maintains consistency with the error formatting approach used throughout the file.


201-201: LGTM: Consistent error formatting in assertion.

The change to use fmt.Errorf("%s", tt.args.err) in the assertion maintains consistency with the error formatting approach. This modification ensures that the error returned by the function matches the expected format, which is crucial for accurate testing.


223-223: LGTM: Consistent error formatting in TestBadRequest.

The change to use fmt.Errorf("%s", errorStr) in the TestBadRequest function maintains the consistent approach to error formatting seen throughout the file.


259-259: LGTM: Consistent error formatting across multiple test functions.

The changes in TestBadRequestFromMessage, TestConflict, and TestConflictFromMessage functions all use fmt.Errorf("%s", ...) for error creation or assertion. This maintains a consistent approach to error formatting throughout the test suite.

Also applies to: 281-281, 317-317


339-339: LGTM: Continued consistency in error formatting.

The changes in TestTooManyRequests, TestUnauthorized, and TestUnauthorizedFromMessage functions maintain the consistent use of fmt.Errorf("%s", ...) for error creation or assertion. This upholds the standardized approach to error formatting across the entire test suite.

Also applies to: 369-369, 405-405


594-594: LGTM: Consistent error formatting in TestResolverSQLError.

The change to use fmt.Errorf("%s", errorMessage) in the assertion of TestResolverSQLError function maintains the consistent approach to error formatting seen throughout the file. This ensures that the error returned by the function matches the expected format, which is crucial for accurate testing.


Line range hint 1-594: Overall: Consistent and beneficial changes to error formatting.

The modifications throughout this file demonstrate a systematic approach to standardizing error creation and assertion using fmt.Errorf("%s", ...). These changes enhance code consistency and maintainability without altering the functionality of the tests. The standardized approach to error formatting will likely make future maintenance and debugging easier.

Some potential benefits of these changes include:

  1. Consistent error message formatting across the entire test suite.
  2. Easier identification and handling of error messages in the future.
  3. Improved readability and maintainability of the test code.

No issues or potential problems were identified in these modifications.

pkg/utl/rediscache/service_test.go (9)

87-87: LGTM: Improved type clarity

The change from *Patches to *gomonkey.Patches enhances code readability by using the fully qualified type name.


110-112: LGTM: Consistent error handling

The updates to error message formatting using fmt.Errorf and the ExpectError method improve consistency in error handling throughout the test cases.


124-125: LGTM: Consistent use of gomonkey package

The updates to the init function signature and the use of gomonkey.ApplyFunc improve consistency in the usage of the gomonkey package throughout the test file.


138-138: LGTM: Consistent updates to function signatures and error handling

The changes to the init function signatures and error message formatting maintain consistency with the previous updates, enhancing type clarity and error handling throughout the test cases.

Also applies to: 158-158, 167-167, 184-184


194-194: LGTM: Consistent function signature updates

The changes to the init function signatures maintain consistency with the previous updates, enhancing type clarity throughout the test cases.

Also applies to: 208-208, 235-235


296-296: LGTM: Consistent function signature updates

The changes to the function signatures to use *gomonkey.Patches maintain consistency with the previous updates, enhancing type clarity throughout the test cases.

Also applies to: 304-304, 318-318


337-337: LGTM: Consistent function signature updates

The changes to the init function signatures to use *gomonkey.Patches maintain consistency with the previous updates, enhancing type clarity throughout the test cases.

Also applies to: 354-354


378-379: LGTM: Consistent updates to function signatures and error handling

The changes to the init function signatures and error message formatting maintain consistency with the previous updates, enhancing type clarity and error handling throughout the test cases.

Also applies to: 383-385, 389-389, 394-394


493-493: LGTM: Consistent updates to function signatures, error handling, and gomonkey usage

The changes to the function signatures, error message formatting, and the use of gomonkey.ApplyMethodFunc maintain consistency with the previous updates. These changes enhance type clarity, improve error handling, and ensure correct usage of the gomonkey package throughout the test cases.

Also applies to: 521-522, 526-526, 536-536, 548-549, 552-552

Dockerfile Show resolved Hide resolved
pkg/utl/rediscache/service_test.go Show resolved Hide resolved
pkg/utl/rediscache/service_test.go Show resolved Hide resolved
Copy link

sonarqube-ws bot commented Sep 26, 2024

Passed

Analysis Details

1 Issue

  • Bug 0 Bugs
  • Vulnerability 1 Vulnerability
  • Code Smell 0 Code Smells

Coverage and Duplications

  • Coverage 100.00% Coverage (95.70% Estimated after merge)
  • Duplications 0.00% Duplicated Code (0.00% Estimated after merge)

Project ID: wednesday-solutions_go-template_AY4Ik1IUB2n8RRmGoUiD

View in SonarQube

@Paras-Wednesday Paras-Wednesday merged commit 01c67ab into master Sep 27, 2024
5 checks passed
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.

2 participants