Debian Codegraph @

github/repos_community_health.go

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