-
Notifications
You must be signed in to change notification settings - Fork 0
Implement Contribution Service #13
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
VishakhaSainani-Josh
wants to merge
17
commits into
main
Choose a base branch
from
feat/contribution-service
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3834565
create contribution fetching for all users in the system from bigquer…
VishakhaSainani 1c7b715
Merge branch 'feat/db_migrations' into feat/contribution-service
VishakhaSainani 284fdaf
Merge branch 'fix/login-timestamp-type' into feat/contribution-service
VishakhaSainani d3d91a4
use userid while adding contribution
VishakhaSainani 1c1135f
get id and score from contribution_score
VishakhaSainani f94000e
fix date format
VishakhaSainani a17215c
refactor processfetchedcontribution function and update http client h…
VishakhaSainani de13e7a
implement users five recent contributions
VishakhaSainani f7e8fa9
fetch all contributions for the user
VishakhaSainani 887faa4
remove unnecessary lines
VishakhaSainani bb68dfa
pass http client in service struct
VishakhaSainani e5a4d0b
add contributors_url in repository table
VishakhaSainani a8e5768
Merge branch 'db/migration/add-contributors-url' into feat/contributi…
VishakhaSainani 5773245
fetch and contributors url for repository
VishakhaSainani f365171
remove fetch five recent contributions for the user- this could be ha…
VishakhaSainani 3ac004e
define contribution fetching query from bigquery as a constant
VishakhaSainani a306776
rename function FetchUsersAllContributions to FetchUserContributions,…
VishakhaSainani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| local.yaml | ||
| local.yaml | ||
|
|
||
| *.ps1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package bigquery | ||
|
|
||
| import "time" | ||
|
|
||
| type ContributionResponse struct { | ||
| ID string `bigquery:"id"` | ||
| Type string `bigquery:"type"` | ||
| ActorID int `bigquery:"actor_id"` | ||
| ActorLogin string `bigquery:"actor_login"` | ||
| RepoID int `bigquery:"repo_id"` | ||
| RepoName string `bigquery:"repo_name"` | ||
| RepoUrl string `bigquery:"repo_url"` | ||
| Payload string `bigquery:"payload"` | ||
| CreatedAt time.Time `bigquery:"created_at"` | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| package bigquery | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "log/slog" | ||
| "strings" | ||
| "time" | ||
|
|
||
| bq "cloud.google.com/go/bigquery" | ||
| "github.com/joshsoftware/code-curiosity-2025/internal/config" | ||
| "github.com/joshsoftware/code-curiosity-2025/internal/pkg/apperrors" | ||
| "github.com/joshsoftware/code-curiosity-2025/internal/repository" | ||
| ) | ||
|
|
||
| type service struct { | ||
| bigqueryInstance config.Bigquery | ||
| userRepository repository.UserRepository | ||
| } | ||
|
|
||
| type Service interface { | ||
| FetchDailyContributions(ctx context.Context) (*bq.RowIterator, error) | ||
| } | ||
|
|
||
| func NewService(bigqueryInstance config.Bigquery, userRepository repository.UserRepository) Service { | ||
| return &service{ | ||
| bigqueryInstance: bigqueryInstance, | ||
| userRepository: userRepository, | ||
| } | ||
| } | ||
|
|
||
| func (s *service) FetchDailyContributions(ctx context.Context) (*bq.RowIterator, error) { | ||
| YesterdayDate := time.Now().AddDate(0, 0, -1) | ||
| YesterdayYearMonthDay := YesterdayDate.Format("20060102") | ||
|
|
||
| usersNamesList, err := s.userRepository.GetAllUsersGithubUsernames(ctx, nil) | ||
| if err != nil { | ||
| slog.Error("error fetching users github usernames") | ||
| return nil, apperrors.ErrInternalServer | ||
| } | ||
|
|
||
| var quotedUsernamesList []string | ||
| for _, username := range usersNamesList { | ||
| quotedUsernamesList = append(quotedUsernamesList, fmt.Sprintf("'%s'", username)) | ||
| } | ||
|
|
||
| githubUsernames := strings.Join(quotedUsernamesList, ",") | ||
| fetchDailyContributionsQuery := fmt.Sprintf(` | ||
| SELECT | ||
| id, | ||
| type, | ||
| public, | ||
| actor.id AS actor_id, | ||
| actor.login AS actor_login, | ||
| actor.gravatar_id AS actor_gravatar_id, | ||
| actor.url AS actor_url, | ||
| actor.avatar_url AS actor_avatar_url, | ||
| repo.id AS repo_id, | ||
| repo.name AS repo_name, | ||
| repo.url AS repo_url, | ||
| payload, | ||
| created_at, | ||
| other | ||
| FROM | ||
| githubarchive.day.%s | ||
| WHERE | ||
| type IN ( | ||
| 'IssuesEvent', | ||
| 'PullRequestEvent', | ||
| 'PullRequestReviewEvent', | ||
| 'IssueCommentEvent', | ||
| 'PullRequestReviewCommentEvent' | ||
| ) | ||
| AND ( | ||
| actor.login IN (%s) | ||
| ) | ||
| `, YesterdayYearMonthDay, githubUsernames) | ||
|
||
|
|
||
| bigqueryQuery := s.bigqueryInstance.Client.Query(fetchDailyContributionsQuery) | ||
| contributionRows, err := bigqueryQuery.Read(ctx) | ||
| if err != nil { | ||
| slog.Error("error fetching contributions", "error", err) | ||
| return nil, err | ||
| } | ||
|
|
||
| return contributionRows, err | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package contribution | ||
|
|
||
| import "time" | ||
|
|
||
| type ContributionResponse struct { | ||
| ID string `bigquery:"id"` | ||
| Type string `bigquery:"type"` | ||
| ActorID int `bigquery:"actor_id"` | ||
| ActorLogin string `bigquery:"actor_login"` | ||
| RepoID int `bigquery:"repo_id"` | ||
| RepoName string `bigquery:"repo_name"` | ||
| RepoUrl string `bigquery:"repo_url"` | ||
| Payload string `bigquery:"payload"` | ||
| CreatedAt time.Time `bigquery:"created_at"` | ||
| } | ||
|
|
||
| type Repository struct { | ||
| Id int | ||
| GithubRepoId int | ||
| RepoName string | ||
| Description string | ||
| LanguagesUrl string | ||
| RepoUrl string | ||
| OwnerName string | ||
| UpdateDate time.Time | ||
| CreatedAt time.Time | ||
| UpdatedAt time.Time | ||
| } | ||
|
|
||
| type Contribution struct { | ||
| Id int | ||
| UserId int | ||
| RepositoryId int | ||
| ContributionScoreId int | ||
| ContributionType string | ||
| BalanceChange int | ||
| ContributedAt time.Time | ||
| CreatedAt time.Time | ||
| UpdatedAt time.Time | ||
| } | ||
|
|
||
| type ContributionScore struct { | ||
| Id int | ||
| AdminId int | ||
| ContributionType string | ||
| Score int | ||
| CreatedAt time.Time | ||
| UpdatedAt time.Time | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package contribution | ||
|
|
||
| import ( | ||
| "log/slog" | ||
| "net/http" | ||
|
|
||
| "github.com/joshsoftware/code-curiosity-2025/internal/pkg/response" | ||
| ) | ||
|
|
||
| type handler struct { | ||
| contributionService Service | ||
| } | ||
|
|
||
| type Handler interface { | ||
| FetchUserLatestContributions(w http.ResponseWriter, r *http.Request) | ||
| } | ||
|
|
||
| func NewHandler(contributionService Service) Handler { | ||
| return &handler{ | ||
| contributionService: contributionService, | ||
| } | ||
| } | ||
|
|
||
| func (h *handler) FetchUserLatestContributions(w http.ResponseWriter, r *http.Request) { | ||
|
|
||
| ctx := r.Context() | ||
|
|
||
| err := h.contributionService.ProcessFetchedContributions(ctx) | ||
| if err != nil { | ||
| slog.Error("error fetching latest contributions") | ||
| return | ||
| } | ||
|
|
||
| response.WriteJson(w, http.StatusOK, "contribution fetched successfully", nil) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
define variables close to where they are used