...

Source file src/github.com/google/go-github/v55/github/repos_community_health.go

Documentation: github.com/google/go-github/v55/github

     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/en/rest/metrics/community#get-community-profile-metrics
    47  func (s *RepositoriesService) GetCommunityHealthMetrics(ctx context.Context, owner, repo string) (*CommunityHealthMetrics, *Response, error) {
    48  	u := fmt.Sprintf("repos/%v/%v/community/profile", owner, repo)
    49  	req, err := s.client.NewRequest("GET", u, nil)
    50  	if err != nil {
    51  		return nil, nil, err
    52  	}
    53  
    54  	metrics := &CommunityHealthMetrics{}
    55  	resp, err := s.client.Do(ctx, req, metrics)
    56  	if err != nil {
    57  		return nil, resp, err
    58  	}
    59  
    60  	return metrics, resp, nil
    61  }
    62  

View as plain text