+
Skip to content

Update repo community profile API #2084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ const (
// https://developer.github.com/changes/2017-02-28-user-blocking-apis-and-webhook/
mediaTypeBlockUsersPreview = "application/vnd.github.giant-sentry-fist-preview+json"

// https://developer.github.com/changes/2017-02-09-community-health/
mediaTypeRepositoryCommunityHealthMetricsPreview = "application/vnd.github.black-panther-preview+json"

// https://developer.github.com/changes/2017-05-23-coc-api/
mediaTypeCodesOfConductPreview = "application/vnd.github.scarlet-witch-preview+json"

Expand Down
17 changes: 10 additions & 7 deletions github/repos_community_health.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ import (
type Metric struct {
Name *string `json:"name"`
Key *string `json:"key"`
SPDXID *string `json:"spdx_id"`
URL *string `json:"url"`
HTMLURL *string `json:"html_url"`
NodeID *string `json:"node_id"`
}

// CommunityHealthFiles represents the different files in the community health metrics response.
type CommunityHealthFiles struct {
CodeOfConduct *Metric `json:"code_of_conduct"`
CodeOfConductFile *Metric `json:"code_of_conduct_file"`
Contributing *Metric `json:"contributing"`
IssueTemplate *Metric `json:"issue_template"`
PullRequestTemplate *Metric `json:"pull_request_template"`
Expand All @@ -31,24 +34,24 @@ type CommunityHealthFiles struct {

// CommunityHealthMetrics represents a response containing the community metrics of a repository.
type CommunityHealthMetrics struct {
HealthPercentage *int `json:"health_percentage"`
Files *CommunityHealthFiles `json:"files"`
UpdatedAt *time.Time `json:"updated_at"`
HealthPercentage *int `json:"health_percentage"`
Description *string `json:"description"`
Documentation *string `json:"documentation"`
Files *CommunityHealthFiles `json:"files"`
UpdatedAt *time.Time `json:"updated_at"`
ContentReportsEnabled *bool `json:"content_reports_enabled"`
}

// GetCommunityHealthMetrics retrieves all the community health metrics for a repository.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-community-profile-metrics
// GitHub API docs: https://docs.github.com/en/rest/reference/repos#get-community-profile-metrics
func (s *RepositoriesService) GetCommunityHealthMetrics(ctx context.Context, owner, repo string) (*CommunityHealthMetrics, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/community/profile", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeRepositoryCommunityHealthMetricsPreview)

metrics := &CommunityHealthMetrics{}
resp, err := s.client.Do(ctx, req, metrics)
if err != nil {
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载