Skip to content

Improvement - use sqlx methods #19

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

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

Conversation

VishakhaSainani-Josh
Copy link
Collaborator

@VishakhaSainani-Josh VishakhaSainani-Josh commented Jun 23, 2025

Use sqlx methods instead of sql methods for simplicity.

Summary by Bito

This pull request enhances the application by integrating BigQuery functionality, refactoring database access with SQLx methods, and improving repository management components. It adds new endpoints for contributions and repository details while updating configuration structures and database migrations for better maintainability.

…y service (in future this will be a cron job that will be scheduled to run daily)
@Suhaan-Bhandary-Josh
Copy link
Collaborator

Repo layer code looks good to me.
nit - propagate errors to upper layer, don't print and return at same time.

@Selectus2
Copy link

/review

Copy link

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
New Feature - Introducing BigQuery, Contribution Modules, and New Endpoints

domain.go - Introduced ContributionResponse struct for BigQuery integration.

service.go - Introduced a new BigQuery service for fetching daily contributions with proper error handling.

domain.go - Defined contribution-related data structures to support detailed contribution processing.

handler.go - Added HTTP endpoints for fetching user-specific and all contributions with structured error responses.

service.go - Implemented comprehensive contribution processing including fetching, creation, and score management using BigQuery and repository services.

domain.go - Implemented repository domain models to support repository-related queries and data encapsulation.

handler.go - Developed repository endpoints for retrieving repository details, contributors, and language statistics.

bigquery.go - Introduced BigQuery service for analytics integration.

router.go - Added new endpoints for user contributions and repository details.

Feature Improvement - Refactor and Enhance SQLx Integration and Application Initialization

main.go - Refactored main function to improve error handling, integrate BigQuery initialization, and adjust dependency injection with HTTP client.

service.go - Refactored repository service to use sqlx for improved query handling.

base.go - Integrated new sqlx methods to streamline database query executions.

contribution.go - Implemented contribution repository methods using sqlx for better transaction management.

repository.go - Refactored repository operations to leverage sqlx methods for improved error handling and efficiency.

user.go - Enhanced and refactored user repository methods using sqlx, including converting QueryRowContext scans into GetContext queries and adding a method to retrieve all Github usernames.

Other Improvements - Update Configuration, Dependency Management, and Schema Adjustments

.gitignore - Adjusted ignore patterns by re-adding local.yaml and including new file patterns (*.ps1).

go.mod - Updated module dependencies to include BigQuery and related packages along with formatting improvements.

go.sum - Reflected updated checksums and metadata for the revised dependency set.

dependencies.go - Updated dependency injection by adding ContributionHandler and RepositoryHandler along with client configuration adjustments.

app.go - Updated AppConfig structure to include Bigquery details and improved configuration management.

1750328591_add_column_contributors_url.up.sql - Modified repositories table by adding contributors_url column with proper constraints.

1750328591_add_column_contributors_url.down.sql - Provided rollback for contributors_url column addition.

errors.go - Standardized error message formatting and handling.

domain.go - Updated domain models with db annotations for consistency.

Copy link

@bito-code-review bito-code-review bot left a comment

Choose a reason for hiding this comment

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

Code Review Agent Run #16718b

Actionable Suggestions - 2
  • internal/repository/repository.go - 1
    • SQL parameter mismatch in query execution · Line 57-57
  • internal/db/migrations/1750328591_add_column_contributors_url.down.sql - 1
    • Migration rollback breaks application queries · Line 1-1
