-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67e4a1c
commit 3ea0b3b
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,65 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"os" | ||
|
||
"github.com/gamoch/popular_repos/internal/pkg/configuration" | ||
"github.com/gamoch/popular_repos/pkg/graphql" | ||
"github.com/gamoch/popular_repos/pkg/graphql/providers/github" | ||
"github.com/gamoch/popular_repos/pkg/logs" | ||
) | ||
|
||
const query = `query PopularRepos($cursor: String) { | ||
search(query: "stars:>1", type: REPOSITORY, first: 100, after: $cursor) { | ||
pageInfo { | ||
hasNextPage | ||
endCursor | ||
} | ||
nodes { | ||
... on Repository { | ||
nameWithOwner | ||
stargazerCount | ||
createdAt | ||
updatedAt | ||
pullRequests(states: MERGED) { | ||
totalCount | ||
} | ||
releases { | ||
totalCount | ||
} | ||
primaryLanguage { | ||
name | ||
} | ||
openIssues: issues(states: OPEN) { | ||
totalCount | ||
} | ||
closedIssues: issues(states: CLOSED) { | ||
totalCount | ||
} | ||
} | ||
} | ||
} | ||
}` | ||
|
||
func main() { | ||
config := configuration.Get() | ||
ctx := context.Background() | ||
|
||
githubClient := github.NewClient(config.Token) | ||
req := graphql.NewRequest(query) | ||
|
||
graphQLData := new(GraphQLData) | ||
if err := githubClient.Run(ctx, req, graphQLData); err != nil { | ||
logs.Error.Fatal(err) | ||
} | ||
|
||
graphqlJSON, err := json.MarshalIndent(graphQLData, "", " ") | ||
if err != nil { | ||
logs.Error.Fatal(err) | ||
} | ||
|
||
graphqlJSON = append(graphqlJSON, '\n') | ||
os.Stdout.Write(graphqlJSON) | ||
} |
This file contains 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,33 @@ | ||
package main | ||
|
||
import "time" | ||
|
||
type GraphQLData struct { | ||
Search struct { | ||
PageInfo struct { | ||
HasNextPage bool `json:"hasNextPage"` | ||
EndCursor string `json:"endCursor"` | ||
} `json:"pageInfo"` | ||
Nodes []struct { | ||
NameWithOwner string `json:"nameWithOwner"` | ||
StargazerCount int `json:"stargazerCount"` | ||
CreatedAt time.Time `json:"createdAt"` | ||
UpdatedAt time.Time `json:"updatedAt"` | ||
PullRequests struct { | ||
TotalCount int `json:"totalCount"` | ||
} `json:"pullRequests"` | ||
Releases struct { | ||
TotalCount int `json:"totalCount"` | ||
} `json:"releases"` | ||
PrimaryLanguage *struct { | ||
Name string `json:"name"` | ||
} `json:"primaryLanguage"` | ||
OpenIssues struct { | ||
TotalCount int `json:"totalCount"` | ||
} `json:"openIssues"` | ||
ClosedIssues struct { | ||
TotalCount int `json:"totalCount"` | ||
} `json:"closedIssues"` | ||
} `json:"nodes"` | ||
} `json:"search"` | ||
} |