1// Copyright 2017 The go-github AUTHORS. All rights reserved. 2// 3// Use of this source code is governed by a BSD-style 4// license that can be found in the LICENSE file. 5 6package github 7 8import ( 9 "context" 10 "fmt" 11 "time" 12) 13 14// Metric represents the different fields for one file in community health files. 15type Metric struct { 16 Name *string `json:"name"` 17 Key *string `json:"key"` 18 SPDXID *string `json:"spdx_id"` 19 URL *string `json:"url"` 20 HTMLURL *string `json:"html_url"` 21 NodeID *string `json:"node_id"` 22} 23 24// CommunityHealthFiles represents the different files in the community health metrics response. 25type CommunityHealthFiles struct { 26 CodeOfConduct *Metric `json:"code_of_conduct"` 27 CodeOfConductFile *Metric `json:"code_of_conduct_file"` 28 Contributing *Metric `json:"contributing"` 29 IssueTemplate *Metric `json:"issue_template"` 30 PullRequestTemplate *Metric `json:"pull_request_template"` 31 License *Metric `json:"license"` 32 Readme *Metric `json:"readme"` 33} 34 35// CommunityHealthMetrics represents a response containing the community metrics of a repository. 36type CommunityHealthMetrics struct { 37 HealthPercentage *int `json:"health_percentage"` 38 Description *string `json:"description"` 39 Documentation *string `json:"documentation"` 40 Files *CommunityHealthFiles `json:"files"` 41 UpdatedAt *time.Time `json:"updated_at"` 42 ContentReportsEnabled *bool `json:"content_reports_enabled"` 43} 44 45// GetCommunityHealthMetrics retrieves all the community health metrics for a repository. 46// 47// GitHub API docs: https://docs.github.com/en/rest/reference/repos#get-community-profile-metrics 48func (s *RepositoriesService) GetCommunityHealthMetrics(ctx context.Context, owner, repo string) (*CommunityHealthMetrics, *Response, error) { 49 u := fmt.Sprintf("repos/%v/%v/community/profile", owner, repo) 50 req, err := s.client.NewRequest("GET", u, nil) 51 if err != nil { 52 return nil, nil, err 53 } 54 55 metrics := &CommunityHealthMetrics{} 56 resp, err := s.client.Do(ctx, req, metrics) 57 if err != nil { 58 return nil, resp, err 59 } 60 61 return metrics, resp, nil 62} 63