From 1bd8bc5eb947c402a5c2fe080e73008a487b0a53 Mon Sep 17 00:00:00 2001 From: Ian Candy Date: Thu, 2 Nov 2023 17:52:51 +0000 Subject: [PATCH] Update result functions - Remove formatCSV functions, which are now unused - Rename on instnace of `buildJSON` to `buildResult` for consistency Co-authored-by: David Gardiner --- .../github/fetchers/contribution_info.go | 16 ------------ .../collectors/github/fetchers/org_info.go | 16 ------------ .../github/fetchers/repos_info_fetcher.go | 26 ++----------------- 3 files changed, 2 insertions(+), 56 deletions(-) diff --git a/backend/business/core/collectors/github/fetchers/contribution_info.go b/backend/business/core/collectors/github/fetchers/contribution_info.go index 7a668b4..9464176 100644 --- a/backend/business/core/collectors/github/fetchers/contribution_info.go +++ b/backend/business/core/collectors/github/fetchers/contribution_info.go @@ -2,7 +2,6 @@ package fetchers import ( "context" - "fmt" "github.com/shurcooL/githubv4" ) @@ -65,21 +64,6 @@ func (c *ContributionInfoFetcher) Fetch(ctx context.Context) (*map[string]Contri return result, nil } -// FormatCSV formats the given data as CSV -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 -} - func (f *ContributionInfoFetcher) buildResult(data []contributionInfo) *map[string]ContributionInfoResult { result := make(map[string]ContributionInfoResult) for _, edge := range data { diff --git a/backend/business/core/collectors/github/fetchers/org_info.go b/backend/business/core/collectors/github/fetchers/org_info.go index 26a5a91..d7b74c5 100644 --- a/backend/business/core/collectors/github/fetchers/org_info.go +++ b/backend/business/core/collectors/github/fetchers/org_info.go @@ -2,7 +2,6 @@ package fetchers import ( "context" - "fmt" "github.com/shurcooL/githubv4" ) @@ -74,21 +73,6 @@ func (oif *OrgInfoFetcher) Fetch(ctx context.Context) (*OrgInfoResult, error) { return result, nil } -func (f *OrgInfoFetcher) formatCSV(data orgInfo) (string, error) { - csvString := "login,name,description,createdAt,totalMembers,totalProjects,totalRepositories,totalTeams\n" - csvString += fmt.Sprintf("%s,%s,%s,%s,%d,%d,%d,%d\n", - data.Login, - data.Name, - data.Description, - data.CreatedAt, - data.MembersWithRole.TotalCount, - data.Projects.TotalCount+data.ProjectsV2.TotalCount, - data.Repositories.TotalCount, - data.Teams.TotalCount, - ) - return csvString, nil -} - func (f *OrgInfoFetcher) buildResult(data orgInfo) *OrgInfoResult { return &OrgInfoResult{ Login: string(data.Login), diff --git a/backend/business/core/collectors/github/fetchers/repos_info_fetcher.go b/backend/business/core/collectors/github/fetchers/repos_info_fetcher.go index 1facd66..db57134 100644 --- a/backend/business/core/collectors/github/fetchers/repos_info_fetcher.go +++ b/backend/business/core/collectors/github/fetchers/repos_info_fetcher.go @@ -109,33 +109,11 @@ func (f *ReposInfoFetcher) Fetch(ctx context.Context) (*map[string]RepoInfoResul variables["reposCursor"] = githubv4.NewString(q.Organization.Repositories.PageInfo.EndCursor) } - result := f.buildJSON(allRepos) + result := f.buildResult(allRepos) return result, nil } -// FormatCSV formats the given data as CSV file -func (f *ReposInfoFetcher) FormatCSV(data []repoInfo) (string, error) { - csvString := "repo_name,collaborators_count,projects_count,discussions_count,forks_count,issues_count,open_issues_count,closed_issues_count,open_pull_requests_count,merged_pull_requests_count,license_name,watchers_count\n" - for _, edge := range data { - csvString += fmt.Sprintf("%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%s,%d\n", - edge.Node.NameWithOwner, - edge.Node.Collaborators.TotalCount, - edge.Node.Projects.TotalCount+edge.Node.ProjectsV2.TotalCount, - edge.Node.Discussions.TotalCount, - edge.Node.Forks.TotalCount, - edge.Node.Issues.TotalCount, - edge.Node.OpenIssues.TotalCount, - edge.Node.ClosedIssues.TotalCount, - edge.Node.OpenPullRequests.TotalCount, - edge.Node.MergedPullRequests.TotalCount, - edge.Node.LicenseInfo.Name, - edge.Node.Watchers.TotalCount, - ) - } - return csvString, nil -} - -func (f *ReposInfoFetcher) buildJSON(data []repoInfo) *map[string]RepoInfoResult { +func (f *ReposInfoFetcher) buildResult(data []repoInfo) *map[string]RepoInfoResult { holder := make(map[string]RepoInfoResult) for _, edge := range data { holder[string(edge.Node.NameWithOwner)] = RepoInfoResult{