Skip to content

Commit

Permalink
Merge pull request #64 from firstcontributions/related_issues
Browse files Browse the repository at this point in the history
Added relevant issues for stories
  • Loading branch information
gokultp authored Aug 13, 2023
2 parents 48d8d92 + 2f57705 commit d0e83ea
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 13 deletions.
4 changes: 3 additions & 1 deletion assets/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ type BadgeEdge {
}

enum BadgeSortBy {
points,
time_created,
points,
}

type Comment implements Node {
Expand Down Expand Up @@ -176,8 +176,10 @@ type Story implements Node {
contentJson: String!
createdBy: User!
id: ID!
issuesFromRepos(first: Int, last: Int, after: String, before: String, sortOrder: SortOrder, sortBy: IssueSortBy): IssuesConnection!
languages: [String]!
reactions(first: Int, last: Int, after: String, before: String, sortOrder: SortOrder, sortBy: ReactionSortBy): ReactionsConnection!
relevantIssues(first: Int, last: Int, after: String, before: String, sortOrder: SortOrder, sortBy: IssueSortBy): IssuesConnection!
repos: [String]!
thumbnail: String!
timeCreated: Time!
Expand Down
6 changes: 6 additions & 0 deletions internal/graphql/schema/issueresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,18 @@ type CreateIssueInput struct {
RepositoryUpdatedAt graphql.Time
Title string
Url string
StoryID graphql.ID
UserID graphql.ID
}

func (n *CreateIssueInput) ToModel() (*issuesstore.Issue, error) {
if n == nil {
return nil, nil
}
storyID, err := ParseGraphqlID(n.StoryID)
if err != nil {
return nil, err
}

return &issuesstore.Issue{
Body: n.Body,
Expand All @@ -69,6 +74,7 @@ func (n *CreateIssueInput) ToModel() (*issuesstore.Issue, error) {
RepositoryUpdatedAt: n.RepositoryUpdatedAt.Time,
Title: n.Title,
Url: n.Url,
StoryID: storyID.ID,
}, nil
}
func (n *Issue) ID(ctx context.Context) graphql.ID {
Expand Down
54 changes: 54 additions & 0 deletions internal/graphql/schema/storyissues_from_reposqueryresolver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package schema

import (
"context"

"github.com/firstcontributions/backend/internal/models/issuesstore"
"github.com/firstcontributions/backend/internal/storemanager"
)

type StoryIssuesFromReposInput struct {
First *int32
Last *int32
After *string
Before *string
SortOrder *string
SortBy *string
}

func (n *Story) IssuesFromRepos(ctx context.Context, in *StoryIssuesFromReposInput) (*IssuesConnection, error) {
var first, last *int64
if in.First != nil {
tmp := int64(*in.First)
first = &tmp
}
if in.Last != nil {
tmp := int64(*in.Last)
last = &tmp
}
store := storemanager.FromContext(ctx)
issueType := "issues_from_repo_story"

filters := &issuesstore.IssueFilters{
IssueType: &issueType,
Story: n.ref,
}
sortByStr := ""
if in.SortBy != nil {
sortByStr = *in.SortBy
}
data, hasNextPage, hasPreviousPage, cursors, err := store.IssuesStore.GetIssues(
ctx,
filters,
in.After,
in.Before,
first,
last,
issuesstore.GetIssueSortByFromString(sortByStr),
in.SortOrder,
)
if err != nil {
return nil, err
}
return NewIssuesConnection(filters, data, hasNextPage, hasPreviousPage, cursors), nil
}
54 changes: 54 additions & 0 deletions internal/graphql/schema/storyrelevant_issuesqueryresolver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package schema

import (
"context"

"github.com/firstcontributions/backend/internal/models/issuesstore"
"github.com/firstcontributions/backend/internal/storemanager"
)

type StoryRelevantIssuesInput struct {
First *int32
Last *int32
After *string
Before *string
SortOrder *string
SortBy *string
}

func (n *Story) RelevantIssues(ctx context.Context, in *StoryRelevantIssuesInput) (*IssuesConnection, error) {
var first, last *int64
if in.First != nil {
tmp := int64(*in.First)
first = &tmp
}
if in.Last != nil {
tmp := int64(*in.Last)
last = &tmp
}
store := storemanager.FromContext(ctx)
issueType := "relevant_issues_story"

filters := &issuesstore.IssueFilters{
IssueType: &issueType,
Story: n.ref,
}
sortByStr := ""
if in.SortBy != nil {
sortByStr = *in.SortBy
}
data, hasNextPage, hasPreviousPage, cursors, err := store.IssuesStore.GetIssues(
ctx,
filters,
in.After,
in.Before,
first,
last,
issuesstore.GetIssueSortByFromString(sortByStr),
in.SortOrder,
)
if err != nil {
return nil, err
}
return NewIssuesConnection(filters, data, hasNextPage, hasPreviousPage, cursors), nil
}
32 changes: 27 additions & 5 deletions internal/models/issuesstore/githubstore/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ import (
"fmt"

"github.com/firstcontributions/backend/internal/models/issuesstore"
"github.com/firstcontributions/backend/internal/models/storiesstore"
"github.com/firstcontributions/backend/internal/models/usersstore"
"github.com/shurcooL/githubv4"
)

const (
IssueTypeLastRepo = "last_repo_issues"
IssueTypeRecentRepo = "issues_from_other_recent_repos"
IssueTypeRelevant = "relevant_issues"
IssueTypeLastRepo = "last_repo_issues"
IssueTypeRecentRepo = "issues_from_other_recent_repos"
IssueTypeRelevant = "relevant_issues"
IssueTypeReposInStory = "issues_from_repo_story"
IssueTypeRelevantForStory = "relevant_issues_story"
)

func getQuery(user *usersstore.User, issueType string) (string, error) {
func getQuery(user *usersstore.User, story *storiesstore.Story, issueType string) (string, error) {
query := "is:issue is:open no:assignee"

switch issueType {
Expand All @@ -35,6 +38,25 @@ func getQuery(user *usersstore.User, issueType string) (string, error) {
query += fmt.Sprintf(" repo:%s", *repo)
}
return query + " label:\"help wanted\",\"good first issue\",\"goodfirstissue\"", nil
case IssueTypeReposInStory:
ln := len(story.Repos)
if len(user.Tags.RecentRepos) < 1 {
return "", fmt.Errorf("no recent repos")
}
count := min(7, ln)

for _, repo := range story.Repos[:count] {
query += fmt.Sprintf(" repo:%s", *repo)
}
return query + " label:\"help wanted\",\"good first issue\",\"goodfirstissue\"", nil
case IssueTypeRelevantForStory:
languageCount := min(3, len(story.Languages))
languages := story.Languages[:languageCount]

for _, lng := range languages {
query += fmt.Sprintf(" language:%s", *lng)
}
return query + " label:\"good first issue\",\"goodfirstissue\"", nil
default:
languageCount := min(3, len(user.Tags.Languages))
languages := user.Tags.Languages[:languageCount]
Expand Down Expand Up @@ -149,7 +171,7 @@ func (g *GitHubStore) GetIssues(
tmp := githubv4.String(*before)
beforeGql = &tmp
}
query, err := getQuery(filters.User, *filters.IssueType)
query, err := getQuery(filters.User, filters.Story, *filters.IssueType)
if err != nil {
return nil, false, false, nil, nil
}
Expand Down
5 changes: 5 additions & 0 deletions internal/models/issuesstore/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package issuesstore
import (
"time"

"github.com/firstcontributions/backend/internal/models/storiesstore"
"github.com/firstcontributions/backend/internal/models/usersstore"
"github.com/firstcontributions/backend/pkg/authorizer"
"github.com/firstcontributions/backend/pkg/cursor"
Expand All @@ -16,6 +17,7 @@ const (
)

type Issue struct {
StoryID string `bson:"story_id"`
UserID string `bson:"user_id"`
Body string `bson:"body,omitempty"`
CommentCount int64 `bson:"comment_count,omitempty"`
Expand All @@ -35,6 +37,8 @@ func NewIssue() *Issue {
}
func (issue *Issue) Get(field string) interface{} {
switch field {
case "story_id":
return issue.StoryID
case "user_id":
return issue.UserID
case "body":
Expand Down Expand Up @@ -65,6 +69,7 @@ func (issue *Issue) Get(field string) interface{} {
type IssueFilters struct {
Ids []string
IssueType *string
Story *storiesstore.Story
User *usersstore.User
}

Expand Down
14 changes: 7 additions & 7 deletions internal/models/usersstore/badge.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ type BadgeSortBy uint8

const (
BadgeSortByDefault BadgeSortBy = iota
BadgeSortByPoints
BadgeSortByTimeCreated
BadgeSortByPoints
)

type Badge struct {
Expand Down Expand Up @@ -72,32 +72,32 @@ type BadgeFilters struct {

func (s BadgeSortBy) String() string {
switch s {
case BadgeSortByPoints:
return "points"
case BadgeSortByTimeCreated:
return "time_created"
case BadgeSortByPoints:
return "points"
default:
return "time_created"
}
}

func GetBadgeSortByFromString(s string) BadgeSortBy {
switch s {
case "points":
return BadgeSortByPoints
case "time_created":
return BadgeSortByTimeCreated
case "points":
return BadgeSortByPoints
default:
return BadgeSortByDefault
}
}

func (s BadgeSortBy) CursorType() cursor.ValueType {
switch s {
case BadgeSortByPoints:
return cursor.ValueTypeInt
case BadgeSortByTimeCreated:
return cursor.ValueTypeTime
case BadgeSortByPoints:
return cursor.ValueTypeInt
default:
return cursor.ValueTypeTime
}
Expand Down
18 changes: 18 additions & 0 deletions matro.json
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,24 @@
"joined_data": true,
"paginated": true
},
"issues_from_repos" : {
"type": "list",
"schema": "issue",
"joined_data": true,
"paginated": true,
"hardcoded_filters" : {
"issue_type": "issues_from_repo_story"
}
},
"relevant_issues" : {
"type": "list",
"schema": "issue",
"joined_data": true,
"paginated": true,
"hardcoded_filters" : {
"issue_type": "relevant_issues_story"
}
},
"created_by" : {
"type": "object",
"schema": "user",
Expand Down

0 comments on commit d0e83ea

Please sign in to comment.