...
1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 "time"
12 )
13
14
15 type Metric struct {
16 Name *string `json:"name"`
17 Key *string `json:"key"`
18 URL *string `json:"url"`
19 HTMLURL *string `json:"html_url"`
20 }
21
22
23 type CommunityHealthFiles struct {
24 CodeOfConduct *Metric `json:"code_of_conduct"`
25 Contributing *Metric `json:"contributing"`
26 IssueTemplate *Metric `json:"issue_template"`
27 PullRequestTemplate *Metric `json:"pull_request_template"`
28 License *Metric `json:"license"`
29 Readme *Metric `json:"readme"`
30 }
31
32
33 type CommunityHealthMetrics struct {
34 HealthPercentage *int `json:"health_percentage"`
35 Files *CommunityHealthFiles `json:"files"`
36 UpdatedAt *time.Time `json:"updated_at"`
37 }
38
39
40
41
42 func (s *RepositoriesService) GetCommunityHealthMetrics(ctx context.Context, owner, repo string) (*CommunityHealthMetrics, *Response, error) {
43 u := fmt.Sprintf("repos/%v/%v/community/profile", owner, repo)
44 req, err := s.client.NewRequest("GET", u, nil)
45 if err != nil {
46 return nil, nil, err
47 }
48
49
50 req.Header.Set("Accept", mediaTypeRepositoryCommunityHealthMetricsPreview)
51
52 metrics := &CommunityHealthMetrics{}
53 resp, err := s.client.Do(ctx, req, metrics)
54 if err != nil {
55 return nil, resp, err
56 }
57
58 return metrics, resp, nil
59 }
60
View as plain text