Additional Suggestions - 3
  • internal/db/migrations/1750328591_add_column_contributors_url.up.sql - 1
    • Redundant WHERE clause in UPDATE statement · Line 3-3
      The UPDATE statement uses `WHERE contributors_url IS NULL` but this condition will always be true for all existing rows since the column was just added without a default value. Remove the WHERE clause to update all existing rows: `UPDATE repositories SET contributors_url = '';`
      Code suggestion
       @@ -3,1 +3,1 @@
      -UPDATE repositories SET contributors_url = '' WHERE contributors_url IS NULL;
      +UPDATE repositories SET contributors_url = '';
  • internal/pkg/apperrors/errors.go - 1
    • Typo in error message text · Line 40-40
      Typo in error message: `ErrContributionCreationFailed` contains "contrbitution" instead of "contribution". This will display incorrect error messages to users. Fix: Change to `errors.New("failed to create contribution")`
      Code suggestion
       @@ -40,1 +40,1 @@
      -	ErrContributionCreationFailed  = errors.New("failed to create contrbitution")
      +	ErrContributionCreationFailed  = errors.New("failed to create contribution")
  • internal/app/bigquery/domain.go - 1
    • Duplicate struct definition across packages · Line 5-5
      Duplicate struct definition: `ContributionResponse` is already defined in `internal/app/contribution/domain.go` with identical fields. This creates type confusion and potential import conflicts when both packages are used together. Consider using a shared domain model or renaming one of the structs to avoid conflicts.
      Code suggestion
       @@ -5,1 +5,1 @@
      -type ContributionResponse struct {
      +type BigQueryContributionResponse struct {
Review Details
  • Files reviewed - 24 · Commit Range: 3834565..187dc89
    • .gitignore
    • cmd/main.go
    • go.mod
    • go.sum
    • internal/app/bigquery/domain.go
    • internal/app/bigquery/service.go
    • internal/app/contribution/domain.go
    • internal/app/contribution/handler.go
    • internal/app/contribution/service.go
    • internal/app/dependencies.go
    • internal/app/repository/domain.go
    • internal/app/repository/handler.go
    • internal/app/repository/service.go
    • internal/app/router.go
    • internal/config/app.go
    • internal/config/bigquery.go
    • internal/db/migrations/1750328591_add_column_contributors_url.down.sql
    • internal/db/migrations/1750328591_add_column_contributors_url.up.sql
    • internal/pkg/apperrors/errors.go
    • internal/repository/base.go
    • internal/repository/contribution.go
    • internal/repository/domain.go
    • internal/repository/repository.go
    • internal/repository/user.go
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • GOVULNCHECK (Security Vulnerability) - ✖︎ Failed
    • OWASP (Security Vulnerability) - ✔︎ Successful
    • SNYK (Security Vulnerability) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo


fetchUsersContributedReposQuery = `SELECT * from repositories where id in (SELECT repository_id from contributions where user_id=$1);`

fetchUserContributionsInRepoQuery = `SELECT * from contributions where repository_id=$1 and user_id=$2;`

Choose a reason for hiding this comment

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

SQL parameter mismatch in query execution

SQL parameter mismatch: The query fetchUserContributionsInRepoQuery expects repository_id as the first parameter, but repoGithubId is passed. This will cause incorrect query results or database errors. Fix by either modifying the query to use github_repo_id or first converting repoGithubId to repository_id.

Code suggestion
Check the AI-generated fix before applying
Suggested change
fetchUserContributionsInRepoQuery = `SELECT * from contributions where repository_id=$1 and user_id=$2;`
fetchUserContributionsInRepoQuery = `SELECT c.* from contributions c JOIN repositories r ON c.repository_id = r.id WHERE r.github_repo_id=$1 and c.user_id=$2;`

Code Review Run #16718b


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

@@ -0,0 +1 @@
ALTER TABLE repositories DROP COLUMN contributors_url;

Choose a reason for hiding this comment

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

Migration rollback breaks application queries

The down migration drops the contributors_url column, but the Go application code still references this column in SQL queries (createRepositoryQuery) and struct definitions. This will cause runtime SQL errors when the migration is rolled back and the application tries to insert or query the non-existent column. Consider adding application code changes to handle the missing column or ensure migrations are coordinated with code deployments.

Code suggestion
Check the AI-generated fix before applying
Suggested change
ALTER TABLE repositories DROP COLUMN contributors_url;
-- WARNING: Rolling back this migration will break the application
-- Ensure application code is updated to remove contributors_url references before running this migration
ALTER TABLE repositories DROP COLUMN contributors_url;

Code Review Run #16718b


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

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.

4 participants