Upgrade go-github to v39 (#17437)

This commit is contained in:
Lunny Xiao 2021-10-26 15:19:21 +08:00 committed by GitHub
parent 849356deaf
commit 812a9daab9
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
126 changed files with 2594 additions and 200 deletions

3
go.mod

@ -53,8 +53,7 @@ require (
github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-github/v37 v37.0.0
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/go-github/v39 v39.2.0
github.com/google/uuid v1.2.0
github.com/gorilla/context v1.1.1
github.com/gorilla/feeds v1.1.1

4
go.sum

@ -562,8 +562,8 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-github/v37 v37.0.0 h1:rCspN8/6kB1BAJWZfuafvHhyfIo5fkAulaP/3bOQ/tM=
github.com/google/go-github/v37 v37.0.0/go.mod h1:LM7in3NmXDrX58GbEHy7FtNLbI2JijX93RnMKvWG3m4=
github.com/google/go-github/v39 v39.2.0 h1:rNNM311XtPOz5rDdsJXAp2o8F67X9FnROXTvto3aSnQ=
github.com/google/go-github/v39 v39.2.0/go.mod h1:C1s8C5aCC9L+JXIYpJM5GYytdX52vC1bLvHEF1IhBrE=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=

@ -8,7 +8,7 @@ package migrations
import (
"errors"
"github.com/google/go-github/v37/github"
"github.com/google/go-github/v39/github"
)
var (

@ -23,7 +23,7 @@ import (
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
"github.com/google/go-github/v37/github"
"github.com/google/go-github/v39/github"
"golang.org/x/oauth2"
)

@ -26,6 +26,7 @@ Alex Bramley <a.bramley@gmail.com>
Alex Orr <Alexorr.CSE@gmail.com>
Alex Unger <zyxancf@gmail.com>
Alexander Harkness <me@bearbin.net>
Alexis Gauthiez <alexis.gauthiez@gmail.com>
Ali Farooq <ali.farooq0@pm.me>
Allen Sun <shlallen1990@gmail.com>
Amey Sakhadeo <me@ameyms.com>
@ -50,6 +51,7 @@ Arıl Bozoluk <arilbozoluk@hotmail.com>
Asier Marruedo <asiermarruedo@gmail.com>
Austin Burdine <acburdine@gmail.com>
Austin Dizzy <dizzy@wow.com>
Azuka Okuleye <azuka@zatechcorp.com>
Ben Batha <bhbatha@gmail.com>
Benjamen Keroack <benjamen@dollarshaveclub.com>
Beshr Kayali <beshrkayali@gmail.com>
@ -63,6 +65,7 @@ Brad Moylan <moylan.brad@gmail.com>
Bradley Falzon <brad@teambrad.net>
Bradley McAllister <brad.mcallister@hotmail.com>
Brandon Cook <phylake@gmail.com>
Brett Logan <lindluni@github.com>
Brian Egizi <brian@mojotech.com>
Bryan Boreham <bryan@weave.works>
Cami Diez <diezcami@gmail.com>
@ -72,7 +75,9 @@ Carlos Tadeu Panato Junior <ctadeu@gmail.com>
chandresh-pancholi <chandreshpancholi007@gmail.com>
Charles Fenwick Elliott <Charles@FenwickElliott.io>
Charlie Yan <charlieyan08@gmail.com>
Chmouel Boudjnah <chmouel@chmouel.com>
Chris King <chriskingnet@gmail.com>
Chris Mc <prince.chrismc@gmail.com>
Chris Raborg <craborg57@gmail.com>
Chris Roche <chris@vsco.co>
Chris Schaefer <chris@dtzq.com>
@ -89,6 +94,7 @@ Daniel Nilsson <daniel.nilsson1989@gmail.com>
Daoq <masseto2002@gmail.com>
Dave Du Cros <davidducros@gmail.com>
Dave Henderson <dhenderson@gmail.com>
Dave Perrett <hello@daveperrett.com>
Dave Protasowski <dprotaso@gmail.com>
David Deng <daviddengcn@gmail.com>
David J. M. Karlsen <david@davidkarlsen.com>
@ -97,6 +103,7 @@ David Ji <github.com/davidji99>
David Lopez Reyes <davidlopezre@gmail.com>
Davide Zipeto <dawez1@gmail.com>
Dennis Webb <dennis@bluesentryit.com>
Derek Jobst <derekjobst@gmail.com>
Dhi Aurrahman <diorahman@rockybars.com>
Diego Lapiduz <diego.lapiduz@cfpb.gov>
Dmitri Shuralyov <shurcooL@gmail.com>
@ -114,6 +121,7 @@ Erick Fejta <erick@fejta.com>
Erik Nobel <hendrik.nobel@transferwise.com>
erwinvaneyk <erwinvaneyk@gmail.com>
Evan Elias <evanjelias@gmail.com>
Fabian Holler <fabian.holler@simplesurance.de>
Fabrice <fabrice.vaillant@student.ecp.fr>
Felix Geisendörfer <felix@debuggable.com>
Filippo Valsorda <hi@filippo.io>
@ -140,15 +148,19 @@ haya14busa <hayabusa1419@gmail.com>
Huy Tr <kingbazoka@gmail.com>
huydx <doxuanhuy@gmail.com>
i2bskn <i2bskn@gmail.com>
Ikko Ashimine <eltociear@gmail.com>
Ioannis Georgoulas <igeorgoulas21@gmail.com>
Isao Jonas <isao.jonas@gmail.com>
ishan upadhyay <ishanupadhyay412@gmail.com>
isqua <isqua@isqua.ru>
Jacob Valdemar <jan@lunar.app>
Jake Krammer <jake.krammer1@gmail.com>
Jake White <jake@jwhite.network>
Jameel Haffejee <RC1140@republiccommandos.co.za>
James Cockbain <james.cockbain@ibm.com>
James Loh <github@jloh.co>
Jan Kosecki <jan.kosecki91@gmail.com>
Jan Švábík <jansvabik@jansvabik.cz>
Javier Campanini <jcampanini@palantir.com>
Jef LeCompte <jeffreylec@gmail.com>
Jens Rantil <jens.rantil@gmail.com>
@ -180,6 +192,7 @@ Katrina Owen <kytrinyx@github.com>
Kautilya Tripathi <tripathi.kautilya@gmail.com>
Keita Urashima <ursm@ursm.jp>
Kevin Burke <kev@inburke.com>
Kirill <g4s8.public@gmail.com>
Konrad Malawski <konrad.malawski@project13.pl>
Kookheon Kwon <kucuny@gmail.com>
Krzysztof Kowalczyk <kkowalczyk@gmail.com>
@ -189,6 +202,7 @@ kyokomi <kyoko1220adword@gmail.com>
Laurent Verdoïa <verdoialaurent@gmail.com>
Liam Galvin <liam@liam-galvin.co.uk>
Lovro Mažgon <lovro.mazgon@gmail.com>
Luca Campese <me@campesel.net>
Lucas Alcantara <lucasalcantaraf@gmail.com>
Luke Evers <me@lukevers.com>
Luke Kysow <lkysow@gmail.com>
@ -196,6 +210,7 @@ Luke Roberts <email@luke-roberts.co.uk>
Luke Young <luke@hydrantlabs.org>
lynn [they] <lynncyrin@gmail.com>
Maksim Zhylinski <uzzable@gmail.com>
Marc Binder <marcandrebinder@gmail.com>
Marcelo Carlos <marcelo@permutive.com>
Mark Tareshawty <tarebyte@github.com>
Martin Holman <me@martinholman.co.nz>
@ -204,6 +219,7 @@ Martins Sipenko <martins.sipenko@gmail.com>
Marwan Sulaiman <marwan.sameer@gmail.com>
Masayuki Izumi <m@izum.in>
Mat Geist <matgeist@gmail.com>
Matin Rahmanian <itsmatinx@gmail.com>
Matt <alpmatthew@gmail.com>
Matt Brender <mjbrender@gmail.com>
Matt Gaunt <matt@gauntface.co.uk>
@ -215,6 +231,7 @@ Michael Tiller <michael.tiller@gmail.com>
Michał Glapa <michal.glapa@gmail.com>
Michelangelo Morrillo <michelangelo@morrillo.it>
Mukundan Senthil <mukundan314@gmail.com>
Munia Balayil <munia.247@gmail.com>
Nadav Kaner <nadavkaner1@gmail.com>
Nathan VanBenschoten <nvanbenschoten@gmail.com>
Navaneeth Suresh <navaneeths1998@gmail.com>
@ -229,6 +246,7 @@ ns-cweber <cweber@narrativescience.com>
Ole Orhagen <ole.orhagen@northern.tech>
Oleg Kovalov <iamolegkovalov@gmail.com>
Ondřej Kupka <ondra.cap@gmail.com>
Ori Talmor <talmorori@gmail.com>
Pablo Pérez Schröder <pablo.perezschroder@wetransfer.com>
Palash Nigam <npalash25@gmail.com>
Panagiotis Moustafellos <pmoust@gmail.com>
@ -265,11 +283,13 @@ Ricco Førgaard <ricco@fiskeben.dk>
Rob Figueiredo <robfig@yext.com>
Rohit Upadhyay <urohit011@gmail.com>
Ronak Jain <ronakjain@outlook.in>
Ross Gustafson <srgustafson8@icloud.com>
Ruben Vereecken <rubenvereecken@gmail.com>
Russell Boley <raboley@gmail.com>
Ryan Leung <rleungx@gmail.com>
Ryan Lower <rpjlower@gmail.com>
Ryo Nakao <nakabonne@gmail.com>
Saaarah <sarah.liusy@gmail.com>
Safwan Olaimat <safwan.olaimat@gmail.com>
Sahil Dua <sahildua2305@gmail.com>
saisi <saisi@users.noreply.github.com>
@ -332,4 +352,6 @@ Yannick Utard <yannickutard@gmail.com>
Yicheng Qin <qycqycqycqycqyc@gmail.com>
Yosuke Akatsuka <yosuke.akatsuka@access-company.com>
Yumikiyo Osanai <yumios.art@gmail.com>
Yusuke Kuoka <ykuoka@gmail.com>
Zach Latta <zach@zachlatta.com>
zhouhaibing089 <zhouhaibing089@gmail.com>

@ -36,12 +36,15 @@ type CreateRunnerGroupRequest struct {
SelectedRepositoryIDs []int64 `json:"selected_repository_ids,omitempty"`
// Runners represent a list of runner IDs to add to the runner group.
Runners []int64 `json:"runners,omitempty"`
// If set to True, public repos can use this runner group
AllowsPublicRepositories *bool `json:"allows_public_repositories,omitempty"`
}
// UpdateRunnerGroupRequest represents a request to update a Runner group for an organization.
type UpdateRunnerGroupRequest struct {
Name *string `json:"name,omitempty"`
Visibility *string `json:"visibility,omitempty"`
Name *string `json:"name,omitempty"`
Visibility *string `json:"visibility,omitempty"`
AllowsPublicRepositories *bool `json:"allows_public_repositories,omitempty"`
}
// SetRepoAccessRunnerGroupRequest represents a request to replace the list of repositories
@ -156,8 +159,13 @@ func (s *ActionsService) UpdateOrganizationRunnerGroup(ctx context.Context, org
// ListRepositoryAccessRunnerGroup lists the repositories with access to a self-hosted runner group configured in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#list-repository-access-to-a-self-hosted-runner-group-in-an-organization
func (s *ActionsService) ListRepositoryAccessRunnerGroup(ctx context.Context, org string, groupID int64) (*ListRepositories, *Response, error) {
func (s *ActionsService) ListRepositoryAccessRunnerGroup(ctx context.Context, org string, groupID int64, opts *ListOptions) (*ListRepositories, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/repositories", org, groupID)
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err

@ -264,6 +264,65 @@ func (s *ActionsService) ListEnabledReposInOrg(ctx context.Context, owner string
return repos, resp, nil
}
// SetEnabledReposInOrg replaces the list of selected repositories that are enabled for GitHub Actions in an organization..
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#set-selected-repositories-enabled-for-github-actions-in-an-organization
func (s *ActionsService) SetEnabledReposInOrg(ctx context.Context, owner string, repositoryIDs []int64) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/permissions/repositories", owner)
req, err := s.client.NewRequest("PUT", u, struct {
IDs []int64 `json:"selected_repository_ids"`
}{IDs: repositoryIDs})
if err != nil {
return nil, err
}
resp, err := s.client.Do(ctx, req, nil)
if err != nil {
return resp, err
}
return resp, nil
}
// AddEnabledReposInOrg adds a repository to the list of selected repositories that are enabled for GitHub Actions in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#enable-a-selected-repository-for-github-actions-in-an-organization
func (s *ActionsService) AddEnabledReposInOrg(ctx context.Context, owner string, repositoryID int64) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/permissions/repositories/%v", owner, repositoryID)
req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, err
}
resp, err := s.client.Do(ctx, req, nil)
if err != nil {
return resp, err
}
return resp, nil
}
// RemoveEnabledRepoInOrg removes a single repository from the list of enabled repos for GitHub Actions in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#disable-a-selected-repository-for-github-actions-in-an-organization
func (s *ActionsService) RemoveEnabledRepoInOrg(ctx context.Context, owner string, repositoryID int64) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/permissions/repositories/%v", owner, repositoryID)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
resp, err := s.client.Do(ctx, req, nil)
if err != nil {
return resp, err
}
return resp, nil
}
// GetOrganizationRunner gets a specific self-hosted runner for an organization using its runner ID.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#get-a-self-hosted-runner-for-an-organization

@ -302,7 +302,7 @@ func (s *ActionsService) SetSelectedReposForOrgSecret(ctx context.Context, org,
u := fmt.Sprintf("orgs/%v/actions/secrets/%v/repositories", org, name)
type repoIDs struct {
SelectedIDs SelectedRepoIDs `json:"selected_repository_ids,omitempty"`
SelectedIDs SelectedRepoIDs `json:"selected_repository_ids"`
}
req, err := s.client.NewRequest("PUT", u, repoIDs{SelectedIDs: ids})

@ -38,6 +38,8 @@ type WorkflowJob struct {
Name *string `json:"name,omitempty"`
Steps []*TaskStep `json:"steps,omitempty"`
CheckRunURL *string `json:"check_run_url,omitempty"`
// Labels represents runner labels from the `runs-on:` key from a GitHub Actions workflow.
Labels []string `json:"labels,omitempty"`
}
// Jobs represents a slice of repository action workflow job.
@ -145,5 +147,4 @@ func (s *ActionsService) getWorkflowLogsFromURL(ctx context.Context, u string, f
resp, err = s.getWorkflowLogsFromURL(ctx, u, false)
}
return resp, err
}

@ -14,31 +14,33 @@ import (
// WorkflowRun represents a repository action workflow run.
type WorkflowRun struct {
ID *int64 `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
NodeID *string `json:"node_id,omitempty"`
HeadBranch *string `json:"head_branch,omitempty"`
HeadSHA *string `json:"head_sha,omitempty"`
RunNumber *int `json:"run_number,omitempty"`
Event *string `json:"event,omitempty"`
Status *string `json:"status,omitempty"`
Conclusion *string `json:"conclusion,omitempty"`
WorkflowID *int64 `json:"workflow_id,omitempty"`
URL *string `json:"url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
PullRequests []*PullRequest `json:"pull_requests,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
JobsURL *string `json:"jobs_url,omitempty"`
LogsURL *string `json:"logs_url,omitempty"`
CheckSuiteURL *string `json:"check_suite_url,omitempty"`
ArtifactsURL *string `json:"artifacts_url,omitempty"`
CancelURL *string `json:"cancel_url,omitempty"`
RerunURL *string `json:"rerun_url,omitempty"`
HeadCommit *HeadCommit `json:"head_commit,omitempty"`
WorkflowURL *string `json:"workflow_url,omitempty"`
Repository *Repository `json:"repository,omitempty"`
HeadRepository *Repository `json:"head_repository,omitempty"`
ID *int64 `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
NodeID *string `json:"node_id,omitempty"`
HeadBranch *string `json:"head_branch,omitempty"`
HeadSHA *string `json:"head_sha,omitempty"`
RunNumber *int `json:"run_number,omitempty"`
Event *string `json:"event,omitempty"`
Status *string `json:"status,omitempty"`
Conclusion *string `json:"conclusion,omitempty"`
WorkflowID *int64 `json:"workflow_id,omitempty"`
CheckSuiteID *int64 `json:"check_suite_id,omitempty"`
CheckSuiteNodeID *string `json:"check_suite_node_id,omitempty"`
URL *string `json:"url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
PullRequests []*PullRequest `json:"pull_requests,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
JobsURL *string `json:"jobs_url,omitempty"`
LogsURL *string `json:"logs_url,omitempty"`
CheckSuiteURL *string `json:"check_suite_url,omitempty"`
ArtifactsURL *string `json:"artifacts_url,omitempty"`
CancelURL *string `json:"cancel_url,omitempty"`
RerunURL *string `json:"rerun_url,omitempty"`
HeadCommit *HeadCommit `json:"head_commit,omitempty"`
WorkflowURL *string `json:"workflow_url,omitempty"`
Repository *Repository `json:"repository,omitempty"`
HeadRepository *Repository `json:"head_repository,omitempty"`
}
// WorkflowRuns represents a slice of repository action workflow run.
@ -49,10 +51,11 @@ type WorkflowRuns struct {
// ListWorkflowRunsOptions specifies optional parameters to ListWorkflowRuns.
type ListWorkflowRunsOptions struct {
Actor string `url:"actor,omitempty"`
Branch string `url:"branch,omitempty"`
Event string `url:"event,omitempty"`
Status string `url:"status,omitempty"`
Actor string `url:"actor,omitempty"`
Branch string `url:"branch,omitempty"`
Event string `url:"event,omitempty"`
Status string `url:"status,omitempty"`
Created string `url:"created,omitempty"`
ListOptions
}

@ -51,7 +51,7 @@ type NotificationListOptions struct {
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#list-notifications-for-the-authenticated-user
func (s *ActivityService) ListNotifications(ctx context.Context, opts *NotificationListOptions) ([]*Notification, *Response, error) {
u := fmt.Sprintf("notifications")
u := "notifications"
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err

@ -47,6 +47,10 @@ type InstallationTokenOptions struct {
// Providing repository IDs restricts the access of an installation token to specific repositories.
RepositoryIDs []int64 `json:"repository_ids,omitempty"`
// The names of the repositories that the installation token can access.
// Providing repository names restricts the access of an installation token to specific repositories.
Repositories []string `json:"repositories,omitempty"`
// The permissions granted to the access token.
// The permissions object includes the permission names and their access type.
Permissions *InstallationPermissions `json:"permissions,omitempty"`

@ -0,0 +1,48 @@
// Copyright 2021 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"context"
)
// GetHookConfig returns the webhook configuration for a GitHub App.
// The underlying transport must be authenticated as an app.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps#get-a-webhook-configuration-for-an-app
func (s *AppsService) GetHookConfig(ctx context.Context) (*HookConfig, *Response, error) {
req, err := s.client.NewRequest("GET", "app/hook/config", nil)
if err != nil {
return nil, nil, err
}
config := new(HookConfig)
resp, err := s.client.Do(ctx, req, &config)
if err != nil {
return nil, resp, err
}
return config, resp, nil
}
// UpdateHookConfig updates the webhook configuration for a GitHub App.
// The underlying transport must be authenticated as an app.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps#update-a-webhook-configuration-for-an-app
func (s *AppsService) UpdateHookConfig(ctx context.Context, config *HookConfig) (*HookConfig, *Response, error) {
req, err := s.client.NewRequest("PATCH", "app/hook/config", config)
if err != nil {
return nil, nil, err
}
c := new(HookConfig)
resp, err := s.client.Do(ctx, req, c)
if err != nil {
return nil, resp, err
}
return c, resp, nil
}

@ -13,6 +13,7 @@ import (
// AppConfig describes the configuration of a GitHub App.
type AppConfig struct {
ID *int64 `json:"id,omitempty"`
Slug *string `json:"slug,omitempty"`
NodeID *string `json:"node_id,omitempty"`
Owner *User `json:"owner,omitempty"`
Name *string `json:"name,omitempty"`

@ -78,6 +78,8 @@ type CheckSuite struct {
AfterSHA *string `json:"after,omitempty"`
Status *string `json:"status,omitempty"`
Conclusion *string `json:"conclusion,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
App *App `json:"app,omitempty"`
Repository *Repository `json:"repository,omitempty"`
PullRequests []*PullRequest `json:"pull_requests,omitempty"`

@ -18,9 +18,45 @@ import (
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/code-scanning/
type CodeScanningService service
// Rule represents the complete details of GitHub Code Scanning alert type.
type Rule struct {
ID *string `json:"id,omitempty"`
Severity *string `json:"severity,omitempty"`
Description *string `json:"description,omitempty"`
Name *string `json:"name,omitempty"`
SecuritySeverityLevel *string `json:"security_severity_level,omitempty"`
FullDescription *string `json:"full_description,omitempty"`
Tags []string `json:"tags,omitempty"`
Help *string `json:"help,omitempty"`
}
// Location represents the exact location of the GitHub Code Scanning Alert in the scanned project.
type Location struct {
Path *string `json:"path,omitempty"`
StartLine *int `json:"start_line,omitempty"`
EndLine *int `json:"end_line,omitempty"`
StartColumn *int `json:"start_column,omitempty"`
EndColumn *int `json:"end_column,omitempty"`
}
// Message is a part of MostRecentInstance struct which provides the appropriate message when any action is performed on the analysis object.
type Message struct {
Text *string `json:"text,omitempty"`
}
// MostRecentInstance provides details of the most recent instance of this alert for the default branch or for the specified Git reference.
type MostRecentInstance struct {
Ref *string `json:"ref,omitempty"`
AnalysisKey *string `json:"analysis_key,omitempty"`
Environment *string `json:"environment,omitempty"`
State *string `json:"state,omitempty"`
CommitSHA *string `json:"commit_sha,omitempty"`
Message *Message `json:"message,omitempty"`
Location *Location `json:"location,omitempty"`
Classifications []string `json:"classifications,omitempty"`
}
// Tool represents the tool used to generate a GitHub Code Scanning Alert.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/code-scanning#list-code-scanning-alerts-for-a-repository
type Tool struct {
Name *string `json:"name,omitempty"`
GUID *string `json:"guid,omitempty"`
@ -31,16 +67,22 @@ type Tool struct {
//
// GitHub API docs: https://docs.github.com/en/rest/reference/code-scanning#list-code-scanning-alerts-for-a-repository
type Alert struct {
RuleID *string `json:"rule_id,omitempty"`
RuleSeverity *string `json:"rule_severity,omitempty"`
RuleDescription *string `json:"rule_description,omitempty"`
Tool *Tool `json:"tool,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
Open *bool `json:"open,omitempty"`
ClosedBy *User `json:"closed_by,omitempty"`
ClosedAt *Timestamp `json:"closed_at,omitempty"`
URL *string `json:"url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
RuleID *string `json:"rule_id,omitempty"`
RuleSeverity *string `json:"rule_severity,omitempty"`
RuleDescription *string `json:"rule_description,omitempty"`
Rule *Rule `json:"rule,omitempty"`
Tool *Tool `json:"tool,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
State *string `json:"state,omitempty"`
ClosedBy *User `json:"closed_by,omitempty"`
ClosedAt *Timestamp `json:"closed_at,omitempty"`
URL *string `json:"url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
MostRecentInstance *MostRecentInstance `json:"most_recent_instance,omitempty"`
DismissedBy *User `json:"dismissed_by,omitempty"`
DismissedAt *Timestamp `json:"dismissed_at,omitempty"`
DismissedReason *string `json:"dismissed_reason,omitempty"`
InstancesURL *string `json:"instances_url,omitempty"`
}
// ID returns the ID associated with an alert. It is the number at the end of the security alert's URL.
@ -73,6 +115,8 @@ type AlertListOptions struct {
// Return code scanning alerts for a specific branch reference. The ref must be formatted as heads/<branch name>.
Ref string `url:"ref,omitempty"`
ListOptions
}
// ListAlertsForRepo lists code scanning alerts for a repository.

@ -8,7 +8,7 @@ Package github provides a client for using the GitHub API.
Usage:
import "github.com/google/go-github/v37/github" // with go modules enabled (GO111MODULE=on or outside GOPATH)
import "github.com/google/go-github/v39/github" // with go modules enabled (GO111MODULE=on or outside GOPATH)
import "github.com/google/go-github/github" // with go modules disabled
Construct a new GitHub client, then use the various services on the client to
@ -73,6 +73,10 @@ BasicAuthTransport.
GitHub Apps authentication can be provided by the
https://github.com/bradleyfalzon/ghinstallation package.
It supports both authentication as an installation, using an installation access token,
and as an app, using a JWT.
To authenticate as an installation:
import "github.com/bradleyfalzon/ghinstallation"
@ -89,6 +93,23 @@ https://github.com/bradleyfalzon/ghinstallation package.
// Use client...
}
To authenticate as an app, using a JWT:
import "github.com/bradleyfalzon/ghinstallation"
func main() {
// Wrap the shared transport for use with the application ID 1.
atr, err := ghinstallation.NewAppsTransportKeyFromFile(http.DefaultTransport, 1, "2016-10-19.private-key.pem")
if err != nil {
// Handle error.
}
// Use app transport with client
client := github.NewClient(&http.Client{Transport: atr})
// Use client...
}
Rate Limiting
GitHub imposes a rate limit on all API clients. Unauthenticated clients are
@ -112,7 +133,7 @@ To detect an API rate limit error, you can check if its type is *github.RateLimi
}
Learn more about GitHub rate limiting at
https://docs.github.com/en/free-pro-team@latest/rest/reference/#rate-limiting.
https://docs.github.com/en/free-pro-team@latest/rest/overview/resources-in-the-rest-api#rate-limiting.
Accepted Status
@ -138,7 +159,7 @@ instead designed to work with a caching http.Transport. We recommend using
https://github.com/gregjones/httpcache for that.
Learn more about GitHub conditional requests at
https://docs.github.com/en/free-pro-team@latest/rest/reference/#conditional-requests.
https://docs.github.com/en/free-pro-team@latest/rest/overview/resources-in-the-rest-api#conditional-requests.
Creating and Updating Resources

@ -30,6 +30,8 @@ func (e Event) String() string {
// a value of the corresponding struct type will be returned.
func (e *Event) ParsePayload() (payload interface{}, err error) {
switch *e.Type {
case "BranchProtectionRuleEvent":
payload = &BranchProtectionRuleEvent{}
case "CheckRunEvent":
payload = &CheckRunEvent{}
case "CheckSuiteEvent":
@ -124,6 +126,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) {
payload = &WatchEvent{}
case "WorkflowDispatchEvent":
payload = &WorkflowDispatchEvent{}
case "WorkflowJobEvent":
payload = &WorkflowJobEvent{}
case "WorkflowRunEvent":
payload = &WorkflowRunEvent{}
}

@ -15,6 +15,19 @@ type RequestedAction struct {
Identifier string `json:"identifier"` // The integrator reference of the action requested by the user.
}
// BranchProtectionRuleEvent triggered when a check suite is "created", "edited", or "deleted".
// The Webhook event name is "branch_protection_rule".
//
// GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#branch_protection_rule
type BranchProtectionRuleEvent struct {
Action *string `json:"action,omitempty"`
Rule *BranchProtectionRule `json:"rule,omitempty"`
Changes *ProtectionChanges `json:"changes,omitempty"`
Repo *Repository `json:"repository,omitempty"`
Org *Organization `json:"organization,omitempty"`
Sender *User `json:"sender,omitempty"`
}
// CheckRunEvent is triggered when a check run is "created", "completed", or "rerequested".
// The Webhook event name is "check_run".
//
@ -130,6 +143,9 @@ type DeployKeyEvent struct {
// The deploy key resource.
Key *Key `json:"key,omitempty"`
// The following fields are only populated by Webhook events.
Installation *Installation `json:"installation,omitempty"`
}
// DeploymentEvent represents a deployment.
@ -186,7 +202,8 @@ type GitHubAppAuthorizationEvent struct {
Action *string `json:"action,omitempty"`
// The following fields are only populated by Webhook events.
Sender *User `json:"sender,omitempty"`
Sender *User `json:"sender,omitempty"`
Installation *Installation `json:"installation,omitempty"`
}
// Page represents a single Wiki page.
@ -367,6 +384,10 @@ type IssueCommentEvent struct {
Repo *Repository `json:"repository,omitempty"`
Sender *User `json:"sender,omitempty"`
Installation *Installation `json:"installation,omitempty"`
// The following field is only present when the webhook is triggered on
// a repository belonging to an organization.
Organization *Organization `json:"organization,omitempty"`
}
// IssuesEvent is triggered when an issue is opened, edited, deleted, transferred,
@ -478,6 +499,9 @@ type MetaEvent struct {
// This will contain different keys based on the type of webhook it is: repository,
// organization, business, app, or GitHub Marketplace.
Hook *Hook `json:"hook,omitempty"`
// The following fields are only populated by Webhook events.
Installation *Installation `json:"installation,omitempty"`
}
// MilestoneEvent is triggered when a milestone is created, closed, opened, edited, or deleted.
@ -551,6 +575,9 @@ type PackageEvent struct {
Repo *Repository `json:"repository,omitempty"`
Org *Organization `json:"organization,omitempty"`
Sender *User `json:"sender,omitempty"`
// The following fields are only populated by Webhook events.
Installation *Installation `json:"installation,omitempty"`
}
// PageBuildEvent represents an attempted build of a GitHub Pages site, whether
@ -796,6 +823,10 @@ type PushEvent struct {
Pusher *User `json:"pusher,omitempty"`
Sender *User `json:"sender,omitempty"`
Installation *Installation `json:"installation,omitempty"`
// The following field is only present when the webhook is triggered on
// a repository belonging to an organization.
Organization *Organization `json:"organization,omitempty"`
}
func (p PushEvent) String() string {
@ -939,6 +970,9 @@ type RepositoryVulnerabilityAlertEvent struct {
//The repository of the vulnerable dependency.
Repository *Repository `json:"repository,omitempty"`
// The following fields are only populated by Webhook events.
Installation *Installation `json:"installation,omitempty"`
}
// RepositoryVulnerabilityAlert represents a repository security alert.
@ -969,9 +1003,10 @@ type StarEvent struct {
StarredAt *Timestamp `json:"starred_at,omitempty"`
// The following fields are only populated by Webhook events.
Org *Organization `json:"organization,omitempty"`
Repo *Repository `json:"repository,omitempty"`
Sender *User `json:"sender,omitempty"`
Org *Organization `json:"organization,omitempty"`
Repo *Repository `json:"repository,omitempty"`
Sender *User `json:"sender,omitempty"`
Installation *Installation `json:"installation,omitempty"`
}
// StatusEvent is triggered when the status of a Git commit changes.
@ -1049,6 +1084,9 @@ type UserEvent struct {
Action *string `json:"action,omitempty"`
Enterprise *Enterprise `json:"enterprise,omitempty"`
Sender *User `json:"sender,omitempty"`
// The following fields are only populated by Webhook events.
Installation *Installation `json:"installation,omitempty"`
}
// WatchEvent is related to starring a repository, not watching. See this API
@ -1078,9 +1116,28 @@ type WorkflowDispatchEvent struct {
Workflow *string `json:"workflow,omitempty"`
// The following fields are only populated by Webhook events.
Repo *Repository `json:"repository,omitempty"`
Org *Organization `json:"organization,omitempty"`
Sender *User `json:"sender,omitempty"`
Repo *Repository `json:"repository,omitempty"`
Org *Organization `json:"organization,omitempty"`
Sender *User `json:"sender,omitempty"`
Installation *Installation `json:"installation,omitempty"`
}
// WorkflowJobEvent is triggered when a job is queued, started or completed.
//
// GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_job
type WorkflowJobEvent struct {
WorkflowJob *WorkflowJob `json:"workflow_job,omitempty"`
Action *string `json:"action,omitempty"`
// The following fields are only populated by Webhook events.
// Org is not nil when the webhook is configured for an organization or the event
// occurs from activity in a repository owned by an organization.
Org *Organization `json:"organization,omitempty"`
Repo *Repository `json:"repository,omitempty"`
Sender *User `json:"sender,omitempty"`
Installation *Installation `json:"installation,omitempty"`
}
// WorkflowRunEvent is triggered when a GitHub Actions workflow run is requested or completed.
@ -1092,7 +1149,8 @@ type WorkflowRunEvent struct {
WorkflowRun *WorkflowRun `json:"workflow_run,omitempty"`
// The following fields are only populated by Webhook events.
Org *Organization `json:"organization,omitempty"`
Repo *Repository `json:"repository,omitempty"`
Sender *User `json:"sender,omitempty"`
Org *Organization `json:"organization,omitempty"`
Repo *Repository `json:"repository,omitempty"`
Sender *User `json:"sender,omitempty"`
Installation *Installation `json:"installation,omitempty"`
}

@ -172,6 +172,30 @@ func (a *Alert) GetCreatedAt() Timestamp {
return *a.CreatedAt
}
// GetDismissedAt returns the DismissedAt field if it's non-nil, zero value otherwise.
func (a *Alert) GetDismissedAt() Timestamp {
if a == nil || a.DismissedAt == nil {
return Timestamp{}
}
return *a.DismissedAt
}
// GetDismissedBy returns the DismissedBy field.
func (a *Alert) GetDismissedBy() *User {
if a == nil {
return nil
}
return a.DismissedBy
}
// GetDismissedReason returns the DismissedReason field if it's non-nil, zero value otherwise.
func (a *Alert) GetDismissedReason() string {
if a == nil || a.DismissedReason == nil {
return ""
}
return *a.DismissedReason
}
// GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise.
func (a *Alert) GetHTMLURL() string {
if a == nil || a.HTMLURL == nil {
@ -180,12 +204,28 @@ func (a *Alert) GetHTMLURL() string {
return *a.HTMLURL
}
// GetOpen returns the Open field if it's non-nil, zero value otherwise.
func (a *Alert) GetOpen() bool {
if a == nil || a.Open == nil {
return false
// GetInstancesURL returns the InstancesURL field if it's non-nil, zero value otherwise.
func (a *Alert) GetInstancesURL() string {
if a == nil || a.InstancesURL == nil {
return ""
}
return *a.Open
return *a.InstancesURL
}
// GetMostRecentInstance returns the MostRecentInstance field.
func (a *Alert) GetMostRecentInstance() *MostRecentInstance {
if a == nil {
return nil
}
return a.MostRecentInstance
}
// GetRule returns the Rule field.
func (a *Alert) GetRule() *Rule {
if a == nil {
return nil
}
return a.Rule
}
// GetRuleDescription returns the RuleDescription field if it's non-nil, zero value otherwise.
@ -212,6 +252,14 @@ func (a *Alert) GetRuleSeverity() string {
return *a.RuleSeverity
}
// GetState returns the State field if it's non-nil, zero value otherwise.
func (a *Alert) GetState() string {
if a == nil || a.State == nil {
return ""
}
return *a.State
}
// GetTool returns the Tool field.
func (a *Alert) GetTool() *Tool {
if a == nil {
@ -412,6 +460,14 @@ func (a *AppConfig) GetPEM() string {
return *a.PEM
}
// GetSlug returns the Slug field if it's non-nil, zero value otherwise.
func (a *AppConfig) GetSlug() string {
if a == nil || a.Slug == nil {
return ""
}
return *a.Slug
}
// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise.
func (a *AppConfig) GetUpdatedAt() Timestamp {
if a == nil || a.UpdatedAt == nil {
@ -1132,6 +1188,54 @@ func (a *AuthorizationUpdateRequest) GetNoteURL() string {
return *a.NoteURL
}
// GetFrom returns the From field if it's non-nil, zero value otherwise.
func (a *AuthorizedActorsOnly) GetFrom() bool {
if a == nil || a.From == nil {
return false
}
return *a.From
}
// GetID returns the ID field if it's non-nil, zero value otherwise.
func (a *Autolink) GetID() int64 {
if a == nil || a.ID == nil {
return 0
}
return *a.ID
}
// GetKeyPrefix returns the KeyPrefix field if it's non-nil, zero value otherwise.
func (a *Autolink) GetKeyPrefix() string {
if a == nil || a.KeyPrefix == nil {
return ""
}
return *a.KeyPrefix
}
// GetURLTemplate returns the URLTemplate field if it's non-nil, zero value otherwise.
func (a *Autolink) GetURLTemplate() string {
if a == nil || a.URLTemplate == nil {
return ""
}
return *a.URLTemplate
}
// GetKeyPrefix returns the KeyPrefix field if it's non-nil, zero value otherwise.
func (a *AutolinkOptions) GetKeyPrefix() string {
if a == nil || a.KeyPrefix == nil {
return ""
}
return *a.KeyPrefix
}
// GetURLTemplate returns the URLTemplate field if it's non-nil, zero value otherwise.
func (a *AutolinkOptions) GetURLTemplate() string {
if a == nil || a.URLTemplate == nil {
return ""
}
return *a.URLTemplate
}
// GetAppID returns the AppID field if it's non-nil, zero value otherwise.
func (a *AutoTriggerCheck) GetAppID() int64 {
if a == nil || a.AppID == nil {
@ -1268,6 +1372,230 @@ func (b *BranchPolicy) GetProtectedBranches() bool {
return *b.ProtectedBranches
}
// GetAdminEnforced returns the AdminEnforced field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetAdminEnforced() bool {
if b == nil || b.AdminEnforced == nil {
return false
}
return *b.AdminEnforced
}
// GetAllowDeletionsEnforcementLevel returns the AllowDeletionsEnforcementLevel field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetAllowDeletionsEnforcementLevel() string {
if b == nil || b.AllowDeletionsEnforcementLevel == nil {
return ""
}
return *b.AllowDeletionsEnforcementLevel
}
// GetAllowForcePushesEnforcementLevel returns the AllowForcePushesEnforcementLevel field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetAllowForcePushesEnforcementLevel() string {
if b == nil || b.AllowForcePushesEnforcementLevel == nil {
return ""
}
return *b.AllowForcePushesEnforcementLevel
}
// GetAuthorizedActorsOnly returns the AuthorizedActorsOnly field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetAuthorizedActorsOnly() bool {
if b == nil || b.AuthorizedActorsOnly == nil {
return false
}
return *b.AuthorizedActorsOnly
}
// GetAuthorizedDismissalActorsOnly returns the AuthorizedDismissalActorsOnly field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetAuthorizedDismissalActorsOnly() bool {
if b == nil || b.AuthorizedDismissalActorsOnly == nil {
return false
}
return *b.AuthorizedDismissalActorsOnly
}
// GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetCreatedAt() Timestamp {
if b == nil || b.CreatedAt == nil {
return Timestamp{}
}
return *b.CreatedAt
}
// GetDismissStaleReviewsOnPush returns the DismissStaleReviewsOnPush field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetDismissStaleReviewsOnPush() bool {
if b == nil || b.DismissStaleReviewsOnPush == nil {
return false
}
return *b.DismissStaleReviewsOnPush
}
// GetID returns the ID field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetID() int64 {
if b == nil || b.ID == nil {
return 0
}
return *b.ID
}
// GetIgnoreApprovalsFromContributors returns the IgnoreApprovalsFromContributors field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetIgnoreApprovalsFromContributors() bool {
if b == nil || b.IgnoreApprovalsFromContributors == nil {
return false
}
return *b.IgnoreApprovalsFromContributors
}
// GetLinearHistoryRequirementEnforcementLevel returns the LinearHistoryRequirementEnforcementLevel field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetLinearHistoryRequirementEnforcementLevel() string {
if b == nil || b.LinearHistoryRequirementEnforcementLevel == nil {
return ""
}
return *b.LinearHistoryRequirementEnforcementLevel
}
// GetMergeQueueEnforcementLevel returns the MergeQueueEnforcementLevel field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetMergeQueueEnforcementLevel() string {
if b == nil || b.MergeQueueEnforcementLevel == nil {
return ""
}
return *b.MergeQueueEnforcementLevel
}
// GetName returns the Name field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetName() string {
if b == nil || b.Name == nil {
return ""
}
return *b.Name
}
// GetPullRequestReviewsEnforcementLevel returns the PullRequestReviewsEnforcementLevel field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetPullRequestReviewsEnforcementLevel() string {
if b == nil || b.PullRequestReviewsEnforcementLevel == nil {
return ""
}
return *b.PullRequestReviewsEnforcementLevel
}
// GetRepositoryID returns the RepositoryID field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetRepositoryID() int64 {
if b == nil || b.RepositoryID == nil {
return 0
}
return *b.RepositoryID
}
// GetRequireCodeOwnerReview returns the RequireCodeOwnerReview field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetRequireCodeOwnerReview() bool {
if b == nil || b.RequireCodeOwnerReview == nil {
return false
}
return *b.RequireCodeOwnerReview
}
// GetRequiredApprovingReviewCount returns the RequiredApprovingReviewCount field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetRequiredApprovingReviewCount() int {
if b == nil || b.RequiredApprovingReviewCount == nil {
return 0
}
return *b.RequiredApprovingReviewCount
}
// GetRequiredConversationResolutionLevel returns the RequiredConversationResolutionLevel field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetRequiredConversationResolutionLevel() string {
if b == nil || b.RequiredConversationResolutionLevel == nil {
return ""
}
return *b.RequiredConversationResolutionLevel
}
// GetRequiredDeploymentsEnforcementLevel returns the RequiredDeploymentsEnforcementLevel field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetRequiredDeploymentsEnforcementLevel() string {
if b == nil || b.RequiredDeploymentsEnforcementLevel == nil {
return ""
}
return *b.RequiredDeploymentsEnforcementLevel
}
// GetRequiredStatusChecksEnforcementLevel returns the RequiredStatusChecksEnforcementLevel field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetRequiredStatusChecksEnforcementLevel() string {
if b == nil || b.RequiredStatusChecksEnforcementLevel == nil {
return ""
}
return *b.RequiredStatusChecksEnforcementLevel
}
// GetSignatureRequirementEnforcementLevel returns the SignatureRequirementEnforcementLevel field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetSignatureRequirementEnforcementLevel() string {
if b == nil || b.SignatureRequirementEnforcementLevel == nil {
return ""
}
return *b.SignatureRequirementEnforcementLevel
}
// GetStrictRequiredStatusChecksPolicy returns the StrictRequiredStatusChecksPolicy field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetStrictRequiredStatusChecksPolicy() bool {
if b == nil || b.StrictRequiredStatusChecksPolicy == nil {
return false
}
return *b.StrictRequiredStatusChecksPolicy
}
// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRule) GetUpdatedAt() Timestamp {
if b == nil || b.UpdatedAt == nil {
return Timestamp{}
}
return *b.UpdatedAt
}
// GetAction returns the Action field if it's non-nil, zero value otherwise.
func (b *BranchProtectionRuleEvent) GetAction() string {
if b == nil || b.Action == nil {
return ""
}
return *b.Action
}
// GetChanges returns the Changes field.
func (b *BranchProtectionRuleEvent) GetChanges() *ProtectionChanges {
if b == nil {
return nil
}
return b.Changes
}
// GetOrg returns the Org field.
func (b *BranchProtectionRuleEvent) GetOrg() *Organization {
if b == nil {
return nil
}
return b.Org
}
// GetRepo returns the Repo field.
func (b *BranchProtectionRuleEvent) GetRepo() *Repository {
if b == nil {
return nil
}
return b.Repo
}
// GetRule returns the Rule field.
func (b *BranchProtectionRuleEvent) GetRule() *BranchProtectionRule {
if b == nil {
return nil
}
return b.Rule
}
// GetSender returns the Sender field.
func (b *BranchProtectionRuleEvent) GetSender() *User {
if b == nil {
return nil
}
return b.Sender
}
// GetApp returns the App field.
func (c *CheckRun) GetApp() *App {
if c == nil {
@ -1612,6 +1940,14 @@ func (c *CheckSuite) GetConclusion() string {
return *c.Conclusion
}
// GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise.
func (c *CheckSuite) GetCreatedAt() Timestamp {
if c == nil || c.CreatedAt == nil {
return Timestamp{}
}
return *c.CreatedAt
}
// GetHeadBranch returns the HeadBranch field if it's non-nil, zero value otherwise.
func (c *CheckSuite) GetHeadBranch() string {
if c == nil || c.HeadBranch == nil {
@ -1668,6 +2004,14 @@ func (c *CheckSuite) GetStatus() string {
return *c.Status
}
// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise.
func (c *CheckSuite) GetUpdatedAt() Timestamp {
if c == nil || c.UpdatedAt == nil {
return Timestamp{}
}
return *c.UpdatedAt
}
// GetURL returns the URL field if it's non-nil, zero value otherwise.
func (c *CheckSuite) GetURL() string {
if c == nil || c.URL == nil {
@ -2436,6 +2780,14 @@ func (c *CommunityHealthFiles) GetCodeOfConduct() *Metric {
return c.CodeOfConduct
}
// GetCodeOfConductFile returns the CodeOfConductFile field.
func (c *CommunityHealthFiles) GetCodeOfConductFile() *Metric {
if c == nil {
return nil
}
return c.CodeOfConductFile
}
// GetContributing returns the Contributing field.
func (c *CommunityHealthFiles) GetContributing() *Metric {
if c == nil {
@ -2476,6 +2828,30 @@ func (c *CommunityHealthFiles) GetReadme() *Metric {
return c.Readme
}
// GetContentReportsEnabled returns the ContentReportsEnabled field if it's non-nil, zero value otherwise.
func (c *CommunityHealthMetrics) GetContentReportsEnabled() bool {
if c == nil || c.ContentReportsEnabled == nil {
return false
}
return *c.ContentReportsEnabled
}
// GetDescription returns the Description field if it's non-nil, zero value otherwise.
func (c *CommunityHealthMetrics) GetDescription() string {
if c == nil || c.Description == nil {
return ""
}
return *c.Description
}
// GetDocumentation returns the Documentation field if it's non-nil, zero value otherwise.
func (c *CommunityHealthMetrics) GetDocumentation() string {
if c == nil || c.Documentation == nil {
return ""
}
return *c.Documentation
}
// GetFiles returns the Files field.
func (c *CommunityHealthMetrics) GetFiles() *CommunityHealthFiles {
if c == nil {
@ -2900,6 +3276,14 @@ func (c *CreateOrgInvitationOptions) GetRole() string {
return *c.Role
}
// GetAllowsPublicRepositories returns the AllowsPublicRepositories field if it's non-nil, zero value otherwise.
func (c *CreateRunnerGroupRequest) GetAllowsPublicRepositories() bool {
if c == nil || c.AllowsPublicRepositories == nil {
return false
}
return *c.AllowsPublicRepositories
}
// GetName returns the Name field if it's non-nil, zero value otherwise.
func (c *CreateRunnerGroupRequest) GetName() string {
if c == nil || c.Name == nil {
@ -2996,6 +3380,14 @@ func (d *DeployKeyEvent) GetAction() string {
return *d.Action
}
// GetInstallation returns the Installation field.
func (d *DeployKeyEvent) GetInstallation() *Installation {
if d == nil {
return nil
}
return d.Installation
}
// GetKey returns the Key field.
func (d *DeployKeyEvent) GetKey() *Key {
if d == nil {
@ -4124,6 +4516,22 @@ func (f *ForkEvent) GetSender() *User {
return f.Sender
}
// GetPreviousTagName returns the PreviousTagName field if it's non-nil, zero value otherwise.
func (g *GenerateNotesOptions) GetPreviousTagName() string {
if g == nil || g.PreviousTagName == nil {
return ""
}
return *g.PreviousTagName
}
// GetTargetCommitish returns the TargetCommitish field if it's non-nil, zero value otherwise.
func (g *GenerateNotesOptions) GetTargetCommitish() string {
if g == nil || g.TargetCommitish == nil {
return ""
}
return *g.TargetCommitish
}
// GetInclude returns the Include field if it's non-nil, zero value otherwise.
func (g *GetAuditLogOptions) GetInclude() string {
if g == nil || g.Include == nil {
@ -4460,6 +4868,14 @@ func (g *GitHubAppAuthorizationEvent) GetAction() string {
return *g.Action
}
// GetInstallation returns the Installation field.
func (g *GitHubAppAuthorizationEvent) GetInstallation() *Installation {
if g == nil {
return nil
}
return g.Installation
}
// GetSender returns the Sender field.
func (g *GitHubAppAuthorizationEvent) GetSender() *User {
if g == nil {
@ -4628,6 +5044,14 @@ func (g *GPGKey) GetPublicKey() string {
return *g.PublicKey
}
// GetRawKey returns the RawKey field if it's non-nil, zero value otherwise.
func (g *GPGKey) GetRawKey() string {
if g == nil || g.RawKey == nil {
return ""
}
return *g.RawKey
}
// GetApp returns the App field.
func (g *Grant) GetApp() *AuthorizationApp {
if g == nil {
@ -4828,6 +5252,14 @@ func (h *HookConfig) GetInsecureSSL() string {
return *h.InsecureSSL
}
// GetSecret returns the Secret field if it's non-nil, zero value otherwise.
func (h *HookConfig) GetSecret() string {
if h == nil || h.Secret == nil {
return ""
}
return *h.Secret
}
// GetURL returns the URL field if it's non-nil, zero value otherwise.
func (h *HookConfig) GetURL() string {
if h == nil || h.URL == nil {
@ -4836,6 +5268,142 @@ func (h *HookConfig) GetURL() string {
return *h.URL
}
// GetAction returns the Action field if it's non-nil, zero value otherwise.
func (h *HookDelivery) GetAction() string {
if h == nil || h.Action == nil {
return ""
}
return *h.Action
}
// GetDeliveredAt returns the DeliveredAt field if it's non-nil, zero value otherwise.
func (h *HookDelivery) GetDeliveredAt() Timestamp {
if h == nil || h.DeliveredAt == nil {
return Timestamp{}
}
return *h.DeliveredAt
}
// GetDuration returns the Duration field.
func (h *HookDelivery) GetDuration() *float64 {
if h == nil {
return nil
}
return h.Duration
}
// GetEvent returns the Event field if it's non-nil, zero value otherwise.
func (h *HookDelivery) GetEvent() string {
if h == nil || h.Event == nil {
return ""
}
return *h.Event
}
// GetGUID returns the GUID field if it's non-nil, zero value otherwise.
func (h *HookDelivery) GetGUID() string {
if h == nil || h.GUID == nil {
return ""
}
return *h.GUID
}
// GetID returns the ID field if it's non-nil, zero value otherwise.
func (h *HookDelivery) GetID() int64 {
if h == nil || h.ID == nil {
return 0
}
return *h.ID
}
// GetInstallationID returns the InstallationID field if it's non-nil, zero value otherwise.
func (h *HookDelivery) GetInstallationID() string {
if h == nil || h.InstallationID == nil {
return ""
}
return *h.InstallationID
}
// GetRedelivery returns the Redelivery field if it's non-nil, zero value otherwise.
func (h *HookDelivery) GetRedelivery() bool {
if h == nil || h.Redelivery == nil {
return false
}
return *h.Redelivery
}
// GetRepositoryID returns the RepositoryID field if it's non-nil, zero value otherwise.
func (h *HookDelivery) GetRepositoryID() int64 {
if h == nil || h.RepositoryID == nil {
return 0
}
return *h.RepositoryID
}
// GetRequest returns the Request field.
func (h *HookDelivery) GetRequest() *HookRequest {
if h == nil {
return nil
}
return h.Request
}
// GetResponse returns the Response field.
func (h *HookDelivery) GetResponse() *HookResponse {
if h == nil {
return nil
}
return h.Response
}
// GetStatus returns the Status field if it's non-nil, zero value otherwise.
func (h *HookDelivery) GetStatus() string {
if h == nil || h.Status == nil {
return ""
}
return *h.Status
}
// GetStatusCode returns the StatusCode field if it's non-nil, zero value otherwise.
func (h *HookDelivery) GetStatusCode() int {
if h == nil || h.StatusCode == nil {
return 0
}
return *h.StatusCode
}
// GetHeaders returns the Headers map if it's non-nil, an empty map otherwise.
func (h *HookRequest) GetHeaders() map[string]string {
if h == nil || h.Headers == nil {
return map[string]string{}
}
return h.Headers
}
// GetRawPayload returns the RawPayload field if it's non-nil, zero value otherwise.
func (h *HookRequest) GetRawPayload() json.RawMessage {
if h == nil || h.RawPayload == nil {
return json.RawMessage{}
}
return *h.RawPayload
}
// GetHeaders returns the Headers map if it's non-nil, an empty map otherwise.
func (h *HookResponse) GetHeaders() map[string]string {
if h == nil || h.Headers == nil {
return map[string]string{}
}
return h.Headers
}
// GetRawPayload returns the RawPayload field if it's non-nil, zero value otherwise.
func (h *HookResponse) GetRawPayload() json.RawMessage {
if h == nil || h.RawPayload == nil {
return json.RawMessage{}
}
return *h.RawPayload
}
// GetActiveHooks returns the ActiveHooks field if it's non-nil, zero value otherwise.
func (h *HookStats) GetActiveHooks() int {
if h == nil || h.ActiveHooks == nil {
@ -6020,6 +6588,14 @@ func (i *IssueCommentEvent) GetIssue() *Issue {
return i.Issue
}
// GetOrganization returns the Organization field.
func (i *IssueCommentEvent) GetOrganization() *Organization {
if i == nil {
return nil
}
return i.Organization
}
// GetRepo returns the Repo field.
func (i *IssueCommentEvent) GetRepo() *Repository {
if i == nil {
@ -6956,6 +7532,70 @@ func (l *ListRepositories) GetTotalCount() int {
return *l.TotalCount
}
// GetCount returns the Count field if it's non-nil, zero value otherwise.
func (l *ListSCIMProvisionedIdentitiesOptions) GetCount() int {
if l == nil || l.Count == nil {
return 0
}
return *l.Count
}
// GetFilter returns the Filter field if it's non-nil, zero value otherwise.
func (l *ListSCIMProvisionedIdentitiesOptions) GetFilter() string {
if l == nil || l.Filter == nil {
return ""
}
return *l.Filter
}
// GetStartIndex returns the StartIndex field if it's non-nil, zero value otherwise.
func (l *ListSCIMProvisionedIdentitiesOptions) GetStartIndex() int {
if l == nil || l.StartIndex == nil {
return 0
}
return *l.StartIndex
}
// GetEndColumn returns the EndColumn field if it's non-nil, zero value otherwise.
func (l *Location) GetEndColumn() int {
if l == nil || l.EndColumn == nil {
return 0
}
return *l.EndColumn
}
// GetEndLine returns the EndLine field if it's non-nil, zero value otherwise.
func (l *Location) GetEndLine() int {
if l == nil || l.EndLine == nil {
return 0
}
return *l.EndLine
}
// GetPath returns the Path field if it's non-nil, zero value otherwise.
func (l *Location) GetPath() string {
if l == nil || l.Path == nil {
return ""
}
return *l.Path
}
// GetStartColumn returns the StartColumn field if it's non-nil, zero value otherwise.
func (l *Location) GetStartColumn() int {
if l == nil || l.StartColumn == nil {
return 0
}
return *l.StartColumn
}
// GetStartLine returns the StartLine field if it's non-nil, zero value otherwise.
func (l *Location) GetStartLine() int {
if l == nil || l.StartLine == nil {
return 0
}
return *l.StartLine
}
// GetEffectiveDate returns the EffectiveDate field if it's non-nil, zero value otherwise.
func (m *MarketplacePendingChange) GetEffectiveDate() Timestamp {
if m == nil || m.EffectiveDate == nil {
@ -7404,6 +8044,14 @@ func (m *MembershipEvent) GetTeam() *Team {
return m.Team
}
// GetText returns the Text field if it's non-nil, zero value otherwise.
func (m *Message) GetText() string {
if m == nil || m.Text == nil {
return ""
}
return *m.Text
}
// GetAction returns the Action field if it's non-nil, zero value otherwise.
func (m *MetaEvent) GetAction() string {
if m == nil || m.Action == nil {
@ -7428,6 +8076,14 @@ func (m *MetaEvent) GetHookID() int64 {
return *m.HookID
}
// GetInstallation returns the Installation field.
func (m *MetaEvent) GetInstallation() *Installation {
if m == nil {
return nil
}
return m.Installation
}
// GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise.
func (m *Metric) GetHTMLURL() string {
if m == nil || m.HTMLURL == nil {
@ -7452,6 +8108,22 @@ func (m *Metric) GetName() string {
return *m.Name
}
// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise.
func (m *Metric) GetNodeID() string {
if m == nil || m.NodeID == nil {
return ""
}
return *m.NodeID
}
// GetSPDXID returns the SPDXID field if it's non-nil, zero value otherwise.
func (m *Metric) GetSPDXID() string {
if m == nil || m.SPDXID == nil {
return ""
}
return *m.SPDXID
}
// GetURL returns the URL field if it's non-nil, zero value otherwise.
func (m *Metric) GetURL() string {
if m == nil || m.URL == nil {
@ -7732,6 +8404,62 @@ func (m *MilestoneStats) GetTotalMilestones() int {
return *m.TotalMilestones
}
// GetAnalysisKey returns the AnalysisKey field if it's non-nil, zero value otherwise.
func (m *MostRecentInstance) GetAnalysisKey() string {
if m == nil || m.AnalysisKey == nil {
return ""
}
return *m.AnalysisKey
}
// GetCommitSHA returns the CommitSHA field if it's non-nil, zero value otherwise.
func (m *MostRecentInstance) GetCommitSHA() string {
if m == nil || m.CommitSHA == nil {
return ""
}
return *m.CommitSHA
}
// GetEnvironment returns the Environment field if it's non-nil, zero value otherwise.
func (m *MostRecentInstance) GetEnvironment() string {
if m == nil || m.Environment == nil {
return ""
}
return *m.Environment
}
// GetLocation returns the Location field.
func (m *MostRecentInstance) GetLocation() *Location {
if m == nil {
return nil
}
return m.Location
}
// GetMessage returns the Message field.
func (m *MostRecentInstance) GetMessage() *Message {
if m == nil {
return nil
}
return m.Message
}
// GetRef returns the Ref field if it's non-nil, zero value otherwise.
func (m *MostRecentInstance) GetRef() string {
if m == nil || m.Ref == nil {
return ""
}
return *m.Ref
}
// GetState returns the State field if it's non-nil, zero value otherwise.
func (m *MostRecentInstance) GetState() string {
if m == nil || m.State == nil {
return ""
}
return *m.State
}
// GetBase returns the Base field if it's non-nil, zero value otherwise.
func (n *NewPullRequest) GetBase() string {
if n == nil || n.Base == nil {
@ -8516,6 +9244,14 @@ func (p *Package) GetRegistry() *PackageRegistry {
return p.Registry
}
// GetRepository returns the Repository field.
func (p *Package) GetRepository() *Repository {
if p == nil {
return nil
}
return p.Repository
}
// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise.
func (p *Package) GetUpdatedAt() Timestamp {
if p == nil || p.UpdatedAt == nil {
@ -8524,6 +9260,30 @@ func (p *Package) GetUpdatedAt() Timestamp {
return *p.UpdatedAt
}
// GetURL returns the URL field if it's non-nil, zero value otherwise.
func (p *Package) GetURL() string {
if p == nil || p.URL == nil {
return ""
}
return *p.URL
}
// GetVersionCount returns the VersionCount field if it's non-nil, zero value otherwise.
func (p *Package) GetVersionCount() int64 {
if p == nil || p.VersionCount == nil {
return 0
}
return *p.VersionCount
}
// GetVisibility returns the Visibility field if it's non-nil, zero value otherwise.
func (p *Package) GetVisibility() string {
if p == nil || p.Visibility == nil {
return ""
}
return *p.Visibility
}
// GetAction returns the Action field if it's non-nil, zero value otherwise.
func (p *PackageEvent) GetAction() string {
if p == nil || p.Action == nil {
@ -8532,6 +9292,14 @@ func (p *PackageEvent) GetAction() string {
return *p.Action
}
// GetInstallation returns the Installation field.
func (p *PackageEvent) GetInstallation() *Installation {
if p == nil {
return nil
}
return p.Installation
}
// GetOrg returns the Org field.
func (p *PackageEvent) GetOrg() *Organization {
if p == nil {
@ -8660,6 +9428,46 @@ func (p *PackageFile) GetUpdatedAt() Timestamp {
return *p.UpdatedAt
}
// GetPackageType returns the PackageType field if it's non-nil, zero value otherwise.
func (p *PackageListOptions) GetPackageType() string {
if p == nil || p.PackageType == nil {
return ""
}
return *p.PackageType
}
// GetState returns the State field if it's non-nil, zero value otherwise.
func (p *PackageListOptions) GetState() string {
if p == nil || p.State == nil {
return ""
}
return *p.State
}
// GetVisibility returns the Visibility field if it's non-nil, zero value otherwise.
func (p *PackageListOptions) GetVisibility() string {
if p == nil || p.Visibility == nil {
return ""
}
return *p.Visibility
}
// GetContainer returns the Container field.
func (p *PackageMetadata) GetContainer() *PackageContainerMetadata {
if p == nil {
return nil
}
return p.Container
}
// GetPackageType returns the PackageType field if it's non-nil, zero value otherwise.
func (p *PackageMetadata) GetPackageType() string {
if p == nil || p.PackageType == nil {
return ""
}
return *p.PackageType
}
// GetAboutURL returns the AboutURL field if it's non-nil, zero value otherwise.
func (p *PackageRegistry) GetAboutURL() string {
if p == nil || p.AboutURL == nil {
@ -8860,6 +9668,30 @@ func (p *PackageVersion) GetManifest() string {
return *p.Manifest
}
// GetMetadata returns the Metadata field.
func (p *PackageVersion) GetMetadata() *PackageMetadata {
if p == nil {
return nil
}
return p.Metadata
}
// GetName returns the Name field if it's non-nil, zero value otherwise.
func (p *PackageVersion) GetName() string {
if p == nil || p.Name == nil {
return ""
}
return *p.Name
}
// GetPackageHTMLURL returns the PackageHTMLURL field if it's non-nil, zero value otherwise.
func (p *PackageVersion) GetPackageHTMLURL() string {
if p == nil || p.PackageHTMLURL == nil {
return ""
}
return *p.PackageHTMLURL
}
// GetPrerelease returns the Prerelease field if it's non-nil, zero value otherwise.
func (p *PackageVersion) GetPrerelease() bool {
if p == nil || p.Prerelease == nil {
@ -8916,6 +9748,14 @@ func (p *PackageVersion) GetUpdatedAt() Timestamp {
return *p.UpdatedAt
}
// GetURL returns the URL field if it's non-nil, zero value otherwise.
func (p *PackageVersion) GetURL() string {
if p == nil || p.URL == nil {
return ""
}
return *p.URL
}
// GetVersion returns the Version field if it's non-nil, zero value otherwise.
func (p *PackageVersion) GetVersion() string {
if p == nil || p.Version == nil {
@ -10036,6 +10876,22 @@ func (p *Protection) GetRestrictions() *BranchRestrictions {
return p.Restrictions
}
// GetAuthorizedActorNames returns the AuthorizedActorNames field.
func (p *ProtectionChanges) GetAuthorizedActorNames() *AuthorizedActorNames {
if p == nil {
return nil
}
return p.AuthorizedActorNames
}
// GetAuthorizedActorsOnly returns the AuthorizedActorsOnly field.
func (p *ProtectionChanges) GetAuthorizedActorsOnly() *AuthorizedActorsOnly {
if p == nil {
return nil
}
return p.AuthorizedActorsOnly
}
// GetAllowDeletions returns the AllowDeletions field if it's non-nil, zero value otherwise.
func (p *ProtectionRequest) GetAllowDeletions() bool {
if p == nil || p.AllowDeletions == nil {
@ -10052,6 +10908,14 @@ func (p *ProtectionRequest) GetAllowForcePushes() bool {
return *p.AllowForcePushes
}
// GetRequiredConversationResolution returns the RequiredConversationResolution field if it's non-nil, zero value otherwise.
func (p *ProtectionRequest) GetRequiredConversationResolution() bool {
if p == nil || p.RequiredConversationResolution == nil {
return false
}
return *p.RequiredConversationResolution
}
// GetRequiredPullRequestReviews returns the RequiredPullRequestReviews field.
func (p *ProtectionRequest) GetRequiredPullRequestReviews() *PullRequestReviewsEnforcementRequest {
if p == nil {
@ -11492,6 +12356,14 @@ func (p *PushEvent) GetInstallation() *Installation {
return p.Installation
}
// GetOrganization returns the Organization field.
func (p *PushEvent) GetOrganization() *Organization {
if p == nil {
return nil
}
return p.Organization
}
// GetPusher returns the Pusher field.
func (p *PushEvent) GetPusher() *User {
if p == nil {
@ -12228,6 +13100,14 @@ func (r *RepositoriesSearchResult) GetTotal() int {
return *r.Total
}
// GetAllowAutoMerge returns the AllowAutoMerge field if it's non-nil, zero value otherwise.
func (r *Repository) GetAllowAutoMerge() bool {
if r == nil || r.AllowAutoMerge == nil {
return false
}
return *r.AllowAutoMerge
}
// GetAllowMergeCommit returns the AllowMergeCommit field if it's non-nil, zero value otherwise.
func (r *Repository) GetAllowMergeCommit() bool {
if r == nil || r.AllowMergeCommit == nil {
@ -13596,6 +14476,14 @@ func (r *RepositoryRelease) GetDraft() bool {
return *r.Draft
}
// GetGenerateReleaseNotes returns the GenerateReleaseNotes field if it's non-nil, zero value otherwise.
func (r *RepositoryRelease) GetGenerateReleaseNotes() bool {
if r == nil || r.GenerateReleaseNotes == nil {
return false
}
return *r.GenerateReleaseNotes
}
// GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise.
func (r *RepositoryRelease) GetHTMLURL() string {
if r == nil || r.HTMLURL == nil {
@ -13836,6 +14724,14 @@ func (r *RepositoryVulnerabilityAlertEvent) GetAlert() *RepositoryVulnerabilityA
return r.Alert
}
// GetInstallation returns the Installation field.
func (r *RepositoryVulnerabilityAlertEvent) GetInstallation() *Installation {
if r == nil {
return nil
}
return r.Installation
}
// GetRepository returns the Repository field.
func (r *RepositoryVulnerabilityAlertEvent) GetRepository() *Repository {
if r == nil {
@ -13892,6 +14788,14 @@ func (r *RepoStats) GetTotalWikis() int {
return *r.TotalWikis
}
// GetAvatarURL returns the AvatarURL field if it's non-nil, zero value otherwise.
func (r *RepoStatus) GetAvatarURL() string {
if r == nil || r.AvatarURL == nil {
return ""
}
return *r.AvatarURL
}
// GetContext returns the Context field if it's non-nil, zero value otherwise.
func (r *RepoStatus) GetContext() string {
if r == nil || r.Context == nil {
@ -13996,6 +14900,62 @@ func (r *ReviewersRequest) GetNodeID() string {
return *r.NodeID
}
// GetDescription returns the Description field if it's non-nil, zero value otherwise.
func (r *Rule) GetDescription() string {
if r == nil || r.Description == nil {
return ""
}
return *r.Description
}
// GetFullDescription returns the FullDescription field if it's non-nil, zero value otherwise.
func (r *Rule) GetFullDescription() string {
if r == nil || r.FullDescription == nil {
return ""
}
return *r.FullDescription
}
// GetHelp returns the Help field if it's non-nil, zero value otherwise.
func (r *Rule) GetHelp() string {
if r == nil || r.Help == nil {
return ""
}
return *r.Help
}
// GetID returns the ID field if it's non-nil, zero value otherwise.
func (r *Rule) GetID() string {
if r == nil || r.ID == nil {
return ""
}
return *r.ID
}
// GetName returns the Name field if it's non-nil, zero value otherwise.
func (r *Rule) GetName() string {
if r == nil || r.Name == nil {
return ""
}
return *r.Name
}
// GetSecuritySeverityLevel returns the SecuritySeverityLevel field if it's non-nil, zero value otherwise.
func (r *Rule) GetSecuritySeverityLevel() string {
if r == nil || r.SecuritySeverityLevel == nil {
return ""
}
return *r.SecuritySeverityLevel
}
// GetSeverity returns the Severity field if it's non-nil, zero value otherwise.
func (r *Rule) GetSeverity() string {
if r == nil || r.Severity == nil {
return ""
}
return *r.Severity
}
// GetBusy returns the Busy field if it's non-nil, zero value otherwise.
func (r *Runner) GetBusy() bool {
if r == nil || r.Busy == nil {
@ -14172,6 +15132,54 @@ func (r *RunnerLabels) GetType() string {
return *r.Type
}
// GetActive returns the Active field if it's non-nil, zero value otherwise.
func (s *SCIMUserAttributes) GetActive() bool {
if s == nil || s.Active == nil {
return false
}
return *s.Active
}
// GetDisplayName returns the DisplayName field if it's non-nil, zero value otherwise.
func (s *SCIMUserAttributes) GetDisplayName() string {
if s == nil || s.DisplayName == nil {
return ""
}
return *s.DisplayName
}
// GetExternalID returns the ExternalID field if it's non-nil, zero value otherwise.
func (s *SCIMUserAttributes) GetExternalID() string {
if s == nil || s.ExternalID == nil {
return ""
}
return *s.ExternalID
}
// GetPrimary returns the Primary field if it's non-nil, zero value otherwise.
func (s *SCIMUserEmail) GetPrimary() bool {
if s == nil || s.Primary == nil {
return false
}
return *s.Primary
}
// GetType returns the Type field if it's non-nil, zero value otherwise.
func (s *SCIMUserEmail) GetType() string {
if s == nil || s.Type == nil {
return ""
}
return *s.Type
}
// GetFormatted returns the Formatted field if it's non-nil, zero value otherwise.
func (s *SCIMUserName) GetFormatted() string {
if s == nil || s.Formatted == nil {
return ""
}
return *s.Formatted
}
// GetTotalCount returns the TotalCount field if it's non-nil, zero value otherwise.
func (s *SelectedReposList) GetTotalCount() int {
if s == nil || s.TotalCount == nil {
@ -14340,6 +15348,14 @@ func (s *StarEvent) GetAction() string {
return *s.Action
}
// GetInstallation returns the Installation field.
func (s *StarEvent) GetInstallation() *Installation {
if s == nil {
return nil
}
return s.Installation
}
// GetOrg returns the Org field.
func (s *StarEvent) GetOrg() *Organization {
if s == nil {
@ -15716,6 +16732,14 @@ func (t *TreeEntry) GetURL() string {
return *t.URL
}
// GetPath returns the Path field if it's non-nil, zero value otherwise.
func (u *UpdateAttributeForSCIMUserOperations) GetPath() string {
if u == nil || u.Path == nil {
return ""
}
return *u.Path
}
// GetCompletedAt returns the CompletedAt field if it's non-nil, zero value otherwise.
func (u *UpdateCheckRunOptions) GetCompletedAt() Timestamp {
if u == nil || u.CompletedAt == nil {
@ -15764,6 +16788,14 @@ func (u *UpdateCheckRunOptions) GetStatus() string {
return *u.Status
}
// GetAllowsPublicRepositories returns the AllowsPublicRepositories field if it's non-nil, zero value otherwise.
func (u *UpdateRunnerGroupRequest) GetAllowsPublicRepositories() bool {
if u == nil || u.AllowsPublicRepositories == nil {
return false
}
return *u.AllowsPublicRepositories
}
// GetName returns the Name field if it's non-nil, zero value otherwise.
func (u *UpdateRunnerGroupRequest) GetName() string {
if u == nil || u.Name == nil {
@ -16268,6 +17300,14 @@ func (u *UserEvent) GetEnterprise() *Enterprise {
return u.Enterprise
}
// GetInstallation returns the Installation field.
func (u *UserEvent) GetInstallation() *Installation {
if u == nil {
return nil
}
return u.Installation
}
// GetSender returns the Sender field.
func (u *UserEvent) GetSender() *User {
if u == nil {
@ -16884,6 +17924,14 @@ func (w *WorkflowBill) GetTotalMS() int64 {
return *w.TotalMS
}
// GetInstallation returns the Installation field.
func (w *WorkflowDispatchEvent) GetInstallation() *Installation {
if w == nil {
return nil
}
return w.Installation
}
// GetOrg returns the Org field.
func (w *WorkflowDispatchEvent) GetOrg() *Organization {
if w == nil {
@ -17052,6 +18100,54 @@ func (w *WorkflowJob) GetURL() string {
return *w.URL
}
// GetAction returns the Action field if it's non-nil, zero value otherwise.
func (w *WorkflowJobEvent) GetAction() string {
if w == nil || w.Action == nil {
return ""
}
return *w.Action
}
// GetInstallation returns the Installation field.
func (w *WorkflowJobEvent) GetInstallation() *Installation {
if w == nil {
return nil
}
return w.Installation
}
// GetOrg returns the Org field.
func (w *WorkflowJobEvent) GetOrg() *Organization {
if w == nil {
return nil
}
return w.Org
}
// GetRepo returns the Repo field.
func (w *WorkflowJobEvent) GetRepo() *Repository {
if w == nil {
return nil
}
return w.Repo
}
// GetSender returns the Sender field.
func (w *WorkflowJobEvent) GetSender() *User {
if w == nil {
return nil
}
return w.Sender
}
// GetWorkflowJob returns the WorkflowJob field.
func (w *WorkflowJobEvent) GetWorkflowJob() *WorkflowJob {
if w == nil {
return nil
}
return w.WorkflowJob
}
// GetArtifactsURL returns the ArtifactsURL field if it's non-nil, zero value otherwise.
func (w *WorkflowRun) GetArtifactsURL() string {
if w == nil || w.ArtifactsURL == nil {
@ -17068,6 +18164,22 @@ func (w *WorkflowRun) GetCancelURL() string {
return *w.CancelURL
}
// GetCheckSuiteID returns the CheckSuiteID field if it's non-nil, zero value otherwise.
func (w *WorkflowRun) GetCheckSuiteID() int64 {
if w == nil || w.CheckSuiteID == nil {
return 0
}
return *w.CheckSuiteID
}
// GetCheckSuiteNodeID returns the CheckSuiteNodeID field if it's non-nil, zero value otherwise.
func (w *WorkflowRun) GetCheckSuiteNodeID() string {
if w == nil || w.CheckSuiteNodeID == nil {
return ""
}
return *w.CheckSuiteNodeID
}
// GetCheckSuiteURL returns the CheckSuiteURL field if it's non-nil, zero value otherwise.
func (w *WorkflowRun) GetCheckSuiteURL() string {
if w == nil || w.CheckSuiteURL == nil {
@ -17292,6 +18404,14 @@ func (w *WorkflowRunEvent) GetAction() string {
return *w.Action
}
// GetInstallation returns the Installation field.
func (w *WorkflowRunEvent) GetInstallation() *Installation {
if w == nil {
return nil
}
return w.Installation
}
// GetOrg returns the Org field.
func (w *WorkflowRunEvent) GetOrg() *Organization {
if w == nil {

@ -37,6 +37,8 @@ const (
headerRateReset = "X-RateLimit-Reset"
headerOTP = "X-GitHub-OTP"
headerTokenExpiration = "GitHub-Authentication-Token-Expiration"
mediaTypeV3 = "application/vnd.github.v3+json"
defaultMediaType = "application/octet-stream"
mediaTypeV3SHA = "application/vnd.github.v3.sha"
@ -74,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"
@ -179,6 +178,7 @@ type Client struct {
PullRequests *PullRequestsService
Reactions *ReactionsService
Repositories *RepositoriesService
SCIM *SCIMService
Search *SearchService
Teams *TeamsService
Users *UsersService
@ -188,6 +188,14 @@ type service struct {
client *Client
}
// Client returns the http.Client used by this GitHub client.
func (c *Client) Client() *http.Client {
c.clientMu.Lock()
defer c.clientMu.Unlock()
clientCopy := *c.client
return &clientCopy
}
// ListOptions specifies the optional parameters to various List methods that
// support offset pagination.
type ListOptions struct {
@ -212,6 +220,9 @@ type ListCursorOptions struct {
// A cursor, as given in the Link header. If specified, the query only searches for events before this cursor.
Before string `url:"before,omitempty"`
// A cursor, as given in the Link header. If specified, the query continues the search using this cursor.
Cursor string `url:"cursor,omitempty"`
}
// UploadOptions specifies the parameters to methods that support uploads.
@ -295,6 +306,7 @@ func NewClient(httpClient *http.Client) *Client {
c.PullRequests = (*PullRequestsService)(&c.common)
c.Reactions = (*ReactionsService)(&c.common)
c.Repositories = (*RepositoriesService)(&c.common)
c.SCIM = (*SCIMService)(&c.common)
c.Search = (*SearchService)(&c.common)
c.Teams = (*TeamsService)(&c.common)
c.Users = (*UsersService)(&c.common)
@ -445,9 +457,17 @@ type Response struct {
// calling the endpoint again.
NextPageToken string
// For APIs that support cursor pagination, such as RepositoriesService.ListHookDeliveries,
// the following field will be populated to point to the next page.
// Set ListCursorOptions.Cursor to this value when calling the endpoint again.
Cursor string
// Explicitly specify the Rate type so Rate's String() receiver doesn't
// propagate to Response.
Rate Rate
// token's expiration date
TokenExpiration Timestamp
}
// newResponse creates a new Response for the provided http.Response.
@ -456,6 +476,7 @@ func newResponse(r *http.Response) *Response {
response := &Response{Response: r}
response.populatePageValues()
response.Rate = parseRate(r)
response.TokenExpiration = parseTokenExpiration(r)
return response
}
@ -481,7 +502,21 @@ func (r *Response) populatePageValues() {
if err != nil {
continue
}
page := url.Query().Get("page")
q := url.Query()
if cursor := q.Get("cursor"); cursor != "" {
for _, segment := range segments[1:] {
switch strings.TrimSpace(segment) {
case `rel="next"`:
r.Cursor = cursor
}
}
continue
}
page := q.Get("page")
if page == "" {
continue
}
@ -499,7 +534,6 @@ func (r *Response) populatePageValues() {
case `rel="last"`:
r.LastPage, _ = strconv.Atoi(page)
}
}
}
}
@ -522,6 +556,17 @@ func parseRate(r *http.Response) Rate {
return rate
}
// parseTokenExpiration parses the TokenExpiration related headers.
func parseTokenExpiration(r *http.Response) Timestamp {
var exp Timestamp
if v := r.Header.Get(headerTokenExpiration); v != "" {
if t, err := time.Parse("2006-01-02 03:04:05 MST", v); err == nil {
exp = Timestamp{t.Local()}
}
}
return exp
}
type requestContext uint8
const (
@ -663,10 +708,10 @@ func (c *Client) checkRateLimitBeforeDo(req *http.Request, rateLimitCategory rat
return nil
}
// compareHttpResponse returns whether two http.Response objects are equal or not.
// compareHTTPResponse returns whether two http.Response objects are equal or not.
// Currently, only StatusCode is checked. This function is used when implementing the
// Is(error) bool interface for the custom error types in this package.
func compareHttpResponse(r1, r2 *http.Response) bool {
func compareHTTPResponse(r1, r2 *http.Response) bool {
if r1 == nil && r2 == nil {
return true
}
@ -716,7 +761,7 @@ func (r *ErrorResponse) Is(target error) bool {
}
if r.Message != v.Message || (r.DocumentationURL != v.DocumentationURL) ||
!compareHttpResponse(r.Response, v.Response) {
!compareHTTPResponse(r.Response, v.Response) {
return false
}
@ -782,7 +827,7 @@ func (r *RateLimitError) Is(target error) bool {
return r.Rate == v.Rate &&
r.Message == v.Message &&
compareHttpResponse(r.Response, v.Response)
compareHTTPResponse(r.Response, v.Response)
}
// AcceptedError occurs when GitHub returns 202 Accepted response with an
@ -836,7 +881,7 @@ func (r *AbuseRateLimitError) Is(target error) bool {
return r.Message == v.Message &&
r.RetryAfter == v.RetryAfter &&
compareHttpResponse(r.Response, v.Response)
compareHTTPResponse(r.Response, v.Response)
}
// sanitizeURL redacts the client_secret parameter from the URL which may be

@ -18,6 +18,7 @@ import (
"errors"
"fmt"
"hash"
"io"
"io/ioutil"
"mime"
"net/http"
@ -31,19 +32,20 @@ const (
// sha256Prefix and sha512Prefix are provided for future compatibility.
sha256Prefix = "sha256"
sha512Prefix = "sha512"
// sha1SignatureHeader is the GitHub header key used to pass the HMAC-SHA1 hexdigest.
sha1SignatureHeader = "X-Hub-Signature"
// sha256SignatureHeader is the GitHub header key used to pass the HMAC-SHA256 hexdigest.
sha256SignatureHeader = "X-Hub-Signature-256"
// eventTypeHeader is the GitHub header key used to pass the event type.
eventTypeHeader = "X-Github-Event"
// deliveryIDHeader is the GitHub header key used to pass the unique ID for the webhook event.
deliveryIDHeader = "X-Github-Delivery"
// SHA1SignatureHeader is the GitHub header key used to pass the HMAC-SHA1 hexdigest.
SHA1SignatureHeader = "X-Hub-Signature"
// SHA256SignatureHeader is the GitHub header key used to pass the HMAC-SHA256 hexdigest.
SHA256SignatureHeader = "X-Hub-Signature-256"
// EventTypeHeader is the GitHub header key used to pass the event type.
EventTypeHeader = "X-Github-Event"
// DeliveryIDHeader is the GitHub header key used to pass the unique ID for the webhook event.
DeliveryIDHeader = "X-Github-Delivery"
)
var (
// eventTypeMapping maps webhooks types to their corresponding go-github struct types.
eventTypeMapping = map[string]string{
"branch_protection_rule": "BranchProtectionRuleEvent",
"check_run": "CheckRunEvent",
"check_suite": "CheckSuiteEvent",
"commit_comment": "CommitCommentEvent",
@ -91,6 +93,7 @@ var (
"user": "UserEvent",
"watch": "WatchEvent",
"workflow_dispatch": "WorkflowDispatchEvent",
"workflow_job": "WorkflowJobEvent",
"workflow_run": "WorkflowRunEvent",
}
)
@ -139,6 +142,70 @@ func messageMAC(signature string) ([]byte, func() hash.Hash, error) {
return buf, hashFunc, nil
}
// ValidatePayload validates an incoming GitHub Webhook event request body
// and returns the (JSON) payload.
// The Content-Type header of the payload can be "application/json" or "application/x-www-form-urlencoded".
// If the Content-Type is neither then an error is returned.
// secretToken is the GitHub Webhook secret token.
// If your webhook does not contain a secret token, you can pass nil or an empty slice.
// This is intended for local development purposes only and all webhooks should ideally set up a secret token.
//
// Example usage:
//
// func (s *GitHubEventMonitor) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// // read signature from request
// signature := ""
// payload, err := github.ValidatePayloadFromBody(r.Header.Get("Content-Type"), r.Body, signature, s.webhookSecretKey)
// if err != nil { ... }
// // Process payload...
// }
func ValidatePayloadFromBody(contentType string, readable io.Reader, signature string, secretToken []byte) (payload []byte, err error) {
var body []byte // Raw body that GitHub uses to calculate the signature.
switch contentType {
case "application/json":
var err error
if body, err = ioutil.ReadAll(readable); err != nil {
return nil, err
}
// If the content type is application/json,
// the JSON payload is just the original body.
payload = body
case "application/x-www-form-urlencoded":
// payloadFormParam is the name of the form parameter that the JSON payload
// will be in if a webhook has its content type set to application/x-www-form-urlencoded.
const payloadFormParam = "payload"
var err error
if body, err = ioutil.ReadAll(readable); err != nil {
return nil, err
}
// If the content type is application/x-www-form-urlencoded,
// the JSON payload will be under the "payload" form param.
form, err := url.ParseQuery(string(body))
if err != nil {
return nil, err
}
payload = []byte(form.Get(payloadFormParam))
default:
return nil, fmt.Errorf("webhook request has unsupported Content-Type %q", contentType)
}
// Only validate the signature if a secret token exists. This is intended for
// local development only and all webhooks should ideally set up a secret token.
if len(secretToken) > 0 {
if err := ValidateSignature(signature, body, secretToken); err != nil {
return nil, err
}
}
return payload, nil
}
// ValidatePayload validates an incoming GitHub Webhook event request
// and returns the (JSON) payload.
// The Content-Type header of the payload can be "application/json" or "application/x-www-form-urlencoded".
@ -156,61 +223,17 @@ func messageMAC(signature string) ([]byte, func() hash.Hash, error) {
// }
//
func ValidatePayload(r *http.Request, secretToken []byte) (payload []byte, err error) {
var body []byte // Raw body that GitHub uses to calculate the signature.
signature := r.Header.Get(SHA256SignatureHeader)
if signature == "" {
signature = r.Header.Get(SHA1SignatureHeader)
}
ct := r.Header.Get("Content-Type")
mediatype, _, err := mime.ParseMediaType(ct)
contentType, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil {
mediatype = ""
return nil, err
}
switch mediatype {
case "application/json":
var err error
if body, err = ioutil.ReadAll(r.Body); err != nil {
return nil, err
}
// If the content type is application/json,
// the JSON payload is just the original body.
payload = body
case "application/x-www-form-urlencoded":
// payloadFormParam is the name of the form parameter that the JSON payload
// will be in if a webhook has its content type set to application/x-www-form-urlencoded.
const payloadFormParam = "payload"
var err error
if body, err = ioutil.ReadAll(r.Body); err != nil {
return nil, err
}
// If the content type is application/x-www-form-urlencoded,
// the JSON payload will be under the "payload" form param.
form, err := url.ParseQuery(string(body))
if err != nil {
return nil, err
}
payload = []byte(form.Get(payloadFormParam))
default:
return nil, fmt.Errorf("Webhook request has unsupported Content-Type %q", ct)
}
// Only validate the signature if a secret token exists. This is intended for
// local development only and all webhooks should ideally set up a secret token.
if len(secretToken) > 0 {
sig := r.Header.Get(sha256SignatureHeader)
if sig == "" {
sig = r.Header.Get(sha1SignatureHeader)
}
if err := ValidateSignature(sig, body, secretToken); err != nil {
return nil, err
}
}
return payload, nil
return ValidatePayloadFromBody(contentType, r.Body, signature, secretToken)
}
// ValidateSignature validates the signature for the given payload.
@ -234,14 +257,14 @@ func ValidateSignature(signature string, payload, secretToken []byte) error {
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/hooks/#webhook-headers
func WebHookType(r *http.Request) string {
return r.Header.Get(eventTypeHeader)
return r.Header.Get(EventTypeHeader)
}
// DeliveryID returns the unique delivery ID of webhook request r.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/hooks/#webhook-headers
func DeliveryID(r *http.Request) string {
return r.Header.Get(deliveryIDHeader)
return r.Header.Get(DeliveryIDHeader)
}
// ParseWebHook parses the event payload. For recognized event types, a

@ -24,6 +24,9 @@ type HookConfig struct {
ContentType *string `json:"content_type,omitempty"`
InsecureSSL *string `json:"insecure_ssl,omitempty"`
URL *string `json:"url,omitempty"`
// Secret is returned obfuscated by GitHub, but it can be set for outgoing requests.
Secret *string `json:"secret,omitempty"`
}
// AuditEntry describes the fields that may be represented by various audit-log "action" entries.

@ -0,0 +1,73 @@
// Copyright 2021 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"context"
"fmt"
)
// ListHookDeliveries lists webhook deliveries for a webhook configured in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/orgs#list-deliveries-for-an-organization-webhook
func (s *OrganizationsService) ListHookDeliveries(ctx context.Context, org string, id int64, opts *ListCursorOptions) ([]*HookDelivery, *Response, error) {
u := fmt.Sprintf("orgs/%v/hooks/%v/deliveries", org, id)
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
deliveries := []*HookDelivery{}
resp, err := s.client.Do(ctx, req, &deliveries)
if err != nil {
return nil, resp, err
}
return deliveries, resp, nil
}
// GetHookDelivery returns a delivery for a webhook configured in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/orgs#get-a-webhook-delivery-for-an-organization-webhook
func (s *OrganizationsService) GetHookDelivery(ctx context.Context, owner string, hookID, deliveryID int64) (*HookDelivery, *Response, error) {
u := fmt.Sprintf("orgs/%v/hooks/%v/deliveries/%v", owner, hookID, deliveryID)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
h := new(HookDelivery)
resp, err := s.client.Do(ctx, req, h)
if err != nil {
return nil, resp, err
}
return h, resp, nil
}
// RedeliverHookDelivery redelivers a delivery for a webhook configured in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/orgs#redeliver-a-delivery-for-an-organization-webhook
func (s *OrganizationsService) RedeliverHookDelivery(ctx context.Context, owner string, hookID, deliveryID int64) (*HookDelivery, *Response, error) {
u := fmt.Sprintf("orgs/%v/hooks/%v/deliveries/%v/attempts", owner, hookID, deliveryID)
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {
return nil, nil, err
}
h := new(HookDelivery)
resp, err := s.client.Do(ctx, req, h)
if err != nil {
return nil, resp, err
}
return h, resp, nil
}

@ -0,0 +1,149 @@
// Copyright 2021 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"context"
"fmt"
)
// List the packages for an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/packages#list-packages-for-an-organization
func (s *OrganizationsService) ListPackages(ctx context.Context, org string, opts *PackageListOptions) ([]*Package, *Response, error) {
u := fmt.Sprintf("orgs/%v/packages", org)
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var packages []*Package
resp, err := s.client.Do(ctx, req, &packages)
if err != nil {
return nil, resp, err
}
return packages, resp, nil
}
// Get a package by name from an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/packages#get-a-package-for-an-organization
func (s *OrganizationsService) GetPackage(ctx context.Context, org, packageType, packageName string) (*Package, *Response, error) {
u := fmt.Sprintf("orgs/%v/packages/%v/%v", org, packageType, packageName)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var pack *Package
resp, err := s.client.Do(ctx, req, &pack)
if err != nil {
return nil, resp, err
}
return pack, resp, nil
}
// Delete a package from an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/packages#delete-a-package-for-an-organization
func (s *OrganizationsService) DeletePackage(ctx context.Context, org, packageType, packageName string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/packages/%v/%v", org, packageType, packageName)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// Restore a package to an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/packages#restore-a-package-for-an-organization
func (s *OrganizationsService) RestorePackage(ctx context.Context, org, packageType, packageName string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/packages/%v/%v/restore", org, packageType, packageName)
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// Get all versions of a package in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/packages#get-all-package-versions-for-a-package-owned-by-an-organization
func (s *OrganizationsService) PackageGetAllVersions(ctx context.Context, org, packageType, packageName string, opts *PackageListOptions) ([]*PackageVersion, *Response, error) {
u := fmt.Sprintf("orgs/%v/packages/%v/%v/versions", org, packageType, packageName)
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var versions []*PackageVersion
resp, err := s.client.Do(ctx, req, &versions)
if err != nil {
return nil, resp, err
}
return versions, resp, nil
}
// Get a specific version of a package in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/packages#get-a-package-version-for-an-organization
func (s *OrganizationsService) PackageGetVersion(ctx context.Context, org, packageType, packageName string, packageVersionID int64) (*PackageVersion, *Response, error) {
u := fmt.Sprintf("orgs/%v/packages/%v/%v/versions/%v", org, packageType, packageName, packageVersionID)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var version *PackageVersion
resp, err := s.client.Do(ctx, req, &version)
if err != nil {
return nil, resp, err
}
return version, resp, nil
}
// Delete a package version from an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/packages#delete-package-version-for-an-organization
func (s *OrganizationsService) PackageDeleteVersion(ctx context.Context, org, packageType, packageName string, packageVersionID int64) (*Response, error) {
u := fmt.Sprintf("orgs/%v/packages/%v/%v/versions/%v", org, packageType, packageName, packageVersionID)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// Restore a package version to an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/packages#restore-package-version-for-an-organization
func (s *OrganizationsService) PackageRestoreVersion(ctx context.Context, org, packageType, packageName string, packageVersionID int64) (*Response, error) {
u := fmt.Sprintf("orgs/%v/packages/%v/%v/versions/%v/restore", org, packageType, packageName, packageVersionID)
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}

@ -16,6 +16,10 @@ type Package struct {
Owner *User `json:"owner,omitempty"`
PackageVersion *PackageVersion `json:"package_version,omitempty"`
Registry *PackageRegistry `json:"registry,omitempty"`
URL *string `json:"url,omitempty"`
VersionCount *int64 `json:"version_count,omitempty"`
Visibility *string `json:"visibility,omitempty"`
Repository *Repository `json:"repository,omitempty"`
}
func (p Package) String() string {
@ -24,24 +28,28 @@ func (p Package) String() string {
// PackageVersion represents a GitHub package version.
type PackageVersion struct {
ID *int64 `json:"id,omitempty"`
Version *string `json:"version,omitempty"`
Summary *string `json:"summary,omitempty"`
Body *string `json:"body,omitempty"`
BodyHTML *string `json:"body_html,omitempty"`
Release *PackageRelease `json:"release,omitempty"`
Manifest *string `json:"manifest,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
TagName *string `json:"tag_name,omitempty"`
TargetCommitish *string `json:"target_commitish,omitempty"`
TargetOID *string `json:"target_oid,omitempty"`
Draft *bool `json:"draft,omitempty"`
Prerelease *bool `json:"prerelease,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
PackageFiles []*PackageFile `json:"package_files,omitempty"`
Author *User `json:"author,omitempty"`
InstallationCommand *string `json:"installation_command,omitempty"`
ID *int64 `json:"id,omitempty"`
Version *string `json:"version,omitempty"`
Summary *string `json:"summary,omitempty"`
Body *string `json:"body,omitempty"`
BodyHTML *string `json:"body_html,omitempty"`
Release *PackageRelease `json:"release,omitempty"`
Manifest *string `json:"manifest,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
TagName *string `json:"tag_name,omitempty"`
TargetCommitish *string `json:"target_commitish,omitempty"`
TargetOID *string `json:"target_oid,omitempty"`
Draft *bool `json:"draft,omitempty"`
Prerelease *bool `json:"prerelease,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
PackageFiles []*PackageFile `json:"package_files,omitempty"`
Author *User `json:"author,omitempty"`
InstallationCommand *string `json:"installation_command,omitempty"`
Metadata *PackageMetadata `json:"metadata,omitempty"`
PackageHTMLURL *string `json:"package_html_url,omitempty"`
Name *string `json:"name,omitempty"`
URL *string `json:"url,omitempty"`
}
func (pv PackageVersion) String() string {
@ -99,3 +107,37 @@ type PackageRegistry struct {
func (r PackageRegistry) String() string {
return Stringify(r)
}
// PackageListOptions represents the optional list options for a package.
type PackageListOptions struct {
// Visibility of packages "public", "internal" or "private".
Visibility *string `url:"visibility,omitempty"`
// PackageType represents the type of package.
// It can be one of "npm", "maven", "rubygems", "nuget", "docker", or "container".
PackageType *string `url:"package_type,omitempty"`
// State of package either "active" or "deleted".
State *string `url:"state,omitempty"`
ListOptions
}
// PackageMetadata represents metadata from a package.
type PackageMetadata struct {
PackageType *string `json:"package_type,omitempty"`
Container *PackageContainerMetadata `json:"container,omitempty"`
}
func (r PackageMetadata) String() string {
return Stringify(r)
}
// PackageContainerMetadata represents container metadata for docker container packages.
type PackageContainerMetadata struct {
Tags []string `json:"tags,omitempty"`
}
func (r PackageContainerMetadata) String() string {
return Stringify(r)
}

@ -125,10 +125,6 @@ func (s *PullRequestsService) ListReviews(ctx context.Context, owner, repo strin
// GetReview fetches the specified pull request review.
//
// TODO: Follow up with GitHub support about an issue with this method's
// returned error format and remove this comment once it's fixed.
// Read more about it here - https://github.com/google/go-github/issues/540
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#get-a-review-for-a-pull-request
func (s *PullRequestsService) GetReview(ctx context.Context, owner, repo string, number int, reviewID int64) (*PullRequestReview, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d", owner, repo, number, reviewID)
@ -149,10 +145,6 @@ func (s *PullRequestsService) GetReview(ctx context.Context, owner, repo string,
// DeletePendingReview deletes the specified pull request pending review.
//
// TODO: Follow up with GitHub support about an issue with this method's
// returned error format and remove this comment once it's fixed.
// Read more about it here - https://github.com/google/go-github/issues/540
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#delete-a-pending-review-for-a-pull-request
func (s *PullRequestsService) DeletePendingReview(ctx context.Context, owner, repo string, number int, reviewID int64) (*PullRequestReview, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d", owner, repo, number, reviewID)
@ -173,10 +165,6 @@ func (s *PullRequestsService) DeletePendingReview(ctx context.Context, owner, re
// ListReviewComments lists all the comments for the specified review.
//
// TODO: Follow up with GitHub support about an issue with this method's
// returned error format and remove this comment once it's fixed.
// Read more about it here - https://github.com/google/go-github/issues/540
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#list-comments-for-a-pull-request-review
func (s *PullRequestsService) ListReviewComments(ctx context.Context, owner, repo string, number int, reviewID int64, opts *ListOptions) ([]*PullRequestComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d/comments", owner, repo, number, reviewID)
@ -201,10 +189,6 @@ func (s *PullRequestsService) ListReviewComments(ctx context.Context, owner, rep
// CreateReview creates a new review on the specified pull request.
//
// TODO: Follow up with GitHub support about an issue with this method's
// returned error format and remove this comment once it's fixed.
// Read more about it here - https://github.com/google/go-github/issues/540
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#create-a-review-for-a-pull-request
//
// In order to use multi-line comments, you must use the "comfort fade" preview.
@ -289,10 +273,6 @@ func (s *PullRequestsService) UpdateReview(ctx context.Context, owner, repo stri
// SubmitReview submits a specified review on the specified pull request.
//
// TODO: Follow up with GitHub support about an issue with this method's
// returned error format and remove this comment once it's fixed.
// Read more about it here - https://github.com/google/go-github/issues/540
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#submit-a-review-for-a-pull-request
func (s *PullRequestsService) SubmitReview(ctx context.Context, owner, repo string, number int, reviewID int64, review *PullRequestReviewRequest) (*PullRequestReview, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d/events", owner, repo, number, reviewID)
@ -313,10 +293,6 @@ func (s *PullRequestsService) SubmitReview(ctx context.Context, owner, repo stri
// DismissReview dismisses a specified review on the specified pull request.
//
// TODO: Follow up with GitHub support about an issue with this method's
// returned error format and remove this comment once it's fixed.
// Read more about it here - https://github.com/google/go-github/issues/540
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#dismiss-a-review-for-a-pull-request
func (s *PullRequestsService) DismissReview(ctx context.Context, owner, repo string, number int, reviewID int64, review *PullRequestReviewDismissalRequest) (*PullRequestReview, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d/dismissals", owner, repo, number, reviewID)

@ -60,6 +60,7 @@ type Repository struct {
AllowRebaseMerge *bool `json:"allow_rebase_merge,omitempty"`
AllowSquashMerge *bool `json:"allow_squash_merge,omitempty"`
AllowMergeCommit *bool `json:"allow_merge_commit,omitempty"`
AllowAutoMerge *bool `json:"allow_auto_merge,omitempty"`
DeleteBranchOnMerge *bool `json:"delete_branch_on_merge,omitempty"`
Topics []string `json:"topics,omitempty"`
Archived *bool `json:"archived,omitempty"`
@ -320,6 +321,7 @@ type createRepoRequest struct {
AllowSquashMerge *bool `json:"allow_squash_merge,omitempty"`
AllowMergeCommit *bool `json:"allow_merge_commit,omitempty"`
AllowRebaseMerge *bool `json:"allow_rebase_merge,omitempty"`
AllowAutoMerge *bool `json:"allow_auto_merge,omitempty"`
DeleteBranchOnMerge *bool `json:"delete_branch_on_merge,omitempty"`
}
@ -362,6 +364,7 @@ func (s *RepositoriesService) Create(ctx context.Context, org string, repo *Repo
AllowSquashMerge: repo.AllowSquashMerge,
AllowMergeCommit: repo.AllowMergeCommit,
AllowRebaseMerge: repo.AllowRebaseMerge,
AllowAutoMerge: repo.AllowAutoMerge,
DeleteBranchOnMerge: repo.DeleteBranchOnMerge,
}
@ -764,6 +767,50 @@ type Protection struct {
RequiredConversationResolution *RequiredConversationResolution `json:"required_conversation_resolution"`
}
// BranchProtectionRule represents the rule applied to a repositories branch.
type BranchProtectionRule struct {
ID *int64 `json:"id,omitempty"`
RepositoryID *int64 `json:"repository_id,omitempty"`
Name *string `json:"name,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
PullRequestReviewsEnforcementLevel *string `json:"pull_request_reviews_enforcement_level,omitempty"`
RequiredApprovingReviewCount *int `json:"required_approving_review_count,omitempty"`
DismissStaleReviewsOnPush *bool `json:"dismiss_stale_reviews_on_push,omitempty"`
AuthorizedDismissalActorsOnly *bool `json:"authorized_dismissal_actors_only,omitempty"`
IgnoreApprovalsFromContributors *bool `json:"ignore_approvals_from_contributors,omitempty"`
RequireCodeOwnerReview *bool `json:"require_code_owner_review,omitempty"`
RequiredStatusChecks []string `json:"required_status_checks,omitempty"`
RequiredStatusChecksEnforcementLevel *string `json:"required_status_checks_enforcement_level,omitempty"`
StrictRequiredStatusChecksPolicy *bool `json:"strict_required_status_checks_policy,omitempty"`
SignatureRequirementEnforcementLevel *string `json:"signature_requirement_enforcement_level,omitempty"`
LinearHistoryRequirementEnforcementLevel *string `json:"linear_history_requirement_enforcement_level,omitempty"`
AdminEnforced *bool `json:"admin_enforced,omitempty"`
AllowForcePushesEnforcementLevel *string `json:"allow_force_pushes_enforcement_level,omitempty"`
AllowDeletionsEnforcementLevel *string `json:"allow_deletions_enforcement_level,omitempty"`
MergeQueueEnforcementLevel *string `json:"merge_queue_enforcement_level,omitempty"`
RequiredDeploymentsEnforcementLevel *string `json:"required_deployments_enforcement_level,omitempty"`
RequiredConversationResolutionLevel *string `json:"required_conversation_resolution_level,omitempty"`
AuthorizedActorsOnly *bool `json:"authorized_actors_only,omitempty"`
AuthorizedActorNames []string `json:"authorized_actor_names,omitempty"`
}
// ProtectionChanges represents the changes to the rule if the BranchProtection was edited.
type ProtectionChanges struct {
AuthorizedActorsOnly *AuthorizedActorsOnly `json:"authorized_actors_only,omitempty"`
AuthorizedActorNames *AuthorizedActorNames `json:"authorized_actor_names,omitempty"`
}
// AuthorizedActorNames represents who are authorized to edit the branch protection rules.
type AuthorizedActorNames struct {
From []string `json:"from,omitempty"`
}
// AuthorizedActorsOnly represents if the branche rule can be edited by authorized actors only.
type AuthorizedActorsOnly struct {
From *bool `json:"from,omitempty"`
}
// ProtectionRequest represents a request to create/edit a branch's protection.
type ProtectionRequest struct {
RequiredStatusChecks *RequiredStatusChecks `json:"required_status_checks"`
@ -776,6 +823,9 @@ type ProtectionRequest struct {
AllowForcePushes *bool `json:"allow_force_pushes,omitempty"`
// Allows deletion of the protected branch by anyone with write access to the repository.
AllowDeletions *bool `json:"allow_deletions,omitempty"`
// RequiredConversationResolution, if set to true, requires all comments
// on the pull request to be resolved before it can be merged to a protected branch.
RequiredConversationResolution *bool `json:"required_conversation_resolution,omitempty"`
}
// RequiredStatusChecks represents the protection status of a individual branch.

@ -0,0 +1,102 @@
// Copyright 2021 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"context"
"fmt"
)
// AutolinkOptions specifies parameters for RepositoriesService.AddAutolink method.
type AutolinkOptions struct {
KeyPrefix *string `json:"key_prefix,omitempty"`
URLTemplate *string `json:"url_template,omitempty"`
}
// Autolink represents autolinks to external resources like JIRA issues and Zendesk tickets.
type Autolink struct {
ID *int64 `json:"id,omitempty"`
KeyPrefix *string `json:"key_prefix,omitempty"`
URLTemplate *string `json:"url_template,omitempty"`
}
// ListAutolinks returns a list of autolinks configured for the given repository.
// Information about autolinks are only available to repository administrators.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/repos#list-all-autolinks-of-a-repository
func (s *RepositoriesService) ListAutolinks(ctx context.Context, owner, repo string, opts *ListOptions) ([]*Autolink, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/autolinks", owner, repo)
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var autolinks []*Autolink
resp, err := s.client.Do(ctx, req, &autolinks)
if err != nil {
return nil, resp, err
}
return autolinks, resp, nil
}
// AddAutolink creates an autolink reference for a repository.
// Users with admin access to the repository can create an autolink.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/repos#create-an-autolink-reference-for-a-repository
func (s *RepositoriesService) AddAutolink(ctx context.Context, owner, repo string, opts *AutolinkOptions) (*Autolink, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/autolinks", owner, repo)
req, err := s.client.NewRequest("POST", u, opts)
if err != nil {
return nil, nil, err
}
al := new(Autolink)
resp, err := s.client.Do(ctx, req, al)
if err != nil {
return nil, resp, err
}
return al, resp, nil
}
// GetAutolink returns a single autolink reference by ID that was configured for the given repository.
// Information about autolinks are only available to repository administrators.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/repos#get-an-autolink-reference-of-a-repository
func (s *RepositoriesService) GetAutolink(ctx context.Context, owner, repo string, id int64) (*Autolink, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/autolinks/%v", owner, repo, id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var autolink *Autolink
resp, err := s.client.Do(ctx, req, &autolink)
if err != nil {
return nil, resp, err
}
return autolink, resp, nil
}
// DeleteAutolink deletes a single autolink reference by ID that was configured for the given repository.
// Information about autolinks are only available to repository administrators.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/repos#delete-an-autolink-reference-from-a-repository
func (s *RepositoriesService) DeleteAutolink(ctx context.Context, owner, repo string, id int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/autolinks/%v", owner, repo, id)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}

@ -150,8 +150,12 @@ func (s *RepositoriesService) ListCommits(ctx context.Context, owner, repo strin
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-a-single-commit
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-a-commit
func (s *RepositoriesService) GetCommit(ctx context.Context, owner, repo, sha string) (*RepositoryCommit, *Response, error) {
func (s *RepositoriesService) GetCommit(ctx context.Context, owner, repo, sha string, opts *ListOptions) (*RepositoryCommit, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v", owner, repo, sha)
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@ -224,11 +228,15 @@ func (s *RepositoriesService) GetCommitSHA1(ctx context.Context, owner, repo, re
// CompareCommits compares a range of commits with each other.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#compare-two-commits
func (s *RepositoriesService) CompareCommits(ctx context.Context, owner, repo string, base, head string) (*CommitsComparison, *Response, error) {
func (s *RepositoriesService) CompareCommits(ctx context.Context, owner, repo string, base, head string, opts *ListOptions) (*CommitsComparison, *Response, error) {
escapedBase := url.QueryEscape(base)
escapedHead := url.QueryEscape(head)
u := fmt.Sprintf("repos/%v/%v/compare/%v...%v", owner, repo, escapedBase, escapedHead)
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {

@ -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"`
@ -31,14 +34,17 @@ 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)
@ -46,9 +52,6 @@ func (s *RepositoriesService) GetCommunityHealthMetrics(ctx context.Context, own
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 {

@ -132,7 +132,7 @@ func (s *RepositoriesService) DownloadContents(ctx context.Context, owner, repo,
for _, contents := range dirContents {
if *contents.Name == filename {
if contents.DownloadURL == nil || *contents.DownloadURL == "" {
return nil, resp, fmt.Errorf("No download link found for %s", filepath)
return nil, resp, fmt.Errorf("no download link found for %s", filepath)
}
dlResp, err := s.client.client.Get(*contents.DownloadURL)
if err != nil {
@ -141,7 +141,7 @@ func (s *RepositoriesService) DownloadContents(ctx context.Context, owner, repo,
return dlResp.Body, &Response{Response: dlResp}, nil
}
}
return nil, resp, fmt.Errorf("No file named %s found in %s", filename, dir)
return nil, resp, fmt.Errorf("no file named %s found in %s", filename, dir)
}
// DownloadContentsWithMeta is identical to DownloadContents but additionally
@ -162,7 +162,7 @@ func (s *RepositoriesService) DownloadContentsWithMeta(ctx context.Context, owne
for _, contents := range dirContents {
if *contents.Name == filename {
if contents.DownloadURL == nil || *contents.DownloadURL == "" {
return nil, contents, resp, fmt.Errorf("No download link found for %s", filepath)
return nil, contents, resp, fmt.Errorf("no download link found for %s", filepath)
}
dlResp, err := s.client.client.Get(*contents.DownloadURL)
if err != nil {
@ -171,7 +171,7 @@ func (s *RepositoriesService) DownloadContentsWithMeta(ctx context.Context, owne
return dlResp.Body, contents, &Response{Response: dlResp}, nil
}
}
return nil, nil, resp, fmt.Errorf("No file named %s found in %s", filename, dir)
return nil, nil, resp, fmt.Errorf("no file named %s found in %s", filename, dir)
}
// GetContents can return either the metadata and content of a single file

@ -0,0 +1,117 @@
// Copyright 2021 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"context"
"encoding/json"
"fmt"
)
// HookDelivery represents the data that is received from GitHub's Webhook Delivery API
//
// GitHub API docs:
// - https://docs.github.com/en/rest/reference/repos#list-deliveries-for-a-repository-webhook
// - https://docs.github.com/en/rest/reference/repos#get-a-delivery-for-a-repository-webhook
type HookDelivery struct {
ID *int64 `json:"id"`
GUID *string `json:"guid"`
DeliveredAt *Timestamp `json:"delivered_at"`
Redelivery *bool `json:"redelivery"`
Duration *float64 `json:"duration"`
Status *string `json:"status"`
StatusCode *int `json:"status_code"`
Event *string `json:"event"`
Action *string `json:"action"`
InstallationID *string `json:"installation_id"`
RepositoryID *int64 `json:"repository_id"`
// Request is populated by GetHookDelivery.
Request *HookRequest `json:"request,omitempty"`
// Response is populated by GetHookDelivery.
Response *HookResponse `json:"response,omitempty"`
}
func (d HookDelivery) String() string {
return Stringify(d)
}
// HookRequest is a part of HookDelivery that contains
// the HTTP headers and the JSON payload of the webhook request.
type HookRequest struct {
Headers map[string]string `json:"headers,omitempty"`
RawPayload *json.RawMessage `json:"payload,omitempty"`
}
func (r HookRequest) String() string {
return Stringify(r)
}
// HookResponse is a part of HookDelivery that contains
// the HTTP headers and the response body served by the webhook endpoint.
type HookResponse struct {
Headers map[string]string `json:"headers,omitempty"`
RawPayload *json.RawMessage `json:"payload,omitempty"`
}
func (r HookResponse) String() string {
return Stringify(r)
}
// ListHookDeliveries lists webhook deliveries for a webhook configured in a repository.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/repos#list-deliveries-for-a-repository-webhook
func (s *RepositoriesService) ListHookDeliveries(ctx context.Context, owner, repo string, id int64, opts *ListCursorOptions) ([]*HookDelivery, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%v/deliveries", owner, repo, id)
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
deliveries := []*HookDelivery{}
resp, err := s.client.Do(ctx, req, &deliveries)
if err != nil {
return nil, resp, err
}
return deliveries, resp, nil
}
// GetHookDelivery returns a delivery for a webhook configured in a repository.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/repos#get-a-delivery-for-a-repository-webhook
func (s *RepositoriesService) GetHookDelivery(ctx context.Context, owner, repo string, hookID, deliveryID int64) (*HookDelivery, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%v/deliveries/%v", owner, repo, hookID, deliveryID)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
h := new(HookDelivery)
resp, err := s.client.Do(ctx, req, h)
if err != nil {
return nil, resp, err
}
return h, resp, nil
}
// ParseRequestPayload parses the request payload. For recognized event types,
// a value of the corresponding struct type will be returned.
func (d *HookDelivery) ParseRequestPayload() (interface{}, error) {
eType, ok := eventTypeMapping[*d.Event]
if !ok {
return nil, fmt.Errorf("unsupported event type %q", *d.Event)
}
e := &Event{Type: &eType, RawPayload: d.Request.RawPayload}
return e.ParsePayload()
}

Some files were not shown because too many files have changed in this diff Show More