-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from sbv-world-health-org-metrics/add-more-fet…
…chers add more fetchers
- Loading branch information
Showing
41 changed files
with
489 additions
and
8,452 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*.env | ||
tmp/* | ||
tmp/* | ||
sbv-world-health-org-metrics.code-workspace |
78 changes: 78 additions & 0 deletions
78
backend/business/core/collectors/github/fetchers/contribution_info.go
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,78 @@ | ||
package fetchers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/shurcooL/githubv4" | ||
) | ||
|
||
type ContributionInfoFetcher struct { | ||
client *githubv4.Client | ||
orgName string | ||
} | ||
|
||
func NewContributionInfoFetcher(client *githubv4.Client, orgName string) *ContributionInfoFetcher { | ||
return &ContributionInfoFetcher{client: client, orgName: orgName} | ||
} | ||
|
||
type contributionInfo struct { | ||
Node struct { | ||
NameWithOwner githubv4.String | ||
} | ||
} | ||
|
||
type contributionInfoQuery struct { | ||
Organization struct { | ||
Repositories struct { | ||
Edges []contributionInfo | ||
PageInfo struct { | ||
EndCursor githubv4.String | ||
HasNextPage bool | ||
} | ||
} `graphql:"repositories(first: 100, privacy: PUBLIC, after: $reposCursor)"` | ||
} `graphql:"organization(login:$organizationLogin)"` | ||
} | ||
|
||
func (c *ContributionInfoFetcher) Fetch(ctx context.Context) (string, error) { | ||
variables := map[string]interface{}{ | ||
"organizationLogin": githubv4.String(c.orgName), | ||
"reposCursor": (*githubv4.String)(nil), // Null after argument to get first page. | ||
} | ||
|
||
var q contributionInfoQuery | ||
|
||
var allRepos []contributionInfo | ||
|
||
for { | ||
err := c.client.Query(ctx, &q, variables) | ||
if err != nil { | ||
return "", err | ||
} | ||
allRepos = append(allRepos, q.Organization.Repositories.Edges...) | ||
if !q.Organization.Repositories.PageInfo.HasNextPage { | ||
break | ||
} | ||
variables["reposCursor"] = githubv4.NewString(q.Organization.Repositories.PageInfo.EndCursor) | ||
} | ||
|
||
csvString, err := c.formatCSV(allRepos) | ||
if err != nil { | ||
return "", err | ||
} | ||
return csvString, nil | ||
} | ||
|
||
func (f *ContributionInfoFetcher) formatCSV(data []contributionInfo) (string, error) { | ||
csvString := "repo_name,issues_opened\n" | ||
for _, edge := range data { | ||
csvString += fmt.Sprintf("%s\n", | ||
edge.Node.NameWithOwner, | ||
// edge.Node.OpenIssues.TotalCount, | ||
// edge.Node.ClosedIssues.TotalCount, | ||
// edge.Node.OpenPullRequests.TotalCount, | ||
// edge.Node.MergedPullRequests.TotalCount, | ||
) | ||
} | ||
return csvString, nil | ||
} |
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
109 changes: 0 additions & 109 deletions
109
backend/business/core/collectors/github/fetchers/org_repos_info.go
This file was deleted.
Oops, something went wrong.
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.