Upgrade github.com/google/go-github v32.1.0 -> v37.0.0 (#16661)

* Upgrade github.com/google/go-github vv32.1.0 -> v37.0.0

* refactor: use GetX() func to reduce code
This commit is contained in:
6543 2021-08-10 11:49:43 +02:00 committed by GitHub
parent d9ef43a712
commit 89245ee309
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
120 changed files with 5427 additions and 1537 deletions

4
go.mod
View file

@ -52,7 +52,7 @@ require (
github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85 github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85
github.com/golang-jwt/jwt v3.2.2+incompatible github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/golang/snappy v0.0.4 // indirect github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-github/v32 v32.1.0 github.com/google/go-github/v37 v37.0.0
github.com/google/go-querystring v1.1.0 // indirect github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.2.0 github.com/google/uuid v1.2.0
github.com/gorilla/context v1.1.1 github.com/gorilla/context v1.1.1
@ -124,7 +124,7 @@ require (
go.uber.org/atomic v1.8.0 // indirect go.uber.org/atomic v1.8.0 // indirect
go.uber.org/multierr v1.7.0 // indirect go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.18.1 // indirect go.uber.org/zap v1.18.1 // indirect
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
golang.org/x/net v0.0.0-20210716203947-853a461950ff golang.org/x/net v0.0.0-20210716203947-853a461950ff
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c

7
go.sum
View file

@ -529,8 +529,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.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 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II= github.com/google/go-github/v37 v37.0.0 h1:rCspN8/6kB1BAJWZfuafvHhyfIo5fkAulaP/3bOQ/tM=
github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI= github.com/google/go-github/v37 v37.0.0/go.mod h1:LM7in3NmXDrX58GbEHy7FtNLbI2JijX93RnMKvWG3m4=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= 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 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
@ -1145,8 +1145,9 @@ golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f/go.mod h1:jdWPYTVW3xRLrWP
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI=
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=

View file

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

View file

@ -20,7 +20,7 @@ import (
"code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
"github.com/google/go-github/v32/github" "github.com/google/go-github/v37/github"
"golang.org/x/oauth2" "golang.org/x/oauth2"
) )
@ -154,20 +154,15 @@ func (g *GithubDownloaderV3) GetRepoInfo() (*base.Repository, error) {
} }
g.rate = &resp.Rate g.rate = &resp.Rate
defaultBranch := ""
if gr.DefaultBranch != nil {
defaultBranch = *gr.DefaultBranch
}
// convert github repo to stand Repo // convert github repo to stand Repo
return &base.Repository{ return &base.Repository{
Owner: g.repoOwner, Owner: g.repoOwner,
Name: gr.GetName(), Name: gr.GetName(),
IsPrivate: *gr.Private, IsPrivate: gr.GetPrivate(),
Description: gr.GetDescription(), Description: gr.GetDescription(),
OriginalURL: gr.GetHTMLURL(), OriginalURL: gr.GetHTMLURL(),
CloneURL: gr.GetCloneURL(), CloneURL: gr.GetCloneURL(),
DefaultBranch: defaultBranch, DefaultBranch: gr.GetDefaultBranch(),
}, nil }, nil
} }
@ -201,20 +196,16 @@ func (g *GithubDownloaderV3) GetMilestones() ([]*base.Milestone, error) {
g.rate = &resp.Rate g.rate = &resp.Rate
for _, m := range ms { for _, m := range ms {
var desc string
if m.Description != nil {
desc = *m.Description
}
var state = "open" var state = "open"
if m.State != nil { if m.State != nil {
state = *m.State state = *m.State
} }
milestones = append(milestones, &base.Milestone{ milestones = append(milestones, &base.Milestone{
Title: *m.Title, Title: m.GetTitle(),
Description: desc, Description: m.GetDescription(),
Deadline: m.DueOn, Deadline: m.DueOn,
State: state, State: state,
Created: *m.CreatedAt, Created: m.GetCreatedAt(),
Updated: m.UpdatedAt, Updated: m.UpdatedAt,
Closed: m.ClosedAt, Closed: m.ClosedAt,
}) })
@ -227,14 +218,10 @@ func (g *GithubDownloaderV3) GetMilestones() ([]*base.Milestone, error) {
} }
func convertGithubLabel(label *github.Label) *base.Label { func convertGithubLabel(label *github.Label) *base.Label {
var desc string
if label.Description != nil {
desc = *label.Description
}
return &base.Label{ return &base.Label{
Name: *label.Name, Name: label.GetName(),
Color: *label.Color, Color: label.GetColor(),
Description: desc, Description: label.GetDescription(),
} }
} }
@ -266,24 +253,16 @@ func (g *GithubDownloaderV3) GetLabels() ([]*base.Label, error) {
func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease) *base.Release { func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease) *base.Release {
r := &base.Release{ r := &base.Release{
TagName: *rel.TagName, Name: rel.GetName(),
TargetCommitish: *rel.TargetCommitish, TagName: rel.GetTagName(),
Draft: *rel.Draft, TargetCommitish: rel.GetTargetCommitish(),
Prerelease: *rel.Prerelease, Draft: rel.GetDraft(),
Created: rel.CreatedAt.Time, Prerelease: rel.GetPrerelease(),
PublisherID: *rel.Author.ID, Created: rel.GetCreatedAt().Time,
PublisherName: *rel.Author.Login, PublisherID: rel.GetAuthor().GetID(),
} PublisherName: rel.GetAuthor().GetLogin(),
PublisherEmail: rel.GetAuthor().GetEmail(),
if rel.Body != nil { Body: rel.GetBody(),
r.Body = *rel.Body
}
if rel.Name != nil {
r.Name = *rel.Name
}
if rel.Author.Email != nil {
r.PublisherEmail = *rel.Author.Email
} }
if rel.PublishedAt != nil { if rel.PublishedAt != nil {
@ -293,8 +272,8 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease)
for _, asset := range rel.Assets { for _, asset := range rel.Assets {
var assetID = *asset.ID // Don't optimize this, for closure we need a local variable var assetID = *asset.ID // Don't optimize this, for closure we need a local variable
r.Assets = append(r.Assets, &base.ReleaseAsset{ r.Assets = append(r.Assets, &base.ReleaseAsset{
ID: *asset.ID, ID: asset.GetID(),
Name: *asset.Name, Name: asset.GetName(),
ContentType: asset.ContentType, ContentType: asset.ContentType,
Size: asset.Size, Size: asset.Size,
DownloadCount: asset.DownloadCount, DownloadCount: asset.DownloadCount,
@ -388,24 +367,12 @@ func (g *GithubDownloaderV3) GetIssues(page, perPage int) ([]*base.Issue, bool,
if issue.IsPullRequest() { if issue.IsPullRequest() {
continue continue
} }
var body string
if issue.Body != nil {
body = *issue.Body
}
var milestone string
if issue.Milestone != nil {
milestone = *issue.Milestone.Title
}
var labels = make([]*base.Label, 0, len(issue.Labels)) var labels = make([]*base.Label, 0, len(issue.Labels))
for _, l := range issue.Labels { for _, l := range issue.Labels {
labels = append(labels, convertGithubLabel(l)) labels = append(labels, convertGithubLabel(l))
} }
var email string
if issue.User.Email != nil {
email = *issue.User.Email
}
// get reactions // get reactions
var reactions []*base.Reaction var reactions []*base.Reaction
for i := 1; ; i++ { for i := 1; ; i++ {
@ -430,21 +397,27 @@ func (g *GithubDownloaderV3) GetIssues(page, perPage int) ([]*base.Issue, bool,
} }
} }
var assignees []string
for i := range issue.Assignees {
assignees = append(assignees, issue.Assignees[i].GetLogin())
}
allIssues = append(allIssues, &base.Issue{ allIssues = append(allIssues, &base.Issue{
Title: *issue.Title, Title: *issue.Title,
Number: int64(*issue.Number), Number: int64(*issue.Number),
PosterID: *issue.User.ID, PosterID: issue.GetUser().GetID(),
PosterName: *issue.User.Login, PosterName: issue.GetUser().GetLogin(),
PosterEmail: email, PosterEmail: issue.GetUser().GetEmail(),
Content: body, Content: issue.GetBody(),
Milestone: milestone, Milestone: issue.GetMilestone().GetTitle(),
State: *issue.State, State: issue.GetState(),
Created: *issue.CreatedAt, Created: issue.GetCreatedAt(),
Updated: *issue.UpdatedAt, Updated: issue.GetUpdatedAt(),
Labels: labels, Labels: labels,
Reactions: reactions, Reactions: reactions,
Closed: issue.ClosedAt, Closed: issue.ClosedAt,
IsLocked: *issue.Locked, IsLocked: issue.GetLocked(),
Assignees: assignees,
}) })
} }
@ -487,11 +460,6 @@ func (g *GithubDownloaderV3) getComments(issueNumber int64) ([]*base.Comment, er
} }
g.rate = &resp.Rate g.rate = &resp.Rate
for _, comment := range comments { for _, comment := range comments {
var email string
if comment.User.Email != nil {
email = *comment.User.Email
}
// get reactions // get reactions
var reactions []*base.Reaction var reactions []*base.Reaction
for i := 1; ; i++ { for i := 1; ; i++ {
@ -515,14 +483,15 @@ func (g *GithubDownloaderV3) getComments(issueNumber int64) ([]*base.Comment, er
}) })
} }
} }
allComments = append(allComments, &base.Comment{ allComments = append(allComments, &base.Comment{
IssueIndex: issueNumber, IssueIndex: issueNumber,
PosterID: *comment.User.ID, PosterID: comment.GetUser().GetID(),
PosterName: *comment.User.Login, PosterName: comment.GetUser().GetLogin(),
PosterEmail: email, PosterEmail: comment.GetUser().GetEmail(),
Content: *comment.Body, Content: comment.GetBody(),
Created: *comment.CreatedAt, Created: comment.GetCreatedAt(),
Updated: *comment.UpdatedAt, Updated: comment.GetUpdatedAt(),
Reactions: reactions, Reactions: reactions,
}) })
} }
@ -558,11 +527,6 @@ func (g *GithubDownloaderV3) GetAllComments(page, perPage int) ([]*base.Comment,
log.Trace("Request get comments %d/%d, but in fact get %d", perPage, page, len(comments)) log.Trace("Request get comments %d/%d, but in fact get %d", perPage, page, len(comments))
g.rate = &resp.Rate g.rate = &resp.Rate
for _, comment := range comments { for _, comment := range comments {
var email string
if comment.User.Email != nil {
email = *comment.User.Email
}
// get reactions // get reactions
var reactions []*base.Reaction var reactions []*base.Reaction
for i := 1; ; i++ { for i := 1; ; i++ {
@ -590,12 +554,12 @@ func (g *GithubDownloaderV3) GetAllComments(page, perPage int) ([]*base.Comment,
issueIndex, _ := strconv.ParseInt((*comment.IssueURL)[idx+1:], 10, 64) issueIndex, _ := strconv.ParseInt((*comment.IssueURL)[idx+1:], 10, 64)
allComments = append(allComments, &base.Comment{ allComments = append(allComments, &base.Comment{
IssueIndex: issueIndex, IssueIndex: issueIndex,
PosterID: *comment.User.ID, PosterID: comment.GetUser().GetID(),
PosterName: *comment.User.Login, PosterName: comment.GetUser().GetLogin(),
PosterEmail: email, PosterEmail: comment.GetUser().GetEmail(),
Content: *comment.Body, Content: comment.GetBody(),
Created: *comment.CreatedAt, Created: comment.GetCreatedAt(),
Updated: *comment.UpdatedAt, Updated: comment.GetUpdatedAt(),
Reactions: reactions, Reactions: reactions,
}) })
} }
@ -626,59 +590,11 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq
log.Trace("Request get pull requests %d/%d, but in fact get %d", perPage, page, len(prs)) log.Trace("Request get pull requests %d/%d, but in fact get %d", perPage, page, len(prs))
g.rate = &resp.Rate g.rate = &resp.Rate
for _, pr := range prs { for _, pr := range prs {
var body string
if pr.Body != nil {
body = *pr.Body
}
var milestone string
if pr.Milestone != nil {
milestone = *pr.Milestone.Title
}
var labels = make([]*base.Label, 0, len(pr.Labels)) var labels = make([]*base.Label, 0, len(pr.Labels))
for _, l := range pr.Labels { for _, l := range pr.Labels {
labels = append(labels, convertGithubLabel(l)) labels = append(labels, convertGithubLabel(l))
} }
var email string
if pr.User.Email != nil {
email = *pr.User.Email
}
var merged bool
// pr.Merged is not valid, so use MergedAt to test if it's merged
if pr.MergedAt != nil {
merged = true
}
var (
headRepoName string
cloneURL string
headRef string
headSHA string
)
if pr.Head.Repo != nil {
if pr.Head.Repo.Name != nil {
headRepoName = *pr.Head.Repo.Name
}
if pr.Head.Repo.CloneURL != nil {
cloneURL = *pr.Head.Repo.CloneURL
}
}
if pr.Head.Ref != nil {
headRef = *pr.Head.Ref
}
if pr.Head.SHA != nil {
headSHA = *pr.Head.SHA
}
var mergeCommitSHA string
if pr.MergeCommitSHA != nil {
mergeCommitSHA = *pr.MergeCommitSHA
}
var headUserName string
if pr.Head.User != nil && pr.Head.User.Login != nil {
headUserName = *pr.Head.User.Login
}
// get reactions // get reactions
var reactions []*base.Reaction var reactions []*base.Reaction
for i := 1; ; i++ { for i := 1; ; i++ {
@ -704,36 +620,36 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq
} }
allPRs = append(allPRs, &base.PullRequest{ allPRs = append(allPRs, &base.PullRequest{
Title: *pr.Title, Title: pr.GetTitle(),
Number: int64(*pr.Number), Number: int64(pr.GetNumber()),
PosterName: *pr.User.Login, PosterID: pr.GetUser().GetID(),
PosterID: *pr.User.ID, PosterName: pr.GetUser().GetLogin(),
PosterEmail: email, PosterEmail: pr.GetUser().GetEmail(),
Content: body, Content: pr.GetBody(),
Milestone: milestone, Milestone: pr.GetMilestone().GetTitle(),
State: *pr.State, State: pr.GetState(),
Created: *pr.CreatedAt, Created: pr.GetCreatedAt(),
Updated: *pr.UpdatedAt, Updated: pr.GetUpdatedAt(),
Closed: pr.ClosedAt, Closed: pr.ClosedAt,
Labels: labels, Labels: labels,
Merged: merged, Merged: pr.MergedAt != nil,
MergeCommitSHA: mergeCommitSHA, MergeCommitSHA: pr.GetMergeCommitSHA(),
MergedTime: pr.MergedAt, MergedTime: pr.MergedAt,
IsLocked: pr.ActiveLockReason != nil, IsLocked: pr.ActiveLockReason != nil,
Head: base.PullRequestBranch{ Head: base.PullRequestBranch{
Ref: headRef, Ref: pr.GetHead().GetRef(),
SHA: headSHA, SHA: pr.GetHead().GetSHA(),
RepoName: headRepoName, OwnerName: pr.GetHead().GetUser().GetLogin(),
OwnerName: headUserName, RepoName: pr.GetHead().GetRepo().GetName(),
CloneURL: cloneURL, CloneURL: pr.GetHead().GetRepo().GetCloneURL(),
}, },
Base: base.PullRequestBranch{ Base: base.PullRequestBranch{
Ref: *pr.Base.Ref, Ref: pr.GetBase().GetRef(),
SHA: *pr.Base.SHA, SHA: pr.GetBase().GetSHA(),
RepoName: *pr.Base.Repo.Name, RepoName: pr.GetBase().GetRepo().GetName(),
OwnerName: *pr.Base.User.Login, OwnerName: pr.GetBase().GetUser().GetLogin(),
}, },
PatchURL: *pr.PatchURL, PatchURL: pr.GetPatchURL(),
Reactions: reactions, Reactions: reactions,
}) })
} }

View file

@ -1,138 +0,0 @@
// Copyright 2020 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"
)
// Workflow represents a repository action workflow.
type Workflow struct {
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
Name *string `json:"name,omitempty"`
Path *string `json:"path,omitempty"`
State *string `json:"state,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
URL *string `json:"url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
BadgeURL *string `json:"badge_url,omitempty"`
}
// Workflows represents a slice of repository action workflows.
type Workflows struct {
TotalCount *int `json:"total_count,omitempty"`
Workflows []*Workflow `json:"workflows,omitempty"`
}
// WorkflowUsage represents a usage of a specific workflow.
type WorkflowUsage struct {
Billable *WorkflowEnvironment `json:"billable,omitempty"`
}
// WorkflowEnvironment represents different runner environments available for a workflow.
type WorkflowEnvironment struct {
Ubuntu *WorkflowBill `json:"UBUNTU,omitempty"`
MacOS *WorkflowBill `json:"MACOS,omitempty"`
Windows *WorkflowBill `json:"WINDOWS,omitempty"`
}
// WorkflowBill specifies billable time for a specific environment in a workflow.
type WorkflowBill struct {
TotalMS *int64 `json:"total_ms,omitempty"`
}
// ListWorkflows lists all workflows in a repository.
//
// GitHub API docs: https://developer.github.com/v3/actions/workflows/#list-repository-workflows
func (s *ActionsService) ListWorkflows(ctx context.Context, owner, repo string, opts *ListOptions) (*Workflows, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/actions/workflows", 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
}
workflows := new(Workflows)
resp, err := s.client.Do(ctx, req, &workflows)
if err != nil {
return nil, resp, err
}
return workflows, resp, nil
}
// GetWorkflowByID gets a specific workflow by ID.
//
// GitHub API docs: https://developer.github.com/v3/actions/workflows/#get-a-workflow
func (s *ActionsService) GetWorkflowByID(ctx context.Context, owner, repo string, workflowID int64) (*Workflow, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v", owner, repo, workflowID)
return s.getWorkflow(ctx, u)
}
// GetWorkflowByFileName gets a specific workflow by file name.
//
// GitHub API docs: https://developer.github.com/v3/actions/workflows/#get-a-workflow
func (s *ActionsService) GetWorkflowByFileName(ctx context.Context, owner, repo, workflowFileName string) (*Workflow, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v", owner, repo, workflowFileName)
return s.getWorkflow(ctx, u)
}
func (s *ActionsService) getWorkflow(ctx context.Context, url string) (*Workflow, *Response, error) {
req, err := s.client.NewRequest("GET", url, nil)
if err != nil {
return nil, nil, err
}
workflow := new(Workflow)
resp, err := s.client.Do(ctx, req, workflow)
if err != nil {
return nil, resp, err
}
return workflow, resp, nil
}
// GetWorkflowUsageByID gets a specific workflow usage by ID in the unit of billable milliseconds.
//
// GitHub API docs: https://developer.github.com/v3/actions/workflows/#get-workflow-usage
func (s *ActionsService) GetWorkflowUsageByID(ctx context.Context, owner, repo string, workflowID int64) (*WorkflowUsage, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/timing", owner, repo, workflowID)
return s.getWorkflowUsage(ctx, u)
}
// GetWorkflowUsageByFileName gets a specific workflow usage by file name in the unit of billable milliseconds.
//
// GitHub API docs: https://developer.github.com/v3/actions/workflows/#get-workflow-usage
func (s *ActionsService) GetWorkflowUsageByFileName(ctx context.Context, owner, repo, workflowFileName string) (*WorkflowUsage, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/timing", owner, repo, workflowFileName)
return s.getWorkflowUsage(ctx, u)
}
func (s *ActionsService) getWorkflowUsage(ctx context.Context, url string) (*WorkflowUsage, *Response, error) {
req, err := s.client.NewRequest("GET", url, nil)
if err != nil {
return nil, nil, err
}
workflowUsage := new(WorkflowUsage)
resp, err := s.client.Do(ctx, req, workflowUsage)
if err != nil {
return nil, resp, err
}
return workflowUsage, resp, nil
}

View file

@ -13,6 +13,7 @@
413x <dedifferentiator@gmail.com> 413x <dedifferentiator@gmail.com>
Abhinav Gupta <mail@abhinavg.net> Abhinav Gupta <mail@abhinavg.net>
adrienzieba <adrien.zieba@appdirect.com> adrienzieba <adrien.zieba@appdirect.com>
afdesk <work@afdesk.com>
Ahmed Hagy <a.akram93@gmail.com> Ahmed Hagy <a.akram93@gmail.com>
Aidan Steele <aidan.steele@glassechidna.com.au> Aidan Steele <aidan.steele@glassechidna.com.au>
Ainsley Chong <ainsley.chong@gmail.com> Ainsley Chong <ainsley.chong@gmail.com>
@ -23,7 +24,9 @@ Alec Thomas <alec@swapoff.org>
Aleks Clark <aleks.clark@gmail.com> Aleks Clark <aleks.clark@gmail.com>
Alex Bramley <a.bramley@gmail.com> Alex Bramley <a.bramley@gmail.com>
Alex Orr <Alexorr.CSE@gmail.com> Alex Orr <Alexorr.CSE@gmail.com>
Alex Unger <zyxancf@gmail.com>
Alexander Harkness <me@bearbin.net> Alexander Harkness <me@bearbin.net>
Ali Farooq <ali.farooq0@pm.me>
Allen Sun <shlallen1990@gmail.com> Allen Sun <shlallen1990@gmail.com>
Amey Sakhadeo <me@ameyms.com> Amey Sakhadeo <me@ameyms.com>
Anders Janmyr <anders@janmyr.com> Anders Janmyr <anders@janmyr.com>
@ -37,22 +40,28 @@ anjanashenoy <anjanashenoy1@gmail.com>
Anshuman Bhartiya <anshuman.bhartiya@gmail.com> Anshuman Bhartiya <anshuman.bhartiya@gmail.com>
Antoine <antoine.tu@mail.mcgill.ca> Antoine <antoine.tu@mail.mcgill.ca>
Antoine Pelisse <apelisse@gmail.com> Antoine Pelisse <apelisse@gmail.com>
Anton Nguyen <afnguyen85@gmail.com>
Anubha Kushwaha <anubha_bt2k14@dtu.ac.in> Anubha Kushwaha <anubha_bt2k14@dtu.ac.in>
appilon <apilon@hashicorp.com> appilon <apilon@hashicorp.com>
aprp <doelaudi@gmail.com>
Aravind <aravindkp@outlook.in> Aravind <aravindkp@outlook.in>
Arda Kuyumcu <kuyumcuarda@gmail.com> Arda Kuyumcu <kuyumcuarda@gmail.com>
Arıl Bozoluk <arilbozoluk@hotmail.com> Arıl Bozoluk <arilbozoluk@hotmail.com>
Asier Marruedo <asiermarruedo@gmail.com>
Austin Burdine <acburdine@gmail.com> Austin Burdine <acburdine@gmail.com>
Austin Dizzy <dizzy@wow.com> Austin Dizzy <dizzy@wow.com>
Ben Batha <bhbatha@gmail.com> Ben Batha <bhbatha@gmail.com>
Benjamen Keroack <benjamen@dollarshaveclub.com> Benjamen Keroack <benjamen@dollarshaveclub.com>
Beshr Kayali <beshrkayali@gmail.com> Beshr Kayali <beshrkayali@gmail.com>
Beyang Liu <beyang.liu@gmail.com> Beyang Liu <beyang.liu@gmail.com>
Billy Keyes <bluekeyes@gmail.com>
Billy Lynch <wlynch92@gmail.com> Billy Lynch <wlynch92@gmail.com>
Björn Häuser <b.haeuser@rebuy.de> Björn Häuser <b.haeuser@rebuy.de>
boljen <bol.christophe@gmail.com>
Brad Harris <bmharris@gmail.com> Brad Harris <bmharris@gmail.com>
Brad Moylan <moylan.brad@gmail.com> Brad Moylan <moylan.brad@gmail.com>
Bradley Falzon <brad@teambrad.net> Bradley Falzon <brad@teambrad.net>
Bradley McAllister <brad.mcallister@hotmail.com>
Brandon Cook <phylake@gmail.com> Brandon Cook <phylake@gmail.com>
Brian Egizi <brian@mojotech.com> Brian Egizi <brian@mojotech.com>
Bryan Boreham <bryan@weave.works> Bryan Boreham <bryan@weave.works>
@ -74,6 +83,7 @@ Colin Misare <github.com/cmisare>
Craig Peterson <cpeterson@stackoverflow.com> Craig Peterson <cpeterson@stackoverflow.com>
Cristian Maglie <c.maglie@bug.st> Cristian Maglie <c.maglie@bug.st>
Daehyeok Mun <daehyeok@gmail.com> Daehyeok Mun <daehyeok@gmail.com>
Daniel Lanner <lanner.dan@gmail.com>
Daniel Leavitt <daniel.leavitt@gmail.com> Daniel Leavitt <daniel.leavitt@gmail.com>
Daniel Nilsson <daniel.nilsson1989@gmail.com> Daniel Nilsson <daniel.nilsson1989@gmail.com>
Daoq <masseto2002@gmail.com> Daoq <masseto2002@gmail.com>
@ -81,6 +91,7 @@ Dave Du Cros <davidducros@gmail.com>
Dave Henderson <dhenderson@gmail.com> Dave Henderson <dhenderson@gmail.com>
Dave Protasowski <dprotaso@gmail.com> Dave Protasowski <dprotaso@gmail.com>
David Deng <daviddengcn@gmail.com> David Deng <daviddengcn@gmail.com>
David J. M. Karlsen <david@davidkarlsen.com>
David Jannotta <djannotta@gmail.com> David Jannotta <djannotta@gmail.com>
David Ji <github.com/davidji99> David Ji <github.com/davidji99>
David Lopez Reyes <davidlopezre@gmail.com> David Lopez Reyes <davidlopezre@gmail.com>
@ -93,12 +104,14 @@ dmnlk <seikima2demon@gmail.com>
Don Petersen <don@donpetersen.net> Don Petersen <don@donpetersen.net>
Doug Turner <doug.turner@gmail.com> Doug Turner <doug.turner@gmail.com>
Drew Fradette <drew.fradette@gmail.com> Drew Fradette <drew.fradette@gmail.com>
Dustin Deus <deusdustin@gmail.com>
Eivind <eivindkn@gmail.com> Eivind <eivindkn@gmail.com>
Eli Uriegas <seemethere101@gmail.com> Eli Uriegas <seemethere101@gmail.com>
Elliott Beach <elliott2.71828@gmail.com> Elliott Beach <elliott2.71828@gmail.com>
Emerson Wood <emersonwood94@gmail.com> Emerson Wood <emersonwood94@gmail.com>
eperm <staffordworrell@gmail.com> eperm <staffordworrell@gmail.com>
Erick Fejta <erick@fejta.com> Erick Fejta <erick@fejta.com>
Erik Nobel <hendrik.nobel@transferwise.com>
erwinvaneyk <erwinvaneyk@gmail.com> erwinvaneyk <erwinvaneyk@gmail.com>
Evan Elias <evanjelias@gmail.com> Evan Elias <evanjelias@gmail.com>
Fabrice <fabrice.vaillant@student.ecp.fr> Fabrice <fabrice.vaillant@student.ecp.fr>
@ -129,13 +142,18 @@ huydx <doxuanhuy@gmail.com>
i2bskn <i2bskn@gmail.com> i2bskn <i2bskn@gmail.com>
Ioannis Georgoulas <igeorgoulas21@gmail.com> Ioannis Georgoulas <igeorgoulas21@gmail.com>
Isao Jonas <isao.jonas@gmail.com> Isao Jonas <isao.jonas@gmail.com>
ishan upadhyay <ishanupadhyay412@gmail.com>
isqua <isqua@isqua.ru> isqua <isqua@isqua.ru>
Jacob Valdemar <jan@lunar.app>
Jake Krammer <jake.krammer1@gmail.com>
Jameel Haffejee <RC1140@republiccommandos.co.za> Jameel Haffejee <RC1140@republiccommandos.co.za>
James Cockbain <james.cockbain@ibm.com> James Cockbain <james.cockbain@ibm.com>
Jan Kosecki <jan.kosecki91@gmail.com> Jan Kosecki <jan.kosecki91@gmail.com>
Javier Campanini <jcampanini@palantir.com> Javier Campanini <jcampanini@palantir.com>
Jef LeCompte <jeffreylec@gmail.com>
Jens Rantil <jens.rantil@gmail.com> Jens Rantil <jens.rantil@gmail.com>
Jeremy Morris <jeremylevanmorris@gmail.com> Jeremy Morris <jeremylevanmorris@gmail.com>
Jesse Haka <haka.jesse@gmail.com>
Jesse Newland <jesse@jnewland.com> Jesse Newland <jesse@jnewland.com>
Jihoon Chung <j.c@navercorp.com> Jihoon Chung <j.c@navercorp.com>
Jimmi Dyson <jimmidyson@gmail.com> Jimmi Dyson <jimmidyson@gmail.com>
@ -143,11 +161,13 @@ Joan Saum <joan.saum@epitech.eu>
Joe Tsai <joetsai@digital-static.net> Joe Tsai <joetsai@digital-static.net>
John Barton <jrbarton@gmail.com> John Barton <jrbarton@gmail.com>
John Engelman <john.r.engelman@gmail.com> John Engelman <john.r.engelman@gmail.com>
John Liu <john.liu@mongodb.com>
Jordan Brockopp <jdbro94@gmail.com> Jordan Brockopp <jdbro94@gmail.com>
Jordan Sussman <jordansail22@gmail.com> Jordan Sussman <jordansail22@gmail.com>
Joshua Bezaleel Abednego <joshua.bezaleel@gmail.com> Joshua Bezaleel Abednego <joshua.bezaleel@gmail.com>
JP Phillips <jonphill9@gmail.com> JP Phillips <jonphill9@gmail.com>
jpbelanger-mtl <jp.belanger@gmail.com> jpbelanger-mtl <jp.belanger@gmail.com>
Juan <juan.rios.28@gmail.com>
Juan Basso <jrbasso@gmail.com> Juan Basso <jrbasso@gmail.com>
Julien Garcia Gonzalez <garciagonzalez.julien@gmail.com> Julien Garcia Gonzalez <garciagonzalez.julien@gmail.com>
Julien Rostand <jrostand@users.noreply.github.com> Julien Rostand <jrostand@users.noreply.github.com>
@ -164,6 +184,7 @@ Konrad Malawski <konrad.malawski@project13.pl>
Kookheon Kwon <kucuny@gmail.com> Kookheon Kwon <kucuny@gmail.com>
Krzysztof Kowalczyk <kkowalczyk@gmail.com> Krzysztof Kowalczyk <kkowalczyk@gmail.com>
Kshitij Saraogi <KshitijSaraogi@gmail.com> Kshitij Saraogi <KshitijSaraogi@gmail.com>
Kumar Saurabh <itsksaurabh@gmail.com>
kyokomi <kyoko1220adword@gmail.com> kyokomi <kyoko1220adword@gmail.com>
Laurent Verdoïa <verdoialaurent@gmail.com> Laurent Verdoïa <verdoialaurent@gmail.com>
Liam Galvin <liam@liam-galvin.co.uk> Liam Galvin <liam@liam-galvin.co.uk>
@ -175,7 +196,9 @@ Luke Roberts <email@luke-roberts.co.uk>
Luke Young <luke@hydrantlabs.org> Luke Young <luke@hydrantlabs.org>
lynn [they] <lynncyrin@gmail.com> lynn [they] <lynncyrin@gmail.com>
Maksim Zhylinski <uzzable@gmail.com> Maksim Zhylinski <uzzable@gmail.com>
Marcelo Carlos <marcelo@permutive.com>
Mark Tareshawty <tarebyte@github.com> Mark Tareshawty <tarebyte@github.com>
Martin Holman <me@martinholman.co.nz>
Martin-Louis Bright <mlbright@gmail.com> Martin-Louis Bright <mlbright@gmail.com>
Martins Sipenko <martins.sipenko@gmail.com> Martins Sipenko <martins.sipenko@gmail.com>
Marwan Sulaiman <marwan.sameer@gmail.com> Marwan Sulaiman <marwan.sameer@gmail.com>
@ -185,22 +208,28 @@ Matt <alpmatthew@gmail.com>
Matt Brender <mjbrender@gmail.com> Matt Brender <mjbrender@gmail.com>
Matt Gaunt <matt@gauntface.co.uk> Matt Gaunt <matt@gauntface.co.uk>
Matt Landis <landis.matt@gmail.com> Matt Landis <landis.matt@gmail.com>
Matt Moore <mattmoor@vmware.com>
Maxime Bury <maxime.bury@gmail.com> Maxime Bury <maxime.bury@gmail.com>
Michael Spiegel <michael.m.spiegel@gmail.com> Michael Spiegel <michael.m.spiegel@gmail.com>
Michael Tiller <michael.tiller@gmail.com> Michael Tiller <michael.tiller@gmail.com>
Michał Glapa <michal.glapa@gmail.com> Michał Glapa <michal.glapa@gmail.com>
Michelangelo Morrillo <michelangelo@morrillo.it>
Mukundan Senthil <mukundan314@gmail.com>
Nadav Kaner <nadavkaner1@gmail.com> Nadav Kaner <nadavkaner1@gmail.com>
Nathan VanBenschoten <nvanbenschoten@gmail.com> Nathan VanBenschoten <nvanbenschoten@gmail.com>
Navaneeth Suresh <navaneeths1998@gmail.com> Navaneeth Suresh <navaneeths1998@gmail.com>
Neil O'Toole <neilotoole@apache.org> Neil O'Toole <neilotoole@apache.org>
Nick Miyake <nmiyake@palantir.com> Nick Miyake <nmiyake@palantir.com>
Nick Platt <hello@nickplatt.co.uk>
Nick Spragg <nick.spragg@bbc.co.uk> Nick Spragg <nick.spragg@bbc.co.uk>
Nikhita Raghunath <nikitaraghunath@gmail.com> Nikhita Raghunath <nikitaraghunath@gmail.com>
Nilesh Singh <nilesh.singh24@outlook.com>
Noah Zoschke <noah+sso2@convox.com> Noah Zoschke <noah+sso2@convox.com>
ns-cweber <cweber@narrativescience.com> ns-cweber <cweber@narrativescience.com>
Ole Orhagen <ole.orhagen@northern.tech> Ole Orhagen <ole.orhagen@northern.tech>
Oleg Kovalov <iamolegkovalov@gmail.com> Oleg Kovalov <iamolegkovalov@gmail.com>
Ondřej Kupka <ondra.cap@gmail.com> Ondřej Kupka <ondra.cap@gmail.com>
Pablo Pérez Schröder <pablo.perezschroder@wetransfer.com>
Palash Nigam <npalash25@gmail.com> Palash Nigam <npalash25@gmail.com>
Panagiotis Moustafellos <pmoust@gmail.com> Panagiotis Moustafellos <pmoust@gmail.com>
Parham Alvani <parham.alvani@gmail.com> Parham Alvani <parham.alvani@gmail.com>
@ -213,6 +242,7 @@ Pete Wagner <thepwagner@github.com>
Petr Shevtsov <petr.shevtsov@gmail.com> Petr Shevtsov <petr.shevtsov@gmail.com>
Pierre Carrier <pierre@meteor.com> Pierre Carrier <pierre@meteor.com>
Piotr Zurek <p.zurek@gmail.com> Piotr Zurek <p.zurek@gmail.com>
Piyush Chugh <piyushchugh1993@gmail.com>
Pratik Mallya <pratik.mallya@gmail.com> Pratik Mallya <pratik.mallya@gmail.com>
Qais Patankar <qaisjp@gmail.com> Qais Patankar <qaisjp@gmail.com>
Quang Le Hong <iamquang95@gmail.com> Quang Le Hong <iamquang95@gmail.com>
@ -228,12 +258,15 @@ Ravi Shekhar Jethani <rsjethani@gmail.com>
RaviTeja Pothana <ravi-teja@live.com> RaviTeja Pothana <ravi-teja@live.com>
rc1140 <jameel@republiccommandos.co.za> rc1140 <jameel@republiccommandos.co.za>
Red Hat, Inc. Red Hat, Inc.
Reetuparna Mukherjee <reetuparna.1988@gmail.com>
Reinier Timmer <reinier.timmer@ah.nl> Reinier Timmer <reinier.timmer@ah.nl>
Renjith R <renjithr201097@gmail.com>
Ricco Førgaard <ricco@fiskeben.dk> Ricco Førgaard <ricco@fiskeben.dk>
Rob Figueiredo <robfig@yext.com> Rob Figueiredo <robfig@yext.com>
Rohit Upadhyay <urohit011@gmail.com> Rohit Upadhyay <urohit011@gmail.com>
Ronak Jain <ronakjain@outlook.in> Ronak Jain <ronakjain@outlook.in>
Ruben Vereecken <rubenvereecken@gmail.com> Ruben Vereecken <rubenvereecken@gmail.com>
Russell Boley <raboley@gmail.com>
Ryan Leung <rleungx@gmail.com> Ryan Leung <rleungx@gmail.com>
Ryan Lower <rpjlower@gmail.com> Ryan Lower <rpjlower@gmail.com>
Ryo Nakao <nakabonne@gmail.com> Ryo Nakao <nakabonne@gmail.com>
@ -251,6 +284,7 @@ Sebastian Mandrean <sebastian.mandrean@gmail.com>
Sebastian Mæland Pedersen <sem.pedersen@stud.uis.no> Sebastian Mæland Pedersen <sem.pedersen@stud.uis.no>
Sergey Romanov <xxsmotur@gmail.com> Sergey Romanov <xxsmotur@gmail.com>
Sergio Garcia <sergio.garcia@gmail.com> Sergio Garcia <sergio.garcia@gmail.com>
Seth Vargo <seth@sethvargo.com>
Sevki <s@sevki.org> Sevki <s@sevki.org>
Shagun Khemka <shagun.khemka60@gmail.com> Shagun Khemka <shagun.khemka60@gmail.com>
shakeelrao <shakeelrao79@gmail.com> shakeelrao <shakeelrao79@gmail.com>
@ -258,17 +292,23 @@ Shawn Catanzarite <me@shawncatz.com>
Shawn Smith <shawnpsmith@gmail.com> Shawn Smith <shawnpsmith@gmail.com>
Shibasis Patel <patelshibasis@gmail.com> Shibasis Patel <patelshibasis@gmail.com>
Shrikrishna Singh <krishnasingh.ss30@gmail.com> Shrikrishna Singh <krishnasingh.ss30@gmail.com>
Simon Davis <sdavis@hashicorp.com>
sona-tar <sona.zip@gmail.com> sona-tar <sona.zip@gmail.com>
SoundCloud, Ltd. SoundCloud, Ltd.
Sridhar Mocherla <srmocher@microsoft.com> Sridhar Mocherla <srmocher@microsoft.com>
SriVignessh Pss <sriknowledge@gmail.com> SriVignessh Pss <sriknowledge@gmail.com>
Stefan Sedich <stefan.sedich@gmail.com> Stefan Sedich <stefan.sedich@gmail.com>
Steve Teuber <github@steveteuber.com>
Stian Eikeland <stian@eikeland.se> Stian Eikeland <stian@eikeland.se>
Suhaib Mujahid <suhaibmujahid@gmail.com> Suhaib Mujahid <suhaibmujahid@gmail.com>
Szymon Kodrebski <simonkey007@gmail.com> Szymon Kodrebski <simonkey007@gmail.com>
Søren Hansen <soren@dinero.dk>
Takayuki Watanabe <takanabe.w@gmail.com> Takayuki Watanabe <takanabe.w@gmail.com>
Taketoshi Fujiwara <fujiwara@leapmind.io>
Taketoshi Fujiwara <taketoshi.fujiwara@gmail.com> Taketoshi Fujiwara <taketoshi.fujiwara@gmail.com>
Tasya Aditya Rukmana <tadityar@gmail.com> Tasya Aditya Rukmana <tadityar@gmail.com>
Theo Henson <theodorehenson@protonmail.com>
Thomas Aidan Curran <thomas@ory.sh>
Thomas Bruyelle <thomas.bruyelle@gmail.com> Thomas Bruyelle <thomas.bruyelle@gmail.com>
Timothée Peignier <timothee.peignier@tryphon.org> Timothée Peignier <timothee.peignier@tryphon.org>
tkhandel <tarunkhandelwal.iitr@gmail.com> tkhandel <tarunkhandelwal.iitr@gmail.com>

View file

@ -8,5 +8,5 @@ package github
// ActionsService handles communication with the actions related // ActionsService handles communication with the actions related
// methods of the GitHub API. // methods of the GitHub API.
// //
// GitHub API docs: https://developer.github.com/v3/actions/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/
type ActionsService service type ActionsService service

View file

@ -16,7 +16,7 @@ import (
// data between jobs in a workflow and provide storage for data // data between jobs in a workflow and provide storage for data
// once a workflow is complete. // once a workflow is complete.
// //
// GitHub API docs: https://developer.github.com/v3/actions/artifacts/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/artifacts/
type Artifact struct { type Artifact struct {
ID *int64 `json:"id,omitempty"` ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"` NodeID *string `json:"node_id,omitempty"`
@ -30,7 +30,7 @@ type Artifact struct {
// ArtifactList represents a list of GitHub artifacts. // ArtifactList represents a list of GitHub artifacts.
// //
// GitHub API docs: https://developer.github.com/v3/actions/artifacts/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/artifacts/
type ArtifactList struct { type ArtifactList struct {
TotalCount *int64 `json:"total_count,omitempty"` TotalCount *int64 `json:"total_count,omitempty"`
Artifacts []*Artifact `json:"artifacts,omitempty"` Artifacts []*Artifact `json:"artifacts,omitempty"`
@ -38,7 +38,7 @@ type ArtifactList struct {
// ListArtifacts lists all artifacts that belong to a repository. // ListArtifacts lists all artifacts that belong to a repository.
// //
// GitHub API docs: https://developer.github.com/v3/actions/artifacts/#list-artifacts-for-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-artifacts-for-a-repository
func (s *ActionsService) ListArtifacts(ctx context.Context, owner, repo string, opts *ListOptions) (*ArtifactList, *Response, error) { func (s *ActionsService) ListArtifacts(ctx context.Context, owner, repo string, opts *ListOptions) (*ArtifactList, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/artifacts", owner, repo) u := fmt.Sprintf("repos/%v/%v/actions/artifacts", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -62,7 +62,7 @@ func (s *ActionsService) ListArtifacts(ctx context.Context, owner, repo string,
// ListWorkflowRunArtifacts lists all artifacts that belong to a workflow run. // ListWorkflowRunArtifacts lists all artifacts that belong to a workflow run.
// //
// GitHub API docs: https://developer.github.com/v3/actions/artifacts/#list-workflow-run-artifacts // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-workflow-run-artifacts
func (s *ActionsService) ListWorkflowRunArtifacts(ctx context.Context, owner, repo string, runID int64, opts *ListOptions) (*ArtifactList, *Response, error) { func (s *ActionsService) ListWorkflowRunArtifacts(ctx context.Context, owner, repo string, runID int64, opts *ListOptions) (*ArtifactList, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/runs/%v/artifacts", owner, repo, runID) u := fmt.Sprintf("repos/%v/%v/actions/runs/%v/artifacts", owner, repo, runID)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -86,7 +86,7 @@ func (s *ActionsService) ListWorkflowRunArtifacts(ctx context.Context, owner, re
// GetArtifact gets a specific artifact for a workflow run. // GetArtifact gets a specific artifact for a workflow run.
// //
// GitHub API docs: https://developer.github.com/v3/actions/artifacts/#get-an-artifact // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#get-an-artifact
func (s *ActionsService) GetArtifact(ctx context.Context, owner, repo string, artifactID int64) (*Artifact, *Response, error) { func (s *ActionsService) GetArtifact(ctx context.Context, owner, repo string, artifactID int64) (*Artifact, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/artifacts/%v", owner, repo, artifactID) u := fmt.Sprintf("repos/%v/%v/actions/artifacts/%v", owner, repo, artifactID)
@ -106,7 +106,7 @@ func (s *ActionsService) GetArtifact(ctx context.Context, owner, repo string, ar
// DownloadArtifact gets a redirect URL to download an archive for a repository. // DownloadArtifact gets a redirect URL to download an archive for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/actions/artifacts/#download-an-artifact // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/artifacts/#download-an-artifact
func (s *ActionsService) DownloadArtifact(ctx context.Context, owner, repo string, artifactID int64, followRedirects bool) (*url.URL, *Response, error) { func (s *ActionsService) DownloadArtifact(ctx context.Context, owner, repo string, artifactID int64, followRedirects bool) (*url.URL, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/artifacts/%v/zip", owner, repo, artifactID) u := fmt.Sprintf("repos/%v/%v/actions/artifacts/%v/zip", owner, repo, artifactID)
@ -151,7 +151,7 @@ func (s *ActionsService) getDownloadArtifactFromURL(ctx context.Context, u strin
// DeleteArtifact deletes a workflow run artifact. // DeleteArtifact deletes a workflow run artifact.
// //
// GitHub API docs: https://developer.github.com/v3/actions/artifacts/#delete-an-artifact // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#delete-an-artifact
func (s *ActionsService) DeleteArtifact(ctx context.Context, owner, repo string, artifactID int64) (*Response, error) { func (s *ActionsService) DeleteArtifact(ctx context.Context, owner, repo string, artifactID int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/artifacts/%v", owner, repo, artifactID) u := fmt.Sprintf("repos/%v/%v/actions/artifacts/%v", owner, repo, artifactID)

View file

@ -0,0 +1,286 @@
// 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"
)
// RunnerGroup represents a self-hosted runner group configured in an organization.
type RunnerGroup struct {
ID *int64 `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Visibility *string `json:"visibility,omitempty"`
Default *bool `json:"default,omitempty"`
SelectedRepositoriesURL *string `json:"selected_repositories_url,omitempty"`
RunnersURL *string `json:"runners_url,omitempty"`
Inherited *bool `json:"inherited,omitempty"`
AllowsPublicRepositories *bool `json:"allows_public_repositories,omitempty"`
}
// RunnerGroups represents a collection of self-hosted runner groups configured for an organization.
type RunnerGroups struct {
TotalCount int `json:"total_count"`
RunnerGroups []*RunnerGroup `json:"runner_groups"`
}
// CreateRunnerGroupRequest represents a request to create a Runner group for an organization.
type CreateRunnerGroupRequest struct {
Name *string `json:"name,omitempty"`
Visibility *string `json:"visibility,omitempty"`
// List of repository IDs that can access the runner group.
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"`
}
// 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"`
}
// SetRepoAccessRunnerGroupRequest represents a request to replace the list of repositories
// that can access a self-hosted runner group configured in an organization.
type SetRepoAccessRunnerGroupRequest struct {
// Updated list of repository IDs that should be given access to the runner group.
SelectedRepositoryIDs []int64 `json:"selected_repository_ids"`
}
// SetRunnerGroupRunnersRequest represents a request to replace the list of
// self-hosted runners that are part of an organization runner group.
type SetRunnerGroupRunnersRequest struct {
// Updated list of runner IDs that should be given access to the runner group.
Runners []int64 `json:"runners"`
}
// ListOrganizationRunnerGroups lists all self-hosted runner groups configured in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#list-self-hosted-runner-groups-for-an-organization
func (s *ActionsService) ListOrganizationRunnerGroups(ctx context.Context, org string, opts *ListOptions) (*RunnerGroups, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runner-groups", 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
}
groups := &RunnerGroups{}
resp, err := s.client.Do(ctx, req, &groups)
if err != nil {
return nil, resp, err
}
return groups, resp, nil
}
// GetOrganizationRunnerGroup gets a specific self-hosted runner group for an organization using its RunnerGroup ID.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#get-a-self-hosted-runner-group-for-an-organization
func (s *ActionsService) GetOrganizationRunnerGroup(ctx context.Context, org string, groupID int64) (*RunnerGroup, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v", org, groupID)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
runnerGroup := new(RunnerGroup)
resp, err := s.client.Do(ctx, req, runnerGroup)
if err != nil {
return nil, resp, err
}
return runnerGroup, resp, nil
}
// DeleteOrganizationRunnerGroup deletes a self-hosted runner group from an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#delete-a-self-hosted-runner-group-from-an-organization
func (s *ActionsService) DeleteOrganizationRunnerGroup(ctx context.Context, org string, groupID int64) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v", org, groupID)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// CreateOrganizationRunnerGroup creates a new self-hosted runner group for an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#create-a-self-hosted-runner-group-for-an-organization
func (s *ActionsService) CreateOrganizationRunnerGroup(ctx context.Context, org string, createReq CreateRunnerGroupRequest) (*RunnerGroup, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runner-groups", org)
req, err := s.client.NewRequest("POST", u, createReq)
if err != nil {
return nil, nil, err
}
runnerGroup := new(RunnerGroup)
resp, err := s.client.Do(ctx, req, runnerGroup)
if err != nil {
return nil, resp, err
}
return runnerGroup, resp, nil
}
// UpdateOrganizationRunnerGroup updates a self-hosted runner group for an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#update-a-self-hosted-runner-group-for-an-organization
func (s *ActionsService) UpdateOrganizationRunnerGroup(ctx context.Context, org string, groupID int64, updateReq UpdateRunnerGroupRequest) (*RunnerGroup, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v", org, groupID)
req, err := s.client.NewRequest("PATCH", u, updateReq)
if err != nil {
return nil, nil, err
}
runnerGroup := new(RunnerGroup)
resp, err := s.client.Do(ctx, req, runnerGroup)
if err != nil {
return nil, resp, err
}
return runnerGroup, resp, nil
}
// 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) {
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/repositories", org, groupID)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
repos := &ListRepositories{}
resp, err := s.client.Do(ctx, req, &repos)
if err != nil {
return nil, resp, err
}
return repos, resp, nil
}
// SetRepositoryAccessRunnerGroup replaces the list of repositories that have access to a self-hosted runner group configured in an organization
// with a new List of repositories.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#set-repository-access-for-a-self-hosted-runner-group-in-an-organization
func (s *ActionsService) SetRepositoryAccessRunnerGroup(ctx context.Context, org string, groupID int64, ids SetRepoAccessRunnerGroupRequest) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/repositories", org, groupID)
req, err := s.client.NewRequest("PUT", u, ids)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// AddRepositoryAccessRunnerGroup adds a repository to the list of selected repositories that can access a self-hosted runner group.
// The runner group must have visibility set to 'selected'.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#add-repository-access-to-a-self-hosted-runner-group-in-an-organization
func (s *ActionsService) AddRepositoryAccessRunnerGroup(ctx context.Context, org string, groupID, repoID int64) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/repositories/%v", org, groupID, repoID)
req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// RemoveRepositoryAccessRunnerGroup removes a repository from the list of selected repositories that can access a self-hosted runner group.
// The runner group must have visibility set to 'selected'.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#remove-repository-access-to-a-self-hosted-runner-group-in-an-organization
func (s *ActionsService) RemoveRepositoryAccessRunnerGroup(ctx context.Context, org string, groupID, repoID int64) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/repositories/%v", org, groupID, repoID)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// ListRunnerGroupRunners lists self-hosted runners that are in a specific organization group.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#list-self-hosted-runners-in-a-group-for-an-organization
func (s *ActionsService) ListRunnerGroupRunners(ctx context.Context, org string, groupID int64, opts *ListOptions) (*Runners, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/runners", 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
}
runners := &Runners{}
resp, err := s.client.Do(ctx, req, &runners)
if err != nil {
return nil, resp, err
}
return runners, resp, nil
}
// SetRunnerGroupRunners replaces the list of self-hosted runners that are part of an organization runner group
// with a new list of runners.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#set-self-hosted-runners-in-a-group-for-an-organization
func (s *ActionsService) SetRunnerGroupRunners(ctx context.Context, org string, groupID int64, ids SetRunnerGroupRunnersRequest) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/runners", org, groupID)
req, err := s.client.NewRequest("PUT", u, ids)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// AddRunnerGroupRunners adds a self-hosted runner to a runner group configured in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#add-a-self-hosted-runner-to-a-group-for-an-organization
func (s *ActionsService) AddRunnerGroupRunners(ctx context.Context, org string, groupID, runnerID int64) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/runners/%v", org, groupID, runnerID)
req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// RemoveRunnerGroupRunners removes a self-hosted runner from a group configured in an organization.
// The runner is then returned to the default group.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#remove-a-self-hosted-runner-from-a-group-for-an-organization
func (s *ActionsService) RemoveRunnerGroupRunners(ctx context.Context, org string, groupID, runnerID int64) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/runners/%v", org, groupID, runnerID)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}

View file

@ -12,15 +12,23 @@ import (
// RunnerApplicationDownload represents a binary for the self-hosted runner application that can be downloaded. // RunnerApplicationDownload represents a binary for the self-hosted runner application that can be downloaded.
type RunnerApplicationDownload struct { type RunnerApplicationDownload struct {
OS *string `json:"os,omitempty"` OS *string `json:"os,omitempty"`
Architecture *string `json:"architecture,omitempty"` Architecture *string `json:"architecture,omitempty"`
DownloadURL *string `json:"download_url,omitempty"` DownloadURL *string `json:"download_url,omitempty"`
Filename *string `json:"filename,omitempty"` Filename *string `json:"filename,omitempty"`
TempDownloadToken *string `json:"temp_download_token,omitempty"`
SHA256Checksum *string `json:"sha256_checksum,omitempty"`
}
// ActionsEnabledOnOrgRepos represents all the repositories in an organization for which Actions is enabled.
type ActionsEnabledOnOrgRepos struct {
TotalCount int `json:"total_count"`
Repositories []*Repository `json:"repositories"`
} }
// ListRunnerApplicationDownloads lists self-hosted runner application binaries that can be downloaded and run. // ListRunnerApplicationDownloads lists self-hosted runner application binaries that can be downloaded and run.
// //
// GitHub API docs: https://developer.github.com/v3/actions/self-hosted-runners/#list-runner-applications-for-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-runner-applications-for-a-repository
func (s *ActionsService) ListRunnerApplicationDownloads(ctx context.Context, owner, repo string) ([]*RunnerApplicationDownload, *Response, error) { func (s *ActionsService) ListRunnerApplicationDownloads(ctx context.Context, owner, repo string) ([]*RunnerApplicationDownload, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/runners/downloads", owner, repo) u := fmt.Sprintf("repos/%v/%v/actions/runners/downloads", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -45,7 +53,7 @@ type RegistrationToken struct {
// CreateRegistrationToken creates a token that can be used to add a self-hosted runner. // CreateRegistrationToken creates a token that can be used to add a self-hosted runner.
// //
// GitHub API docs: https://developer.github.com/v3/actions/self-hosted-runners/#create-a-registration-token-for-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#create-a-registration-token-for-a-repository
func (s *ActionsService) CreateRegistrationToken(ctx context.Context, owner, repo string) (*RegistrationToken, *Response, error) { func (s *ActionsService) CreateRegistrationToken(ctx context.Context, owner, repo string) (*RegistrationToken, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/runners/registration-token", owner, repo) u := fmt.Sprintf("repos/%v/%v/actions/runners/registration-token", owner, repo)
@ -65,10 +73,19 @@ func (s *ActionsService) CreateRegistrationToken(ctx context.Context, owner, rep
// Runner represents a self-hosted runner registered with a repository. // Runner represents a self-hosted runner registered with a repository.
type Runner struct { type Runner struct {
ID *int64 `json:"id,omitempty"` ID *int64 `json:"id,omitempty"`
Name *string `json:"name,omitempty"` Name *string `json:"name,omitempty"`
OS *string `json:"os,omitempty"` OS *string `json:"os,omitempty"`
Status *string `json:"status,omitempty"` Status *string `json:"status,omitempty"`
Busy *bool `json:"busy,omitempty"`
Labels []*RunnerLabels `json:"labels,omitempty"`
}
// RunnerLabels represents a collection of labels attached to each runner.
type RunnerLabels struct {
ID *int64 `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Type *string `json:"type,omitempty"`
} }
// Runners represents a collection of self-hosted runners for a repository. // Runners represents a collection of self-hosted runners for a repository.
@ -79,7 +96,7 @@ type Runners struct {
// ListRunners lists all the self-hosted runners for a repository. // ListRunners lists all the self-hosted runners for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/actions/self-hosted-runners/#list-self-hosted-runners-for-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-self-hosted-runners-for-a-repository
func (s *ActionsService) ListRunners(ctx context.Context, owner, repo string, opts *ListOptions) (*Runners, *Response, error) { func (s *ActionsService) ListRunners(ctx context.Context, owner, repo string, opts *ListOptions) (*Runners, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/runners", owner, repo) u := fmt.Sprintf("repos/%v/%v/actions/runners", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -103,7 +120,7 @@ func (s *ActionsService) ListRunners(ctx context.Context, owner, repo string, op
// GetRunner gets a specific self-hosted runner for a repository using its runner ID. // GetRunner gets a specific self-hosted runner for a repository using its runner ID.
// //
// GitHub API docs: https://developer.github.com/v3/actions/self-hosted-runners/#get-a-self-hosted-runner-for-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#get-a-self-hosted-runner-for-a-repository
func (s *ActionsService) GetRunner(ctx context.Context, owner, repo string, runnerID int64) (*Runner, *Response, error) { func (s *ActionsService) GetRunner(ctx context.Context, owner, repo string, runnerID int64) (*Runner, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/runners/%v", owner, repo, runnerID) u := fmt.Sprintf("repos/%v/%v/actions/runners/%v", owner, repo, runnerID)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -128,7 +145,7 @@ type RemoveToken struct {
// CreateRemoveToken creates a token that can be used to remove a self-hosted runner from a repository. // CreateRemoveToken creates a token that can be used to remove a self-hosted runner from a repository.
// //
// GitHub API docs: https://developer.github.com/v3/actions/self-hosted-runners/#create-a-remove-token-for-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#create-a-remove-token-for-a-repository
func (s *ActionsService) CreateRemoveToken(ctx context.Context, owner, repo string) (*RemoveToken, *Response, error) { func (s *ActionsService) CreateRemoveToken(ctx context.Context, owner, repo string) (*RemoveToken, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/runners/remove-token", owner, repo) u := fmt.Sprintf("repos/%v/%v/actions/runners/remove-token", owner, repo)
@ -148,7 +165,7 @@ func (s *ActionsService) CreateRemoveToken(ctx context.Context, owner, repo stri
// RemoveRunner forces the removal of a self-hosted runner in a repository using the runner id. // RemoveRunner forces the removal of a self-hosted runner in a repository using the runner id.
// //
// GitHub API docs: https://developer.github.com/v3/actions/self-hosted-runners/#delete-a-self-hosted-runner-from-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#delete-a-self-hosted-runner-from-a-repository
func (s *ActionsService) RemoveRunner(ctx context.Context, owner, repo string, runnerID int64) (*Response, error) { func (s *ActionsService) RemoveRunner(ctx context.Context, owner, repo string, runnerID int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/runners/%v", owner, repo, runnerID) u := fmt.Sprintf("repos/%v/%v/actions/runners/%v", owner, repo, runnerID)
@ -162,7 +179,7 @@ func (s *ActionsService) RemoveRunner(ctx context.Context, owner, repo string, r
// ListOrganizationRunnerApplicationDownloads lists self-hosted runner application binaries that can be downloaded and run. // ListOrganizationRunnerApplicationDownloads lists self-hosted runner application binaries that can be downloaded and run.
// //
// GitHub API docs: https://developer.github.com/v3/actions/self-hosted-runners/#list-runner-applications-for-an-organization // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-runner-applications-for-an-organization
func (s *ActionsService) ListOrganizationRunnerApplicationDownloads(ctx context.Context, owner string) ([]*RunnerApplicationDownload, *Response, error) { func (s *ActionsService) ListOrganizationRunnerApplicationDownloads(ctx context.Context, owner string) ([]*RunnerApplicationDownload, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runners/downloads", owner) u := fmt.Sprintf("orgs/%v/actions/runners/downloads", owner)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -181,7 +198,7 @@ func (s *ActionsService) ListOrganizationRunnerApplicationDownloads(ctx context.
// CreateOrganizationRegistrationToken creates a token that can be used to add a self-hosted runner to an organization. // CreateOrganizationRegistrationToken creates a token that can be used to add a self-hosted runner to an organization.
// //
// GitHub API docs: https://developer.github.com/v3/actions/self-hosted-runners/#create-a-registration-token-for-an-organization // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#create-a-registration-token-for-an-organization
func (s *ActionsService) CreateOrganizationRegistrationToken(ctx context.Context, owner string) (*RegistrationToken, *Response, error) { func (s *ActionsService) CreateOrganizationRegistrationToken(ctx context.Context, owner string) (*RegistrationToken, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runners/registration-token", owner) u := fmt.Sprintf("orgs/%v/actions/runners/registration-token", owner)
@ -201,7 +218,7 @@ func (s *ActionsService) CreateOrganizationRegistrationToken(ctx context.Context
// ListOrganizationRunners lists all the self-hosted runners for an organization. // ListOrganizationRunners lists all the self-hosted runners for an organization.
// //
// GitHub API docs: https://developer.github.com/v3/actions/self-hosted-runners/#list-self-hosted-runners-for-an-organization // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-self-hosted-runners-for-an-organization
func (s *ActionsService) ListOrganizationRunners(ctx context.Context, owner string, opts *ListOptions) (*Runners, *Response, error) { func (s *ActionsService) ListOrganizationRunners(ctx context.Context, owner string, opts *ListOptions) (*Runners, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runners", owner) u := fmt.Sprintf("orgs/%v/actions/runners", owner)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -223,9 +240,33 @@ func (s *ActionsService) ListOrganizationRunners(ctx context.Context, owner stri
return runners, resp, nil return runners, resp, nil
} }
// ListEnabledReposInOrg lists the selected repositories that are enabled for GitHub Actions in an organization.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-selected-repositories-enabled-for-github-actions-in-an-organization
func (s *ActionsService) ListEnabledReposInOrg(ctx context.Context, owner string, opts *ListOptions) (*ActionsEnabledOnOrgRepos, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/permissions/repositories", owner)
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
}
repos := &ActionsEnabledOnOrgRepos{}
resp, err := s.client.Do(ctx, req, repos)
if err != nil {
return nil, resp, err
}
return repos, resp, nil
}
// GetOrganizationRunner gets a specific self-hosted runner for an organization using its runner ID. // GetOrganizationRunner gets a specific self-hosted runner for an organization using its runner ID.
// //
// GitHub API docs: https://developer.github.com/v3/actions/self-hosted-runners/#get-a-self-hosted-runner-for-an-organization // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#get-a-self-hosted-runner-for-an-organization
func (s *ActionsService) GetOrganizationRunner(ctx context.Context, owner string, runnerID int64) (*Runner, *Response, error) { func (s *ActionsService) GetOrganizationRunner(ctx context.Context, owner string, runnerID int64) (*Runner, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runners/%v", owner, runnerID) u := fmt.Sprintf("orgs/%v/actions/runners/%v", owner, runnerID)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -244,7 +285,7 @@ func (s *ActionsService) GetOrganizationRunner(ctx context.Context, owner string
// CreateOrganizationRemoveToken creates a token that can be used to remove a self-hosted runner from an organization. // CreateOrganizationRemoveToken creates a token that can be used to remove a self-hosted runner from an organization.
// //
// GitHub API docs: https://developer.github.com/v3/actions/self-hosted-runners/#create-a-remove-token-for-an-organization // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#create-a-remove-token-for-an-organization
func (s *ActionsService) CreateOrganizationRemoveToken(ctx context.Context, owner string) (*RemoveToken, *Response, error) { func (s *ActionsService) CreateOrganizationRemoveToken(ctx context.Context, owner string) (*RemoveToken, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runners/remove-token", owner) u := fmt.Sprintf("orgs/%v/actions/runners/remove-token", owner)
@ -264,7 +305,7 @@ func (s *ActionsService) CreateOrganizationRemoveToken(ctx context.Context, owne
// RemoveOrganizationRunner forces the removal of a self-hosted runner from an organization using the runner id. // RemoveOrganizationRunner forces the removal of a self-hosted runner from an organization using the runner id.
// //
// GitHub API docs: https://developer.github.com/v3/actions/self-hosted-runners/#delete-a-self-hosted-runner-from-an-organization // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#delete-a-self-hosted-runner-from-an-organization
func (s *ActionsService) RemoveOrganizationRunner(ctx context.Context, owner string, runnerID int64) (*Response, error) { func (s *ActionsService) RemoveOrganizationRunner(ctx context.Context, owner string, runnerID int64) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runners/%v", owner, runnerID) u := fmt.Sprintf("orgs/%v/actions/runners/%v", owner, runnerID)

View file

@ -7,7 +7,9 @@ package github
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"strconv"
) )
// PublicKey represents the public key that should be used to encrypt secrets. // PublicKey represents the public key that should be used to encrypt secrets.
@ -16,9 +18,38 @@ type PublicKey struct {
Key *string `json:"key"` Key *string `json:"key"`
} }
// UnmarshalJSON implements the json.Unmarshaler interface.
// This ensures GitHub Enterprise versions which return a numeric key id
// do not error out when unmarshaling.
func (p *PublicKey) UnmarshalJSON(data []byte) error {
var pk struct {
KeyID interface{} `json:"key_id,string"`
Key *string `json:"key"`
}
if err := json.Unmarshal(data, &pk); err != nil {
return err
}
p.Key = pk.Key
switch v := pk.KeyID.(type) {
case nil:
return nil
case string:
p.KeyID = &v
case float64:
p.KeyID = String(strconv.FormatFloat(v, 'f', -1, 64))
default:
return fmt.Errorf("unable to unmarshal %T as a string", v)
}
return nil
}
// GetRepoPublicKey gets a public key that should be used for secret encryption. // GetRepoPublicKey gets a public key that should be used for secret encryption.
// //
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#get-a-repository-public-key // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#get-a-repository-public-key
func (s *ActionsService) GetRepoPublicKey(ctx context.Context, owner, repo string) (*PublicKey, *Response, error) { func (s *ActionsService) GetRepoPublicKey(ctx context.Context, owner, repo string) (*PublicKey, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/secrets/public-key", owner, repo) u := fmt.Sprintf("repos/%v/%v/actions/secrets/public-key", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -37,7 +68,7 @@ func (s *ActionsService) GetRepoPublicKey(ctx context.Context, owner, repo strin
// GetOrgPublicKey gets a public key that should be used for secret encryption. // GetOrgPublicKey gets a public key that should be used for secret encryption.
// //
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#get-an-organization-public-key // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#get-an-organization-public-key
func (s *ActionsService) GetOrgPublicKey(ctx context.Context, org string) (*PublicKey, *Response, error) { func (s *ActionsService) GetOrgPublicKey(ctx context.Context, org string) (*PublicKey, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/secrets/public-key", org) u := fmt.Sprintf("orgs/%v/actions/secrets/public-key", org)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -54,6 +85,25 @@ func (s *ActionsService) GetOrgPublicKey(ctx context.Context, org string) (*Publ
return pubKey, resp, nil return pubKey, resp, nil
} }
// GetEnvPublicKey gets a public key that should be used for secret encryption.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#get-an-environment-public-key
func (s *ActionsService) GetEnvPublicKey(ctx context.Context, repoID int, env string) (*PublicKey, *Response, error) {
u := fmt.Sprintf("repositories/%v/environments/%v/secrets/public-key", repoID, env)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
pubKey := new(PublicKey)
resp, err := s.client.Do(ctx, req, pubKey)
if err != nil {
return nil, resp, err
}
return pubKey, resp, nil
}
// Secret represents a repository action secret. // Secret represents a repository action secret.
type Secret struct { type Secret struct {
Name string `json:"name"` Name string `json:"name"`
@ -72,7 +122,7 @@ type Secrets struct {
// ListRepoSecrets lists all secrets available in a repository // ListRepoSecrets lists all secrets available in a repository
// without revealing their encrypted values. // without revealing their encrypted values.
// //
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#list-repository-secrets // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-repository-secrets
func (s *ActionsService) ListRepoSecrets(ctx context.Context, owner, repo string, opts *ListOptions) (*Secrets, *Response, error) { func (s *ActionsService) ListRepoSecrets(ctx context.Context, owner, repo string, opts *ListOptions) (*Secrets, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/secrets", owner, repo) u := fmt.Sprintf("repos/%v/%v/actions/secrets", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -96,7 +146,7 @@ func (s *ActionsService) ListRepoSecrets(ctx context.Context, owner, repo string
// GetRepoSecret gets a single repository secret without revealing its encrypted value. // GetRepoSecret gets a single repository secret without revealing its encrypted value.
// //
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#get-a-repository-secret // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#get-a-repository-secret
func (s *ActionsService) GetRepoSecret(ctx context.Context, owner, repo, name string) (*Secret, *Response, error) { func (s *ActionsService) GetRepoSecret(ctx context.Context, owner, repo, name string) (*Secret, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/secrets/%v", owner, repo, name) u := fmt.Sprintf("repos/%v/%v/actions/secrets/%v", owner, repo, name)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -131,7 +181,7 @@ type EncryptedSecret struct {
// CreateOrUpdateRepoSecret creates or updates a repository secret with an encrypted value. // CreateOrUpdateRepoSecret creates or updates a repository secret with an encrypted value.
// //
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#create-or-update-a-repository-secret // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#create-or-update-a-repository-secret
func (s *ActionsService) CreateOrUpdateRepoSecret(ctx context.Context, owner, repo string, eSecret *EncryptedSecret) (*Response, error) { func (s *ActionsService) CreateOrUpdateRepoSecret(ctx context.Context, owner, repo string, eSecret *EncryptedSecret) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/secrets/%v", owner, repo, eSecret.Name) u := fmt.Sprintf("repos/%v/%v/actions/secrets/%v", owner, repo, eSecret.Name)
@ -145,7 +195,7 @@ func (s *ActionsService) CreateOrUpdateRepoSecret(ctx context.Context, owner, re
// DeleteRepoSecret deletes a secret in a repository using the secret name. // DeleteRepoSecret deletes a secret in a repository using the secret name.
// //
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#delete-a-repository-secret // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#delete-a-repository-secret
func (s *ActionsService) DeleteRepoSecret(ctx context.Context, owner, repo, name string) (*Response, error) { func (s *ActionsService) DeleteRepoSecret(ctx context.Context, owner, repo, name string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/secrets/%v", owner, repo, name) u := fmt.Sprintf("repos/%v/%v/actions/secrets/%v", owner, repo, name)
@ -160,7 +210,7 @@ func (s *ActionsService) DeleteRepoSecret(ctx context.Context, owner, repo, name
// ListOrgSecrets lists all secrets available in an organization // ListOrgSecrets lists all secrets available in an organization
// without revealing their encrypted values. // without revealing their encrypted values.
// //
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#list-organization-secrets // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-organization-secrets
func (s *ActionsService) ListOrgSecrets(ctx context.Context, org string, opts *ListOptions) (*Secrets, *Response, error) { func (s *ActionsService) ListOrgSecrets(ctx context.Context, org string, opts *ListOptions) (*Secrets, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/secrets", org) u := fmt.Sprintf("orgs/%v/actions/secrets", org)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -184,7 +234,7 @@ func (s *ActionsService) ListOrgSecrets(ctx context.Context, org string, opts *L
// GetOrgSecret gets a single organization secret without revealing its encrypted value. // GetOrgSecret gets a single organization secret without revealing its encrypted value.
// //
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#get-an-organization-secret // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#get-an-organization-secret
func (s *ActionsService) GetOrgSecret(ctx context.Context, org, name string) (*Secret, *Response, error) { func (s *ActionsService) GetOrgSecret(ctx context.Context, org, name string) (*Secret, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/secrets/%v", org, name) u := fmt.Sprintf("orgs/%v/actions/secrets/%v", org, name)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -203,7 +253,7 @@ func (s *ActionsService) GetOrgSecret(ctx context.Context, org, name string) (*S
// CreateOrUpdateOrgSecret creates or updates an organization secret with an encrypted value. // CreateOrUpdateOrgSecret creates or updates an organization secret with an encrypted value.
// //
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#create-or-update-an-organization-secret // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#create-or-update-an-organization-secret
func (s *ActionsService) CreateOrUpdateOrgSecret(ctx context.Context, org string, eSecret *EncryptedSecret) (*Response, error) { func (s *ActionsService) CreateOrUpdateOrgSecret(ctx context.Context, org string, eSecret *EncryptedSecret) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/secrets/%v", org, eSecret.Name) u := fmt.Sprintf("orgs/%v/actions/secrets/%v", org, eSecret.Name)
@ -223,9 +273,14 @@ type SelectedReposList struct {
// ListSelectedReposForOrgSecret lists all repositories that have access to a secret. // ListSelectedReposForOrgSecret lists all repositories that have access to a secret.
// //
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#list-selected-repositories-for-an-organization-secret // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-selected-repositories-for-an-organization-secret
func (s *ActionsService) ListSelectedReposForOrgSecret(ctx context.Context, org, name string) (*SelectedReposList, *Response, error) { func (s *ActionsService) ListSelectedReposForOrgSecret(ctx context.Context, org, name string, opts *ListOptions) (*SelectedReposList, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/secrets/%v/repositories", org, name) u := fmt.Sprintf("orgs/%v/actions/secrets/%v/repositories", org, name)
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -242,7 +297,7 @@ func (s *ActionsService) ListSelectedReposForOrgSecret(ctx context.Context, org,
// SetSelectedReposForOrgSecret sets the repositories that have access to a secret. // SetSelectedReposForOrgSecret sets the repositories that have access to a secret.
// //
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#set-selected-repositories-for-an-organization-secret // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#set-selected-repositories-for-an-organization-secret
func (s *ActionsService) SetSelectedReposForOrgSecret(ctx context.Context, org, name string, ids SelectedRepoIDs) (*Response, error) { func (s *ActionsService) SetSelectedReposForOrgSecret(ctx context.Context, org, name string, ids SelectedRepoIDs) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/secrets/%v/repositories", org, name) u := fmt.Sprintf("orgs/%v/actions/secrets/%v/repositories", org, name)
@ -260,7 +315,7 @@ func (s *ActionsService) SetSelectedReposForOrgSecret(ctx context.Context, org,
// AddSelectedRepoToOrgSecret adds a repository to an organization secret. // AddSelectedRepoToOrgSecret adds a repository to an organization secret.
// //
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#add-selected-repository-to-an-organization-secret // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#add-selected-repository-to-an-organization-secret
func (s *ActionsService) AddSelectedRepoToOrgSecret(ctx context.Context, org, name string, repo *Repository) (*Response, error) { func (s *ActionsService) AddSelectedRepoToOrgSecret(ctx context.Context, org, name string, repo *Repository) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/secrets/%v/repositories/%v", org, name, *repo.ID) u := fmt.Sprintf("orgs/%v/actions/secrets/%v/repositories/%v", org, name, *repo.ID)
req, err := s.client.NewRequest("PUT", u, nil) req, err := s.client.NewRequest("PUT", u, nil)
@ -273,7 +328,7 @@ func (s *ActionsService) AddSelectedRepoToOrgSecret(ctx context.Context, org, na
// RemoveSelectedRepoFromOrgSecret removes a repository from an organization secret. // RemoveSelectedRepoFromOrgSecret removes a repository from an organization secret.
// //
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#remove-selected-repository-from-an-organization-secret // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#remove-selected-repository-from-an-organization-secret
func (s *ActionsService) RemoveSelectedRepoFromOrgSecret(ctx context.Context, org, name string, repo *Repository) (*Response, error) { func (s *ActionsService) RemoveSelectedRepoFromOrgSecret(ctx context.Context, org, name string, repo *Repository) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/secrets/%v/repositories/%v", org, name, *repo.ID) u := fmt.Sprintf("orgs/%v/actions/secrets/%v/repositories/%v", org, name, *repo.ID)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -286,7 +341,7 @@ func (s *ActionsService) RemoveSelectedRepoFromOrgSecret(ctx context.Context, or
// DeleteOrgSecret deletes a secret in an organization using the secret name. // DeleteOrgSecret deletes a secret in an organization using the secret name.
// //
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#delete-an-organization-secret // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#delete-an-organization-secret
func (s *ActionsService) DeleteOrgSecret(ctx context.Context, org, name string) (*Response, error) { func (s *ActionsService) DeleteOrgSecret(ctx context.Context, org, name string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/secrets/%v", org, name) u := fmt.Sprintf("orgs/%v/actions/secrets/%v", org, name)
@ -297,3 +352,74 @@ func (s *ActionsService) DeleteOrgSecret(ctx context.Context, org, name string)
return s.client.Do(ctx, req, nil) return s.client.Do(ctx, req, nil)
} }
// ListEnvSecrets lists all secrets available in an environment.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#list-environment-secrets
func (s *ActionsService) ListEnvSecrets(ctx context.Context, repoID int, env string, opts *ListOptions) (*Secrets, *Response, error) {
u := fmt.Sprintf("repositories/%v/environments/%v/secrets", repoID, env)
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
}
secrets := new(Secrets)
resp, err := s.client.Do(ctx, req, &secrets)
if err != nil {
return nil, resp, err
}
return secrets, resp, nil
}
// GetEnvSecret gets a single environment secret without revealing its encrypted value.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#list-environment-secrets
func (s *ActionsService) GetEnvSecret(ctx context.Context, repoID int, env, secretName string) (*Secret, *Response, error) {
u := fmt.Sprintf("repositories/%v/environments/%v/secrets/%v", repoID, env, secretName)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
secret := new(Secret)
resp, err := s.client.Do(ctx, req, secret)
if err != nil {
return nil, resp, err
}
return secret, resp, nil
}
// CreateOrUpdateEnvSecret creates or updates a repository secret with an encrypted value.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#create-or-update-an-environment-secret
func (s *ActionsService) CreateOrUpdateEnvSecret(ctx context.Context, repoID int, env string, eSecret *EncryptedSecret) (*Response, error) {
u := fmt.Sprintf("repositories/%v/environments/%v/secrets/%v", repoID, env, eSecret.Name)
req, err := s.client.NewRequest("PUT", u, eSecret)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// DeleteEnvSecret deletes a secret in an environment using the secret name.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#delete-an-environment-secret
func (s *ActionsService) DeleteEnvSecret(ctx context.Context, repoID int, env, secretName string) (*Response, error) {
u := fmt.Sprintf("repositories/%v/environments/%v/secrets/%v", repoID, env, secretName)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}

View file

@ -60,7 +60,7 @@ type ListWorkflowJobsOptions struct {
// ListWorkflowJobs lists all jobs for a workflow run. // ListWorkflowJobs lists all jobs for a workflow run.
// //
// GitHub API docs: https://developer.github.com/v3/actions/workflow-jobs/#list-jobs-for-a-workflow-run // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-jobs-for-a-workflow-run
func (s *ActionsService) ListWorkflowJobs(ctx context.Context, owner, repo string, runID int64, opts *ListWorkflowJobsOptions) (*Jobs, *Response, error) { func (s *ActionsService) ListWorkflowJobs(ctx context.Context, owner, repo string, runID int64, opts *ListWorkflowJobsOptions) (*Jobs, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/actions/runs/%v/jobs", owner, repo, runID) u := fmt.Sprintf("repos/%s/%s/actions/runs/%v/jobs", owner, repo, runID)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -84,7 +84,7 @@ func (s *ActionsService) ListWorkflowJobs(ctx context.Context, owner, repo strin
// GetWorkflowJobByID gets a specific job in a workflow run by ID. // GetWorkflowJobByID gets a specific job in a workflow run by ID.
// //
// GitHub API docs: https://developer.github.com/v3/actions/workflow-jobs/#get-a-job-for-a-workflow-run // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#get-a-job-for-a-workflow-run
func (s *ActionsService) GetWorkflowJobByID(ctx context.Context, owner, repo string, jobID int64) (*WorkflowJob, *Response, error) { func (s *ActionsService) GetWorkflowJobByID(ctx context.Context, owner, repo string, jobID int64) (*WorkflowJob, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/jobs/%v", owner, repo, jobID) u := fmt.Sprintf("repos/%v/%v/actions/jobs/%v", owner, repo, jobID)
@ -104,7 +104,7 @@ func (s *ActionsService) GetWorkflowJobByID(ctx context.Context, owner, repo str
// GetWorkflowJobLogs gets a redirect URL to download a plain text file of logs for a workflow job. // GetWorkflowJobLogs gets a redirect URL to download a plain text file of logs for a workflow job.
// //
// GitHub API docs: https://developer.github.com/v3/actions/workflow-jobs/#download-job-logs-for-a-workflow-run // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#download-job-logs-for-a-workflow-run
func (s *ActionsService) GetWorkflowJobLogs(ctx context.Context, owner, repo string, jobID int64, followRedirects bool) (*url.URL, *Response, error) { func (s *ActionsService) GetWorkflowJobLogs(ctx context.Context, owner, repo string, jobID int64, followRedirects bool) (*url.URL, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/jobs/%v/logs", owner, repo, jobID) u := fmt.Sprintf("repos/%v/%v/actions/jobs/%v/logs", owner, repo, jobID)

View file

@ -15,6 +15,7 @@ import (
// WorkflowRun represents a repository action workflow run. // WorkflowRun represents a repository action workflow run.
type WorkflowRun struct { type WorkflowRun struct {
ID *int64 `json:"id,omitempty"` ID *int64 `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
NodeID *string `json:"node_id,omitempty"` NodeID *string `json:"node_id,omitempty"`
HeadBranch *string `json:"head_branch,omitempty"` HeadBranch *string `json:"head_branch,omitempty"`
HeadSHA *string `json:"head_sha,omitempty"` HeadSHA *string `json:"head_sha,omitempty"`
@ -96,7 +97,7 @@ func (s *ActionsService) listWorkflowRuns(ctx context.Context, endpoint string,
// ListWorkflowRunsByID lists all workflow runs by workflow ID. // ListWorkflowRunsByID lists all workflow runs by workflow ID.
// //
// GitHub API docs: https://developer.github.com/v3/actions/workflow-runs/#list-workflow-runs // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-workflow-runs
func (s *ActionsService) ListWorkflowRunsByID(ctx context.Context, owner, repo string, workflowID int64, opts *ListWorkflowRunsOptions) (*WorkflowRuns, *Response, error) { func (s *ActionsService) ListWorkflowRunsByID(ctx context.Context, owner, repo string, workflowID int64, opts *ListWorkflowRunsOptions) (*WorkflowRuns, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/actions/workflows/%v/runs", owner, repo, workflowID) u := fmt.Sprintf("repos/%s/%s/actions/workflows/%v/runs", owner, repo, workflowID)
return s.listWorkflowRuns(ctx, u, opts) return s.listWorkflowRuns(ctx, u, opts)
@ -104,7 +105,7 @@ func (s *ActionsService) ListWorkflowRunsByID(ctx context.Context, owner, repo s
// ListWorkflowRunsByFileName lists all workflow runs by workflow file name. // ListWorkflowRunsByFileName lists all workflow runs by workflow file name.
// //
// GitHub API docs: https://developer.github.com/v3/actions/workflow-runs/#list-workflow-runs // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-workflow-runs
func (s *ActionsService) ListWorkflowRunsByFileName(ctx context.Context, owner, repo, workflowFileName string, opts *ListWorkflowRunsOptions) (*WorkflowRuns, *Response, error) { func (s *ActionsService) ListWorkflowRunsByFileName(ctx context.Context, owner, repo, workflowFileName string, opts *ListWorkflowRunsOptions) (*WorkflowRuns, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/actions/workflows/%v/runs", owner, repo, workflowFileName) u := fmt.Sprintf("repos/%s/%s/actions/workflows/%v/runs", owner, repo, workflowFileName)
return s.listWorkflowRuns(ctx, u, opts) return s.listWorkflowRuns(ctx, u, opts)
@ -112,7 +113,7 @@ func (s *ActionsService) ListWorkflowRunsByFileName(ctx context.Context, owner,
// ListRepositoryWorkflowRuns lists all workflow runs for a repository. // ListRepositoryWorkflowRuns lists all workflow runs for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/actions/workflow-runs/#list-workflow-runs-for-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-workflow-runs-for-a-repository
func (s *ActionsService) ListRepositoryWorkflowRuns(ctx context.Context, owner, repo string, opts *ListWorkflowRunsOptions) (*WorkflowRuns, *Response, error) { func (s *ActionsService) ListRepositoryWorkflowRuns(ctx context.Context, owner, repo string, opts *ListWorkflowRunsOptions) (*WorkflowRuns, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/actions/runs", owner, repo) u := fmt.Sprintf("repos/%s/%s/actions/runs", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -136,7 +137,7 @@ func (s *ActionsService) ListRepositoryWorkflowRuns(ctx context.Context, owner,
// GetWorkflowRunByID gets a specific workflow run by ID. // GetWorkflowRunByID gets a specific workflow run by ID.
// //
// GitHub API docs: https://developer.github.com/v3/actions/workflow-runs/#get-a-workflow-run // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#get-a-workflow-run
func (s *ActionsService) GetWorkflowRunByID(ctx context.Context, owner, repo string, runID int64) (*WorkflowRun, *Response, error) { func (s *ActionsService) GetWorkflowRunByID(ctx context.Context, owner, repo string, runID int64) (*WorkflowRun, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/runs/%v", owner, repo, runID) u := fmt.Sprintf("repos/%v/%v/actions/runs/%v", owner, repo, runID)
@ -154,9 +155,9 @@ func (s *ActionsService) GetWorkflowRunByID(ctx context.Context, owner, repo str
return run, resp, nil return run, resp, nil
} }
// RerunWorkflow re-runs a workflow by ID. // RerunWorkflowByID re-runs a workflow by ID.
// //
// GitHub API docs: https://developer.github.com/v3/actions/workflow-runs/#re-run-a-workflow // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#re-run-a-workflow
func (s *ActionsService) RerunWorkflowByID(ctx context.Context, owner, repo string, runID int64) (*Response, error) { func (s *ActionsService) RerunWorkflowByID(ctx context.Context, owner, repo string, runID int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/runs/%v/rerun", owner, repo, runID) u := fmt.Sprintf("repos/%v/%v/actions/runs/%v/rerun", owner, repo, runID)
@ -170,7 +171,7 @@ func (s *ActionsService) RerunWorkflowByID(ctx context.Context, owner, repo stri
// CancelWorkflowRunByID cancels a workflow run by ID. // CancelWorkflowRunByID cancels a workflow run by ID.
// //
// GitHub API docs: https://developer.github.com/v3/actions/workflow-runs/#cancel-a-workflow-run // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#cancel-a-workflow-run
func (s *ActionsService) CancelWorkflowRunByID(ctx context.Context, owner, repo string, runID int64) (*Response, error) { func (s *ActionsService) CancelWorkflowRunByID(ctx context.Context, owner, repo string, runID int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/runs/%v/cancel", owner, repo, runID) u := fmt.Sprintf("repos/%v/%v/actions/runs/%v/cancel", owner, repo, runID)
@ -184,7 +185,7 @@ func (s *ActionsService) CancelWorkflowRunByID(ctx context.Context, owner, repo
// GetWorkflowRunLogs gets a redirect URL to download a plain text file of logs for a workflow run. // GetWorkflowRunLogs gets a redirect URL to download a plain text file of logs for a workflow run.
// //
// GitHub API docs: https://developer.github.com/v3/actions/workflow-runs/#download-workflow-run-logs // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#download-workflow-run-logs
func (s *ActionsService) GetWorkflowRunLogs(ctx context.Context, owner, repo string, runID int64, followRedirects bool) (*url.URL, *Response, error) { func (s *ActionsService) GetWorkflowRunLogs(ctx context.Context, owner, repo string, runID int64, followRedirects bool) (*url.URL, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/runs/%v/logs", owner, repo, runID) u := fmt.Sprintf("repos/%v/%v/actions/runs/%v/logs", owner, repo, runID)
@ -202,7 +203,7 @@ func (s *ActionsService) GetWorkflowRunLogs(ctx context.Context, owner, repo str
// DeleteWorkflowRunLogs deletes all logs for a workflow run. // DeleteWorkflowRunLogs deletes all logs for a workflow run.
// //
// GitHub API docs: https://developer.github.com/v3/actions/workflow-runs/#delete-workflow-run-logs // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#delete-workflow-run-logs
func (s *ActionsService) DeleteWorkflowRunLogs(ctx context.Context, owner, repo string, runID int64) (*Response, error) { func (s *ActionsService) DeleteWorkflowRunLogs(ctx context.Context, owner, repo string, runID int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/runs/%v/logs", owner, repo, runID) u := fmt.Sprintf("repos/%v/%v/actions/runs/%v/logs", owner, repo, runID)
@ -216,7 +217,7 @@ func (s *ActionsService) DeleteWorkflowRunLogs(ctx context.Context, owner, repo
// GetWorkflowRunUsageByID gets a specific workflow usage run by run ID in the unit of billable milliseconds. // GetWorkflowRunUsageByID gets a specific workflow usage run by run ID in the unit of billable milliseconds.
// //
// GitHub API docs: https://developer.github.com/v3/actions/workflow-runs/#get-workflow-run-usage // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#get-workflow-run-usage
func (s *ActionsService) GetWorkflowRunUsageByID(ctx context.Context, owner, repo string, runID int64) (*WorkflowRunUsage, *Response, error) { func (s *ActionsService) GetWorkflowRunUsageByID(ctx context.Context, owner, repo string, runID int64) (*WorkflowRunUsage, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/runs/%v/timing", owner, repo, runID) u := fmt.Sprintf("repos/%v/%v/actions/runs/%v/timing", owner, repo, runID)

View file

@ -0,0 +1,218 @@
// Copyright 2020 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"
)
// Workflow represents a repository action workflow.
type Workflow struct {
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
Name *string `json:"name,omitempty"`
Path *string `json:"path,omitempty"`
State *string `json:"state,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
URL *string `json:"url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
BadgeURL *string `json:"badge_url,omitempty"`
}
// Workflows represents a slice of repository action workflows.
type Workflows struct {
TotalCount *int `json:"total_count,omitempty"`
Workflows []*Workflow `json:"workflows,omitempty"`
}
// WorkflowUsage represents a usage of a specific workflow.
type WorkflowUsage struct {
Billable *WorkflowEnvironment `json:"billable,omitempty"`
}
// WorkflowEnvironment represents different runner environments available for a workflow.
type WorkflowEnvironment struct {
Ubuntu *WorkflowBill `json:"UBUNTU,omitempty"`
MacOS *WorkflowBill `json:"MACOS,omitempty"`
Windows *WorkflowBill `json:"WINDOWS,omitempty"`
}
// WorkflowBill specifies billable time for a specific environment in a workflow.
type WorkflowBill struct {
TotalMS *int64 `json:"total_ms,omitempty"`
}
// CreateWorkflowDispatchEventRequest represents a request to create a workflow dispatch event.
type CreateWorkflowDispatchEventRequest struct {
// Ref represents the reference of the workflow run.
// The reference can be a branch, tag, or a commit SHA.
// Ref is required when creating a workflow dispatch event.
Ref string `json:"ref"`
// Inputs represents input keys and values configured in the workflow file.
// The maximum number of properties is 10.
// Default: Any default properties configured in the workflow file will be used when `inputs` are omitted.
Inputs map[string]interface{} `json:"inputs,omitempty"`
}
// ListWorkflows lists all workflows in a repository.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-repository-workflows
func (s *ActionsService) ListWorkflows(ctx context.Context, owner, repo string, opts *ListOptions) (*Workflows, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/actions/workflows", 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
}
workflows := new(Workflows)
resp, err := s.client.Do(ctx, req, &workflows)
if err != nil {
return nil, resp, err
}
return workflows, resp, nil
}
// GetWorkflowByID gets a specific workflow by ID.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#get-a-workflow
func (s *ActionsService) GetWorkflowByID(ctx context.Context, owner, repo string, workflowID int64) (*Workflow, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v", owner, repo, workflowID)
return s.getWorkflow(ctx, u)
}
// GetWorkflowByFileName gets a specific workflow by file name.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#get-a-workflow
func (s *ActionsService) GetWorkflowByFileName(ctx context.Context, owner, repo, workflowFileName string) (*Workflow, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v", owner, repo, workflowFileName)
return s.getWorkflow(ctx, u)
}
func (s *ActionsService) getWorkflow(ctx context.Context, url string) (*Workflow, *Response, error) {
req, err := s.client.NewRequest("GET", url, nil)
if err != nil {
return nil, nil, err
}
workflow := new(Workflow)
resp, err := s.client.Do(ctx, req, workflow)
if err != nil {
return nil, resp, err
}
return workflow, resp, nil
}
// GetWorkflowUsageByID gets a specific workflow usage by ID in the unit of billable milliseconds.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#get-workflow-usage
func (s *ActionsService) GetWorkflowUsageByID(ctx context.Context, owner, repo string, workflowID int64) (*WorkflowUsage, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/timing", owner, repo, workflowID)
return s.getWorkflowUsage(ctx, u)
}
// GetWorkflowUsageByFileName gets a specific workflow usage by file name in the unit of billable milliseconds.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#get-workflow-usage
func (s *ActionsService) GetWorkflowUsageByFileName(ctx context.Context, owner, repo, workflowFileName string) (*WorkflowUsage, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/timing", owner, repo, workflowFileName)
return s.getWorkflowUsage(ctx, u)
}
func (s *ActionsService) getWorkflowUsage(ctx context.Context, url string) (*WorkflowUsage, *Response, error) {
req, err := s.client.NewRequest("GET", url, nil)
if err != nil {
return nil, nil, err
}
workflowUsage := new(WorkflowUsage)
resp, err := s.client.Do(ctx, req, workflowUsage)
if err != nil {
return nil, resp, err
}
return workflowUsage, resp, nil
}
// CreateWorkflowDispatchEventByID manually triggers a GitHub Actions workflow run.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#create-a-workflow-dispatch-event
func (s *ActionsService) CreateWorkflowDispatchEventByID(ctx context.Context, owner, repo string, workflowID int64, event CreateWorkflowDispatchEventRequest) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/dispatches", owner, repo, workflowID)
return s.createWorkflowDispatchEvent(ctx, u, &event)
}
// CreateWorkflowDispatchEventByFileName manually triggers a GitHub Actions workflow run.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#create-a-workflow-dispatch-event
func (s *ActionsService) CreateWorkflowDispatchEventByFileName(ctx context.Context, owner, repo, workflowFileName string, event CreateWorkflowDispatchEventRequest) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/dispatches", owner, repo, workflowFileName)
return s.createWorkflowDispatchEvent(ctx, u, &event)
}
func (s *ActionsService) createWorkflowDispatchEvent(ctx context.Context, url string, event *CreateWorkflowDispatchEventRequest) (*Response, error) {
req, err := s.client.NewRequest("POST", url, event)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// EnableWorkflowByID enables a workflow and sets the state of the workflow to "active".
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#enable-a-workflow
func (s *ActionsService) EnableWorkflowByID(ctx context.Context, owner, repo string, workflowID int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/enable", owner, repo, workflowID)
return s.doNewPutRequest(ctx, u)
}
// EnableWorkflowByFileName enables a workflow and sets the state of the workflow to "active".
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#enable-a-workflow
func (s *ActionsService) EnableWorkflowByFileName(ctx context.Context, owner, repo, workflowFileName string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/enable", owner, repo, workflowFileName)
return s.doNewPutRequest(ctx, u)
}
// DisableWorkflowByID disables a workflow and sets the state of the workflow to "disabled_manually".
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#disable-a-workflow
func (s *ActionsService) DisableWorkflowByID(ctx context.Context, owner, repo string, workflowID int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/disable", owner, repo, workflowID)
return s.doNewPutRequest(ctx, u)
}
// DisableWorkflowByFileName disables a workflow and sets the state of the workflow to "disabled_manually".
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#disable-a-workflow
func (s *ActionsService) DisableWorkflowByFileName(ctx context.Context, owner, repo, workflowFileName string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/disable", owner, repo, workflowFileName)
return s.doNewPutRequest(ctx, u)
}
func (s *ActionsService) doNewPutRequest(ctx context.Context, url string) (*Response, error) {
req, err := s.client.NewRequest("PUT", url, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}

View file

@ -10,7 +10,7 @@ import "context"
// ActivityService handles communication with the activity related // ActivityService handles communication with the activity related
// methods of the GitHub API. // methods of the GitHub API.
// //
// GitHub API docs: https://developer.github.com/v3/activity/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/
type ActivityService service type ActivityService service
// FeedLink represents a link to a related resource. // FeedLink represents a link to a related resource.
@ -21,22 +21,25 @@ type FeedLink struct {
// Feeds represents timeline resources in Atom format. // Feeds represents timeline resources in Atom format.
type Feeds struct { type Feeds struct {
TimelineURL *string `json:"timeline_url,omitempty"` TimelineURL *string `json:"timeline_url,omitempty"`
UserURL *string `json:"user_url,omitempty"` UserURL *string `json:"user_url,omitempty"`
CurrentUserPublicURL *string `json:"current_user_public_url,omitempty"` CurrentUserPublicURL *string `json:"current_user_public_url,omitempty"`
CurrentUserURL *string `json:"current_user_url,omitempty"` CurrentUserURL *string `json:"current_user_url,omitempty"`
CurrentUserActorURL *string `json:"current_user_actor_url,omitempty"` CurrentUserActorURL *string `json:"current_user_actor_url,omitempty"`
CurrentUserOrganizationURL *string `json:"current_user_organization_url,omitempty"` CurrentUserOrganizationURL *string `json:"current_user_organization_url,omitempty"`
CurrentUserOrganizationURLs []string `json:"current_user_organization_urls,omitempty"` CurrentUserOrganizationURLs []string `json:"current_user_organization_urls,omitempty"`
Links *struct { Links *FeedLinks `json:"_links,omitempty"`
Timeline *FeedLink `json:"timeline,omitempty"` }
User *FeedLink `json:"user,omitempty"`
CurrentUserPublic *FeedLink `json:"current_user_public,omitempty"` // FeedLinks represents the links in a Feed.
CurrentUser *FeedLink `json:"current_user,omitempty"` type FeedLinks struct {
CurrentUserActor *FeedLink `json:"current_user_actor,omitempty"` Timeline *FeedLink `json:"timeline,omitempty"`
CurrentUserOrganization *FeedLink `json:"current_user_organization,omitempty"` User *FeedLink `json:"user,omitempty"`
CurrentUserOrganizations []*FeedLink `json:"current_user_organizations,omitempty"` CurrentUserPublic *FeedLink `json:"current_user_public,omitempty"`
} `json:"_links,omitempty"` CurrentUser *FeedLink `json:"current_user,omitempty"`
CurrentUserActor *FeedLink `json:"current_user_actor,omitempty"`
CurrentUserOrganization *FeedLink `json:"current_user_organization,omitempty"`
CurrentUserOrganizations []*FeedLink `json:"current_user_organizations,omitempty"`
} }
// ListFeeds lists all the feeds available to the authenticated user. // ListFeeds lists all the feeds available to the authenticated user.

View file

@ -12,7 +12,7 @@ import (
// ListEvents drinks from the firehose of all public events across GitHub. // ListEvents drinks from the firehose of all public events across GitHub.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-public-events // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#list-public-events
func (s *ActivityService) ListEvents(ctx context.Context, opts *ListOptions) ([]*Event, *Response, error) { func (s *ActivityService) ListEvents(ctx context.Context, opts *ListOptions) ([]*Event, *Response, error) {
u, err := addOptions("events", opts) u, err := addOptions("events", opts)
if err != nil { if err != nil {
@ -35,7 +35,7 @@ func (s *ActivityService) ListEvents(ctx context.Context, opts *ListOptions) ([]
// ListRepositoryEvents lists events for a repository. // ListRepositoryEvents lists events for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-repository-events // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#list-repository-events
func (s *ActivityService) ListRepositoryEvents(ctx context.Context, owner, repo string, opts *ListOptions) ([]*Event, *Response, error) { func (s *ActivityService) ListRepositoryEvents(ctx context.Context, owner, repo string, opts *ListOptions) ([]*Event, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/events", owner, repo) u := fmt.Sprintf("repos/%v/%v/events", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -59,7 +59,7 @@ func (s *ActivityService) ListRepositoryEvents(ctx context.Context, owner, repo
// ListIssueEventsForRepository lists issue events for a repository. // ListIssueEventsForRepository lists issue events for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/issues/events/#list-issue-events-for-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#list-issue-events-for-a-repository
func (s *ActivityService) ListIssueEventsForRepository(ctx context.Context, owner, repo string, opts *ListOptions) ([]*IssueEvent, *Response, error) { func (s *ActivityService) ListIssueEventsForRepository(ctx context.Context, owner, repo string, opts *ListOptions) ([]*IssueEvent, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/events", owner, repo) u := fmt.Sprintf("repos/%v/%v/issues/events", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -83,7 +83,7 @@ func (s *ActivityService) ListIssueEventsForRepository(ctx context.Context, owne
// ListEventsForRepoNetwork lists public events for a network of repositories. // ListEventsForRepoNetwork lists public events for a network of repositories.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-public-events-for-a-network-of-repositories // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#list-public-events-for-a-network-of-repositories
func (s *ActivityService) ListEventsForRepoNetwork(ctx context.Context, owner, repo string, opts *ListOptions) ([]*Event, *Response, error) { func (s *ActivityService) ListEventsForRepoNetwork(ctx context.Context, owner, repo string, opts *ListOptions) ([]*Event, *Response, error) {
u := fmt.Sprintf("networks/%v/%v/events", owner, repo) u := fmt.Sprintf("networks/%v/%v/events", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -107,7 +107,7 @@ func (s *ActivityService) ListEventsForRepoNetwork(ctx context.Context, owner, r
// ListEventsForOrganization lists public events for an organization. // ListEventsForOrganization lists public events for an organization.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-public-organization-events // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#list-public-organization-events
func (s *ActivityService) ListEventsForOrganization(ctx context.Context, org string, opts *ListOptions) ([]*Event, *Response, error) { func (s *ActivityService) ListEventsForOrganization(ctx context.Context, org string, opts *ListOptions) ([]*Event, *Response, error) {
u := fmt.Sprintf("orgs/%v/events", org) u := fmt.Sprintf("orgs/%v/events", org)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -132,8 +132,8 @@ func (s *ActivityService) ListEventsForOrganization(ctx context.Context, org str
// ListEventsPerformedByUser lists the events performed by a user. If publicOnly is // ListEventsPerformedByUser lists the events performed by a user. If publicOnly is
// true, only public events will be returned. // true, only public events will be returned.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-events-for-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#list-events-for-the-authenticated-user
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-public-events-for-a-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#list-public-events-for-a-user
func (s *ActivityService) ListEventsPerformedByUser(ctx context.Context, user string, publicOnly bool, opts *ListOptions) ([]*Event, *Response, error) { func (s *ActivityService) ListEventsPerformedByUser(ctx context.Context, user string, publicOnly bool, opts *ListOptions) ([]*Event, *Response, error) {
var u string var u string
if publicOnly { if publicOnly {
@ -163,8 +163,8 @@ func (s *ActivityService) ListEventsPerformedByUser(ctx context.Context, user st
// ListEventsReceivedByUser lists the events received by a user. If publicOnly is // ListEventsReceivedByUser lists the events received by a user. If publicOnly is
// true, only public events will be returned. // true, only public events will be returned.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-events-received-by-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#list-events-received-by-the-authenticated-user
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-public-events-received-by-a-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#list-public-events-received-by-a-user
func (s *ActivityService) ListEventsReceivedByUser(ctx context.Context, user string, publicOnly bool, opts *ListOptions) ([]*Event, *Response, error) { func (s *ActivityService) ListEventsReceivedByUser(ctx context.Context, user string, publicOnly bool, opts *ListOptions) ([]*Event, *Response, error) {
var u string var u string
if publicOnly { if publicOnly {
@ -194,7 +194,7 @@ func (s *ActivityService) ListEventsReceivedByUser(ctx context.Context, user str
// ListUserEventsForOrganization provides the users organization dashboard. You // ListUserEventsForOrganization provides the users organization dashboard. You
// must be authenticated as the user to view this. // must be authenticated as the user to view this.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-organization-events-for-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#list-organization-events-for-the-authenticated-user
func (s *ActivityService) ListUserEventsForOrganization(ctx context.Context, org, user string, opts *ListOptions) ([]*Event, *Response, error) { func (s *ActivityService) ListUserEventsForOrganization(ctx context.Context, org, user string, opts *ListOptions) ([]*Event, *Response, error) {
u := fmt.Sprintf("users/%v/events/orgs/%v", user, org) u := fmt.Sprintf("users/%v/events/orgs/%v", user, org)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)

View file

@ -19,7 +19,7 @@ type Notification struct {
// Reason identifies the event that triggered the notification. // Reason identifies the event that triggered the notification.
// //
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#notification-reasons // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity#notification-reasons
Reason *string `json:"reason,omitempty"` Reason *string `json:"reason,omitempty"`
Unread *bool `json:"unread,omitempty"` Unread *bool `json:"unread,omitempty"`
@ -49,7 +49,7 @@ type NotificationListOptions struct {
// ListNotifications lists all notifications for the authenticated user. // ListNotifications lists all notifications for the authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#list-notifications-for-the-authenticated-user // 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) { func (s *ActivityService) ListNotifications(ctx context.Context, opts *NotificationListOptions) ([]*Notification, *Response, error) {
u := fmt.Sprintf("notifications") u := fmt.Sprintf("notifications")
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -74,7 +74,7 @@ func (s *ActivityService) ListNotifications(ctx context.Context, opts *Notificat
// ListRepositoryNotifications lists all notifications in a given repository // ListRepositoryNotifications lists all notifications in a given repository
// for the authenticated user. // for the authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#list-repository-notifications-for-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#list-repository-notifications-for-the-authenticated-user
func (s *ActivityService) ListRepositoryNotifications(ctx context.Context, owner, repo string, opts *NotificationListOptions) ([]*Notification, *Response, error) { func (s *ActivityService) ListRepositoryNotifications(ctx context.Context, owner, repo string, opts *NotificationListOptions) ([]*Notification, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/notifications", owner, repo) u := fmt.Sprintf("repos/%v/%v/notifications", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -102,7 +102,7 @@ type markReadOptions struct {
// MarkNotificationsRead marks all notifications up to lastRead as read. // MarkNotificationsRead marks all notifications up to lastRead as read.
// //
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#mark-as-read // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity#mark-as-read
func (s *ActivityService) MarkNotificationsRead(ctx context.Context, lastRead time.Time) (*Response, error) { func (s *ActivityService) MarkNotificationsRead(ctx context.Context, lastRead time.Time) (*Response, error) {
opts := &markReadOptions{ opts := &markReadOptions{
LastReadAt: lastRead, LastReadAt: lastRead,
@ -118,7 +118,7 @@ func (s *ActivityService) MarkNotificationsRead(ctx context.Context, lastRead ti
// MarkRepositoryNotificationsRead marks all notifications up to lastRead in // MarkRepositoryNotificationsRead marks all notifications up to lastRead in
// the specified repository as read. // the specified repository as read.
// //
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#mark-repository-notifications-as-read // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#mark-repository-notifications-as-read
func (s *ActivityService) MarkRepositoryNotificationsRead(ctx context.Context, owner, repo string, lastRead time.Time) (*Response, error) { func (s *ActivityService) MarkRepositoryNotificationsRead(ctx context.Context, owner, repo string, lastRead time.Time) (*Response, error) {
opts := &markReadOptions{ opts := &markReadOptions{
LastReadAt: lastRead, LastReadAt: lastRead,
@ -134,7 +134,7 @@ func (s *ActivityService) MarkRepositoryNotificationsRead(ctx context.Context, o
// GetThread gets the specified notification thread. // GetThread gets the specified notification thread.
// //
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#get-a-thread // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#get-a-thread
func (s *ActivityService) GetThread(ctx context.Context, id string) (*Notification, *Response, error) { func (s *ActivityService) GetThread(ctx context.Context, id string) (*Notification, *Response, error) {
u := fmt.Sprintf("notifications/threads/%v", id) u := fmt.Sprintf("notifications/threads/%v", id)
@ -154,7 +154,7 @@ func (s *ActivityService) GetThread(ctx context.Context, id string) (*Notificati
// MarkThreadRead marks the specified thread as read. // MarkThreadRead marks the specified thread as read.
// //
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#mark-a-thread-as-read
func (s *ActivityService) MarkThreadRead(ctx context.Context, id string) (*Response, error) { func (s *ActivityService) MarkThreadRead(ctx context.Context, id string) (*Response, error) {
u := fmt.Sprintf("notifications/threads/%v", id) u := fmt.Sprintf("notifications/threads/%v", id)
@ -169,7 +169,7 @@ func (s *ActivityService) MarkThreadRead(ctx context.Context, id string) (*Respo
// GetThreadSubscription checks to see if the authenticated user is subscribed // GetThreadSubscription checks to see if the authenticated user is subscribed
// to a thread. // to a thread.
// //
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#get-a-thread-subscription-for-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#get-a-thread-subscription-for-the-authenticated-user
func (s *ActivityService) GetThreadSubscription(ctx context.Context, id string) (*Subscription, *Response, error) { func (s *ActivityService) GetThreadSubscription(ctx context.Context, id string) (*Subscription, *Response, error) {
u := fmt.Sprintf("notifications/threads/%v/subscription", id) u := fmt.Sprintf("notifications/threads/%v/subscription", id)
@ -190,7 +190,7 @@ func (s *ActivityService) GetThreadSubscription(ctx context.Context, id string)
// SetThreadSubscription sets the subscription for the specified thread for the // SetThreadSubscription sets the subscription for the specified thread for the
// authenticated user. // authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#set-a-thread-subscription // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#set-a-thread-subscription
func (s *ActivityService) SetThreadSubscription(ctx context.Context, id string, subscription *Subscription) (*Subscription, *Response, error) { func (s *ActivityService) SetThreadSubscription(ctx context.Context, id string, subscription *Subscription) (*Subscription, *Response, error) {
u := fmt.Sprintf("notifications/threads/%v/subscription", id) u := fmt.Sprintf("notifications/threads/%v/subscription", id)
@ -211,7 +211,7 @@ func (s *ActivityService) SetThreadSubscription(ctx context.Context, id string,
// DeleteThreadSubscription deletes the subscription for the specified thread // DeleteThreadSubscription deletes the subscription for the specified thread
// for the authenticated user. // for the authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#delete-a-thread-subscription // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#delete-a-thread-subscription
func (s *ActivityService) DeleteThreadSubscription(ctx context.Context, id string) (*Response, error) { func (s *ActivityService) DeleteThreadSubscription(ctx context.Context, id string) (*Response, error) {
u := fmt.Sprintf("notifications/threads/%v/subscription", id) u := fmt.Sprintf("notifications/threads/%v/subscription", id)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)

View file

@ -25,7 +25,7 @@ type Stargazer struct {
// ListStargazers lists people who have starred the specified repo. // ListStargazers lists people who have starred the specified repo.
// //
// GitHub API docs: https://developer.github.com/v3/activity/starring/#list-stargazers // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#list-stargazers
func (s *ActivityService) ListStargazers(ctx context.Context, owner, repo string, opts *ListOptions) ([]*Stargazer, *Response, error) { func (s *ActivityService) ListStargazers(ctx context.Context, owner, repo string, opts *ListOptions) ([]*Stargazer, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/stargazers", owner, repo) u := fmt.Sprintf("repos/%s/%s/stargazers", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -67,8 +67,8 @@ type ActivityListStarredOptions struct {
// ListStarred lists all the repos starred by a user. Passing the empty string // ListStarred lists all the repos starred by a user. Passing the empty string
// will list the starred repositories for the authenticated user. // will list the starred repositories for the authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/activity/starring/#list-repositories-starred-by-a-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#list-repositories-starred-by-the-authenticated-user
// GitHub API docs: https://developer.github.com/v3/activity/starring/#list-repositories-starred-by-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#list-repositories-starred-by-a-user
func (s *ActivityService) ListStarred(ctx context.Context, user string, opts *ActivityListStarredOptions) ([]*StarredRepository, *Response, error) { func (s *ActivityService) ListStarred(ctx context.Context, user string, opts *ActivityListStarredOptions) ([]*StarredRepository, *Response, error) {
var u string var u string
if user != "" { if user != "" {
@ -101,7 +101,7 @@ func (s *ActivityService) ListStarred(ctx context.Context, user string, opts *Ac
// IsStarred checks if a repository is starred by authenticated user. // IsStarred checks if a repository is starred by authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/activity/starring/#check-if-a-repository-is-starred-by-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#check-if-a-repository-is-starred-by-the-authenticated-user
func (s *ActivityService) IsStarred(ctx context.Context, owner, repo string) (bool, *Response, error) { func (s *ActivityService) IsStarred(ctx context.Context, owner, repo string) (bool, *Response, error) {
u := fmt.Sprintf("user/starred/%v/%v", owner, repo) u := fmt.Sprintf("user/starred/%v/%v", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -115,7 +115,7 @@ func (s *ActivityService) IsStarred(ctx context.Context, owner, repo string) (bo
// Star a repository as the authenticated user. // Star a repository as the authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/activity/starring/#star-a-repository-for-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#star-a-repository-for-the-authenticated-user
func (s *ActivityService) Star(ctx context.Context, owner, repo string) (*Response, error) { func (s *ActivityService) Star(ctx context.Context, owner, repo string) (*Response, error) {
u := fmt.Sprintf("user/starred/%v/%v", owner, repo) u := fmt.Sprintf("user/starred/%v/%v", owner, repo)
req, err := s.client.NewRequest("PUT", u, nil) req, err := s.client.NewRequest("PUT", u, nil)
@ -127,7 +127,7 @@ func (s *ActivityService) Star(ctx context.Context, owner, repo string) (*Respon
// Unstar a repository as the authenticated user. // Unstar a repository as the authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/activity/starring/#unstar-a-repository-for-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#unstar-a-repository-for-the-authenticated-user
func (s *ActivityService) Unstar(ctx context.Context, owner, repo string) (*Response, error) { func (s *ActivityService) Unstar(ctx context.Context, owner, repo string) (*Response, error) {
u := fmt.Sprintf("user/starred/%v/%v", owner, repo) u := fmt.Sprintf("user/starred/%v/%v", owner, repo)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)

View file

@ -27,7 +27,7 @@ type Subscription struct {
// ListWatchers lists watchers of a particular repo. // ListWatchers lists watchers of a particular repo.
// //
// GitHub API docs: https://developer.github.com/v3/activity/watching/#list-watchers // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#list-watchers
func (s *ActivityService) ListWatchers(ctx context.Context, owner, repo string, opts *ListOptions) ([]*User, *Response, error) { func (s *ActivityService) ListWatchers(ctx context.Context, owner, repo string, opts *ListOptions) ([]*User, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/subscribers", owner, repo) u := fmt.Sprintf("repos/%s/%s/subscribers", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -52,8 +52,8 @@ func (s *ActivityService) ListWatchers(ctx context.Context, owner, repo string,
// ListWatched lists the repositories the specified user is watching. Passing // ListWatched lists the repositories the specified user is watching. Passing
// the empty string will fetch watched repos for the authenticated user. // the empty string will fetch watched repos for the authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/activity/watching/#list-repositories-watched-by-a-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#list-repositories-watched-by-the-authenticated-user
// GitHub API docs: https://developer.github.com/v3/activity/watching/#list-repositories-watched-by-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#list-repositories-watched-by-a-user
func (s *ActivityService) ListWatched(ctx context.Context, user string, opts *ListOptions) ([]*Repository, *Response, error) { func (s *ActivityService) ListWatched(ctx context.Context, user string, opts *ListOptions) ([]*Repository, *Response, error) {
var u string var u string
if user != "" { if user != "" {
@ -84,7 +84,7 @@ func (s *ActivityService) ListWatched(ctx context.Context, user string, opts *Li
// repository for the authenticated user. If the authenticated user is not // repository for the authenticated user. If the authenticated user is not
// watching the repository, a nil Subscription is returned. // watching the repository, a nil Subscription is returned.
// //
// GitHub API docs: https://developer.github.com/v3/activity/watching/#get-a-repository-subscription // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#get-a-repository-subscription
func (s *ActivityService) GetRepositorySubscription(ctx context.Context, owner, repo string) (*Subscription, *Response, error) { func (s *ActivityService) GetRepositorySubscription(ctx context.Context, owner, repo string) (*Subscription, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo) u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo)
@ -111,7 +111,7 @@ func (s *ActivityService) GetRepositorySubscription(ctx context.Context, owner,
// To ignore notifications made within a repository, set subscription.Ignored to true. // To ignore notifications made within a repository, set subscription.Ignored to true.
// To stop watching a repository, use DeleteRepositorySubscription. // To stop watching a repository, use DeleteRepositorySubscription.
// //
// GitHub API docs: https://developer.github.com/v3/activity/watching/#set-a-repository-subscription // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#set-a-repository-subscription
func (s *ActivityService) SetRepositorySubscription(ctx context.Context, owner, repo string, subscription *Subscription) (*Subscription, *Response, error) { func (s *ActivityService) SetRepositorySubscription(ctx context.Context, owner, repo string, subscription *Subscription) (*Subscription, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo) u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo)
@ -135,7 +135,7 @@ func (s *ActivityService) SetRepositorySubscription(ctx context.Context, owner,
// This is used to stop watching a repository. To control whether or not to // This is used to stop watching a repository. To control whether or not to
// receive notifications from a repository, use SetRepositorySubscription. // receive notifications from a repository, use SetRepositorySubscription.
// //
// GitHub API docs: https://developer.github.com/v3/activity/watching/#delete-a-repository-subscription // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/activity/#delete-a-repository-subscription
func (s *ActivityService) DeleteRepositorySubscription(ctx context.Context, owner, repo string) (*Response, error) { func (s *ActivityService) DeleteRepositorySubscription(ctx context.Context, owner, repo string) (*Response, error) {
u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo) u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)

View file

@ -14,7 +14,7 @@ import (
// GitHub API. These API routes are normally only accessible for GitHub // GitHub API. These API routes are normally only accessible for GitHub
// Enterprise installations. // Enterprise installations.
// //
// GitHub API docs: https://developer.github.com/v3/enterprise/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/enterprise/
type AdminService service type AdminService service
// TeamLDAPMapping represents the mapping between a GitHub team and an LDAP group. // TeamLDAPMapping represents the mapping between a GitHub team and an LDAP group.
@ -82,7 +82,7 @@ func (m Enterprise) String() string {
// UpdateUserLDAPMapping updates the mapping between a GitHub user and an LDAP user. // UpdateUserLDAPMapping updates the mapping between a GitHub user and an LDAP user.
// //
// GitHub API docs: https://developer.github.com/v3/enterprise/ldap/#update-ldap-mapping-for-a-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/enterprise/ldap/#update-ldap-mapping-for-a-user
func (s *AdminService) UpdateUserLDAPMapping(ctx context.Context, user string, mapping *UserLDAPMapping) (*UserLDAPMapping, *Response, error) { func (s *AdminService) UpdateUserLDAPMapping(ctx context.Context, user string, mapping *UserLDAPMapping) (*UserLDAPMapping, *Response, error) {
u := fmt.Sprintf("admin/ldap/users/%v/mapping", user) u := fmt.Sprintf("admin/ldap/users/%v/mapping", user)
req, err := s.client.NewRequest("PATCH", u, mapping) req, err := s.client.NewRequest("PATCH", u, mapping)
@ -101,7 +101,7 @@ func (s *AdminService) UpdateUserLDAPMapping(ctx context.Context, user string, m
// UpdateTeamLDAPMapping updates the mapping between a GitHub team and an LDAP group. // UpdateTeamLDAPMapping updates the mapping between a GitHub team and an LDAP group.
// //
// GitHub API docs: https://developer.github.com/v3/enterprise/ldap/#update-ldap-mapping-for-a-team // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/enterprise/ldap/#update-ldap-mapping-for-a-team
func (s *AdminService) UpdateTeamLDAPMapping(ctx context.Context, team int64, mapping *TeamLDAPMapping) (*TeamLDAPMapping, *Response, error) { func (s *AdminService) UpdateTeamLDAPMapping(ctx context.Context, team int64, mapping *TeamLDAPMapping) (*TeamLDAPMapping, *Response, error) {
u := fmt.Sprintf("admin/ldap/teams/%v/mapping", team) u := fmt.Sprintf("admin/ldap/teams/%v/mapping", team)
req, err := s.client.NewRequest("PATCH", u, mapping) req, err := s.client.NewRequest("PATCH", u, mapping)

View file

@ -153,7 +153,7 @@ func (s RepoStats) String() string {
// Please note that this is only available to site administrators, // Please note that this is only available to site administrators,
// otherwise it will error with a 404 not found (instead of 401 or 403). // otherwise it will error with a 404 not found (instead of 401 or 403).
// //
// GitHub API docs: https://developer.github.com/v3/enterprise-admin/admin_stats/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/enterprise-admin/admin_stats/
func (s *AdminService) GetAdminStats(ctx context.Context) (*AdminStats, *Response, error) { func (s *AdminService) GetAdminStats(ctx context.Context) (*AdminStats, *Response, error) {
u := fmt.Sprintf("enterprise/stats/all") u := fmt.Sprintf("enterprise/stats/all")
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)

View file

@ -14,7 +14,7 @@ import (
// AppsService provides access to the installation related functions // AppsService provides access to the installation related functions
// in the GitHub API. // in the GitHub API.
// //
// GitHub API docs: https://developer.github.com/v3/apps/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/
type AppsService service type AppsService service
// App represents a GitHub App. // App represents a GitHub App.
@ -55,54 +55,68 @@ type InstallationTokenOptions struct {
// InstallationPermissions lists the repository and organization permissions for an installation. // InstallationPermissions lists the repository and organization permissions for an installation.
// //
// Permission names taken from: // Permission names taken from:
// https://developer.github.com/v3/apps/permissions/ // https://docs.github.com/en/enterprise-server@3.0/rest/reference/apps#create-an-installation-access-token-for-an-app
// https://developer.github.com/enterprise/v3/apps/permissions/ // https://docs.github.com/en/rest/reference/apps#create-an-installation-access-token-for-an-app
type InstallationPermissions struct { type InstallationPermissions struct {
Administration *string `json:"administration,omitempty"` Actions *string `json:"actions,omitempty"`
Blocking *string `json:"blocking,omitempty"` Administration *string `json:"administration,omitempty"`
Checks *string `json:"checks,omitempty"` Blocking *string `json:"blocking,omitempty"`
Contents *string `json:"contents,omitempty"` Checks *string `json:"checks,omitempty"`
ContentReferences *string `json:"content_references,omitempty"` Contents *string `json:"contents,omitempty"`
Deployments *string `json:"deployments,omitempty"` ContentReferences *string `json:"content_references,omitempty"`
Emails *string `json:"emails,omitempty"` Deployments *string `json:"deployments,omitempty"`
Followers *string `json:"followers,omitempty"` Emails *string `json:"emails,omitempty"`
Issues *string `json:"issues,omitempty"` Environments *string `json:"environments,omitempty"`
Metadata *string `json:"metadata,omitempty"` Followers *string `json:"followers,omitempty"`
Members *string `json:"members,omitempty"` Issues *string `json:"issues,omitempty"`
OrganizationAdministration *string `json:"organization_administration,omitempty"` Metadata *string `json:"metadata,omitempty"`
OrganizationHooks *string `json:"organization_hooks,omitempty"` Members *string `json:"members,omitempty"`
OrganizationPlan *string `json:"organization_plan,omitempty"` OrganizationAdministration *string `json:"organization_administration,omitempty"`
OrganizationPreReceiveHooks *string `json:"organization_pre_receive_hooks,omitempty"` OrganizationHooks *string `json:"organization_hooks,omitempty"`
OrganizationProjects *string `json:"organization_projects,omitempty"` OrganizationPlan *string `json:"organization_plan,omitempty"`
OrganizationUserBlocking *string `json:"organization_user_blocking,omitempty"` OrganizationPreReceiveHooks *string `json:"organization_pre_receive_hooks,omitempty"`
Packages *string `json:"packages,omitempty"` OrganizationProjects *string `json:"organization_projects,omitempty"`
Pages *string `json:"pages,omitempty"` OrganizationSecrets *string `json:"organization_secrets,omitempty"`
PullRequests *string `json:"pull_requests,omitempty"` OrganizationSelfHostedRunners *string `json:"organization_self_hosted_runners,omitempty"`
RepositoryHooks *string `json:"repository_hooks,omitempty"` OrganizationUserBlocking *string `json:"organization_user_blocking,omitempty"`
RepositoryProjects *string `json:"repository_projects,omitempty"` Packages *string `json:"packages,omitempty"`
RepositoryPreReceiveHooks *string `json:"repository_pre_receive_hooks,omitempty"` Pages *string `json:"pages,omitempty"`
SingleFile *string `json:"single_file,omitempty"` PullRequests *string `json:"pull_requests,omitempty"`
Statuses *string `json:"statuses,omitempty"` RepositoryHooks *string `json:"repository_hooks,omitempty"`
TeamDiscussions *string `json:"team_discussions,omitempty"` RepositoryProjects *string `json:"repository_projects,omitempty"`
VulnerabilityAlerts *string `json:"vulnerability_alerts,omitempty"` RepositoryPreReceiveHooks *string `json:"repository_pre_receive_hooks,omitempty"`
Secrets *string `json:"secrets,omitempty"`
SecretScanningAlerts *string `json:"secret_scanning_alerts,omitempty"`
SecurityEvents *string `json:"security_events,omitempty"`
SingleFile *string `json:"single_file,omitempty"`
Statuses *string `json:"statuses,omitempty"`
TeamDiscussions *string `json:"team_discussions,omitempty"`
VulnerabilityAlerts *string `json:"vulnerability_alerts,omitempty"`
Workflows *string `json:"workflows,omitempty"`
} }
// Installation represents a GitHub Apps installation. // Installation represents a GitHub Apps installation.
type Installation struct { type Installation struct {
ID *int64 `json:"id,omitempty"` ID *int64 `json:"id,omitempty"`
AppID *int64 `json:"app_id,omitempty"` NodeID *string `json:"node_id,omitempty"`
TargetID *int64 `json:"target_id,omitempty"` AppID *int64 `json:"app_id,omitempty"`
Account *User `json:"account,omitempty"` AppSlug *string `json:"app_slug,omitempty"`
AccessTokensURL *string `json:"access_tokens_url,omitempty"` TargetID *int64 `json:"target_id,omitempty"`
RepositoriesURL *string `json:"repositories_url,omitempty"` Account *User `json:"account,omitempty"`
HTMLURL *string `json:"html_url,omitempty"` AccessTokensURL *string `json:"access_tokens_url,omitempty"`
TargetType *string `json:"target_type,omitempty"` RepositoriesURL *string `json:"repositories_url,omitempty"`
SingleFileName *string `json:"single_file_name,omitempty"` HTMLURL *string `json:"html_url,omitempty"`
RepositorySelection *string `json:"repository_selection,omitempty"` TargetType *string `json:"target_type,omitempty"`
Events []string `json:"events,omitempty"` SingleFileName *string `json:"single_file_name,omitempty"`
Permissions *InstallationPermissions `json:"permissions,omitempty"` RepositorySelection *string `json:"repository_selection,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"` Events []string `json:"events,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"` SingleFilePaths []string `json:"single_file_paths,omitempty"`
Permissions *InstallationPermissions `json:"permissions,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
HasMultipleSingleFiles *bool `json:"has_multiple_single_files,omitempty"`
SuspendedBy *User `json:"suspended_by,omitempty"`
SuspendedAt *Timestamp `json:"suspended_at,omitempty"`
} }
// Attachment represents a GitHub Apps attachment. // Attachment represents a GitHub Apps attachment.
@ -112,6 +126,13 @@ type Attachment struct {
Body *string `json:"body,omitempty"` Body *string `json:"body,omitempty"`
} }
// ContentReference represents a reference to a URL in an issue or pull request.
type ContentReference struct {
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
Reference *string `json:"reference,omitempty"`
}
func (i Installation) String() string { func (i Installation) String() string {
return Stringify(i) return Stringify(i)
} }
@ -123,8 +144,8 @@ func (i Installation) String() string {
// You can find this on the settings page for your GitHub App // You can find this on the settings page for your GitHub App
// (e.g., https://github.com/settings/apps/:app_slug). // (e.g., https://github.com/settings/apps/:app_slug).
// //
// GitHub API docs: https://developer.github.com/v3/apps/#get-the-authenticated-app // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#get-the-authenticated-app
// GitHub API docs: https://developer.github.com/v3/apps/#get-an-app // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#get-an-app
func (s *AppsService) Get(ctx context.Context, appSlug string) (*App, *Response, error) { func (s *AppsService) Get(ctx context.Context, appSlug string) (*App, *Response, error) {
var u string var u string
if appSlug != "" { if appSlug != "" {
@ -138,9 +159,6 @@ func (s *AppsService) Get(ctx context.Context, appSlug string) (*App, *Response,
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeIntegrationPreview)
app := new(App) app := new(App)
resp, err := s.client.Do(ctx, req, app) resp, err := s.client.Do(ctx, req, app)
if err != nil { if err != nil {
@ -152,7 +170,7 @@ func (s *AppsService) Get(ctx context.Context, appSlug string) (*App, *Response,
// ListInstallations lists the installations that the current GitHub App has. // ListInstallations lists the installations that the current GitHub App has.
// //
// GitHub API docs: https://developer.github.com/v3/apps/#list-installations-for-the-authenticated-app // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#list-installations-for-the-authenticated-app
func (s *AppsService) ListInstallations(ctx context.Context, opts *ListOptions) ([]*Installation, *Response, error) { func (s *AppsService) ListInstallations(ctx context.Context, opts *ListOptions) ([]*Installation, *Response, error) {
u, err := addOptions("app/installations", opts) u, err := addOptions("app/installations", opts)
if err != nil { if err != nil {
@ -164,9 +182,6 @@ func (s *AppsService) ListInstallations(ctx context.Context, opts *ListOptions)
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeIntegrationPreview)
var i []*Installation var i []*Installation
resp, err := s.client.Do(ctx, req, &i) resp, err := s.client.Do(ctx, req, &i)
if err != nil { if err != nil {
@ -178,14 +193,14 @@ func (s *AppsService) ListInstallations(ctx context.Context, opts *ListOptions)
// GetInstallation returns the specified installation. // GetInstallation returns the specified installation.
// //
// GitHub API docs: https://developer.github.com/v3/apps/#get-an-installation-for-the-authenticated-app // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#get-an-installation-for-the-authenticated-app
func (s *AppsService) GetInstallation(ctx context.Context, id int64) (*Installation, *Response, error) { func (s *AppsService) GetInstallation(ctx context.Context, id int64) (*Installation, *Response, error) {
return s.getInstallation(ctx, fmt.Sprintf("app/installations/%v", id)) return s.getInstallation(ctx, fmt.Sprintf("app/installations/%v", id))
} }
// ListUserInstallations lists installations that are accessible to the authenticated user. // ListUserInstallations lists installations that are accessible to the authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/apps/installations/#list-app-installations-accessible-to-the-user-access-token // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#list-app-installations-accessible-to-the-user-access-token
func (s *AppsService) ListUserInstallations(ctx context.Context, opts *ListOptions) ([]*Installation, *Response, error) { func (s *AppsService) ListUserInstallations(ctx context.Context, opts *ListOptions) ([]*Installation, *Response, error) {
u, err := addOptions("user/installations", opts) u, err := addOptions("user/installations", opts)
if err != nil { if err != nil {
@ -197,9 +212,6 @@ func (s *AppsService) ListUserInstallations(ctx context.Context, opts *ListOptio
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeIntegrationPreview)
var i struct { var i struct {
Installations []*Installation `json:"installations"` Installations []*Installation `json:"installations"`
} }
@ -213,7 +225,7 @@ func (s *AppsService) ListUserInstallations(ctx context.Context, opts *ListOptio
// SuspendInstallation suspends the specified installation. // SuspendInstallation suspends the specified installation.
// //
// GitHub API docs: https://developer.github.com/v3/apps/#suspend-an-app-installation // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#suspend-an-app-installation
func (s *AppsService) SuspendInstallation(ctx context.Context, id int64) (*Response, error) { func (s *AppsService) SuspendInstallation(ctx context.Context, id int64) (*Response, error) {
u := fmt.Sprintf("app/installations/%v/suspended", id) u := fmt.Sprintf("app/installations/%v/suspended", id)
@ -227,7 +239,7 @@ func (s *AppsService) SuspendInstallation(ctx context.Context, id int64) (*Respo
// UnsuspendInstallation unsuspends the specified installation. // UnsuspendInstallation unsuspends the specified installation.
// //
// GitHub API docs: https://developer.github.com/v3/apps/#unsuspend-an-app-installation // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#unsuspend-an-app-installation
func (s *AppsService) UnsuspendInstallation(ctx context.Context, id int64) (*Response, error) { func (s *AppsService) UnsuspendInstallation(ctx context.Context, id int64) (*Response, error) {
u := fmt.Sprintf("app/installations/%v/suspended", id) u := fmt.Sprintf("app/installations/%v/suspended", id)
@ -241,7 +253,7 @@ func (s *AppsService) UnsuspendInstallation(ctx context.Context, id int64) (*Res
// DeleteInstallation deletes the specified installation. // DeleteInstallation deletes the specified installation.
// //
// GitHub API docs: https://developer.github.com/v3/apps/#delete-an-installation-for-the-authenticated-app // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#delete-an-installation-for-the-authenticated-app
func (s *AppsService) DeleteInstallation(ctx context.Context, id int64) (*Response, error) { func (s *AppsService) DeleteInstallation(ctx context.Context, id int64) (*Response, error) {
u := fmt.Sprintf("app/installations/%v", id) u := fmt.Sprintf("app/installations/%v", id)
@ -250,15 +262,12 @@ func (s *AppsService) DeleteInstallation(ctx context.Context, id int64) (*Respon
return nil, err return nil, err
} }
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeIntegrationPreview)
return s.client.Do(ctx, req, nil) return s.client.Do(ctx, req, nil)
} }
// CreateInstallationToken creates a new installation token. // CreateInstallationToken creates a new installation token.
// //
// GitHub API docs: https://developer.github.com/v3/apps/#create-an-installation-access-token-for-an-app // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#create-an-installation-access-token-for-an-app
func (s *AppsService) CreateInstallationToken(ctx context.Context, id int64, opts *InstallationTokenOptions) (*InstallationToken, *Response, error) { func (s *AppsService) CreateInstallationToken(ctx context.Context, id int64, opts *InstallationTokenOptions) (*InstallationToken, *Response, error) {
u := fmt.Sprintf("app/installations/%v/access_tokens", id) u := fmt.Sprintf("app/installations/%v/access_tokens", id)
@ -267,9 +276,6 @@ func (s *AppsService) CreateInstallationToken(ctx context.Context, id int64, opt
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeIntegrationPreview)
t := new(InstallationToken) t := new(InstallationToken)
resp, err := s.client.Do(ctx, req, t) resp, err := s.client.Do(ctx, req, t)
if err != nil { if err != nil {
@ -281,7 +287,7 @@ func (s *AppsService) CreateInstallationToken(ctx context.Context, id int64, opt
// CreateAttachment creates a new attachment on user comment containing a url. // CreateAttachment creates a new attachment on user comment containing a url.
// //
// GitHub API docs: https://developer.github.com/v3/apps/installations/#create-a-content-attachment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#create-a-content-attachment
func (s *AppsService) CreateAttachment(ctx context.Context, contentReferenceID int64, title, body string) (*Attachment, *Response, error) { func (s *AppsService) CreateAttachment(ctx context.Context, contentReferenceID int64, title, body string) (*Attachment, *Response, error) {
u := fmt.Sprintf("content_references/%v/attachments", contentReferenceID) u := fmt.Sprintf("content_references/%v/attachments", contentReferenceID)
payload := &Attachment{Title: String(title), Body: String(body)} payload := &Attachment{Title: String(title), Body: String(body)}
@ -291,7 +297,7 @@ func (s *AppsService) CreateAttachment(ctx context.Context, contentReferenceID i
} }
// TODO: remove custom Accept headers when APIs fully launch. // TODO: remove custom Accept headers when APIs fully launch.
req.Header.Set("Accept", mediaTypeReactionsPreview) req.Header.Set("Accept", mediaTypeContentAttachmentsPreview)
m := &Attachment{} m := &Attachment{}
resp, err := s.client.Do(ctx, req, m) resp, err := s.client.Do(ctx, req, m)
@ -304,14 +310,14 @@ func (s *AppsService) CreateAttachment(ctx context.Context, contentReferenceID i
// FindOrganizationInstallation finds the organization's installation information. // FindOrganizationInstallation finds the organization's installation information.
// //
// GitHub API docs: https://developer.github.com/v3/apps/#get-an-organization-installation-for-the-authenticated-app // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#get-an-organization-installation-for-the-authenticated-app
func (s *AppsService) FindOrganizationInstallation(ctx context.Context, org string) (*Installation, *Response, error) { func (s *AppsService) FindOrganizationInstallation(ctx context.Context, org string) (*Installation, *Response, error) {
return s.getInstallation(ctx, fmt.Sprintf("orgs/%v/installation", org)) return s.getInstallation(ctx, fmt.Sprintf("orgs/%v/installation", org))
} }
// FindRepositoryInstallation finds the repository's installation information. // FindRepositoryInstallation finds the repository's installation information.
// //
// GitHub API docs: https://developer.github.com/v3/apps/#get-a-repository-installation-for-the-authenticated-app // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#get-a-repository-installation-for-the-authenticated-app
func (s *AppsService) FindRepositoryInstallation(ctx context.Context, owner, repo string) (*Installation, *Response, error) { func (s *AppsService) FindRepositoryInstallation(ctx context.Context, owner, repo string) (*Installation, *Response, error) {
return s.getInstallation(ctx, fmt.Sprintf("repos/%v/%v/installation", owner, repo)) return s.getInstallation(ctx, fmt.Sprintf("repos/%v/%v/installation", owner, repo))
} }
@ -325,7 +331,7 @@ func (s *AppsService) FindRepositoryInstallationByID(ctx context.Context, id int
// FindUserInstallation finds the user's installation information. // FindUserInstallation finds the user's installation information.
// //
// GitHub API docs: https://developer.github.com/v3/apps/#get-a-user-installation-for-the-authenticated-app // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#get-a-user-installation-for-the-authenticated-app
func (s *AppsService) FindUserInstallation(ctx context.Context, user string) (*Installation, *Response, error) { func (s *AppsService) FindUserInstallation(ctx context.Context, user string) (*Installation, *Response, error) {
return s.getInstallation(ctx, fmt.Sprintf("users/%v/installation", user)) return s.getInstallation(ctx, fmt.Sprintf("users/%v/installation", user))
} }
@ -336,9 +342,6 @@ func (s *AppsService) getInstallation(ctx context.Context, url string) (*Install
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeIntegrationPreview)
i := new(Installation) i := new(Installation)
resp, err := s.client.Do(ctx, req, i) resp, err := s.client.Do(ctx, req, i)
if err != nil { if err != nil {

View file

@ -8,12 +8,19 @@ package github
import ( import (
"context" "context"
"fmt" "fmt"
"strings"
) )
// ListRepositories represents the response from the list repos endpoints.
type ListRepositories struct {
TotalCount *int `json:"total_count,omitempty"`
Repositories []*Repository `json:"repositories"`
}
// ListRepos lists the repositories that are accessible to the authenticated installation. // ListRepos lists the repositories that are accessible to the authenticated installation.
// //
// GitHub API docs: https://developer.github.com/v3/apps/installations/#list-repositories-accessible-to-the-app-installation // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#list-repositories-accessible-to-the-app-installation
func (s *AppsService) ListRepos(ctx context.Context, opts *ListOptions) ([]*Repository, *Response, error) { func (s *AppsService) ListRepos(ctx context.Context, opts *ListOptions) (*ListRepositories, *Response, error) {
u, err := addOptions("installation/repositories", opts) u, err := addOptions("installation/repositories", opts)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -24,25 +31,29 @@ func (s *AppsService) ListRepos(ctx context.Context, opts *ListOptions) ([]*Repo
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept header when this API fully launches. // TODO: remove custom Accept headers when APIs fully launch.
req.Header.Set("Accept", mediaTypeIntegrationPreview) acceptHeaders := []string{
mediaTypeTopicsPreview,
var r struct { mediaTypeRepositoryVisibilityPreview,
Repositories []*Repository `json:"repositories"` mediaTypeRepositoryTemplatePreview,
} }
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
var r *ListRepositories
resp, err := s.client.Do(ctx, req, &r) resp, err := s.client.Do(ctx, req, &r)
if err != nil { if err != nil {
return nil, resp, err return nil, resp, err
} }
return r.Repositories, resp, nil return r, resp, nil
} }
// ListUserRepos lists repositories that are accessible // ListUserRepos lists repositories that are accessible
// to the authenticated user for an installation. // to the authenticated user for an installation.
// //
// GitHub API docs: https://developer.github.com/v3/apps/installations/#list-repositories-accessible-to-the-user-access-token // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#list-repositories-accessible-to-the-user-access-token
func (s *AppsService) ListUserRepos(ctx context.Context, id int64, opts *ListOptions) ([]*Repository, *Response, error) { func (s *AppsService) ListUserRepos(ctx context.Context, id int64, opts *ListOptions) (*ListRepositories, *Response, error) {
u := fmt.Sprintf("user/installations/%v/repositories", id) u := fmt.Sprintf("user/installations/%v/repositories", id)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
if err != nil { if err != nil {
@ -54,30 +65,32 @@ func (s *AppsService) ListUserRepos(ctx context.Context, id int64, opts *ListOpt
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept header when this API fully launches. // TODO: remove custom Accept headers when APIs fully launch.
req.Header.Set("Accept", mediaTypeIntegrationPreview) acceptHeaders := []string{
mediaTypeTopicsPreview,
var r struct { mediaTypeRepositoryVisibilityPreview,
Repositories []*Repository `json:"repositories"` mediaTypeRepositoryTemplatePreview,
} }
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
var r *ListRepositories
resp, err := s.client.Do(ctx, req, &r) resp, err := s.client.Do(ctx, req, &r)
if err != nil { if err != nil {
return nil, resp, err return nil, resp, err
} }
return r.Repositories, resp, nil return r, resp, nil
} }
// AddRepository adds a single repository to an installation. // AddRepository adds a single repository to an installation.
// //
// GitHub API docs: https://developer.github.com/v3/apps/installations/#add-a-repository-to-an-app-installation // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#add-a-repository-to-an-app-installation
func (s *AppsService) AddRepository(ctx context.Context, instID, repoID int64) (*Repository, *Response, error) { func (s *AppsService) AddRepository(ctx context.Context, instID, repoID int64) (*Repository, *Response, error) {
u := fmt.Sprintf("user/installations/%v/repositories/%v", instID, repoID) u := fmt.Sprintf("user/installations/%v/repositories/%v", instID, repoID)
req, err := s.client.NewRequest("PUT", u, nil) req, err := s.client.NewRequest("PUT", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
req.Header.Set("Accept", mediaTypeIntegrationPreview)
r := new(Repository) r := new(Repository)
resp, err := s.client.Do(ctx, req, r) resp, err := s.client.Do(ctx, req, r)
@ -90,21 +103,20 @@ func (s *AppsService) AddRepository(ctx context.Context, instID, repoID int64) (
// RemoveRepository removes a single repository from an installation. // RemoveRepository removes a single repository from an installation.
// //
// GitHub API docs: https://developer.github.com/v3/apps/installations/#remove-a-repository-from-an-app-installation // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#remove-a-repository-from-an-app-installation
func (s *AppsService) RemoveRepository(ctx context.Context, instID, repoID int64) (*Response, error) { func (s *AppsService) RemoveRepository(ctx context.Context, instID, repoID int64) (*Response, error) {
u := fmt.Sprintf("user/installations/%v/repositories/%v", instID, repoID) u := fmt.Sprintf("user/installations/%v/repositories/%v", instID, repoID)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
req.Header.Set("Accept", mediaTypeIntegrationPreview)
return s.client.Do(ctx, req, nil) return s.client.Do(ctx, req, nil)
} }
// RevokeInstallationToken revokes an installation token. // RevokeInstallationToken revokes an installation token.
// //
// GitHub API docs: https://developer.github.com/v3/apps/installations/#revoke-an-installation-access-token // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#revoke-an-installation-access-token
func (s *AppsService) RevokeInstallationToken(ctx context.Context) (*Response, error) { func (s *AppsService) RevokeInstallationToken(ctx context.Context) (*Response, error) {
u := "installation/token" u := "installation/token"
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)

View file

@ -10,10 +10,6 @@ import (
"fmt" "fmt"
) )
const (
mediaTypeAppManifestPreview = "application/vnd.github.fury-preview+json"
)
// AppConfig describes the configuration of a GitHub App. // AppConfig describes the configuration of a GitHub App.
type AppConfig struct { type AppConfig struct {
ID *int64 `json:"id,omitempty"` ID *int64 `json:"id,omitempty"`
@ -34,14 +30,13 @@ type AppConfig struct {
// CompleteAppManifest completes the App manifest handshake flow for the given // CompleteAppManifest completes the App manifest handshake flow for the given
// code. // code.
// //
// GitHub API docs: https://developer.github.com/v3/apps/#create-a-github-app-from-a-manifest // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#create-a-github-app-from-a-manifest
func (s *AppsService) CompleteAppManifest(ctx context.Context, code string) (*AppConfig, *Response, error) { func (s *AppsService) CompleteAppManifest(ctx context.Context, code string) (*AppConfig, *Response, error) {
u := fmt.Sprintf("app-manifests/%s/conversions", code) u := fmt.Sprintf("app-manifests/%s/conversions", code)
req, err := s.client.NewRequest("POST", u, nil) req, err := s.client.NewRequest("POST", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
req.Header.Set("Accept", mediaTypeAppManifestPreview)
cfg := new(AppConfig) cfg := new(AppConfig)
resp, err := s.client.Do(ctx, req, cfg) resp, err := s.client.Do(ctx, req, cfg)

View file

@ -13,7 +13,7 @@ import (
// MarketplaceService handles communication with the marketplace related // MarketplaceService handles communication with the marketplace related
// methods of the GitHub API. // methods of the GitHub API.
// //
// GitHub API docs: https://developer.github.com/v3/apps/marketplace/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps#marketplace
type MarketplaceService struct { type MarketplaceService struct {
client *Client client *Client
// Stubbed controls whether endpoints that return stubbed data are used // Stubbed controls whether endpoints that return stubbed data are used
@ -21,7 +21,7 @@ type MarketplaceService struct {
// for testing your GitHub Apps. Stubbed data is hard-coded and will not // for testing your GitHub Apps. Stubbed data is hard-coded and will not
// change based on actual subscriptions. // change based on actual subscriptions.
// //
// GitHub API docs: https://developer.github.com/v3/apps/marketplace/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps#testing-with-stubbed-endpoints
Stubbed bool Stubbed bool
} }
@ -30,6 +30,7 @@ type MarketplacePlan struct {
URL *string `json:"url,omitempty"` URL *string `json:"url,omitempty"`
AccountsURL *string `json:"accounts_url,omitempty"` AccountsURL *string `json:"accounts_url,omitempty"`
ID *int64 `json:"id,omitempty"` ID *int64 `json:"id,omitempty"`
Number *int `json:"number,omitempty"`
Name *string `json:"name,omitempty"` Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"` Description *string `json:"description,omitempty"`
MonthlyPriceInCents *int `json:"monthly_price_in_cents,omitempty"` MonthlyPriceInCents *int `json:"monthly_price_in_cents,omitempty"`
@ -46,13 +47,13 @@ type MarketplacePlan struct {
// MarketplacePurchase represents a GitHub Apps Marketplace Purchase. // MarketplacePurchase represents a GitHub Apps Marketplace Purchase.
type MarketplacePurchase struct { type MarketplacePurchase struct {
// BillingCycle can be one of the values "yearly", "monthly" or nil. // BillingCycle can be one of the values "yearly", "monthly" or nil.
BillingCycle *string `json:"billing_cycle,omitempty"` BillingCycle *string `json:"billing_cycle,omitempty"`
NextBillingDate *Timestamp `json:"next_billing_date,omitempty"` NextBillingDate *Timestamp `json:"next_billing_date,omitempty"`
UnitCount *int `json:"unit_count,omitempty"` UnitCount *int `json:"unit_count,omitempty"`
Plan *MarketplacePlan `json:"plan,omitempty"` Plan *MarketplacePlan `json:"plan,omitempty"`
Account *MarketplacePlanAccount `json:"account,omitempty"` OnFreeTrial *bool `json:"on_free_trial,omitempty"`
OnFreeTrial *bool `json:"on_free_trial,omitempty"` FreeTrialEndsOn *Timestamp `json:"free_trial_ends_on,omitempty"`
FreeTrialEndsOn *Timestamp `json:"free_trial_ends_on,omitempty"` UpdatedAt *Timestamp `json:"updated_at,omitempty"`
} }
// MarketplacePendingChange represents a pending change to a GitHub Apps Marketplace Plan. // MarketplacePendingChange represents a pending change to a GitHub Apps Marketplace Plan.
@ -68,9 +69,7 @@ type MarketplacePlanAccount struct {
URL *string `json:"url,omitempty"` URL *string `json:"url,omitempty"`
Type *string `json:"type,omitempty"` Type *string `json:"type,omitempty"`
ID *int64 `json:"id,omitempty"` ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
Login *string `json:"login,omitempty"` Login *string `json:"login,omitempty"`
Email *string `json:"email,omitempty"`
OrganizationBillingEmail *string `json:"organization_billing_email,omitempty"` OrganizationBillingEmail *string `json:"organization_billing_email,omitempty"`
MarketplacePurchase *MarketplacePurchase `json:"marketplace_purchase,omitempty"` MarketplacePurchase *MarketplacePurchase `json:"marketplace_purchase,omitempty"`
MarketplacePendingChange *MarketplacePendingChange `json:"marketplace_pending_change,omitempty"` MarketplacePendingChange *MarketplacePendingChange `json:"marketplace_pending_change,omitempty"`
@ -78,7 +77,7 @@ type MarketplacePlanAccount struct {
// ListPlans lists all plans for your Marketplace listing. // ListPlans lists all plans for your Marketplace listing.
// //
// GitHub API docs: https://developer.github.com/v3/apps/marketplace/#list-all-plans-for-your-marketplace-listing // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps#list-plans
func (s *MarketplaceService) ListPlans(ctx context.Context, opts *ListOptions) ([]*MarketplacePlan, *Response, error) { func (s *MarketplaceService) ListPlans(ctx context.Context, opts *ListOptions) ([]*MarketplacePlan, *Response, error) {
uri := s.marketplaceURI("plans") uri := s.marketplaceURI("plans")
u, err := addOptions(uri, opts) u, err := addOptions(uri, opts)
@ -102,7 +101,7 @@ func (s *MarketplaceService) ListPlans(ctx context.Context, opts *ListOptions) (
// ListPlanAccountsForPlan lists all GitHub accounts (user or organization) on a specific plan. // ListPlanAccountsForPlan lists all GitHub accounts (user or organization) on a specific plan.
// //
// GitHub API docs: https://developer.github.com/v3/apps/marketplace/#list-all-github-accounts-user-or-organization-on-a-specific-plan // GitHub API docs: https://docs.github.com/en/rest/reference/apps#list-accounts-for-a-plan
func (s *MarketplaceService) ListPlanAccountsForPlan(ctx context.Context, planID int64, opts *ListOptions) ([]*MarketplacePlanAccount, *Response, error) { func (s *MarketplaceService) ListPlanAccountsForPlan(ctx context.Context, planID int64, opts *ListOptions) ([]*MarketplacePlanAccount, *Response, error) {
uri := s.marketplaceURI(fmt.Sprintf("plans/%v/accounts", planID)) uri := s.marketplaceURI(fmt.Sprintf("plans/%v/accounts", planID))
u, err := addOptions(uri, opts) u, err := addOptions(uri, opts)
@ -124,34 +123,30 @@ func (s *MarketplaceService) ListPlanAccountsForPlan(ctx context.Context, planID
return accounts, resp, nil return accounts, resp, nil
} }
// ListPlanAccountsForAccount lists all GitHub accounts (user or organization) associated with an account. // GetPlanAccountForAccount get GitHub account (user or organization) associated with an account.
// //
// GitHub API docs: https://developer.github.com/v3/apps/marketplace/#check-if-a-github-account-is-associated-with-any-marketplace-listing // GitHub API docs: https://docs.github.com/en/rest/reference/apps#get-a-subscription-plan-for-an-account
func (s *MarketplaceService) ListPlanAccountsForAccount(ctx context.Context, accountID int64, opts *ListOptions) ([]*MarketplacePlanAccount, *Response, error) { func (s *MarketplaceService) GetPlanAccountForAccount(ctx context.Context, accountID int64) (*MarketplacePlanAccount, *Response, error) {
uri := s.marketplaceURI(fmt.Sprintf("accounts/%v", accountID)) uri := s.marketplaceURI(fmt.Sprintf("accounts/%v", accountID))
u, err := addOptions(uri, opts)
req, err := s.client.NewRequest("GET", uri, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
req, err := s.client.NewRequest("GET", u, nil) var account *MarketplacePlanAccount
if err != nil { resp, err := s.client.Do(ctx, req, &account)
return nil, nil, err
}
var accounts []*MarketplacePlanAccount
resp, err := s.client.Do(ctx, req, &accounts)
if err != nil { if err != nil {
return nil, resp, err return nil, resp, err
} }
return accounts, resp, nil return account, resp, nil
} }
// ListMarketplacePurchasesForUser lists all GitHub marketplace purchases made by a user. // ListMarketplacePurchasesForUser lists all GitHub marketplace purchases made by a user.
// //
// GitHub API docs: https://developer.github.com/v3/apps/marketplace/#list-subscriptions-for-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#list-subscriptions-for-the-authenticated-user-stubbed
// GitHub API docs: https://developer.github.com/v3/apps/marketplace/#list-subscriptions-for-the-authenticated-user-stubbed // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#list-subscriptions-for-the-authenticated-user
func (s *MarketplaceService) ListMarketplacePurchasesForUser(ctx context.Context, opts *ListOptions) ([]*MarketplacePurchase, *Response, error) { func (s *MarketplaceService) ListMarketplacePurchasesForUser(ctx context.Context, opts *ListOptions) ([]*MarketplacePurchase, *Response, error) {
uri := "user/marketplace_purchases" uri := "user/marketplace_purchases"
if s.Stubbed { if s.Stubbed {

View file

@ -12,7 +12,7 @@ import (
// Scope models a GitHub authorization scope. // Scope models a GitHub authorization scope.
// //
// GitHub API docs: https://developer.github.com/v3/oauth/#scopes // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/oauth/#scopes
type Scope string type Scope string
// This is the set of scopes for GitHub API V3 // This is the set of scopes for GitHub API V3
@ -50,7 +50,7 @@ const (
// This service requires HTTP Basic Authentication; it cannot be accessed using // This service requires HTTP Basic Authentication; it cannot be accessed using
// an OAuth token. // an OAuth token.
// //
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/oauth_authorizations/
type AuthorizationsService service type AuthorizationsService service
// Authorization represents an individual GitHub authorization. // Authorization represents an individual GitHub authorization.
@ -121,7 +121,7 @@ func (a AuthorizationRequest) String() string {
// fields. That is, you may provide only one of "Scopes", or "AddScopes", or // fields. That is, you may provide only one of "Scopes", or "AddScopes", or
// "RemoveScopes". // "RemoveScopes".
// //
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#update-an-existing-authorization // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/oauth_authorizations/#update-an-existing-authorization
type AuthorizationUpdateRequest struct { type AuthorizationUpdateRequest struct {
Scopes []string `json:"scopes,omitempty"` Scopes []string `json:"scopes,omitempty"`
AddScopes []string `json:"add_scopes,omitempty"` AddScopes []string `json:"add_scopes,omitempty"`
@ -143,7 +143,7 @@ func (a AuthorizationUpdateRequest) String() string {
// //
// The returned Authorization.User field will be populated. // The returned Authorization.User field will be populated.
// //
// GitHub API docs: https://developer.github.com/v3/apps/oauth_applications/#check-a-token // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#check-a-token
func (s *AuthorizationsService) Check(ctx context.Context, clientID, accessToken string) (*Authorization, *Response, error) { func (s *AuthorizationsService) Check(ctx context.Context, clientID, accessToken string) (*Authorization, *Response, error) {
u := fmt.Sprintf("applications/%v/token", clientID) u := fmt.Sprintf("applications/%v/token", clientID)
@ -176,7 +176,7 @@ func (s *AuthorizationsService) Check(ctx context.Context, clientID, accessToken
// //
// The returned Authorization.User field will be populated. // The returned Authorization.User field will be populated.
// //
// GitHub API docs: https://developer.github.com/v3/apps/oauth_applications/#reset-a-token // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#reset-a-token
func (s *AuthorizationsService) Reset(ctx context.Context, clientID, accessToken string) (*Authorization, *Response, error) { func (s *AuthorizationsService) Reset(ctx context.Context, clientID, accessToken string) (*Authorization, *Response, error) {
u := fmt.Sprintf("applications/%v/token", clientID) u := fmt.Sprintf("applications/%v/token", clientID)
@ -205,7 +205,7 @@ func (s *AuthorizationsService) Reset(ctx context.Context, clientID, accessToken
// username is the OAuth application clientID, and the password is its // username is the OAuth application clientID, and the password is its
// clientSecret. Invalid tokens will return a 404 Not Found. // clientSecret. Invalid tokens will return a 404 Not Found.
// //
// GitHub API docs: https://developer.github.com/v3/apps/oauth_applications/#delete-an-app-token // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#delete-an-app-token
func (s *AuthorizationsService) Revoke(ctx context.Context, clientID, accessToken string) (*Response, error) { func (s *AuthorizationsService) Revoke(ctx context.Context, clientID, accessToken string) (*Response, error) {
u := fmt.Sprintf("applications/%v/token", clientID) u := fmt.Sprintf("applications/%v/token", clientID)
@ -226,7 +226,7 @@ func (s *AuthorizationsService) Revoke(ctx context.Context, clientID, accessToke
// grant will also delete all OAuth tokens associated with the application for // grant will also delete all OAuth tokens associated with the application for
// the user. // the user.
// //
// GitHub API docs: https://developer.github.com/v3/apps/oauth_applications/#delete-an-app-authorization // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#delete-an-app-authorization
func (s *AuthorizationsService) DeleteGrant(ctx context.Context, clientID, accessToken string) (*Response, error) { func (s *AuthorizationsService) DeleteGrant(ctx context.Context, clientID, accessToken string) (*Response, error) {
u := fmt.Sprintf("applications/%v/grant", clientID) u := fmt.Sprintf("applications/%v/grant", clientID)

View file

@ -0,0 +1,131 @@
// 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"
)
// BillingService provides access to the billing related functions
// in the GitHub API.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/billing
type BillingService service
// ActionBilling represents a GitHub Action billing.
type ActionBilling struct {
TotalMinutesUsed int `json:"total_minutes_used"`
TotalPaidMinutesUsed int `json:"total_paid_minutes_used"`
IncludedMinutes int `json:"included_minutes"`
MinutesUsedBreakdown MinutesUsedBreakdown `json:"minutes_used_breakdown"`
}
type MinutesUsedBreakdown struct {
Ubuntu int `json:"UBUNTU"`
MacOS int `json:"MACOS"`
Windows int `json:"WINDOWS"`
}
// PackageBilling represents a GitHub Package billing.
type PackageBilling struct {
TotalGigabytesBandwidthUsed int `json:"total_gigabytes_bandwidth_used"`
TotalPaidGigabytesBandwidthUsed int `json:"total_paid_gigabytes_bandwidth_used"`
IncludedGigabytesBandwidth int `json:"included_gigabytes_bandwidth"`
}
// StorageBilling represents a GitHub Storage billing.
type StorageBilling struct {
DaysLeftInBillingCycle int `json:"days_left_in_billing_cycle"`
EstimatedPaidStorageForMonth int `json:"estimated_paid_storage_for_month"`
EstimatedStorageForMonth int `json:"estimated_storage_for_month"`
}
// GetActionsBillingOrg returns the summary of the free and paid GitHub Actions minutes used for an Org.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/billing#get-github-actions-billing-for-an-organization
func (s *BillingService) GetActionsBillingOrg(ctx context.Context, org string) (*ActionBilling, *Response, error) {
u := fmt.Sprintf("orgs/%v/settings/billing/actions", org)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
actionsOrgBilling := new(ActionBilling)
resp, err := s.client.Do(ctx, req, actionsOrgBilling)
return actionsOrgBilling, resp, err
}
// GetPackagesBillingOrg returns the free and paid storage used for GitHub Packages in gigabytes for an Org.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/billing#get-github-packages-billing-for-an-organization
func (s *BillingService) GetPackagesBillingOrg(ctx context.Context, org string) (*PackageBilling, *Response, error) {
u := fmt.Sprintf("orgs/%v/settings/billing/packages", org)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
packagesOrgBilling := new(PackageBilling)
resp, err := s.client.Do(ctx, req, packagesOrgBilling)
return packagesOrgBilling, resp, err
}
// GetStorageBillingOrg returns the estimated paid and estimated total storage used for GitHub Actions
// and GitHub Packages in gigabytes for an Org.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/billing#get-shared-storage-billing-for-an-organization
func (s *BillingService) GetStorageBillingOrg(ctx context.Context, org string) (*StorageBilling, *Response, error) {
u := fmt.Sprintf("orgs/%v/settings/billing/shared-storage", org)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
storageOrgBilling := new(StorageBilling)
resp, err := s.client.Do(ctx, req, storageOrgBilling)
return storageOrgBilling, resp, err
}
// GetActionsBillingUser returns the summary of the free and paid GitHub Actions minutes used for a user.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/billing#get-github-actions-billing-for-a-user
func (s *BillingService) GetActionsBillingUser(ctx context.Context, user string) (*ActionBilling, *Response, error) {
u := fmt.Sprintf("users/%v/settings/billing/actions", user)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
actionsUserBilling := new(ActionBilling)
resp, err := s.client.Do(ctx, req, actionsUserBilling)
return actionsUserBilling, resp, err
}
// GetPackagesBillingUser returns the free and paid storage used for GitHub Packages in gigabytes for a user.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/billing#get-github-packages-billing-for-an-organization
func (s *BillingService) GetPackagesBillingUser(ctx context.Context, user string) (*PackageBilling, *Response, error) {
u := fmt.Sprintf("users/%v/settings/billing/packages", user)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
packagesUserBilling := new(PackageBilling)
resp, err := s.client.Do(ctx, req, packagesUserBilling)
return packagesUserBilling, resp, err
}
// GetStorageBillingUser returns the estimated paid and estimated total storage used for GitHub Actions
// and GitHub Packages in gigabytes for a user.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/billing#get-shared-storage-billing-for-a-user
func (s *BillingService) GetStorageBillingUser(ctx context.Context, user string) (*StorageBilling, *Response, error) {
u := fmt.Sprintf("users/%v/settings/billing/shared-storage", user)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
storageUserBilling := new(StorageBilling)
resp, err := s.client.Do(ctx, req, storageUserBilling)
return storageUserBilling, resp, err
}

View file

@ -13,7 +13,7 @@ import (
// ChecksService provides access to the Checks API in the // ChecksService provides access to the Checks API in the
// GitHub API. // GitHub API.
// //
// GitHub API docs: https://developer.github.com/v3/checks/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/checks/
type ChecksService service type ChecksService service
// CheckRun represents a GitHub check run on a repository associated with a GitHub app. // CheckRun represents a GitHub check run on a repository associated with a GitHub app.
@ -96,7 +96,7 @@ func (c CheckSuite) String() string {
// GetCheckRun gets a check-run for a repository. // GetCheckRun gets a check-run for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/checks/runs/#get-a-check-run // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/checks/#get-a-check-run
func (s *ChecksService) GetCheckRun(ctx context.Context, owner, repo string, checkRunID int64) (*CheckRun, *Response, error) { func (s *ChecksService) GetCheckRun(ctx context.Context, owner, repo string, checkRunID int64) (*CheckRun, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/check-runs/%v", owner, repo, checkRunID) u := fmt.Sprintf("repos/%v/%v/check-runs/%v", owner, repo, checkRunID)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -104,8 +104,6 @@ func (s *ChecksService) GetCheckRun(ctx context.Context, owner, repo string, che
return nil, nil, err return nil, nil, err
} }
req.Header.Set("Accept", mediaTypeCheckRunsPreview)
checkRun := new(CheckRun) checkRun := new(CheckRun)
resp, err := s.client.Do(ctx, req, checkRun) resp, err := s.client.Do(ctx, req, checkRun)
if err != nil { if err != nil {
@ -117,7 +115,7 @@ func (s *ChecksService) GetCheckRun(ctx context.Context, owner, repo string, che
// GetCheckSuite gets a single check suite. // GetCheckSuite gets a single check suite.
// //
// GitHub API docs: https://developer.github.com/v3/checks/suites/#get-a-check-suite // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/checks/#get-a-check-suite
func (s *ChecksService) GetCheckSuite(ctx context.Context, owner, repo string, checkSuiteID int64) (*CheckSuite, *Response, error) { func (s *ChecksService) GetCheckSuite(ctx context.Context, owner, repo string, checkSuiteID int64) (*CheckSuite, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/check-suites/%v", owner, repo, checkSuiteID) u := fmt.Sprintf("repos/%v/%v/check-suites/%v", owner, repo, checkSuiteID)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -125,8 +123,6 @@ func (s *ChecksService) GetCheckSuite(ctx context.Context, owner, repo string, c
return nil, nil, err return nil, nil, err
} }
req.Header.Set("Accept", mediaTypeCheckRunsPreview)
checkSuite := new(CheckSuite) checkSuite := new(CheckSuite)
resp, err := s.client.Do(ctx, req, checkSuite) resp, err := s.client.Do(ctx, req, checkSuite)
if err != nil { if err != nil {
@ -159,7 +155,7 @@ type CheckRunAction struct {
// CreateCheckRun creates a check run for repository. // CreateCheckRun creates a check run for repository.
// //
// GitHub API docs: https://developer.github.com/v3/checks/runs/#create-a-check-run // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/checks/#create-a-check-run
func (s *ChecksService) CreateCheckRun(ctx context.Context, owner, repo string, opts CreateCheckRunOptions) (*CheckRun, *Response, error) { func (s *ChecksService) CreateCheckRun(ctx context.Context, owner, repo string, opts CreateCheckRunOptions) (*CheckRun, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/check-runs", owner, repo) u := fmt.Sprintf("repos/%v/%v/check-runs", owner, repo)
req, err := s.client.NewRequest("POST", u, opts) req, err := s.client.NewRequest("POST", u, opts)
@ -167,8 +163,6 @@ func (s *ChecksService) CreateCheckRun(ctx context.Context, owner, repo string,
return nil, nil, err return nil, nil, err
} }
req.Header.Set("Accept", mediaTypeCheckRunsPreview)
checkRun := new(CheckRun) checkRun := new(CheckRun)
resp, err := s.client.Do(ctx, req, checkRun) resp, err := s.client.Do(ctx, req, checkRun)
if err != nil { if err != nil {
@ -181,7 +175,6 @@ func (s *ChecksService) CreateCheckRun(ctx context.Context, owner, repo string,
// UpdateCheckRunOptions sets up parameters needed to update a CheckRun. // UpdateCheckRunOptions sets up parameters needed to update a CheckRun.
type UpdateCheckRunOptions struct { type UpdateCheckRunOptions struct {
Name string `json:"name"` // The name of the check (e.g., "code-coverage"). (Required.) Name string `json:"name"` // The name of the check (e.g., "code-coverage"). (Required.)
HeadSHA *string `json:"head_sha,omitempty"` // The SHA of the commit. (Optional.)
DetailsURL *string `json:"details_url,omitempty"` // The URL of the integrator's site that has the full details of the check. (Optional.) DetailsURL *string `json:"details_url,omitempty"` // The URL of the integrator's site that has the full details of the check. (Optional.)
ExternalID *string `json:"external_id,omitempty"` // A reference for the run on the integrator's system. (Optional.) ExternalID *string `json:"external_id,omitempty"` // A reference for the run on the integrator's system. (Optional.)
Status *string `json:"status,omitempty"` // The current status. Can be one of "queued", "in_progress", or "completed". Default: "queued". (Optional.) Status *string `json:"status,omitempty"` // The current status. Can be one of "queued", "in_progress", or "completed". Default: "queued". (Optional.)
@ -193,7 +186,7 @@ type UpdateCheckRunOptions struct {
// UpdateCheckRun updates a check run for a specific commit in a repository. // UpdateCheckRun updates a check run for a specific commit in a repository.
// //
// GitHub API docs: https://developer.github.com/v3/checks/runs/#update-a-check-run // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/checks/#update-a-check-run
func (s *ChecksService) UpdateCheckRun(ctx context.Context, owner, repo string, checkRunID int64, opts UpdateCheckRunOptions) (*CheckRun, *Response, error) { func (s *ChecksService) UpdateCheckRun(ctx context.Context, owner, repo string, checkRunID int64, opts UpdateCheckRunOptions) (*CheckRun, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/check-runs/%v", owner, repo, checkRunID) u := fmt.Sprintf("repos/%v/%v/check-runs/%v", owner, repo, checkRunID)
req, err := s.client.NewRequest("PATCH", u, opts) req, err := s.client.NewRequest("PATCH", u, opts)
@ -201,8 +194,6 @@ func (s *ChecksService) UpdateCheckRun(ctx context.Context, owner, repo string,
return nil, nil, err return nil, nil, err
} }
req.Header.Set("Accept", mediaTypeCheckRunsPreview)
checkRun := new(CheckRun) checkRun := new(CheckRun)
resp, err := s.client.Do(ctx, req, checkRun) resp, err := s.client.Do(ctx, req, checkRun)
if err != nil { if err != nil {
@ -214,7 +205,7 @@ func (s *ChecksService) UpdateCheckRun(ctx context.Context, owner, repo string,
// ListCheckRunAnnotations lists the annotations for a check run. // ListCheckRunAnnotations lists the annotations for a check run.
// //
// GitHub API docs: https://developer.github.com/v3/checks/runs/#list-check-run-annotations // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/checks/#list-check-run-annotations
func (s *ChecksService) ListCheckRunAnnotations(ctx context.Context, owner, repo string, checkRunID int64, opts *ListOptions) ([]*CheckRunAnnotation, *Response, error) { func (s *ChecksService) ListCheckRunAnnotations(ctx context.Context, owner, repo string, checkRunID int64, opts *ListOptions) ([]*CheckRunAnnotation, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/check-runs/%v/annotations", owner, repo, checkRunID) u := fmt.Sprintf("repos/%v/%v/check-runs/%v/annotations", owner, repo, checkRunID)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -227,8 +218,6 @@ func (s *ChecksService) ListCheckRunAnnotations(ctx context.Context, owner, repo
return nil, nil, err return nil, nil, err
} }
req.Header.Set("Accept", mediaTypeCheckRunsPreview)
var checkRunAnnotations []*CheckRunAnnotation var checkRunAnnotations []*CheckRunAnnotation
resp, err := s.client.Do(ctx, req, &checkRunAnnotations) resp, err := s.client.Do(ctx, req, &checkRunAnnotations)
if err != nil { if err != nil {
@ -255,7 +244,7 @@ type ListCheckRunsResults struct {
// ListCheckRunsForRef lists check runs for a specific ref. // ListCheckRunsForRef lists check runs for a specific ref.
// //
// GitHub API docs: https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-git-reference // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/checks/#list-check-runs-for-a-git-reference
func (s *ChecksService) ListCheckRunsForRef(ctx context.Context, owner, repo, ref string, opts *ListCheckRunsOptions) (*ListCheckRunsResults, *Response, error) { func (s *ChecksService) ListCheckRunsForRef(ctx context.Context, owner, repo, ref string, opts *ListCheckRunsOptions) (*ListCheckRunsResults, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v/check-runs", owner, repo, refURLEscape(ref)) u := fmt.Sprintf("repos/%v/%v/commits/%v/check-runs", owner, repo, refURLEscape(ref))
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -268,8 +257,6 @@ func (s *ChecksService) ListCheckRunsForRef(ctx context.Context, owner, repo, re
return nil, nil, err return nil, nil, err
} }
req.Header.Set("Accept", mediaTypeCheckRunsPreview)
var checkRunResults *ListCheckRunsResults var checkRunResults *ListCheckRunsResults
resp, err := s.client.Do(ctx, req, &checkRunResults) resp, err := s.client.Do(ctx, req, &checkRunResults)
if err != nil { if err != nil {
@ -281,7 +268,7 @@ func (s *ChecksService) ListCheckRunsForRef(ctx context.Context, owner, repo, re
// ListCheckRunsCheckSuite lists check runs for a check suite. // ListCheckRunsCheckSuite lists check runs for a check suite.
// //
// GitHub API docs: https://developer.github.com/v3/checks/runs/#list-check-runs-in-a-check-suite // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/checks/#list-check-runs-in-a-check-suite
func (s *ChecksService) ListCheckRunsCheckSuite(ctx context.Context, owner, repo string, checkSuiteID int64, opts *ListCheckRunsOptions) (*ListCheckRunsResults, *Response, error) { func (s *ChecksService) ListCheckRunsCheckSuite(ctx context.Context, owner, repo string, checkSuiteID int64, opts *ListCheckRunsOptions) (*ListCheckRunsResults, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/check-suites/%v/check-runs", owner, repo, checkSuiteID) u := fmt.Sprintf("repos/%v/%v/check-suites/%v/check-runs", owner, repo, checkSuiteID)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -294,8 +281,6 @@ func (s *ChecksService) ListCheckRunsCheckSuite(ctx context.Context, owner, repo
return nil, nil, err return nil, nil, err
} }
req.Header.Set("Accept", mediaTypeCheckRunsPreview)
var checkRunResults *ListCheckRunsResults var checkRunResults *ListCheckRunsResults
resp, err := s.client.Do(ctx, req, &checkRunResults) resp, err := s.client.Do(ctx, req, &checkRunResults)
if err != nil { if err != nil {
@ -321,7 +306,7 @@ type ListCheckSuiteResults struct {
// ListCheckSuitesForRef lists check suite for a specific ref. // ListCheckSuitesForRef lists check suite for a specific ref.
// //
// GitHub API docs: https://developer.github.com/v3/checks/suites/#list-check-suites-for-a-git-reference // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/checks/#list-check-suites-for-a-git-reference
func (s *ChecksService) ListCheckSuitesForRef(ctx context.Context, owner, repo, ref string, opts *ListCheckSuiteOptions) (*ListCheckSuiteResults, *Response, error) { func (s *ChecksService) ListCheckSuitesForRef(ctx context.Context, owner, repo, ref string, opts *ListCheckSuiteOptions) (*ListCheckSuiteResults, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v/check-suites", owner, repo, refURLEscape(ref)) u := fmt.Sprintf("repos/%v/%v/commits/%v/check-suites", owner, repo, refURLEscape(ref))
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -334,8 +319,6 @@ func (s *ChecksService) ListCheckSuitesForRef(ctx context.Context, owner, repo,
return nil, nil, err return nil, nil, err
} }
req.Header.Set("Accept", mediaTypeCheckRunsPreview)
var checkSuiteResults *ListCheckSuiteResults var checkSuiteResults *ListCheckSuiteResults
resp, err := s.client.Do(ctx, req, &checkSuiteResults) resp, err := s.client.Do(ctx, req, &checkSuiteResults)
if err != nil { if err != nil {
@ -369,7 +352,7 @@ type PreferenceList struct {
// SetCheckSuitePreferences changes the default automatic flow when creating check suites. // SetCheckSuitePreferences changes the default automatic flow when creating check suites.
// //
// GitHub API docs: https://developer.github.com/v3/checks/suites/#update-repository-preferences-for-check-suites // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/checks/#update-repository-preferences-for-check-suites
func (s *ChecksService) SetCheckSuitePreferences(ctx context.Context, owner, repo string, opts CheckSuitePreferenceOptions) (*CheckSuitePreferenceResults, *Response, error) { func (s *ChecksService) SetCheckSuitePreferences(ctx context.Context, owner, repo string, opts CheckSuitePreferenceOptions) (*CheckSuitePreferenceResults, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/check-suites/preferences", owner, repo) u := fmt.Sprintf("repos/%v/%v/check-suites/preferences", owner, repo)
req, err := s.client.NewRequest("PATCH", u, opts) req, err := s.client.NewRequest("PATCH", u, opts)
@ -377,8 +360,6 @@ func (s *ChecksService) SetCheckSuitePreferences(ctx context.Context, owner, rep
return nil, nil, err return nil, nil, err
} }
req.Header.Set("Accept", mediaTypeCheckRunsPreview)
var checkSuitePrefResults *CheckSuitePreferenceResults var checkSuitePrefResults *CheckSuitePreferenceResults
resp, err := s.client.Do(ctx, req, &checkSuitePrefResults) resp, err := s.client.Do(ctx, req, &checkSuitePrefResults)
if err != nil { if err != nil {
@ -396,7 +377,7 @@ type CreateCheckSuiteOptions struct {
// CreateCheckSuite manually creates a check suite for a repository. // CreateCheckSuite manually creates a check suite for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/checks/suites/#create-a-check-suite // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/checks/#create-a-check-suite
func (s *ChecksService) CreateCheckSuite(ctx context.Context, owner, repo string, opts CreateCheckSuiteOptions) (*CheckSuite, *Response, error) { func (s *ChecksService) CreateCheckSuite(ctx context.Context, owner, repo string, opts CreateCheckSuiteOptions) (*CheckSuite, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/check-suites", owner, repo) u := fmt.Sprintf("repos/%v/%v/check-suites", owner, repo)
req, err := s.client.NewRequest("POST", u, opts) req, err := s.client.NewRequest("POST", u, opts)
@ -404,8 +385,6 @@ func (s *ChecksService) CreateCheckSuite(ctx context.Context, owner, repo string
return nil, nil, err return nil, nil, err
} }
req.Header.Set("Accept", mediaTypeCheckRunsPreview)
checkSuite := new(CheckSuite) checkSuite := new(CheckSuite)
resp, err := s.client.Do(ctx, req, checkSuite) resp, err := s.client.Do(ctx, req, checkSuite)
if err != nil { if err != nil {
@ -417,7 +396,7 @@ func (s *ChecksService) CreateCheckSuite(ctx context.Context, owner, repo string
// ReRequestCheckSuite triggers GitHub to rerequest an existing check suite, without pushing new code to a repository. // ReRequestCheckSuite triggers GitHub to rerequest an existing check suite, without pushing new code to a repository.
// //
// GitHub API docs: https://developer.github.com/v3/checks/suites/#rerequest-a-check-suite // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/checks/#rerequest-a-check-suite
func (s *ChecksService) ReRequestCheckSuite(ctx context.Context, owner, repo string, checkSuiteID int64) (*Response, error) { func (s *ChecksService) ReRequestCheckSuite(ctx context.Context, owner, repo string, checkSuiteID int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/check-suites/%v/rerequest", owner, repo, checkSuiteID) u := fmt.Sprintf("repos/%v/%v/check-suites/%v/rerequest", owner, repo, checkSuiteID)
@ -426,8 +405,6 @@ func (s *ChecksService) ReRequestCheckSuite(ctx context.Context, owner, repo str
return nil, err return nil, err
} }
req.Header.Set("Accept", mediaTypeCheckRunsPreview)
resp, err := s.client.Do(ctx, req, nil) resp, err := s.client.Do(ctx, req, nil)
return resp, err return resp, err
} }

View file

@ -15,14 +15,26 @@ import (
// CodeScanningService handles communication with the code scanning related // CodeScanningService handles communication with the code scanning related
// methods of the GitHub API. // methods of the GitHub API.
// //
// GitHub API docs: https://developer.github.com/v3/code-scanning/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/code-scanning/
type CodeScanningService service type CodeScanningService service
// 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"`
Version *string `json:"version,omitempty"`
}
// Alert represents an individual GitHub Code Scanning Alert on a single repository.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/code-scanning#list-code-scanning-alerts-for-a-repository
type Alert struct { type Alert struct {
RuleID *string `json:"rule_id,omitempty"` RuleID *string `json:"rule_id,omitempty"`
RuleSeverity *string `json:"rule_severity,omitempty"` RuleSeverity *string `json:"rule_severity,omitempty"`
RuleDescription *string `json:"rule_description,omitempty"` RuleDescription *string `json:"rule_description,omitempty"`
Tool *string `json:"tool,omitempty"` Tool *Tool `json:"tool,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"` CreatedAt *Timestamp `json:"created_at,omitempty"`
Open *bool `json:"open,omitempty"` Open *bool `json:"open,omitempty"`
ClosedBy *User `json:"closed_by,omitempty"` ClosedBy *User `json:"closed_by,omitempty"`
@ -69,7 +81,7 @@ type AlertListOptions struct {
// You must use an access token with the security_events scope to use this endpoint. GitHub Apps must have the security_events // You must use an access token with the security_events scope to use this endpoint. GitHub Apps must have the security_events
// read permission to use this endpoint. // read permission to use this endpoint.
// //
// GitHub API docs: https://developer.github.com/v3/code-scanning/#list-code-scanning-alerts-for-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/code-scanning/#list-code-scanning-alerts-for-a-repository
func (s *CodeScanningService) ListAlertsForRepo(ctx context.Context, owner, repo string, opts *AlertListOptions) ([]*Alert, *Response, error) { func (s *CodeScanningService) ListAlertsForRepo(ctx context.Context, owner, repo string, opts *AlertListOptions) ([]*Alert, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/code-scanning/alerts", owner, repo) u := fmt.Sprintf("repos/%v/%v/code-scanning/alerts", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -98,7 +110,7 @@ func (s *CodeScanningService) ListAlertsForRepo(ctx context.Context, owner, repo
// //
// The security alert_id is the number at the end of the security alert's URL. // The security alert_id is the number at the end of the security alert's URL.
// //
// GitHub API docs: https://developer.github.com/v3/code-scanning/#get-a-code-scanning-alert // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/code-scanning/#get-a-code-scanning-alert
func (s *CodeScanningService) GetAlert(ctx context.Context, owner, repo string, id int64) (*Alert, *Response, error) { func (s *CodeScanningService) GetAlert(ctx context.Context, owner, repo string, id int64) (*Alert, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/code-scanning/alerts/%v", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/code-scanning/alerts/%v", owner, repo, id)

View file

@ -8,7 +8,7 @@ Package github provides a client for using the GitHub API.
Usage: Usage:
import "github.com/google/go-github/v32/github" // with go modules enabled (GO111MODULE=on or outside GOPATH) import "github.com/google/go-github/v37/github" // with go modules enabled (GO111MODULE=on or outside GOPATH)
import "github.com/google/go-github/github" // with go modules disabled 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 Construct a new GitHub client, then use the various services on the client to
@ -29,7 +29,7 @@ Some API methods have optional parameters that can be passed. For example:
The services of a client divide the API into logical chunks and correspond to The services of a client divide the API into logical chunks and correspond to
the structure of the GitHub API documentation at the structure of the GitHub API documentation at
https://developer.github.com/v3/. https://docs.github.com/en/free-pro-team@latest/rest/reference/.
NOTE: Using the https://godoc.org/context package, one can easily NOTE: Using the https://godoc.org/context package, one can easily
pass cancelation signals and deadlines to various services of the client for pass cancelation signals and deadlines to various services of the client for
@ -112,7 +112,7 @@ To detect an API rate limit error, you can check if its type is *github.RateLimi
} }
Learn more about GitHub rate limiting at Learn more about GitHub rate limiting at
https://developer.github.com/v3/#rate-limiting. https://docs.github.com/en/free-pro-team@latest/rest/reference/#rate-limiting.
Accepted Status Accepted Status
@ -138,7 +138,7 @@ instead designed to work with a caching http.Transport. We recommend using
https://github.com/gregjones/httpcache for that. https://github.com/gregjones/httpcache for that.
Learn more about GitHub conditional requests at Learn more about GitHub conditional requests at
https://developer.github.com/v3/#conditional-requests. https://docs.github.com/en/free-pro-team@latest/rest/reference/#conditional-requests.
Creating and Updating Resources Creating and Updating Resources

View file

@ -0,0 +1,12 @@
// Copyright 2020 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
// EnterpriseService provides access to the enterprise related functions
// in the GitHub API.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/enterprise-admin/
type EnterpriseService service

View file

@ -0,0 +1,69 @@
// Copyright 2020 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"
)
// CreateRegistrationToken creates a token that can be used to add a self-hosted runner.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/enterprise-admin/#create-a-registration-token-for-an-enterprise
func (s *EnterpriseService) CreateRegistrationToken(ctx context.Context, enterprise string) (*RegistrationToken, *Response, error) {
u := fmt.Sprintf("enterprises/%v/actions/runners/registration-token", enterprise)
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {
return nil, nil, err
}
registrationToken := new(RegistrationToken)
resp, err := s.client.Do(ctx, req, registrationToken)
if err != nil {
return nil, resp, err
}
return registrationToken, resp, nil
}
// ListRunners lists all the self-hosted runners for a enterprise.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/enterprise-admin/#list-self-hosted-runners-for-an-enterprise
func (s *EnterpriseService) ListRunners(ctx context.Context, enterprise string, opts *ListOptions) (*Runners, *Response, error) {
u := fmt.Sprintf("enterprises/%v/actions/runners", enterprise)
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
}
runners := &Runners{}
resp, err := s.client.Do(ctx, req, &runners)
if err != nil {
return nil, resp, err
}
return runners, resp, nil
}
// RemoveRunner forces the removal of a self-hosted runner from an enterprise using the runner id.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/enterprise-admin/#delete-a-self-hosted-runner-from-an-enterprise
func (s *EnterpriseService) RemoveRunner(ctx context.Context, enterprise string, runnerID int64) (*Response, error) {
u := fmt.Sprintf("enterprises/%v/actions/runners/%v", enterprise, runnerID)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}

View file

@ -0,0 +1,35 @@
// 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"
)
// GetAuditLog gets the audit-log entries for an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/enterprise-admin#get-the-audit-log-for-an-enterprise
func (s *EnterpriseService) GetAuditLog(ctx context.Context, enterprise string, opts *GetAuditLogOptions) ([]*AuditEntry, *Response, error) {
u := fmt.Sprintf("enterprises/%v/audit-log", enterprise)
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 auditEntries []*AuditEntry
resp, err := s.client.Do(ctx, req, &auditEntries)
if err != nil {
return nil, resp, err
}
return auditEntries, resp, nil
}

View file

@ -36,6 +36,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) {
payload = &CheckSuiteEvent{} payload = &CheckSuiteEvent{}
case "CommitCommentEvent": case "CommitCommentEvent":
payload = &CommitCommentEvent{} payload = &CommitCommentEvent{}
case "ContentReferenceEvent":
payload = &ContentReferenceEvent{}
case "CreateEvent": case "CreateEvent":
payload = &CreateEvent{} payload = &CreateEvent{}
case "DeleteEvent": case "DeleteEvent":
@ -96,6 +98,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) {
payload = &PullRequestReviewEvent{} payload = &PullRequestReviewEvent{}
case "PullRequestReviewCommentEvent": case "PullRequestReviewCommentEvent":
payload = &PullRequestReviewCommentEvent{} payload = &PullRequestReviewCommentEvent{}
case "PullRequestTargetEvent":
payload = &PullRequestTargetEvent{}
case "PushEvent": case "PushEvent":
payload = &PushEvent{} payload = &PushEvent{}
case "ReleaseEvent": case "ReleaseEvent":
@ -118,6 +122,10 @@ func (e *Event) ParsePayload() (payload interface{}, err error) {
payload = &UserEvent{} payload = &UserEvent{}
case "WatchEvent": case "WatchEvent":
payload = &WatchEvent{} payload = &WatchEvent{}
case "WorkflowDispatchEvent":
payload = &WorkflowDispatchEvent{}
case "WorkflowRunEvent":
payload = &WorkflowRunEvent{}
} }
err = json.Unmarshal(*e.RawPayload, &payload) err = json.Unmarshal(*e.RawPayload, &payload)
return payload, err return payload, err

View file

@ -15,13 +15,13 @@ type RequestedAction struct {
Identifier string `json:"identifier"` // The integrator reference of the action requested by the user. Identifier string `json:"identifier"` // The integrator reference of the action requested by the user.
} }
// CheckRunEvent is triggered when a check run is "created", "updated", or "rerequested". // CheckRunEvent is triggered when a check run is "created", "completed", or "rerequested".
// The Webhook event name is "check_run". // The Webhook event name is "check_run".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#checkrunevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#check_run
type CheckRunEvent struct { type CheckRunEvent struct {
CheckRun *CheckRun `json:"check_run,omitempty"` CheckRun *CheckRun `json:"check_run,omitempty"`
// The action performed. Possible values are: "created", "updated", "rerequested" or "requested_action". // The action performed. Possible values are: "created", "completed", "rerequested" or "requested_action".
Action *string `json:"action,omitempty"` Action *string `json:"action,omitempty"`
// The following fields are only populated by Webhook events. // The following fields are only populated by Webhook events.
@ -37,7 +37,7 @@ type CheckRunEvent struct {
// CheckSuiteEvent is triggered when a check suite is "completed", "requested", or "rerequested". // CheckSuiteEvent is triggered when a check suite is "completed", "requested", or "rerequested".
// The Webhook event name is "check_suite". // The Webhook event name is "check_suite".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#checksuiteevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#check_suite
type CheckSuiteEvent struct { type CheckSuiteEvent struct {
CheckSuite *CheckSuite `json:"check_suite,omitempty"` CheckSuite *CheckSuite `json:"check_suite,omitempty"`
// The action performed. Possible values are: "completed", "requested" or "rerequested". // The action performed. Possible values are: "completed", "requested" or "rerequested".
@ -53,7 +53,7 @@ type CheckSuiteEvent struct {
// CommitCommentEvent is triggered when a commit comment is created. // CommitCommentEvent is triggered when a commit comment is created.
// The Webhook event name is "commit_comment". // The Webhook event name is "commit_comment".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#commitcommentevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#commit_comment
type CommitCommentEvent struct { type CommitCommentEvent struct {
Comment *RepositoryComment `json:"comment,omitempty"` Comment *RepositoryComment `json:"comment,omitempty"`
@ -64,6 +64,20 @@ type CommitCommentEvent struct {
Installation *Installation `json:"installation,omitempty"` Installation *Installation `json:"installation,omitempty"`
} }
// ContentReferenceEvent is triggered when the body or comment of an issue or
// pull request includes a URL that matches a configured content reference
// domain.
// The Webhook event name is "content_reference".
//
// GitHub API docs: https://developer.github.com/webhooks/event-payloads/#content_reference
type ContentReferenceEvent struct {
Action *string `json:"action,omitempty"`
ContentReference *ContentReference `json:"content_reference,omitempty"`
Repo *Repository `json:"repository,omitempty"`
Sender *User `json:"sender,omitempty"`
Installation *Installation `json:"installation,omitempty"`
}
// CreateEvent represents a created repository, branch, or tag. // CreateEvent represents a created repository, branch, or tag.
// The Webhook event name is "create". // The Webhook event name is "create".
// //
@ -71,7 +85,7 @@ type CommitCommentEvent struct {
// Additionally, webhooks will not receive this event for tags if more // Additionally, webhooks will not receive this event for tags if more
// than three tags are pushed at once. // than three tags are pushed at once.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#createevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/github-event-types#createevent
type CreateEvent struct { type CreateEvent struct {
Ref *string `json:"ref,omitempty"` Ref *string `json:"ref,omitempty"`
// RefType is the object that was created. Possible values are: "repository", "branch", "tag". // RefType is the object that was created. Possible values are: "repository", "branch", "tag".
@ -92,7 +106,7 @@ type CreateEvent struct {
// Note: webhooks will not receive this event for tags if more than three tags // Note: webhooks will not receive this event for tags if more than three tags
// are deleted at once. // are deleted at once.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#deleteevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/github-event-types#deleteevent
type DeleteEvent struct { type DeleteEvent struct {
Ref *string `json:"ref,omitempty"` Ref *string `json:"ref,omitempty"`
// RefType is the object that was deleted. Possible values are: "branch", "tag". // RefType is the object that was deleted. Possible values are: "branch", "tag".
@ -108,7 +122,7 @@ type DeleteEvent struct {
// DeployKeyEvent is triggered when a deploy key is added or removed from a repository. // DeployKeyEvent is triggered when a deploy key is added or removed from a repository.
// The Webhook event name is "deploy_key". // The Webhook event name is "deploy_key".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#deploykeyevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#deploy_key
type DeployKeyEvent struct { type DeployKeyEvent struct {
// Action is the action that was performed. Possible values are: // Action is the action that was performed. Possible values are:
// "created" or "deleted". // "created" or "deleted".
@ -123,7 +137,7 @@ type DeployKeyEvent struct {
// //
// Events of this type are not visible in timelines, they are only used to trigger hooks. // Events of this type are not visible in timelines, they are only used to trigger hooks.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#deploymentevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#deployment
type DeploymentEvent struct { type DeploymentEvent struct {
Deployment *Deployment `json:"deployment,omitempty"` Deployment *Deployment `json:"deployment,omitempty"`
Repo *Repository `json:"repository,omitempty"` Repo *Repository `json:"repository,omitempty"`
@ -138,7 +152,7 @@ type DeploymentEvent struct {
// //
// Events of this type are not visible in timelines, they are only used to trigger hooks. // Events of this type are not visible in timelines, they are only used to trigger hooks.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#deploymentstatusevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#deployment_status
type DeploymentStatusEvent struct { type DeploymentStatusEvent struct {
Deployment *Deployment `json:"deployment,omitempty"` Deployment *Deployment `json:"deployment,omitempty"`
DeploymentStatus *DeploymentStatus `json:"deployment_status,omitempty"` DeploymentStatus *DeploymentStatus `json:"deployment_status,omitempty"`
@ -152,7 +166,7 @@ type DeploymentStatusEvent struct {
// ForkEvent is triggered when a user forks a repository. // ForkEvent is triggered when a user forks a repository.
// The Webhook event name is "fork". // The Webhook event name is "fork".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#forkevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#fork
type ForkEvent struct { type ForkEvent struct {
// Forkee is the created repository. // Forkee is the created repository.
Forkee *Repository `json:"forkee,omitempty"` Forkee *Repository `json:"forkee,omitempty"`
@ -166,7 +180,7 @@ type ForkEvent struct {
// GitHubAppAuthorizationEvent is triggered when a user's authorization for a // GitHubAppAuthorizationEvent is triggered when a user's authorization for a
// GitHub Application is revoked. // GitHub Application is revoked.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#githubappauthorizationevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#github_app_authorization
type GitHubAppAuthorizationEvent struct { type GitHubAppAuthorizationEvent struct {
// The action performed. Possible value is: "revoked". // The action performed. Possible value is: "revoked".
Action *string `json:"action,omitempty"` Action *string `json:"action,omitempty"`
@ -188,7 +202,7 @@ type Page struct {
// GollumEvent is triggered when a Wiki page is created or updated. // GollumEvent is triggered when a Wiki page is created or updated.
// The Webhook event name is "gollum". // The Webhook event name is "gollum".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#gollumevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#gollum
type GollumEvent struct { type GollumEvent struct {
Pages []*Page `json:"pages,omitempty"` Pages []*Page `json:"pages,omitempty"`
@ -201,76 +215,131 @@ type GollumEvent struct {
// EditChange represents the changes when an issue, pull request, or comment has // EditChange represents the changes when an issue, pull request, or comment has
// been edited. // been edited.
type EditChange struct { type EditChange struct {
Title *struct { Title *EditTitle `json:"title,omitempty"`
From *string `json:"from,omitempty"` Body *EditBody `json:"body,omitempty"`
} `json:"title,omitempty"` Base *EditBase `json:"base,omitempty"`
Body *struct { }
From *string `json:"from,omitempty"`
} `json:"body,omitempty"` // EditTitle represents a pull-request title change.
type EditTitle struct {
From *string `json:"from,omitempty"`
}
// EditBody represents a change of pull-request body.
type EditBody struct {
From *string `json:"from,omitempty"`
}
// EditBase represents the change of a pull-request base branch.
type EditBase struct {
Ref *EditRef `json:"ref,omitempty"`
SHA *EditSHA `json:"sha,omitempty"`
}
// EditRef represents a ref change of a pull-request.
type EditRef struct {
From *string `json:"from,omitempty"`
}
// EditSHA represents a sha change of a pull-request.
type EditSHA struct {
From *string `json:"from,omitempty"`
} }
// ProjectChange represents the changes when a project has been edited. // ProjectChange represents the changes when a project has been edited.
type ProjectChange struct { type ProjectChange struct {
Name *struct { Name *ProjectName `json:"name,omitempty"`
From *string `json:"from,omitempty"` Body *ProjectBody `json:"body,omitempty"`
} `json:"name,omitempty"` }
Body *struct {
From *string `json:"from,omitempty"` // ProjectName represents a project name change.
} `json:"body,omitempty"` type ProjectName struct {
From *string `json:"from,omitempty"`
}
// ProjectBody represents a project body change.
type ProjectBody struct {
From *string `json:"from,omitempty"`
} }
// ProjectCardChange represents the changes when a project card has been edited. // ProjectCardChange represents the changes when a project card has been edited.
type ProjectCardChange struct { type ProjectCardChange struct {
Note *struct { Note *ProjectCardNote `json:"note,omitempty"`
From *string `json:"from,omitempty"` }
} `json:"note,omitempty"`
// ProjectCardNote represents a change of a note of a project card.
type ProjectCardNote struct {
From *string `json:"from,omitempty"`
} }
// ProjectColumnChange represents the changes when a project column has been edited. // ProjectColumnChange represents the changes when a project column has been edited.
type ProjectColumnChange struct { type ProjectColumnChange struct {
Name *struct { Name *ProjectColumnName `json:"name,omitempty"`
From *string `json:"from,omitempty"` }
} `json:"name,omitempty"`
// ProjectColumnName represents a project column name change.
type ProjectColumnName struct {
From *string `json:"from,omitempty"`
} }
// TeamChange represents the changes when a team has been edited. // TeamChange represents the changes when a team has been edited.
type TeamChange struct { type TeamChange struct {
Description *struct { Description *TeamDescription `json:"description,omitempty"`
From *string `json:"from,omitempty"` Name *TeamName `json:"name,omitempty"`
} `json:"description,omitempty"` Privacy *TeamPrivacy `json:"privacy,omitempty"`
Name *struct { Repository *TeamRepository `json:"repository,omitempty"`
From *string `json:"from,omitempty"`
} `json:"name,omitempty"`
Privacy *struct {
From *string `json:"from,omitempty"`
} `json:"privacy,omitempty"`
Repository *struct {
Permissions *struct {
From *struct {
Admin *bool `json:"admin,omitempty"`
Pull *bool `json:"pull,omitempty"`
Push *bool `json:"push,omitempty"`
} `json:"from,omitempty"`
} `json:"permissions,omitempty"`
} `json:"repository,omitempty"`
} }
// InstallationEvent is triggered when a GitHub App has been installed or uninstalled. // TeamDescription represents a team description change.
type TeamDescription struct {
From *string `json:"from,omitempty"`
}
// TeamName represents a team name change.
type TeamName struct {
From *string `json:"from,omitempty"`
}
// TeamPrivacy represents a team privacy change.
type TeamPrivacy struct {
From *string `json:"from,omitempty"`
}
// TeamRepository represents a team repository permission change.
type TeamRepository struct {
Permissions *TeamPermissions `json:"permissions,omitempty"`
}
// TeamPermissions represents a team permission change.
type TeamPermissions struct {
From *TeamPermissionsFrom `json:"from,omitempty"`
}
// TeamPermissionsFrom represents a team permission change.
type TeamPermissionsFrom struct {
Admin *bool `json:"admin,omitempty"`
Pull *bool `json:"pull,omitempty"`
Push *bool `json:"push,omitempty"`
}
// InstallationEvent is triggered when a GitHub App has been installed, uninstalled, suspend, unsuspended
// or new permissions have been accepted.
// The Webhook event name is "installation". // The Webhook event name is "installation".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#installationevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#installation
type InstallationEvent struct { type InstallationEvent struct {
// The action that was performed. Can be either "created" or "deleted". // The action that was performed. Can be either "created", "deleted", "suspend", "unsuspend" or "new_permissions_accepted".
Action *string `json:"action,omitempty"` Action *string `json:"action,omitempty"`
Repositories []*Repository `json:"repositories,omitempty"` Repositories []*Repository `json:"repositories,omitempty"`
Sender *User `json:"sender,omitempty"` Sender *User `json:"sender,omitempty"`
Installation *Installation `json:"installation,omitempty"` Installation *Installation `json:"installation,omitempty"`
// TODO key "requester" is not covered
} }
// InstallationRepositoriesEvent is triggered when a repository is added or // InstallationRepositoriesEvent is triggered when a repository is added or
// removed from an installation. The Webhook event name is "installation_repositories". // removed from an installation. The Webhook event name is "installation_repositories".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#installationrepositoriesevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#installation_repositories
type InstallationRepositoriesEvent struct { type InstallationRepositoriesEvent struct {
// The action that was performed. Can be either "added" or "removed". // The action that was performed. Can be either "added" or "removed".
Action *string `json:"action,omitempty"` Action *string `json:"action,omitempty"`
@ -285,7 +354,7 @@ type InstallationRepositoriesEvent struct {
// or pull request. // or pull request.
// The Webhook event name is "issue_comment". // The Webhook event name is "issue_comment".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#issuecommentevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#issue_comment
type IssueCommentEvent struct { type IssueCommentEvent struct {
// Action is the action that was performed on the comment. // Action is the action that was performed on the comment.
// Possible values are: "created", "edited", "deleted". // Possible values are: "created", "edited", "deleted".
@ -305,7 +374,7 @@ type IssueCommentEvent struct {
// locked, unlocked, milestoned, or demilestoned. // locked, unlocked, milestoned, or demilestoned.
// The Webhook event name is "issues". // The Webhook event name is "issues".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#issuesevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#issues
type IssuesEvent struct { type IssuesEvent struct {
// Action is the action that was performed. Possible values are: "opened", // Action is the action that was performed. Possible values are: "opened",
// "edited", "deleted", "transferred", "pinned", "unpinned", "closed", "reopened", // "edited", "deleted", "transferred", "pinned", "unpinned", "closed", "reopened",
@ -326,7 +395,7 @@ type IssuesEvent struct {
// LabelEvent is triggered when a repository's label is created, edited, or deleted. // LabelEvent is triggered when a repository's label is created, edited, or deleted.
// The Webhook event name is "label" // The Webhook event name is "label"
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#labelevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#label
type LabelEvent struct { type LabelEvent struct {
// Action is the action that was performed. Possible values are: // Action is the action that was performed. Possible values are:
// "created", "edited", "deleted" // "created", "edited", "deleted"
@ -344,7 +413,7 @@ type LabelEvent struct {
// their GitHub Marketplace plan. // their GitHub Marketplace plan.
// Webhook event name "marketplace_purchase". // Webhook event name "marketplace_purchase".
// //
// Github API docs: https://developer.github.com/v3/activity/events/types/#marketplacepurchaseevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#marketplace_purchase
type MarketplacePurchaseEvent struct { type MarketplacePurchaseEvent struct {
// Action is the action that was performed. Possible values are: // Action is the action that was performed. Possible values are:
// "purchased", "cancelled", "pending_change", "pending_change_cancelled", "changed". // "purchased", "cancelled", "pending_change", "pending_change_cancelled", "changed".
@ -361,7 +430,7 @@ type MarketplacePurchaseEvent struct {
// MemberEvent is triggered when a user is added as a collaborator to a repository. // MemberEvent is triggered when a user is added as a collaborator to a repository.
// The Webhook event name is "member". // The Webhook event name is "member".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#memberevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#member
type MemberEvent struct { type MemberEvent struct {
// Action is the action that was performed. Possible value is: "added". // Action is the action that was performed. Possible value is: "added".
Action *string `json:"action,omitempty"` Action *string `json:"action,omitempty"`
@ -379,7 +448,7 @@ type MemberEvent struct {
// Events of this type are not visible in timelines, they are only used to // Events of this type are not visible in timelines, they are only used to
// trigger organization webhooks. // trigger organization webhooks.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#membershipevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#membership
type MembershipEvent struct { type MembershipEvent struct {
// Action is the action that was performed. Possible values are: "added", "removed". // Action is the action that was performed. Possible values are: "added", "removed".
Action *string `json:"action,omitempty"` Action *string `json:"action,omitempty"`
@ -399,7 +468,7 @@ type MembershipEvent struct {
// Therefore, it must be selected for each hook that you'd like to receive meta events for. // Therefore, it must be selected for each hook that you'd like to receive meta events for.
// The Webhook event name is "meta". // The Webhook event name is "meta".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#metaevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#meta
type MetaEvent struct { type MetaEvent struct {
// Action is the action that was performed. Possible value is: "deleted". // Action is the action that was performed. Possible value is: "deleted".
Action *string `json:"action,omitempty"` Action *string `json:"action,omitempty"`
@ -414,7 +483,7 @@ type MetaEvent struct {
// MilestoneEvent is triggered when a milestone is created, closed, opened, edited, or deleted. // MilestoneEvent is triggered when a milestone is created, closed, opened, edited, or deleted.
// The Webhook event name is "milestone". // The Webhook event name is "milestone".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#milestoneevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#milestone
type MilestoneEvent struct { type MilestoneEvent struct {
// Action is the action that was performed. Possible values are: // Action is the action that was performed. Possible values are:
// "created", "closed", "opened", "edited", "deleted" // "created", "closed", "opened", "edited", "deleted"
@ -434,7 +503,7 @@ type MilestoneEvent struct {
// Events of this type are not visible in timelines. These events are only used to trigger organization hooks. // Events of this type are not visible in timelines. These events are only used to trigger organization hooks.
// Webhook event name is "organization". // Webhook event name is "organization".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#organizationevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#organization
type OrganizationEvent struct { type OrganizationEvent struct {
// Action is the action that was performed. // Action is the action that was performed.
// Possible values are: "deleted", "renamed", "member_added", "member_removed", or "member_invited". // Possible values are: "deleted", "renamed", "member_added", "member_removed", or "member_invited".
@ -455,7 +524,7 @@ type OrganizationEvent struct {
// OrgBlockEvent is triggered when an organization blocks or unblocks a user. // OrgBlockEvent is triggered when an organization blocks or unblocks a user.
// The Webhook event name is "org_block". // The Webhook event name is "org_block".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#orgblockevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#org_block
type OrgBlockEvent struct { type OrgBlockEvent struct {
// Action is the action that was performed. // Action is the action that was performed.
// Can be "blocked" or "unblocked". // Can be "blocked" or "unblocked".
@ -493,7 +562,7 @@ type PackageEvent struct {
// //
// Events of this type are not visible in timelines, they are only used to trigger hooks. // Events of this type are not visible in timelines, they are only used to trigger hooks.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#pagebuildevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#page_build
type PageBuildEvent struct { type PageBuildEvent struct {
Build *PagesBuild `json:"build,omitempty"` Build *PagesBuild `json:"build,omitempty"`
@ -520,7 +589,7 @@ type PingEvent struct {
// ProjectEvent is triggered when project is created, modified or deleted. // ProjectEvent is triggered when project is created, modified or deleted.
// The webhook event name is "project". // The webhook event name is "project".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#projectevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#project
type ProjectEvent struct { type ProjectEvent struct {
Action *string `json:"action,omitempty"` Action *string `json:"action,omitempty"`
Changes *ProjectChange `json:"changes,omitempty"` Changes *ProjectChange `json:"changes,omitempty"`
@ -536,7 +605,7 @@ type ProjectEvent struct {
// ProjectCardEvent is triggered when a project card is created, updated, moved, converted to an issue, or deleted. // ProjectCardEvent is triggered when a project card is created, updated, moved, converted to an issue, or deleted.
// The webhook event name is "project_card". // The webhook event name is "project_card".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#projectcardevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#project_card
type ProjectCardEvent struct { type ProjectCardEvent struct {
Action *string `json:"action,omitempty"` Action *string `json:"action,omitempty"`
Changes *ProjectCardChange `json:"changes,omitempty"` Changes *ProjectCardChange `json:"changes,omitempty"`
@ -553,7 +622,7 @@ type ProjectCardEvent struct {
// ProjectColumnEvent is triggered when a project column is created, updated, moved, or deleted. // ProjectColumnEvent is triggered when a project column is created, updated, moved, or deleted.
// The webhook event name is "project_column". // The webhook event name is "project_column".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#projectcolumnevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#project_column
type ProjectColumnEvent struct { type ProjectColumnEvent struct {
Action *string `json:"action,omitempty"` Action *string `json:"action,omitempty"`
Changes *ProjectColumnChange `json:"changes,omitempty"` Changes *ProjectColumnChange `json:"changes,omitempty"`
@ -571,7 +640,7 @@ type ProjectColumnEvent struct {
// According to GitHub: "Without a doubt: the best GitHub event." // According to GitHub: "Without a doubt: the best GitHub event."
// The Webhook event name is "public". // The Webhook event name is "public".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#publicevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#public
type PublicEvent struct { type PublicEvent struct {
// The following fields are only populated by Webhook events. // The following fields are only populated by Webhook events.
Repo *Repository `json:"repository,omitempty"` Repo *Repository `json:"repository,omitempty"`
@ -584,7 +653,7 @@ type PublicEvent struct {
// locked, unlocked, a pull request review is requested, or a review request is removed. // locked, unlocked, a pull request review is requested, or a review request is removed.
// The Webhook event name is "pull_request". // The Webhook event name is "pull_request".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#pullrequestevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/github-event-types#pullrequestevent
type PullRequestEvent struct { type PullRequestEvent struct {
// Action is the action that was performed. Possible values are: // Action is the action that was performed. Possible values are:
// "assigned", "unassigned", "review_requested", "review_request_removed", "labeled", "unlabeled", // "assigned", "unassigned", "review_requested", "review_request_removed", "labeled", "unlabeled",
@ -625,7 +694,7 @@ type PullRequestEvent struct {
// request. // request.
// The Webhook event name is "pull_request_review". // The Webhook event name is "pull_request_review".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#pullrequestreviewevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#pull_request_review
type PullRequestReviewEvent struct { type PullRequestReviewEvent struct {
// Action is always "submitted". // Action is always "submitted".
Action *string `json:"action,omitempty"` Action *string `json:"action,omitempty"`
@ -646,7 +715,7 @@ type PullRequestReviewEvent struct {
// portion of the unified diff of a pull request. // portion of the unified diff of a pull request.
// The Webhook event name is "pull_request_review_comment". // The Webhook event name is "pull_request_review_comment".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#pullrequestreviewcommentevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#pull_request_review_comment
type PullRequestReviewCommentEvent struct { type PullRequestReviewCommentEvent struct {
// Action is the action that was performed on the comment. // Action is the action that was performed on the comment.
// Possible values are: "created", "edited", "deleted". // Possible values are: "created", "edited", "deleted".
@ -661,9 +730,51 @@ type PullRequestReviewCommentEvent struct {
Installation *Installation `json:"installation,omitempty"` Installation *Installation `json:"installation,omitempty"`
} }
// PullRequestTargetEvent is triggered when a pull request is assigned, unassigned, labeled,
// unlabeled, opened, edited, closed, reopened, synchronize, ready_for_review,
// locked, unlocked, a pull request review is requested, or a review request is removed.
// The Webhook event name is "pull_request_target".
//
// GitHub API docs: https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target
type PullRequestTargetEvent struct {
// Action is the action that was performed. Possible values are:
// "assigned", "unassigned", "labeled", "unlabeled", "opened", "edited", "closed", "reopened",
// "ready_for_review", "locked", "unlocked", "review_requested" or "review_request_removed".
// If the action is "closed" and the "merged" key is "false", the pull request was closed with unmerged commits.
// If the action is "closed" and the "merged" key is "true", the pull request was merged.
// While webhooks are also triggered when a pull request is synchronized, Events API timelines
// don't include pull request events with the "synchronize" action.
Action *string `json:"action,omitempty"`
Assignee *User `json:"assignee,omitempty"`
Number *int `json:"number,omitempty"`
PullRequest *PullRequest `json:"pull_request,omitempty"`
// The following fields are only populated by Webhook events.
Changes *EditChange `json:"changes,omitempty"`
// RequestedReviewer is populated in "review_requested", "review_request_removed" event deliveries.
// A request affecting multiple reviewers at once is split into multiple
// such event deliveries, each with a single, different RequestedReviewer.
RequestedReviewer *User `json:"requested_reviewer,omitempty"`
// In the event that a team is requested instead of a user, "requested_team" gets sent in place of
// "requested_user" with the same delivery behavior.
RequestedTeam *Team `json:"requested_team,omitempty"`
Repo *Repository `json:"repository,omitempty"`
Sender *User `json:"sender,omitempty"`
Installation *Installation `json:"installation,omitempty"`
Label *Label `json:"label,omitempty"` // Populated in "labeled" event deliveries.
// The following field is only present when the webhook is triggered on
// a repository belonging to an organization.
Organization *Organization `json:"organization,omitempty"`
// The following fields are only populated when the Action is "synchronize".
Before *string `json:"before,omitempty"`
After *string `json:"after,omitempty"`
}
// PushEvent represents a git push to a GitHub repository. // PushEvent represents a git push to a GitHub repository.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#pushevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#push
type PushEvent struct { type PushEvent struct {
PushID *int64 `json:"push_id,omitempty"` PushID *int64 `json:"push_id,omitempty"`
Head *string `json:"head,omitempty"` Head *string `json:"head,omitempty"`
@ -765,7 +876,7 @@ type PushEventRepoOwner struct {
// edited, deleted, or prereleased. // edited, deleted, or prereleased.
// The Webhook event name is "release". // The Webhook event name is "release".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#releaseevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#release
type ReleaseEvent struct { type ReleaseEvent struct {
// Action is the action that was performed. Possible values are: "published", "unpublished", // Action is the action that was performed. Possible values are: "published", "unpublished",
// "created", "edited", "deleted", or "prereleased". // "created", "edited", "deleted", or "prereleased".
@ -786,7 +897,7 @@ type ReleaseEvent struct {
// Events of this type are not visible in timelines, they are only used to // Events of this type are not visible in timelines, they are only used to
// trigger organization webhooks. // trigger organization webhooks.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#repositoryevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#repository
type RepositoryEvent struct { type RepositoryEvent struct {
// Action is the action that was performed. Possible values are: "created", // Action is the action that was performed. Possible values are: "created",
// "deleted" (organization hooks only), "archived", "unarchived", "edited", "renamed", // "deleted" (organization hooks only), "archived", "unarchived", "edited", "renamed",
@ -802,7 +913,7 @@ type RepositoryEvent struct {
// RepositoryDispatchEvent is triggered when a client sends a POST request to the repository dispatch event endpoint. // RepositoryDispatchEvent is triggered when a client sends a POST request to the repository dispatch event endpoint.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#repositorydispatchevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#repository_dispatch
type RepositoryDispatchEvent struct { type RepositoryDispatchEvent struct {
// Action is the event_type that submitted with the repository dispatch payload. Value can be any string. // Action is the event_type that submitted with the repository dispatch payload. Value can be any string.
Action *string `json:"action,omitempty"` Action *string `json:"action,omitempty"`
@ -818,38 +929,49 @@ type RepositoryDispatchEvent struct {
// RepositoryVulnerabilityAlertEvent is triggered when a security alert is created, dismissed, or resolved. // RepositoryVulnerabilityAlertEvent is triggered when a security alert is created, dismissed, or resolved.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#repositoryvulnerabilityalertevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#repository_vulnerability_alert
type RepositoryVulnerabilityAlertEvent struct { type RepositoryVulnerabilityAlertEvent struct {
// Action is the action that was performed. Possible values are: "create", "dismiss", "resolve". // Action is the action that was performed. Possible values are: "create", "dismiss", "resolve".
Action *string `json:"action,omitempty"` Action *string `json:"action,omitempty"`
//The security alert of the vulnerable dependency. //The security alert of the vulnerable dependency.
Alert *struct { Alert *RepositoryVulnerabilityAlert `json:"alert,omitempty"`
ID *int64 `json:"id,omitempty"`
AffectedRange *string `json:"affected_range,omitempty"`
AffectedPackageName *string `json:"affected_package_name,omitempty"`
ExternalReference *string `json:"external_reference,omitempty"`
ExternalIdentifier *string `json:"external_identifier,omitempty"`
FixedIn *string `json:"fixed_in,omitempty"`
Dismisser *User `json:"dismisser,omitempty"`
DismissReason *string `json:"dismiss_reason,omitempty"`
DismissedAt *Timestamp `json:"dismissed_at,omitempty"`
} `json:"alert,omitempty"`
//The repository of the vulnerable dependency. //The repository of the vulnerable dependency.
Repository *Repository `json:"repository,omitempty"` Repository *Repository `json:"repository,omitempty"`
} }
// RepositoryVulnerabilityAlert represents a repository security alert.
type RepositoryVulnerabilityAlert struct {
ID *int64 `json:"id,omitempty"`
AffectedRange *string `json:"affected_range,omitempty"`
AffectedPackageName *string `json:"affected_package_name,omitempty"`
ExternalReference *string `json:"external_reference,omitempty"`
ExternalIdentifier *string `json:"external_identifier,omitempty"`
GitHubSecurityAdvisoryID *string `json:"ghsa_id,omitempty"`
Severity *string `json:"severity,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
FixedIn *string `json:"fixed_in,omitempty"`
Dismisser *User `json:"dismisser,omitempty"`
DismissReason *string `json:"dismiss_reason,omitempty"`
DismissedAt *Timestamp `json:"dismissed_at,omitempty"`
}
// StarEvent is triggered when a star is added or removed from a repository. // StarEvent is triggered when a star is added or removed from a repository.
// The Webhook event name is "star". // The Webhook event name is "star".
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#starevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#star
type StarEvent struct { type StarEvent struct {
// Action is the action that was performed. Possible values are: "created" or "deleted". // Action is the action that was performed. Possible values are: "created" or "deleted".
Action *string `json:"action,omitempty"` Action *string `json:"action,omitempty"`
// StarredAt is the time the star was created. It will be null for the "deleted" action. // StarredAt is the time the star was created. It will be null for the "deleted" action.
StarredAt *Timestamp `json:"starred_at,omitempty"` 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"`
} }
// StatusEvent is triggered when the status of a Git commit changes. // StatusEvent is triggered when the status of a Git commit changes.
@ -858,7 +980,7 @@ type StarEvent struct {
// Events of this type are not visible in timelines, they are only used to // Events of this type are not visible in timelines, they are only used to
// trigger hooks. // trigger hooks.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#statusevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#status
type StatusEvent struct { type StatusEvent struct {
SHA *string `json:"sha,omitempty"` SHA *string `json:"sha,omitempty"`
// State is the new state. Possible values are: "pending", "success", "failure", "error". // State is the new state. Possible values are: "pending", "success", "failure", "error".
@ -885,7 +1007,7 @@ type StatusEvent struct {
// Events of this type are not visible in timelines. These events are only used // Events of this type are not visible in timelines. These events are only used
// to trigger hooks. // to trigger hooks.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#teamevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#team
type TeamEvent struct { type TeamEvent struct {
Action *string `json:"action,omitempty"` Action *string `json:"action,omitempty"`
Team *Team `json:"team,omitempty"` Team *Team `json:"team,omitempty"`
@ -904,7 +1026,7 @@ type TeamEvent struct {
// Events of this type are not visible in timelines. These events are only used // Events of this type are not visible in timelines. These events are only used
// to trigger hooks. // to trigger hooks.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#teamaddevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#team_add
type TeamAddEvent struct { type TeamAddEvent struct {
Team *Team `json:"team,omitempty"` Team *Team `json:"team,omitempty"`
Repo *Repository `json:"repository,omitempty"` Repo *Repository `json:"repository,omitempty"`
@ -935,7 +1057,7 @@ type UserEvent struct {
// The events actor is the user who starred a repository, and the events // The events actor is the user who starred a repository, and the events
// repository is the repository that was starred. // repository is the repository that was starred.
// //
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#watchevent // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#watch
type WatchEvent struct { type WatchEvent struct {
// Action is the action that was performed. Possible value is: "started". // Action is the action that was performed. Possible value is: "started".
Action *string `json:"action,omitempty"` Action *string `json:"action,omitempty"`
@ -945,3 +1067,32 @@ type WatchEvent struct {
Sender *User `json:"sender,omitempty"` Sender *User `json:"sender,omitempty"`
Installation *Installation `json:"installation,omitempty"` Installation *Installation `json:"installation,omitempty"`
} }
// WorkflowDispatchEvent is triggered when someone triggers a workflow run on GitHub or
// sends a POST request to the create a workflow dispatch event endpoint.
//
// GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#workflow_dispatch
type WorkflowDispatchEvent struct {
Inputs json.RawMessage `json:"inputs,omitempty"`
Ref *string `json:"ref,omitempty"`
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"`
}
// WorkflowRunEvent is triggered when a GitHub Actions workflow run is requested or completed.
//
// GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#workflow_run
type WorkflowRunEvent struct {
Action *string `json:"action,omitempty"`
Workflow *Workflow `json:"workflow,omitempty"`
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"`
}

View file

@ -14,7 +14,7 @@ import (
// GistsService handles communication with the Gist related // GistsService handles communication with the Gist related
// methods of the GitHub API. // methods of the GitHub API.
// //
// GitHub API docs: https://developer.github.com/v3/gists/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/
type GistsService service type GistsService service
// Gist represents a GitHub's gist. // Gist represents a GitHub's gist.
@ -96,8 +96,8 @@ type GistListOptions struct {
// is authenticated, it will returns all gists for the authenticated // is authenticated, it will returns all gists for the authenticated
// user. // user.
// //
// GitHub API docs: https://developer.github.com/v3/gists/#list-gists-for-a-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#list-gists-for-the-authenticated-user
// GitHub API docs: https://developer.github.com/v3/gists/#list-gists-for-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#list-gists-for-a-user
func (s *GistsService) List(ctx context.Context, user string, opts *GistListOptions) ([]*Gist, *Response, error) { func (s *GistsService) List(ctx context.Context, user string, opts *GistListOptions) ([]*Gist, *Response, error) {
var u string var u string
if user != "" { if user != "" {
@ -126,7 +126,7 @@ func (s *GistsService) List(ctx context.Context, user string, opts *GistListOpti
// ListAll lists all public gists. // ListAll lists all public gists.
// //
// GitHub API docs: https://developer.github.com/v3/gists/#list-public-gists // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#list-public-gists
func (s *GistsService) ListAll(ctx context.Context, opts *GistListOptions) ([]*Gist, *Response, error) { func (s *GistsService) ListAll(ctx context.Context, opts *GistListOptions) ([]*Gist, *Response, error) {
u, err := addOptions("gists/public", opts) u, err := addOptions("gists/public", opts)
if err != nil { if err != nil {
@ -149,7 +149,7 @@ func (s *GistsService) ListAll(ctx context.Context, opts *GistListOptions) ([]*G
// ListStarred lists starred gists of authenticated user. // ListStarred lists starred gists of authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/gists/#list-starred-gists // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#list-starred-gists
func (s *GistsService) ListStarred(ctx context.Context, opts *GistListOptions) ([]*Gist, *Response, error) { func (s *GistsService) ListStarred(ctx context.Context, opts *GistListOptions) ([]*Gist, *Response, error) {
u, err := addOptions("gists/starred", opts) u, err := addOptions("gists/starred", opts)
if err != nil { if err != nil {
@ -172,7 +172,7 @@ func (s *GistsService) ListStarred(ctx context.Context, opts *GistListOptions) (
// Get a single gist. // Get a single gist.
// //
// GitHub API docs: https://developer.github.com/v3/gists/#get-a-gist // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#get-a-gist
func (s *GistsService) Get(ctx context.Context, id string) (*Gist, *Response, error) { func (s *GistsService) Get(ctx context.Context, id string) (*Gist, *Response, error) {
u := fmt.Sprintf("gists/%v", id) u := fmt.Sprintf("gists/%v", id)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -191,7 +191,7 @@ func (s *GistsService) Get(ctx context.Context, id string) (*Gist, *Response, er
// GetRevision gets a specific revision of a gist. // GetRevision gets a specific revision of a gist.
// //
// GitHub API docs: https://developer.github.com/v3/gists/#get-a-gist-revision // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#get-a-gist-revision
func (s *GistsService) GetRevision(ctx context.Context, id, sha string) (*Gist, *Response, error) { func (s *GistsService) GetRevision(ctx context.Context, id, sha string) (*Gist, *Response, error) {
u := fmt.Sprintf("gists/%v/%v", id, sha) u := fmt.Sprintf("gists/%v/%v", id, sha)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -210,7 +210,7 @@ func (s *GistsService) GetRevision(ctx context.Context, id, sha string) (*Gist,
// Create a gist for authenticated user. // Create a gist for authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/gists/#create-a-gist // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#create-a-gist
func (s *GistsService) Create(ctx context.Context, gist *Gist) (*Gist, *Response, error) { func (s *GistsService) Create(ctx context.Context, gist *Gist) (*Gist, *Response, error) {
u := "gists" u := "gists"
req, err := s.client.NewRequest("POST", u, gist) req, err := s.client.NewRequest("POST", u, gist)
@ -229,7 +229,7 @@ func (s *GistsService) Create(ctx context.Context, gist *Gist) (*Gist, *Response
// Edit a gist. // Edit a gist.
// //
// GitHub API docs: https://developer.github.com/v3/gists/#update-a-gist // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#update-a-gist
func (s *GistsService) Edit(ctx context.Context, id string, gist *Gist) (*Gist, *Response, error) { func (s *GistsService) Edit(ctx context.Context, id string, gist *Gist) (*Gist, *Response, error) {
u := fmt.Sprintf("gists/%v", id) u := fmt.Sprintf("gists/%v", id)
req, err := s.client.NewRequest("PATCH", u, gist) req, err := s.client.NewRequest("PATCH", u, gist)
@ -248,7 +248,7 @@ func (s *GistsService) Edit(ctx context.Context, id string, gist *Gist) (*Gist,
// ListCommits lists commits of a gist. // ListCommits lists commits of a gist.
// //
// GitHub API docs: https://developer.github.com/v3/gists/#list-gist-commits // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#list-gist-commits
func (s *GistsService) ListCommits(ctx context.Context, id string, opts *ListOptions) ([]*GistCommit, *Response, error) { func (s *GistsService) ListCommits(ctx context.Context, id string, opts *ListOptions) ([]*GistCommit, *Response, error) {
u := fmt.Sprintf("gists/%v/commits", id) u := fmt.Sprintf("gists/%v/commits", id)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -272,7 +272,7 @@ func (s *GistsService) ListCommits(ctx context.Context, id string, opts *ListOpt
// Delete a gist. // Delete a gist.
// //
// GitHub API docs: https://developer.github.com/v3/gists/#delete-a-gist // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#delete-a-gist
func (s *GistsService) Delete(ctx context.Context, id string) (*Response, error) { func (s *GistsService) Delete(ctx context.Context, id string) (*Response, error) {
u := fmt.Sprintf("gists/%v", id) u := fmt.Sprintf("gists/%v", id)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -284,7 +284,7 @@ func (s *GistsService) Delete(ctx context.Context, id string) (*Response, error)
// Star a gist on behalf of authenticated user. // Star a gist on behalf of authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/gists/#star-a-gist // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#star-a-gist
func (s *GistsService) Star(ctx context.Context, id string) (*Response, error) { func (s *GistsService) Star(ctx context.Context, id string) (*Response, error) {
u := fmt.Sprintf("gists/%v/star", id) u := fmt.Sprintf("gists/%v/star", id)
req, err := s.client.NewRequest("PUT", u, nil) req, err := s.client.NewRequest("PUT", u, nil)
@ -296,7 +296,7 @@ func (s *GistsService) Star(ctx context.Context, id string) (*Response, error) {
// Unstar a gist on a behalf of authenticated user. // Unstar a gist on a behalf of authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/gists/#unstar-a-gist // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#unstar-a-gist
func (s *GistsService) Unstar(ctx context.Context, id string) (*Response, error) { func (s *GistsService) Unstar(ctx context.Context, id string) (*Response, error) {
u := fmt.Sprintf("gists/%v/star", id) u := fmt.Sprintf("gists/%v/star", id)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -308,7 +308,7 @@ func (s *GistsService) Unstar(ctx context.Context, id string) (*Response, error)
// IsStarred checks if a gist is starred by authenticated user. // IsStarred checks if a gist is starred by authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/gists/#check-if-a-gist-is-starred // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#check-if-a-gist-is-starred
func (s *GistsService) IsStarred(ctx context.Context, id string) (bool, *Response, error) { func (s *GistsService) IsStarred(ctx context.Context, id string) (bool, *Response, error) {
u := fmt.Sprintf("gists/%v/star", id) u := fmt.Sprintf("gists/%v/star", id)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -322,7 +322,7 @@ func (s *GistsService) IsStarred(ctx context.Context, id string) (bool, *Respons
// Fork a gist. // Fork a gist.
// //
// GitHub API docs: https://developer.github.com/v3/gists/#fork-a-gist // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#fork-a-gist
func (s *GistsService) Fork(ctx context.Context, id string) (*Gist, *Response, error) { func (s *GistsService) Fork(ctx context.Context, id string) (*Gist, *Response, error) {
u := fmt.Sprintf("gists/%v/forks", id) u := fmt.Sprintf("gists/%v/forks", id)
req, err := s.client.NewRequest("POST", u, nil) req, err := s.client.NewRequest("POST", u, nil)
@ -341,7 +341,7 @@ func (s *GistsService) Fork(ctx context.Context, id string) (*Gist, *Response, e
// ListForks lists forks of a gist. // ListForks lists forks of a gist.
// //
// GitHub API docs: https://developer.github.com/v3/gists/#list-gist-forks // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#list-gist-forks
func (s *GistsService) ListForks(ctx context.Context, id string, opts *ListOptions) ([]*GistFork, *Response, error) { func (s *GistsService) ListForks(ctx context.Context, id string, opts *ListOptions) ([]*GistFork, *Response, error) {
u := fmt.Sprintf("gists/%v/forks", id) u := fmt.Sprintf("gists/%v/forks", id)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)

View file

@ -26,7 +26,7 @@ func (g GistComment) String() string {
// ListComments lists all comments for a gist. // ListComments lists all comments for a gist.
// //
// GitHub API docs: https://developer.github.com/v3/gists/comments/#list-gist-comments // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#list-gist-comments
func (s *GistsService) ListComments(ctx context.Context, gistID string, opts *ListOptions) ([]*GistComment, *Response, error) { func (s *GistsService) ListComments(ctx context.Context, gistID string, opts *ListOptions) ([]*GistComment, *Response, error) {
u := fmt.Sprintf("gists/%v/comments", gistID) u := fmt.Sprintf("gists/%v/comments", gistID)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -50,7 +50,7 @@ func (s *GistsService) ListComments(ctx context.Context, gistID string, opts *Li
// GetComment retrieves a single comment from a gist. // GetComment retrieves a single comment from a gist.
// //
// GitHub API docs: https://developer.github.com/v3/gists/comments/#get-a-gist-comment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#get-a-gist-comment
func (s *GistsService) GetComment(ctx context.Context, gistID string, commentID int64) (*GistComment, *Response, error) { func (s *GistsService) GetComment(ctx context.Context, gistID string, commentID int64) (*GistComment, *Response, error) {
u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID) u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -69,7 +69,7 @@ func (s *GistsService) GetComment(ctx context.Context, gistID string, commentID
// CreateComment creates a comment for a gist. // CreateComment creates a comment for a gist.
// //
// GitHub API docs: https://developer.github.com/v3/gists/comments/#create-a-gist-comment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#create-a-gist-comment
func (s *GistsService) CreateComment(ctx context.Context, gistID string, comment *GistComment) (*GistComment, *Response, error) { func (s *GistsService) CreateComment(ctx context.Context, gistID string, comment *GistComment) (*GistComment, *Response, error) {
u := fmt.Sprintf("gists/%v/comments", gistID) u := fmt.Sprintf("gists/%v/comments", gistID)
req, err := s.client.NewRequest("POST", u, comment) req, err := s.client.NewRequest("POST", u, comment)
@ -88,7 +88,7 @@ func (s *GistsService) CreateComment(ctx context.Context, gistID string, comment
// EditComment edits an existing gist comment. // EditComment edits an existing gist comment.
// //
// GitHub API docs: https://developer.github.com/v3/gists/comments/#update-a-gist-comment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#update-a-gist-comment
func (s *GistsService) EditComment(ctx context.Context, gistID string, commentID int64, comment *GistComment) (*GistComment, *Response, error) { func (s *GistsService) EditComment(ctx context.Context, gistID string, commentID int64, comment *GistComment) (*GistComment, *Response, error) {
u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID) u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID)
req, err := s.client.NewRequest("PATCH", u, comment) req, err := s.client.NewRequest("PATCH", u, comment)
@ -107,7 +107,7 @@ func (s *GistsService) EditComment(ctx context.Context, gistID string, commentID
// DeleteComment deletes a gist comment. // DeleteComment deletes a gist comment.
// //
// GitHub API docs: https://developer.github.com/v3/gists/comments/#delete-a-gist-comment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#delete-a-gist-comment
func (s *GistsService) DeleteComment(ctx context.Context, gistID string, commentID int64) (*Response, error) { func (s *GistsService) DeleteComment(ctx context.Context, gistID string, commentID int64) (*Response, error) {
u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID) u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)

View file

@ -8,5 +8,5 @@ package github
// GitService handles communication with the git data related // GitService handles communication with the git data related
// methods of the GitHub API. // methods of the GitHub API.
// //
// GitHub API docs: https://developer.github.com/v3/git/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/git/
type GitService service type GitService service

View file

@ -23,7 +23,7 @@ type Blob struct {
// GetBlob fetches a blob from a repo given a SHA. // GetBlob fetches a blob from a repo given a SHA.
// //
// GitHub API docs: https://developer.github.com/v3/git/blobs/#get-a-blob // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/git/#get-a-blob
func (s *GitService) GetBlob(ctx context.Context, owner string, repo string, sha string) (*Blob, *Response, error) { func (s *GitService) GetBlob(ctx context.Context, owner string, repo string, sha string) (*Blob, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/blobs/%v", owner, repo, sha) u := fmt.Sprintf("repos/%v/%v/git/blobs/%v", owner, repo, sha)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -39,7 +39,7 @@ func (s *GitService) GetBlob(ctx context.Context, owner string, repo string, sha
// GetBlobRaw fetches a blob's contents from a repo. // GetBlobRaw fetches a blob's contents from a repo.
// Unlike GetBlob, it returns the raw bytes rather than the base64-encoded data. // Unlike GetBlob, it returns the raw bytes rather than the base64-encoded data.
// //
// GitHub API docs: https://developer.github.com/v3/git/blobs/#get-a-blob // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/git/#get-a-blob
func (s *GitService) GetBlobRaw(ctx context.Context, owner, repo, sha string) ([]byte, *Response, error) { func (s *GitService) GetBlobRaw(ctx context.Context, owner, repo, sha string) ([]byte, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/blobs/%v", owner, repo, sha) u := fmt.Sprintf("repos/%v/%v/git/blobs/%v", owner, repo, sha)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -55,7 +55,7 @@ func (s *GitService) GetBlobRaw(ctx context.Context, owner, repo, sha string) ([
// CreateBlob creates a blob object. // CreateBlob creates a blob object.
// //
// GitHub API docs: https://developer.github.com/v3/git/blobs/#create-a-blob // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/git/#create-a-blob
func (s *GitService) CreateBlob(ctx context.Context, owner string, repo string, blob *Blob) (*Blob, *Response, error) { func (s *GitService) CreateBlob(ctx context.Context, owner string, repo string, blob *Blob) (*Blob, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/blobs", owner, repo) u := fmt.Sprintf("repos/%v/%v/git/blobs", owner, repo)
req, err := s.client.NewRequest("POST", u, blob) req, err := s.client.NewRequest("POST", u, blob)

View file

@ -70,7 +70,7 @@ func (c CommitAuthor) String() string {
// GetCommit fetches the Commit object for a given SHA. // GetCommit fetches the Commit object for a given SHA.
// //
// GitHub API docs: https://developer.github.com/v3/git/commits/#get-a-commit // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/git/#get-a-commit
func (s *GitService) GetCommit(ctx context.Context, owner string, repo string, sha string) (*Commit, *Response, error) { func (s *GitService) GetCommit(ctx context.Context, owner string, repo string, sha string) (*Commit, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/commits/%v", owner, repo, sha) u := fmt.Sprintf("repos/%v/%v/git/commits/%v", owner, repo, sha)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -104,7 +104,7 @@ type createCommit struct {
// data if omitted. If the commit.Author is omitted, it will be filled in with // data if omitted. If the commit.Author is omitted, it will be filled in with
// the authenticated users information and the current date. // the authenticated users information and the current date.
// //
// GitHub API docs: https://developer.github.com/v3/git/commits/#create-a-commit // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/git/#create-a-commit
func (s *GitService) CreateCommit(ctx context.Context, owner string, repo string, commit *Commit) (*Commit, *Response, error) { func (s *GitService) CreateCommit(ctx context.Context, owner string, repo string, commit *Commit) (*Commit, *Response, error) {
if commit == nil { if commit == nil {
return nil, nil, fmt.Errorf("commit must be provided") return nil, nil, fmt.Errorf("commit must be provided")

View file

@ -49,7 +49,7 @@ type updateRefRequest struct {
// GetRef fetches a single reference in a repository. // GetRef fetches a single reference in a repository.
// //
// GitHub API docs: https://developer.github.com/v3/git/refs/#get-a-reference // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/git/#get-a-reference
func (s *GitService) GetRef(ctx context.Context, owner string, repo string, ref string) (*Reference, *Response, error) { func (s *GitService) GetRef(ctx context.Context, owner string, repo string, ref string) (*Reference, *Response, error) {
ref = strings.TrimPrefix(ref, "refs/") ref = strings.TrimPrefix(ref, "refs/")
u := fmt.Sprintf("repos/%v/%v/git/ref/%v", owner, repo, refURLEscape(ref)) u := fmt.Sprintf("repos/%v/%v/git/ref/%v", owner, repo, refURLEscape(ref))
@ -88,7 +88,7 @@ type ReferenceListOptions struct {
// ListMatchingRefs lists references in a repository that match a supplied ref. // ListMatchingRefs lists references in a repository that match a supplied ref.
// Use an empty ref to list all references. // Use an empty ref to list all references.
// //
// GitHub API docs: https://developer.github.com/v3/git/refs/#list-matching-references // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/git/#list-matching-references
func (s *GitService) ListMatchingRefs(ctx context.Context, owner, repo string, opts *ReferenceListOptions) ([]*Reference, *Response, error) { func (s *GitService) ListMatchingRefs(ctx context.Context, owner, repo string, opts *ReferenceListOptions) ([]*Reference, *Response, error) {
var ref string var ref string
if opts != nil { if opts != nil {
@ -116,7 +116,7 @@ func (s *GitService) ListMatchingRefs(ctx context.Context, owner, repo string, o
// CreateRef creates a new ref in a repository. // CreateRef creates a new ref in a repository.
// //
// GitHub API docs: https://developer.github.com/v3/git/refs/#create-a-reference // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/git/#create-a-reference
func (s *GitService) CreateRef(ctx context.Context, owner string, repo string, ref *Reference) (*Reference, *Response, error) { func (s *GitService) CreateRef(ctx context.Context, owner string, repo string, ref *Reference) (*Reference, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/refs", owner, repo) u := fmt.Sprintf("repos/%v/%v/git/refs", owner, repo)
req, err := s.client.NewRequest("POST", u, &createRefRequest{ req, err := s.client.NewRequest("POST", u, &createRefRequest{
@ -139,7 +139,7 @@ func (s *GitService) CreateRef(ctx context.Context, owner string, repo string, r
// UpdateRef updates an existing ref in a repository. // UpdateRef updates an existing ref in a repository.
// //
// GitHub API docs: https://developer.github.com/v3/git/refs/#update-a-reference // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/git/#update-a-reference
func (s *GitService) UpdateRef(ctx context.Context, owner string, repo string, ref *Reference, force bool) (*Reference, *Response, error) { func (s *GitService) UpdateRef(ctx context.Context, owner string, repo string, ref *Reference, force bool) (*Reference, *Response, error) {
refPath := strings.TrimPrefix(*ref.Ref, "refs/") refPath := strings.TrimPrefix(*ref.Ref, "refs/")
u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, refPath) u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, refPath)
@ -162,7 +162,7 @@ func (s *GitService) UpdateRef(ctx context.Context, owner string, repo string, r
// DeleteRef deletes a ref from a repository. // DeleteRef deletes a ref from a repository.
// //
// GitHub API docs: https://developer.github.com/v3/git/refs/#delete-a-reference // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/git/#delete-a-reference
func (s *GitService) DeleteRef(ctx context.Context, owner string, repo string, ref string) (*Response, error) { func (s *GitService) DeleteRef(ctx context.Context, owner string, repo string, ref string) (*Response, error) {
ref = strings.TrimPrefix(ref, "refs/") ref = strings.TrimPrefix(ref, "refs/")
u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, refURLEscape(ref)) u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, refURLEscape(ref))

View file

@ -35,7 +35,7 @@ type createTagRequest struct {
// GetTag fetches a tag from a repo given a SHA. // GetTag fetches a tag from a repo given a SHA.
// //
// GitHub API docs: https://developer.github.com/v3/git/tags/#get-a-tag // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/git/#get-a-tag
func (s *GitService) GetTag(ctx context.Context, owner string, repo string, sha string) (*Tag, *Response, error) { func (s *GitService) GetTag(ctx context.Context, owner string, repo string, sha string) (*Tag, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/tags/%v", owner, repo, sha) u := fmt.Sprintf("repos/%v/%v/git/tags/%v", owner, repo, sha)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -50,7 +50,7 @@ func (s *GitService) GetTag(ctx context.Context, owner string, repo string, sha
// CreateTag creates a tag object. // CreateTag creates a tag object.
// //
// GitHub API docs: https://developer.github.com/v3/git/tags/#create-a-tag-object // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/git/#create-a-tag-object
func (s *GitService) CreateTag(ctx context.Context, owner string, repo string, tag *Tag) (*Tag, *Response, error) { func (s *GitService) CreateTag(ctx context.Context, owner string, repo string, tag *Tag) (*Tag, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/tags", owner, repo) u := fmt.Sprintf("repos/%v/%v/git/tags", owner, repo)

View file

@ -93,7 +93,7 @@ func (t *TreeEntry) MarshalJSON() ([]byte, error) {
// GetTree fetches the Tree object for a given sha hash from a repository. // GetTree fetches the Tree object for a given sha hash from a repository.
// //
// GitHub API docs: https://developer.github.com/v3/git/trees/#get-a-tree // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/git/#get-a-tree
func (s *GitService) GetTree(ctx context.Context, owner string, repo string, sha string, recursive bool) (*Tree, *Response, error) { func (s *GitService) GetTree(ctx context.Context, owner string, repo string, sha string, recursive bool) (*Tree, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/trees/%v", owner, repo, sha) u := fmt.Sprintf("repos/%v/%v/git/trees/%v", owner, repo, sha)
if recursive { if recursive {
@ -124,7 +124,7 @@ type createTree struct {
// path modifying that tree are specified, it will overwrite the contents of // path modifying that tree are specified, it will overwrite the contents of
// that tree with the new path contents and write a new tree out. // that tree with the new path contents and write a new tree out.
// //
// GitHub API docs: https://developer.github.com/v3/git/trees/#create-a-tree // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/git/#create-a-tree
func (s *GitService) CreateTree(ctx context.Context, owner string, repo string, baseTree string, entries []*TreeEntry) (*Tree, *Response, error) { func (s *GitService) CreateTree(ctx context.Context, owner string, repo string, baseTree string, entries []*TreeEntry) (*Tree, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/trees", owner, repo) u := fmt.Sprintf("repos/%v/%v/git/trees", owner, repo)

View file

@ -43,6 +43,7 @@ const (
mediaTypeV3Diff = "application/vnd.github.v3.diff" mediaTypeV3Diff = "application/vnd.github.v3.diff"
mediaTypeV3Patch = "application/vnd.github.v3.patch" mediaTypeV3Patch = "application/vnd.github.v3.patch"
mediaTypeOrgPermissionRepo = "application/vnd.github.v3.repository+json" mediaTypeOrgPermissionRepo = "application/vnd.github.v3.repository+json"
mediaTypeIssueImportAPI = "application/vnd.github.golden-comet-preview+json"
// Media Type values to access preview APIs // Media Type values to access preview APIs
@ -67,9 +68,6 @@ const (
// https://developer.github.com/changes/2016-09-14-projects-api/ // https://developer.github.com/changes/2016-09-14-projects-api/
mediaTypeProjectsPreview = "application/vnd.github.inertia-preview+json" mediaTypeProjectsPreview = "application/vnd.github.inertia-preview+json"
// https://developer.github.com/changes/2016-09-14-Integrations-Early-Access/
mediaTypeIntegrationPreview = "application/vnd.github.machine-man-preview+json"
// https://developer.github.com/changes/2017-01-05-commit-search-api/ // https://developer.github.com/changes/2017-01-05-commit-search-api/
mediaTypeCommitSearchPreview = "application/vnd.github.cloak-preview+json" mediaTypeCommitSearchPreview = "application/vnd.github.cloak-preview+json"
@ -88,12 +86,6 @@ const (
// https://developer.github.com/changes/2018-03-16-protected-branches-required-approving-reviews/ // https://developer.github.com/changes/2018-03-16-protected-branches-required-approving-reviews/
mediaTypeRequiredApprovingReviewsPreview = "application/vnd.github.luke-cage-preview+json" mediaTypeRequiredApprovingReviewsPreview = "application/vnd.github.luke-cage-preview+json"
// https://developer.github.com/changes/2018-01-10-lock-reason-api-preview/
mediaTypeLockReasonPreview = "application/vnd.github.sailor-v-preview+json"
// https://developer.github.com/changes/2018-05-07-new-checks-api-public-beta/
mediaTypeCheckRunsPreview = "application/vnd.github.antiope-preview+json"
// https://developer.github.com/enterprise/2.13/v3/repos/pre_receive_hooks/ // https://developer.github.com/enterprise/2.13/v3/repos/pre_receive_hooks/
mediaTypePreReceiveHooksPreview = "application/vnd.github.eye-scream-preview" mediaTypePreReceiveHooksPreview = "application/vnd.github.eye-scream-preview"
@ -121,10 +113,10 @@ const (
// https://developer.github.com/changes/2019-04-11-pulls-branches-for-commit/ // https://developer.github.com/changes/2019-04-11-pulls-branches-for-commit/
mediaTypeListPullsOrBranchesForCommitPreview = "application/vnd.github.groot-preview+json" mediaTypeListPullsOrBranchesForCommitPreview = "application/vnd.github.groot-preview+json"
// https://developer.github.com/v3/previews/#repository-creation-permissions // https://docs.github.com/en/free-pro-team@latest/rest/reference/previews/#repository-creation-permissions
mediaTypeMemberAllowedRepoCreationTypePreview = "application/vnd.github.surtur-preview+json" mediaTypeMemberAllowedRepoCreationTypePreview = "application/vnd.github.surtur-preview+json"
// https://developer.github.com/v3/previews/#create-and-use-repository-templates // https://docs.github.com/en/free-pro-team@latest/rest/reference/previews/#create-and-use-repository-templates
mediaTypeRepositoryTemplatePreview = "application/vnd.github.baptiste-preview+json" mediaTypeRepositoryTemplatePreview = "application/vnd.github.baptiste-preview+json"
// https://developer.github.com/changes/2019-10-03-multi-line-comments/ // https://developer.github.com/changes/2019-10-03-multi-line-comments/
@ -135,8 +127,13 @@ const (
// https://developer.github.com/changes/2019-12-03-internal-visibility-changes/ // https://developer.github.com/changes/2019-12-03-internal-visibility-changes/
mediaTypeRepositoryVisibilityPreview = "application/vnd.github.nebula-preview+json" mediaTypeRepositoryVisibilityPreview = "application/vnd.github.nebula-preview+json"
// https://developer.github.com/changes/2018-12-10-content-attachments-api/
mediaTypeContentAttachmentsPreview = "application/vnd.github.corsair-preview+json"
) )
var errNonNilContext = errors.New("context must be non-nil")
// A Client manages communication with the GitHub API. // A Client manages communication with the GitHub API.
type Client struct { type Client struct {
clientMu sync.Mutex // clientMu protects the client during calls that modify the CheckRedirect func. clientMu sync.Mutex // clientMu protects the client during calls that modify the CheckRedirect func.
@ -164,12 +161,15 @@ type Client struct {
Admin *AdminService Admin *AdminService
Apps *AppsService Apps *AppsService
Authorizations *AuthorizationsService Authorizations *AuthorizationsService
Billing *BillingService
Checks *ChecksService Checks *ChecksService
CodeScanning *CodeScanningService CodeScanning *CodeScanningService
Enterprise *EnterpriseService
Gists *GistsService Gists *GistsService
Git *GitService Git *GitService
Gitignores *GitignoresService Gitignores *GitignoresService
Interactions *InteractionsService Interactions *InteractionsService
IssueImport *IssueImportService
Issues *IssuesService Issues *IssuesService
Licenses *LicensesService Licenses *LicensesService
Marketplace *MarketplaceService Marketplace *MarketplaceService
@ -206,6 +206,12 @@ type ListCursorOptions struct {
// For paginated result sets, the number of results to include per page. // For paginated result sets, the number of results to include per page.
PerPage int `url:"per_page,omitempty"` PerPage int `url:"per_page,omitempty"`
// A cursor, as given in the Link header. If specified, the query only searches for events after this cursor.
After string `url:"after,omitempty"`
// A cursor, as given in the Link header. If specified, the query only searches for events before this cursor.
Before string `url:"before,omitempty"`
} }
// UploadOptions specifies the parameters to methods that support uploads. // UploadOptions specifies the parameters to methods that support uploads.
@ -271,12 +277,15 @@ func NewClient(httpClient *http.Client) *Client {
c.Admin = (*AdminService)(&c.common) c.Admin = (*AdminService)(&c.common)
c.Apps = (*AppsService)(&c.common) c.Apps = (*AppsService)(&c.common)
c.Authorizations = (*AuthorizationsService)(&c.common) c.Authorizations = (*AuthorizationsService)(&c.common)
c.Billing = (*BillingService)(&c.common)
c.Checks = (*ChecksService)(&c.common) c.Checks = (*ChecksService)(&c.common)
c.CodeScanning = (*CodeScanningService)(&c.common) c.CodeScanning = (*CodeScanningService)(&c.common)
c.Enterprise = (*EnterpriseService)(&c.common)
c.Gists = (*GistsService)(&c.common) c.Gists = (*GistsService)(&c.common)
c.Git = (*GitService)(&c.common) c.Git = (*GitService)(&c.common)
c.Gitignores = (*GitignoresService)(&c.common) c.Gitignores = (*GitignoresService)(&c.common)
c.Interactions = (*InteractionsService)(&c.common) c.Interactions = (*InteractionsService)(&c.common)
c.IssueImport = (*IssueImportService)(&c.common)
c.Issues = (*IssuesService)(&c.common) c.Issues = (*IssuesService)(&c.common)
c.Licenses = (*LicensesService)(&c.common) c.Licenses = (*LicensesService)(&c.common)
c.Marketplace = &MarketplaceService{client: c} c.Marketplace = &MarketplaceService{client: c}
@ -313,7 +322,9 @@ func NewEnterpriseClient(baseURL, uploadURL string, httpClient *http.Client) (*C
if !strings.HasSuffix(baseEndpoint.Path, "/") { if !strings.HasSuffix(baseEndpoint.Path, "/") {
baseEndpoint.Path += "/" baseEndpoint.Path += "/"
} }
if !strings.HasSuffix(baseEndpoint.Path, "/api/v3/") { if !strings.HasSuffix(baseEndpoint.Path, "/api/v3/") &&
!strings.HasPrefix(baseEndpoint.Host, "api.") &&
!strings.Contains(baseEndpoint.Host, ".api.") {
baseEndpoint.Path += "api/v3/" baseEndpoint.Path += "api/v3/"
} }
@ -324,7 +335,9 @@ func NewEnterpriseClient(baseURL, uploadURL string, httpClient *http.Client) (*C
if !strings.HasSuffix(uploadEndpoint.Path, "/") { if !strings.HasSuffix(uploadEndpoint.Path, "/") {
uploadEndpoint.Path += "/" uploadEndpoint.Path += "/"
} }
if !strings.HasSuffix(uploadEndpoint.Path, "/api/uploads/") { if !strings.HasSuffix(uploadEndpoint.Path, "/api/uploads/") &&
!strings.HasPrefix(uploadEndpoint.Host, "api.") &&
!strings.Contains(uploadEndpoint.Host, ".api.") {
uploadEndpoint.Path += "api/uploads/" uploadEndpoint.Path += "api/uploads/"
} }
@ -509,29 +522,36 @@ func parseRate(r *http.Response) Rate {
return rate return rate
} }
// Do sends an API request and returns the API response. The API response is type requestContext uint8
// JSON decoded and stored in the value pointed to by v, or returned as an
// error if an API error has occurred. If v implements the io.Writer const (
// interface, the raw response body will be written to v, without attempting to bypassRateLimitCheck requestContext = iota
// first decode it. If rate limit is exceeded and reset time is in the future, )
// Do returns *RateLimitError immediately without making a network API call.
// BareDo sends an API request and lets you handle the api response. If an error
// or API Error occurs, the error will contain more information. Otherwise you
// are supposed to read and close the response's Body. If rate limit is exceeded
// and reset time is in the future, BareDo returns *RateLimitError immediately
// without making a network API call.
// //
// The provided ctx must be non-nil, if it is nil an error is returned. If it is canceled or times out, // The provided ctx must be non-nil, if it is nil an error is returned. If it is
// ctx.Err() will be returned. // canceled or times out, ctx.Err() will be returned.
func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error) { func (c *Client) BareDo(ctx context.Context, req *http.Request) (*Response, error) {
if ctx == nil { if ctx == nil {
return nil, errors.New("context must be non-nil") return nil, errNonNilContext
} }
req = withContext(ctx, req) req = withContext(ctx, req)
rateLimitCategory := category(req.URL.Path) rateLimitCategory := category(req.URL.Path)
// If we've hit rate limit, don't make further requests before Reset time. if bypass := ctx.Value(bypassRateLimitCheck); bypass == nil {
if err := c.checkRateLimitBeforeDo(req, rateLimitCategory); err != nil { // If we've hit rate limit, don't make further requests before Reset time.
return &Response{ if err := c.checkRateLimitBeforeDo(req, rateLimitCategory); err != nil {
Response: err.Response, return &Response{
Rate: err.Rate, Response: err.Response,
}, err Rate: err.Rate,
}, err
}
} }
resp, err := c.client.Do(req) resp, err := c.client.Do(req)
@ -554,7 +574,6 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Res
return nil, err return nil, err
} }
defer resp.Body.Close()
response := newResponse(resp) response := newResponse(resp)
@ -564,6 +583,7 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Res
err = CheckResponse(resp) err = CheckResponse(resp)
if err != nil { if err != nil {
defer resp.Body.Close()
// Special case for AcceptedErrors. If an AcceptedError // Special case for AcceptedErrors. If an AcceptedError
// has been encountered, the response's payload will be // has been encountered, the response's payload will be
// added to the AcceptedError and returned. // added to the AcceptedError and returned.
@ -577,29 +597,45 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Res
} }
aerr.Raw = b aerr.Raw = b
return response, aerr err = aerr
}
return response, err
}
if v != nil {
if w, ok := v.(io.Writer); ok {
io.Copy(w, resp.Body)
} else {
decErr := json.NewDecoder(resp.Body).Decode(v)
if decErr == io.EOF {
decErr = nil // ignore EOF errors caused by empty response body
}
if decErr != nil {
err = decErr
}
} }
} }
return response, err return response, err
} }
// Do sends an API request and returns the API response. The API response is
// JSON decoded and stored in the value pointed to by v, or returned as an
// error if an API error has occurred. If v implements the io.Writer interface,
// the raw response body will be written to v, without attempting to first
// decode it. If v is nil, and no error hapens, the response is returned as is.
// If rate limit is exceeded and reset time is in the future, Do returns
// *RateLimitError immediately without making a network API call.
//
// The provided ctx must be non-nil, if it is nil an error is returned. If it
// is canceled or times out, ctx.Err() will be returned.
func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error) {
resp, err := c.BareDo(ctx, req)
if err != nil {
return resp, err
}
defer resp.Body.Close()
switch v := v.(type) {
case nil:
case io.Writer:
_, err = io.Copy(v, resp.Body)
default:
decErr := json.NewDecoder(resp.Body).Decode(v)
if decErr == io.EOF {
decErr = nil // ignore EOF errors caused by empty response body
}
if decErr != nil {
err = decErr
}
}
return resp, err
}
// checkRateLimitBeforeDo does not make any network calls, but uses existing knowledge from // checkRateLimitBeforeDo does not make any network calls, but uses existing knowledge from
// current client state in order to quickly check if *RateLimitError can be immediately returned // current client state in order to quickly check if *RateLimitError can be immediately returned
// from Client.Do, and if so, returns it so that Client.Do can skip making a network API call unnecessarily. // from Client.Do, and if so, returns it so that Client.Do can skip making a network API call unnecessarily.
@ -627,34 +663,95 @@ func (c *Client) checkRateLimitBeforeDo(req *http.Request, rateLimitCategory rat
return nil return nil
} }
// 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 {
if r1 == nil && r2 == nil {
return true
}
if r1 != nil && r2 != nil {
return r1.StatusCode == r2.StatusCode
}
return false
}
/* /*
An ErrorResponse reports one or more errors caused by an API request. An ErrorResponse reports one or more errors caused by an API request.
GitHub API docs: https://developer.github.com/v3/#client-errors GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/#client-errors
*/ */
type ErrorResponse struct { type ErrorResponse struct {
Response *http.Response // HTTP response that caused this error Response *http.Response // HTTP response that caused this error
Message string `json:"message"` // error message Message string `json:"message"` // error message
Errors []Error `json:"errors"` // more detail on individual errors Errors []Error `json:"errors"` // more detail on individual errors
// Block is only populated on certain types of errors such as code 451. // Block is only populated on certain types of errors such as code 451.
// See https://developer.github.com/changes/2016-03-17-the-451-status-code-is-now-supported/ Block *ErrorBlock `json:"block,omitempty"`
// for more information.
Block *struct {
Reason string `json:"reason,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
} `json:"block,omitempty"`
// Most errors will also include a documentation_url field pointing // Most errors will also include a documentation_url field pointing
// to some content that might help you resolve the error, see // to some content that might help you resolve the error, see
// https://developer.github.com/v3/#client-errors // https://docs.github.com/en/free-pro-team@latest/rest/reference/#client-errors
DocumentationURL string `json:"documentation_url,omitempty"` DocumentationURL string `json:"documentation_url,omitempty"`
} }
// ErrorBlock contains a further explanation for the reason of an error.
// See https://developer.github.com/changes/2016-03-17-the-451-status-code-is-now-supported/
// for more information.
type ErrorBlock struct {
Reason string `json:"reason,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
}
func (r *ErrorResponse) Error() string { func (r *ErrorResponse) Error() string {
return fmt.Sprintf("%v %v: %d %v %+v", return fmt.Sprintf("%v %v: %d %v %+v",
r.Response.Request.Method, sanitizeURL(r.Response.Request.URL), r.Response.Request.Method, sanitizeURL(r.Response.Request.URL),
r.Response.StatusCode, r.Message, r.Errors) r.Response.StatusCode, r.Message, r.Errors)
} }
// Is returns whether the provided error equals this error.
func (r *ErrorResponse) Is(target error) bool {
v, ok := target.(*ErrorResponse)
if !ok {
return false
}
if r.Message != v.Message || (r.DocumentationURL != v.DocumentationURL) ||
!compareHttpResponse(r.Response, v.Response) {
return false
}
// Compare Errors.
if len(r.Errors) != len(v.Errors) {
return false
}
for idx := range r.Errors {
if r.Errors[idx] != v.Errors[idx] {
return false
}
}
// Compare Block.
if (r.Block != nil && v.Block == nil) || (r.Block == nil && v.Block != nil) {
return false
}
if r.Block != nil && v.Block != nil {
if r.Block.Reason != v.Block.Reason {
return false
}
if (r.Block.CreatedAt != nil && v.Block.CreatedAt == nil) || (r.Block.CreatedAt ==
nil && v.Block.CreatedAt != nil) {
return false
}
if r.Block.CreatedAt != nil && v.Block.CreatedAt != nil {
if *(r.Block.CreatedAt) != *(v.Block.CreatedAt) {
return false
}
}
}
return true
}
// TwoFactorAuthError occurs when using HTTP Basic Authentication for a user // TwoFactorAuthError occurs when using HTTP Basic Authentication for a user
// that has two-factor authentication enabled. The request can be reattempted // that has two-factor authentication enabled. The request can be reattempted
// by providing a one-time password in the request. // by providing a one-time password in the request.
@ -676,6 +773,18 @@ func (r *RateLimitError) Error() string {
r.Response.StatusCode, r.Message, formatRateReset(time.Until(r.Rate.Reset.Time))) r.Response.StatusCode, r.Message, formatRateReset(time.Until(r.Rate.Reset.Time)))
} }
// Is returns whether the provided error equals this error.
func (r *RateLimitError) Is(target error) bool {
v, ok := target.(*RateLimitError)
if !ok {
return false
}
return r.Rate == v.Rate &&
r.Message == v.Message &&
compareHttpResponse(r.Response, v.Response)
}
// AcceptedError occurs when GitHub returns 202 Accepted response with an // AcceptedError occurs when GitHub returns 202 Accepted response with an
// empty body, which means a job was scheduled on the GitHub side to process // empty body, which means a job was scheduled on the GitHub side to process
// the information needed and cache it. // the information needed and cache it.
@ -691,8 +800,17 @@ func (*AcceptedError) Error() string {
return "job scheduled on GitHub side; try again later" return "job scheduled on GitHub side; try again later"
} }
// Is returns whether the provided error equals this error.
func (ae *AcceptedError) Is(target error) bool {
v, ok := target.(*AcceptedError)
if !ok {
return false
}
return bytes.Compare(ae.Raw, v.Raw) == 0
}
// AbuseRateLimitError occurs when GitHub returns 403 Forbidden response with the // AbuseRateLimitError occurs when GitHub returns 403 Forbidden response with the
// "documentation_url" field value equal to "https://developer.github.com/v3/#abuse-rate-limits". // "documentation_url" field value equal to "https://docs.github.com/en/free-pro-team@latest/rest/reference/#abuse-rate-limits".
type AbuseRateLimitError struct { type AbuseRateLimitError struct {
Response *http.Response // HTTP response that caused this error Response *http.Response // HTTP response that caused this error
Message string `json:"message"` // error message Message string `json:"message"` // error message
@ -709,6 +827,18 @@ func (r *AbuseRateLimitError) Error() string {
r.Response.StatusCode, r.Message) r.Response.StatusCode, r.Message)
} }
// Is returns whether the provided error equals this error.
func (r *AbuseRateLimitError) Is(target error) bool {
v, ok := target.(*AbuseRateLimitError)
if !ok {
return false
}
return r.Message == v.Message &&
r.RetryAfter == v.RetryAfter &&
compareHttpResponse(r.Response, v.Response)
}
// sanitizeURL redacts the client_secret parameter from the URL which may be // sanitizeURL redacts the client_secret parameter from the URL which may be
// exposed to the user. // exposed to the user.
func sanitizeURL(uri *url.URL) *url.URL { func sanitizeURL(uri *url.URL) *url.URL {
@ -743,7 +873,7 @@ GitHub error responses structure are often undocumented and inconsistent.
Sometimes error is just a simple string (Issue #540). Sometimes error is just a simple string (Issue #540).
In such cases, Message represents an error message as a workaround. In such cases, Message represents an error message as a workaround.
GitHub API docs: https://developer.github.com/v3/#client-errors GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/#client-errors
*/ */
type Error struct { type Error struct {
Resource string `json:"resource"` // resource on which the error occurred Resource string `json:"resource"` // resource on which the error occurred
@ -799,7 +929,7 @@ func CheckResponse(r *http.Response) error {
Response: errorResponse.Response, Response: errorResponse.Response,
Message: errorResponse.Message, Message: errorResponse.Message,
} }
case r.StatusCode == http.StatusForbidden && strings.HasSuffix(errorResponse.DocumentationURL, "/v3/#abuse-rate-limits"): case r.StatusCode == http.StatusForbidden && strings.HasSuffix(errorResponse.DocumentationURL, "#abuse-rate-limits"):
abuseRateLimitError := &AbuseRateLimitError{ abuseRateLimitError := &AbuseRateLimitError{
Response: errorResponse.Response, Response: errorResponse.Response,
Message: errorResponse.Message, Message: errorResponse.Message,
@ -859,14 +989,14 @@ type RateLimits struct {
// requests are limited to 60 per hour. Authenticated requests are // requests are limited to 60 per hour. Authenticated requests are
// limited to 5,000 per hour. // limited to 5,000 per hour.
// //
// GitHub API docs: https://developer.github.com/v3/#rate-limiting // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/#rate-limiting
Core *Rate `json:"core"` Core *Rate `json:"core"`
// The rate limit for search API requests. Unauthenticated requests // The rate limit for search API requests. Unauthenticated requests
// are limited to 10 requests per minutes. Authenticated requests are // are limited to 10 requests per minutes. Authenticated requests are
// limited to 30 per minute. // limited to 30 per minute.
// //
// GitHub API docs: https://developer.github.com/v3/search/#rate-limit // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/search/#rate-limit
Search *Rate `json:"search"` Search *Rate `json:"search"`
} }
@ -903,9 +1033,12 @@ func (c *Client) RateLimits(ctx context.Context) (*RateLimits, *Response, error)
response := new(struct { response := new(struct {
Resources *RateLimits `json:"resources"` Resources *RateLimits `json:"resources"`
}) })
// This resource is not subject to rate limits.
ctx = context.WithValue(ctx, bypassRateLimitCheck, true)
resp, err := c.Do(ctx, req, response) resp, err := c.Do(ctx, req, response)
if err != nil { if err != nil {
return nil, nil, err return nil, resp, err
} }
if response.Resources != nil { if response.Resources != nil {
@ -953,7 +1086,7 @@ that need to use a higher rate limit associated with your OAuth application.
This will add the client id and secret as a base64-encoded string in the format This will add the client id and secret as a base64-encoded string in the format
ClientID:ClientSecret and apply it as an "Authorization": "Basic" header. ClientID:ClientSecret and apply it as an "Authorization": "Basic" header.
See https://developer.github.com/v3/#unauthenticated-rate-limited-requests for See https://docs.github.com/en/free-pro-team@latest/rest/reference/#unauthenticated-rate-limited-requests for
more information. more information.
*/ */
type UnauthenticatedRateLimitedTransport struct { type UnauthenticatedRateLimitedTransport struct {

View file

@ -13,7 +13,7 @@ import (
// GitignoresService provides access to the gitignore related functions in the // GitignoresService provides access to the gitignore related functions in the
// GitHub API. // GitHub API.
// //
// GitHub API docs: https://developer.github.com/v3/gitignore/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gitignore/
type GitignoresService service type GitignoresService service
// Gitignore represents a .gitignore file as returned by the GitHub API. // Gitignore represents a .gitignore file as returned by the GitHub API.
@ -28,7 +28,7 @@ func (g Gitignore) String() string {
// List all available Gitignore templates. // List all available Gitignore templates.
// //
// GitHub API docs: https://developer.github.com/v3/gitignore/#listing-available-templates // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gitignore/#listing-available-templates
func (s *GitignoresService) List(ctx context.Context) ([]string, *Response, error) { func (s *GitignoresService) List(ctx context.Context) ([]string, *Response, error) {
req, err := s.client.NewRequest("GET", "gitignore/templates", nil) req, err := s.client.NewRequest("GET", "gitignore/templates", nil)
if err != nil { if err != nil {
@ -46,7 +46,7 @@ func (s *GitignoresService) List(ctx context.Context) ([]string, *Response, erro
// Get a Gitignore by name. // Get a Gitignore by name.
// //
// GitHub API docs: https://developer.github.com/v3/gitignore/#get-a-gitignore-template // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gitignore/#get-a-gitignore-template
func (s *GitignoresService) Get(ctx context.Context, name string) (*Gitignore, *Response, error) { func (s *GitignoresService) Get(ctx context.Context, name string) (*Gitignore, *Response, error) {
u := fmt.Sprintf("gitignore/templates/%v", name) u := fmt.Sprintf("gitignore/templates/%v", name)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)

View file

@ -8,7 +8,7 @@ package github
// InteractionsService handles communication with the repository and organization related // InteractionsService handles communication with the repository and organization related
// methods of the GitHub API. // methods of the GitHub API.
// //
// GitHub API docs: https://developer.github.com/v3/interactions/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/interactions/
type InteractionsService service type InteractionsService service
// InteractionRestriction represents the interaction restrictions for repository and organization. // InteractionRestriction represents the interaction restrictions for repository and organization.

View file

@ -12,7 +12,7 @@ import (
// GetRestrictionsForOrg fetches the interaction restrictions for an organization. // GetRestrictionsForOrg fetches the interaction restrictions for an organization.
// //
// GitHub API docs: https://developer.github.com/v3/interactions/orgs/#get-interaction-restrictions-for-an-organization // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/interactions/#get-interaction-restrictions-for-an-organization
func (s *InteractionsService) GetRestrictionsForOrg(ctx context.Context, organization string) (*InteractionRestriction, *Response, error) { func (s *InteractionsService) GetRestrictionsForOrg(ctx context.Context, organization string) (*InteractionRestriction, *Response, error) {
u := fmt.Sprintf("orgs/%v/interaction-limits", organization) u := fmt.Sprintf("orgs/%v/interaction-limits", organization)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -39,7 +39,7 @@ func (s *InteractionsService) GetRestrictionsForOrg(ctx context.Context, organiz
// in public repositories for the given organization. // in public repositories for the given organization.
// Possible values are: "existing_users", "contributors_only", "collaborators_only". // Possible values are: "existing_users", "contributors_only", "collaborators_only".
// //
// GitHub API docs: https://developer.github.com/v3/interactions/orgs/#set-interaction-restrictions-for-an-organization // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/interactions/#set-interaction-restrictions-for-an-organization
func (s *InteractionsService) UpdateRestrictionsForOrg(ctx context.Context, organization, limit string) (*InteractionRestriction, *Response, error) { func (s *InteractionsService) UpdateRestrictionsForOrg(ctx context.Context, organization, limit string) (*InteractionRestriction, *Response, error) {
u := fmt.Sprintf("orgs/%v/interaction-limits", organization) u := fmt.Sprintf("orgs/%v/interaction-limits", organization)
@ -65,7 +65,7 @@ func (s *InteractionsService) UpdateRestrictionsForOrg(ctx context.Context, orga
// RemoveRestrictionsFromOrg removes the interaction restrictions for an organization. // RemoveRestrictionsFromOrg removes the interaction restrictions for an organization.
// //
// GitHub API docs: https://developer.github.com/v3/interactions/orgs/#remove-interaction-restrictions-for-an-organization // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/interactions/#remove-interaction-restrictions-for-an-organization
func (s *InteractionsService) RemoveRestrictionsFromOrg(ctx context.Context, organization string) (*Response, error) { func (s *InteractionsService) RemoveRestrictionsFromOrg(ctx context.Context, organization string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/interaction-limits", organization) u := fmt.Sprintf("orgs/%v/interaction-limits", organization)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)

View file

@ -12,7 +12,7 @@ import (
// GetRestrictionsForRepo fetches the interaction restrictions for a repository. // GetRestrictionsForRepo fetches the interaction restrictions for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/interactions/repos/#get-interaction-restrictions-for-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/interactions/#get-interaction-restrictions-for-a-repository
func (s *InteractionsService) GetRestrictionsForRepo(ctx context.Context, owner, repo string) (*InteractionRestriction, *Response, error) { func (s *InteractionsService) GetRestrictionsForRepo(ctx context.Context, owner, repo string) (*InteractionRestriction, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/interaction-limits", owner, repo) u := fmt.Sprintf("repos/%v/%v/interaction-limits", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -39,7 +39,7 @@ func (s *InteractionsService) GetRestrictionsForRepo(ctx context.Context, owner,
// for the given repository. // for the given repository.
// Possible values are: "existing_users", "contributors_only", "collaborators_only". // Possible values are: "existing_users", "contributors_only", "collaborators_only".
// //
// GitHub API docs: https://developer.github.com/v3/interactions/repos/#set-interaction-restrictions-for-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/interactions/#set-interaction-restrictions-for-a-repository
func (s *InteractionsService) UpdateRestrictionsForRepo(ctx context.Context, owner, repo, limit string) (*InteractionRestriction, *Response, error) { func (s *InteractionsService) UpdateRestrictionsForRepo(ctx context.Context, owner, repo, limit string) (*InteractionRestriction, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/interaction-limits", owner, repo) u := fmt.Sprintf("repos/%v/%v/interaction-limits", owner, repo)
@ -65,7 +65,7 @@ func (s *InteractionsService) UpdateRestrictionsForRepo(ctx context.Context, own
// RemoveRestrictionsFromRepo removes the interaction restrictions for a repository. // RemoveRestrictionsFromRepo removes the interaction restrictions for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/interactions/repos/#remove-interaction-restrictions-for-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/interactions/#remove-interaction-restrictions-for-a-repository
func (s *InteractionsService) RemoveRestrictionsFromRepo(ctx context.Context, owner, repo string) (*Response, error) { func (s *InteractionsService) RemoveRestrictionsFromRepo(ctx context.Context, owner, repo string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/interaction-limits", owner, repo) u := fmt.Sprintf("repos/%v/%v/interaction-limits", owner, repo)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)

View file

@ -0,0 +1,152 @@
// Copyright 2020 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 (
"bytes"
"context"
"encoding/json"
"fmt"
"time"
)
// IssueImportService handles communication with the issue import related
// methods of the Issue Import GitHub API.
type IssueImportService service
// IssueImportRequest represents a request to create an issue.
//
// https://gist.github.com/jonmagic/5282384165e0f86ef105#supported-issue-and-comment-fields
type IssueImportRequest struct {
IssueImport IssueImport `json:"issue"`
Comments []*Comment `json:"comments,omitempty"`
}
// IssueImport represents body of issue to import.
type IssueImport struct {
Title string `json:"title"`
Body string `json:"body"`
CreatedAt *time.Time `json:"created_at,omitempty"`
ClosedAt *time.Time `json:"closed_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
Assignee *string `json:"assignee,omitempty"`
Milestone *int `json:"milestone,omitempty"`
Closed *bool `json:"closed,omitempty"`
Labels []string `json:"labels,omitempty"`
}
// Comment represents comments of issue to import.
type Comment struct {
CreatedAt *time.Time `json:"created_at,omitempty"`
Body string `json:"body"`
}
// IssueImportResponse represents the response of an issue import create request.
//
// https://gist.github.com/jonmagic/5282384165e0f86ef105#import-issue-response
type IssueImportResponse struct {
ID *int `json:"id,omitempty"`
Status *string `json:"status,omitempty"`
URL *string `json:"url,omitempty"`
ImportIssuesURL *string `json:"import_issues_url,omitempty"`
RepositoryURL *string `json:"repository_url,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
Message *string `json:"message,omitempty"`
DocumentationURL *string `json:"documentation_url,omitempty"`
Errors []*IssueImportError `json:"errors,omitempty"`
}
// IssueImportError represents errors of an issue import create request.
type IssueImportError struct {
Location *string `json:"location,omitempty"`
Resource *string `json:"resource,omitempty"`
Field *string `json:"field,omitempty"`
Value *string `json:"value,omitempty"`
Code *string `json:"code,omitempty"`
}
// Create a new imported issue on the specified repository.
//
// https://gist.github.com/jonmagic/5282384165e0f86ef105#start-an-issue-import
func (s *IssueImportService) Create(ctx context.Context, owner, repo string, issue *IssueImportRequest) (*IssueImportResponse, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/import/issues", owner, repo)
req, err := s.client.NewRequest("POST", u, issue)
if err != nil {
return nil, nil, err
}
// TODO: remove custom Accept headers when APIs fully launch.
req.Header.Set("Accept", mediaTypeIssueImportAPI)
i := new(IssueImportResponse)
resp, err := s.client.Do(ctx, req, i)
if err != nil {
aerr, ok := err.(*AcceptedError)
if ok {
decErr := json.Unmarshal(aerr.Raw, i)
if decErr != nil {
err = decErr
}
return i, resp, nil
}
return nil, resp, err
}
return i, resp, nil
}
// CheckStatus checks the status of an imported issue.
//
// https://gist.github.com/jonmagic/5282384165e0f86ef105#import-status-request
func (s *IssueImportService) CheckStatus(ctx context.Context, owner, repo string, issueID int64) (*IssueImportResponse, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/import/issues/%v", owner, repo, issueID)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
// TODO: remove custom Accept headers when APIs fully launch.
req.Header.Set("Accept", mediaTypeIssueImportAPI)
i := new(IssueImportResponse)
resp, err := s.client.Do(ctx, req, i)
if err != nil {
return nil, resp, err
}
return i, resp, nil
}
// CheckStatusSince checks the status of multiple imported issues since a given date.
//
// https://gist.github.com/jonmagic/5282384165e0f86ef105#check-status-of-multiple-issues
func (s *IssueImportService) CheckStatusSince(ctx context.Context, owner, repo string, since time.Time) ([]*IssueImportResponse, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/import/issues?since=%v", owner, repo, since.Format("2006-01-02"))
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
// TODO: remove custom Accept headers when APIs fully launch.
req.Header.Set("Accept", mediaTypeIssueImportAPI)
var b bytes.Buffer
resp, err := s.client.Do(ctx, req, &b)
if err != nil {
return nil, resp, err
}
var i []*IssueImportResponse
err = json.Unmarshal(b.Bytes(), &i)
if err != nil {
return nil, resp, err
}
return i, resp, nil
}

View file

@ -8,14 +8,13 @@ package github
import ( import (
"context" "context"
"fmt" "fmt"
"strings"
"time" "time"
) )
// IssuesService handles communication with the issue related // IssuesService handles communication with the issue related
// methods of the GitHub API. // methods of the GitHub API.
// //
// GitHub API docs: https://developer.github.com/v3/issues/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/
type IssuesService service type IssuesService service
// Issue represents a GitHub issue on a repository. // Issue represents a GitHub issue on a repository.
@ -55,7 +54,7 @@ type Issue struct {
NodeID *string `json:"node_id,omitempty"` NodeID *string `json:"node_id,omitempty"`
// TextMatches is only populated from search results that request text matches // TextMatches is only populated from search results that request text matches
// See: search.go and https://developer.github.com/v3/search/#text-match-metadata // See: search.go and https://docs.github.com/en/free-pro-team@latest/rest/reference/search/#text-match-metadata
TextMatches []*TextMatch `json:"text_matches,omitempty"` TextMatches []*TextMatch `json:"text_matches,omitempty"`
// ActiveLockReason is populated only when LockReason is provided while locking the issue. // ActiveLockReason is populated only when LockReason is provided while locking the issue.
@ -129,8 +128,8 @@ type PullRequestLinks struct {
// organization repositories; if false, list only owned and member // organization repositories; if false, list only owned and member
// repositories. // repositories.
// //
// GitHub API docs: https://developer.github.com/v3/issues/#list-issues-assigned-to-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#list-user-account-issues-assigned-to-the-authenticated-user
// GitHub API docs: https://developer.github.com/v3/issues/#list-user-account-issues-assigned-to-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#list-issues-assigned-to-the-authenticated-user
func (s *IssuesService) List(ctx context.Context, all bool, opts *IssueListOptions) ([]*Issue, *Response, error) { func (s *IssuesService) List(ctx context.Context, all bool, opts *IssueListOptions) ([]*Issue, *Response, error) {
var u string var u string
if all { if all {
@ -144,7 +143,7 @@ func (s *IssuesService) List(ctx context.Context, all bool, opts *IssueListOptio
// ListByOrg fetches the issues in the specified organization for the // ListByOrg fetches the issues in the specified organization for the
// authenticated user. // authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/issues/#list-organization-issues-assigned-to-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#list-organization-issues-assigned-to-the-authenticated-user
func (s *IssuesService) ListByOrg(ctx context.Context, org string, opts *IssueListOptions) ([]*Issue, *Response, error) { func (s *IssuesService) ListByOrg(ctx context.Context, org string, opts *IssueListOptions) ([]*Issue, *Response, error) {
u := fmt.Sprintf("orgs/%v/issues", org) u := fmt.Sprintf("orgs/%v/issues", org)
return s.listIssues(ctx, u, opts) return s.listIssues(ctx, u, opts)
@ -161,9 +160,8 @@ func (s *IssuesService) listIssues(ctx context.Context, u string, opts *IssueLis
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept headers when APIs fully launch. // TODO: remove custom Accept header when this API fully launch.
acceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeLockReasonPreview} req.Header.Set("Accept", mediaTypeReactionsPreview)
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
var issues []*Issue var issues []*Issue
resp, err := s.client.Do(ctx, req, &issues) resp, err := s.client.Do(ctx, req, &issues)
@ -216,7 +214,7 @@ type IssueListByRepoOptions struct {
// ListByRepo lists the issues for the specified repository. // ListByRepo lists the issues for the specified repository.
// //
// GitHub API docs: https://developer.github.com/v3/issues/#list-repository-issues // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#list-repository-issues
func (s *IssuesService) ListByRepo(ctx context.Context, owner string, repo string, opts *IssueListByRepoOptions) ([]*Issue, *Response, error) { func (s *IssuesService) ListByRepo(ctx context.Context, owner string, repo string, opts *IssueListByRepoOptions) ([]*Issue, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues", owner, repo) u := fmt.Sprintf("repos/%v/%v/issues", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -229,9 +227,8 @@ func (s *IssuesService) ListByRepo(ctx context.Context, owner string, repo strin
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept headers when APIs fully launch. // TODO: remove custom Accept header when this API fully launches.
acceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeIntegrationPreview} req.Header.Set("Accept", mediaTypeReactionsPreview)
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
var issues []*Issue var issues []*Issue
resp, err := s.client.Do(ctx, req, &issues) resp, err := s.client.Do(ctx, req, &issues)
@ -244,7 +241,7 @@ func (s *IssuesService) ListByRepo(ctx context.Context, owner string, repo strin
// Get a single issue. // Get a single issue.
// //
// GitHub API docs: https://developer.github.com/v3/issues/#get-an-issue // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#get-an-issue
func (s *IssuesService) Get(ctx context.Context, owner string, repo string, number int) (*Issue, *Response, error) { func (s *IssuesService) Get(ctx context.Context, owner string, repo string, number int) (*Issue, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/issues/%d", owner, repo, number)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -252,9 +249,8 @@ func (s *IssuesService) Get(ctx context.Context, owner string, repo string, numb
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept headers when APIs fully launch. // TODO: remove custom Accept header when this API fully launch.
acceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeLockReasonPreview} req.Header.Set("Accept", mediaTypeReactionsPreview)
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
issue := new(Issue) issue := new(Issue)
resp, err := s.client.Do(ctx, req, issue) resp, err := s.client.Do(ctx, req, issue)
@ -267,7 +263,7 @@ func (s *IssuesService) Get(ctx context.Context, owner string, repo string, numb
// Create a new issue on the specified repository. // Create a new issue on the specified repository.
// //
// GitHub API docs: https://developer.github.com/v3/issues/#create-an-issue // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#create-an-issue
func (s *IssuesService) Create(ctx context.Context, owner string, repo string, issue *IssueRequest) (*Issue, *Response, error) { func (s *IssuesService) Create(ctx context.Context, owner string, repo string, issue *IssueRequest) (*Issue, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues", owner, repo) u := fmt.Sprintf("repos/%v/%v/issues", owner, repo)
req, err := s.client.NewRequest("POST", u, issue) req, err := s.client.NewRequest("POST", u, issue)
@ -286,7 +282,7 @@ func (s *IssuesService) Create(ctx context.Context, owner string, repo string, i
// Edit an issue. // Edit an issue.
// //
// GitHub API docs: https://developer.github.com/v3/issues/#update-an-issue // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#update-an-issue
func (s *IssuesService) Edit(ctx context.Context, owner string, repo string, number int, issue *IssueRequest) (*Issue, *Response, error) { func (s *IssuesService) Edit(ctx context.Context, owner string, repo string, number int, issue *IssueRequest) (*Issue, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/issues/%d", owner, repo, number)
req, err := s.client.NewRequest("PATCH", u, issue) req, err := s.client.NewRequest("PATCH", u, issue)
@ -314,7 +310,7 @@ type LockIssueOptions struct {
// Lock an issue's conversation. // Lock an issue's conversation.
// //
// GitHub API docs: https://developer.github.com/v3/issues/#lock-an-issue // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#lock-an-issue
func (s *IssuesService) Lock(ctx context.Context, owner string, repo string, number int, opts *LockIssueOptions) (*Response, error) { func (s *IssuesService) Lock(ctx context.Context, owner string, repo string, number int, opts *LockIssueOptions) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/lock", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/issues/%d/lock", owner, repo, number)
req, err := s.client.NewRequest("PUT", u, opts) req, err := s.client.NewRequest("PUT", u, opts)
@ -322,16 +318,12 @@ func (s *IssuesService) Lock(ctx context.Context, owner string, repo string, num
return nil, err return nil, err
} }
if opts != nil {
req.Header.Set("Accept", mediaTypeLockReasonPreview)
}
return s.client.Do(ctx, req, nil) return s.client.Do(ctx, req, nil)
} }
// Unlock an issue's conversation. // Unlock an issue's conversation.
// //
// GitHub API docs: https://developer.github.com/v3/issues/#unlock-an-issue // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#unlock-an-issue
func (s *IssuesService) Unlock(ctx context.Context, owner string, repo string, number int) (*Response, error) { func (s *IssuesService) Unlock(ctx context.Context, owner string, repo string, number int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/lock", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/issues/%d/lock", owner, repo, number)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)

View file

@ -13,7 +13,7 @@ import (
// ListAssignees fetches all available assignees (owners and collaborators) to // ListAssignees fetches all available assignees (owners and collaborators) to
// which issues may be assigned. // which issues may be assigned.
// //
// GitHub API docs: https://developer.github.com/v3/issues/assignees/#list-assignees // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#list-assignees
func (s *IssuesService) ListAssignees(ctx context.Context, owner, repo string, opts *ListOptions) ([]*User, *Response, error) { func (s *IssuesService) ListAssignees(ctx context.Context, owner, repo string, opts *ListOptions) ([]*User, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/assignees", owner, repo) u := fmt.Sprintf("repos/%v/%v/assignees", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -36,7 +36,7 @@ func (s *IssuesService) ListAssignees(ctx context.Context, owner, repo string, o
// IsAssignee checks if a user is an assignee for the specified repository. // IsAssignee checks if a user is an assignee for the specified repository.
// //
// GitHub API docs: https://developer.github.com/v3/issues/assignees/#check-if-a-user-can-be-assigned // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#check-if-a-user-can-be-assigned
func (s *IssuesService) IsAssignee(ctx context.Context, owner, repo, user string) (bool, *Response, error) { func (s *IssuesService) IsAssignee(ctx context.Context, owner, repo, user string) (bool, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/assignees/%v", owner, repo, user) u := fmt.Sprintf("repos/%v/%v/assignees/%v", owner, repo, user)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -50,7 +50,7 @@ func (s *IssuesService) IsAssignee(ctx context.Context, owner, repo, user string
// AddAssignees adds the provided GitHub users as assignees to the issue. // AddAssignees adds the provided GitHub users as assignees to the issue.
// //
// GitHub API docs: https://developer.github.com/v3/issues/assignees/#add-assignees-to-an-issue // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#add-assignees-to-an-issue
func (s *IssuesService) AddAssignees(ctx context.Context, owner, repo string, number int, assignees []string) (*Issue, *Response, error) { func (s *IssuesService) AddAssignees(ctx context.Context, owner, repo string, number int, assignees []string) (*Issue, *Response, error) {
users := &struct { users := &struct {
Assignees []string `json:"assignees,omitempty"` Assignees []string `json:"assignees,omitempty"`
@ -68,7 +68,7 @@ func (s *IssuesService) AddAssignees(ctx context.Context, owner, repo string, nu
// RemoveAssignees removes the provided GitHub users as assignees from the issue. // RemoveAssignees removes the provided GitHub users as assignees from the issue.
// //
// GitHub API docs: https://developer.github.com/v3/issues/assignees/#remove-assignees-from-an-issue // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#remove-assignees-from-an-issue
func (s *IssuesService) RemoveAssignees(ctx context.Context, owner, repo string, number int, assignees []string) (*Issue, *Response, error) { func (s *IssuesService) RemoveAssignees(ctx context.Context, owner, repo string, number int, assignees []string) (*Issue, *Response, error) {
users := &struct { users := &struct {
Assignees []string `json:"assignees,omitempty"` Assignees []string `json:"assignees,omitempty"`

View file

@ -50,8 +50,8 @@ type IssueListCommentsOptions struct {
// ListComments lists all comments on the specified issue. Specifying an issue // ListComments lists all comments on the specified issue. Specifying an issue
// number of 0 will return all comments on all issues for the repository. // number of 0 will return all comments on all issues for the repository.
// //
// GitHub API docs: https://developer.github.com/v3/issues/comments/#list-issue-comments // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#list-issue-comments
// GitHub API docs: https://developer.github.com/v3/issues/comments/#list-issue-comments-for-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#list-issue-comments-for-a-repository
func (s *IssuesService) ListComments(ctx context.Context, owner string, repo string, number int, opts *IssueListCommentsOptions) ([]*IssueComment, *Response, error) { func (s *IssuesService) ListComments(ctx context.Context, owner string, repo string, number int, opts *IssueListCommentsOptions) ([]*IssueComment, *Response, error) {
var u string var u string
if number == 0 { if number == 0 {
@ -83,7 +83,7 @@ func (s *IssuesService) ListComments(ctx context.Context, owner string, repo str
// GetComment fetches the specified issue comment. // GetComment fetches the specified issue comment.
// //
// GitHub API docs: https://developer.github.com/v3/issues/comments/#get-an-issue-comment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#get-an-issue-comment
func (s *IssuesService) GetComment(ctx context.Context, owner string, repo string, commentID int64) (*IssueComment, *Response, error) { func (s *IssuesService) GetComment(ctx context.Context, owner string, repo string, commentID int64) (*IssueComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, commentID) u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, commentID)
@ -106,7 +106,7 @@ func (s *IssuesService) GetComment(ctx context.Context, owner string, repo strin
// CreateComment creates a new comment on the specified issue. // CreateComment creates a new comment on the specified issue.
// //
// GitHub API docs: https://developer.github.com/v3/issues/comments/#create-an-issue-comment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#create-an-issue-comment
func (s *IssuesService) CreateComment(ctx context.Context, owner string, repo string, number int, comment *IssueComment) (*IssueComment, *Response, error) { func (s *IssuesService) CreateComment(ctx context.Context, owner string, repo string, number int, comment *IssueComment) (*IssueComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number)
req, err := s.client.NewRequest("POST", u, comment) req, err := s.client.NewRequest("POST", u, comment)
@ -125,7 +125,7 @@ func (s *IssuesService) CreateComment(ctx context.Context, owner string, repo st
// EditComment updates an issue comment. // EditComment updates an issue comment.
// A non-nil comment.Body must be provided. Other comment fields should be left nil. // A non-nil comment.Body must be provided. Other comment fields should be left nil.
// //
// GitHub API docs: https://developer.github.com/v3/issues/comments/#update-an-issue-comment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#update-an-issue-comment
func (s *IssuesService) EditComment(ctx context.Context, owner string, repo string, commentID int64, comment *IssueComment) (*IssueComment, *Response, error) { func (s *IssuesService) EditComment(ctx context.Context, owner string, repo string, commentID int64, comment *IssueComment) (*IssueComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, commentID) u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, commentID)
req, err := s.client.NewRequest("PATCH", u, comment) req, err := s.client.NewRequest("PATCH", u, comment)
@ -143,7 +143,7 @@ func (s *IssuesService) EditComment(ctx context.Context, owner string, repo stri
// DeleteComment deletes an issue comment. // DeleteComment deletes an issue comment.
// //
// GitHub API docs: https://developer.github.com/v3/issues/comments/#delete-an-issue-comment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#delete-an-issue-comment
func (s *IssuesService) DeleteComment(ctx context.Context, owner string, repo string, commentID int64) (*Response, error) { func (s *IssuesService) DeleteComment(ctx context.Context, owner string, repo string, commentID int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, commentID) u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, commentID)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)

View file

@ -8,7 +8,6 @@ package github
import ( import (
"context" "context"
"fmt" "fmt"
"strings"
"time" "time"
) )
@ -66,21 +65,27 @@ type IssueEvent struct {
// review_dismissed // review_dismissed
// The review was dismissed and `DismissedReview` will be populated below. // The review was dismissed and `DismissedReview` will be populated below.
// //
// review_requested, review_request_removed
// The Actor requested or removed the request for a review.
// RequestedReviewer and ReviewRequester will be populated below.
//
Event *string `json:"event,omitempty"` Event *string `json:"event,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"` CreatedAt *time.Time `json:"created_at,omitempty"`
Issue *Issue `json:"issue,omitempty"` Issue *Issue `json:"issue,omitempty"`
// Only present on certain events; see above. // Only present on certain events; see above.
Assignee *User `json:"assignee,omitempty"` Assignee *User `json:"assignee,omitempty"`
Assigner *User `json:"assigner,omitempty"` Assigner *User `json:"assigner,omitempty"`
CommitID *string `json:"commit_id,omitempty"` CommitID *string `json:"commit_id,omitempty"`
Milestone *Milestone `json:"milestone,omitempty"` Milestone *Milestone `json:"milestone,omitempty"`
Label *Label `json:"label,omitempty"` Label *Label `json:"label,omitempty"`
Rename *Rename `json:"rename,omitempty"` Rename *Rename `json:"rename,omitempty"`
LockReason *string `json:"lock_reason,omitempty"` LockReason *string `json:"lock_reason,omitempty"`
ProjectCard *ProjectCard `json:"project_card,omitempty"` ProjectCard *ProjectCard `json:"project_card,omitempty"`
DismissedReview *DismissedReview `json:"dismissed_review,omitempty"` DismissedReview *DismissedReview `json:"dismissed_review,omitempty"`
RequestedReviewer *User `json:"requested_reviewer,omitempty"`
ReviewRequester *User `json:"review_requester,omitempty"`
} }
// DismissedReview represents details for 'dismissed_review' events. // DismissedReview represents details for 'dismissed_review' events.
@ -95,7 +100,7 @@ type DismissedReview struct {
// ListIssueEvents lists events for the specified issue. // ListIssueEvents lists events for the specified issue.
// //
// GitHub API docs: https://developer.github.com/v3/issues/events/#list-issue-events // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#list-issue-events
func (s *IssuesService) ListIssueEvents(ctx context.Context, owner, repo string, number int, opts *ListOptions) ([]*IssueEvent, *Response, error) { func (s *IssuesService) ListIssueEvents(ctx context.Context, owner, repo string, number int, opts *ListOptions) ([]*IssueEvent, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%v/events", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/issues/%v/events", owner, repo, number)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -108,8 +113,7 @@ func (s *IssuesService) ListIssueEvents(ctx context.Context, owner, repo string,
return nil, nil, err return nil, nil, err
} }
acceptHeaders := []string{mediaTypeLockReasonPreview, mediaTypeProjectCardDetailsPreview} req.Header.Set("Accept", mediaTypeProjectCardDetailsPreview)
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
var events []*IssueEvent var events []*IssueEvent
resp, err := s.client.Do(ctx, req, &events) resp, err := s.client.Do(ctx, req, &events)
@ -122,7 +126,7 @@ func (s *IssuesService) ListIssueEvents(ctx context.Context, owner, repo string,
// ListRepositoryEvents lists events for the specified repository. // ListRepositoryEvents lists events for the specified repository.
// //
// GitHub API docs: https://developer.github.com/v3/issues/events/#list-issue-events-for-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#list-issue-events-for-a-repository
func (s *IssuesService) ListRepositoryEvents(ctx context.Context, owner, repo string, opts *ListOptions) ([]*IssueEvent, *Response, error) { func (s *IssuesService) ListRepositoryEvents(ctx context.Context, owner, repo string, opts *ListOptions) ([]*IssueEvent, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/events", owner, repo) u := fmt.Sprintf("repos/%v/%v/issues/events", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -146,7 +150,7 @@ func (s *IssuesService) ListRepositoryEvents(ctx context.Context, owner, repo st
// GetEvent returns the specified issue event. // GetEvent returns the specified issue event.
// //
// GitHub API docs: https://developer.github.com/v3/issues/events/#get-an-issue-event // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#get-an-issue-event
func (s *IssuesService) GetEvent(ctx context.Context, owner, repo string, id int64) (*IssueEvent, *Response, error) { func (s *IssuesService) GetEvent(ctx context.Context, owner, repo string, id int64) (*IssueEvent, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/events/%v", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/issues/events/%v", owner, repo, id)

View file

@ -27,7 +27,7 @@ func (l Label) String() string {
// ListLabels lists all labels for a repository. // ListLabels lists all labels for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/issues/labels/#list-labels-for-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#list-labels-for-a-repository
func (s *IssuesService) ListLabels(ctx context.Context, owner string, repo string, opts *ListOptions) ([]*Label, *Response, error) { func (s *IssuesService) ListLabels(ctx context.Context, owner string, repo string, opts *ListOptions) ([]*Label, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/labels", owner, repo) u := fmt.Sprintf("repos/%v/%v/labels", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -51,7 +51,7 @@ func (s *IssuesService) ListLabels(ctx context.Context, owner string, repo strin
// GetLabel gets a single label. // GetLabel gets a single label.
// //
// GitHub API docs: https://developer.github.com/v3/issues/labels/#get-a-label // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#get-a-label
func (s *IssuesService) GetLabel(ctx context.Context, owner string, repo string, name string) (*Label, *Response, error) { func (s *IssuesService) GetLabel(ctx context.Context, owner string, repo string, name string) (*Label, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/labels/%v", owner, repo, name) u := fmt.Sprintf("repos/%v/%v/labels/%v", owner, repo, name)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -70,7 +70,7 @@ func (s *IssuesService) GetLabel(ctx context.Context, owner string, repo string,
// CreateLabel creates a new label on the specified repository. // CreateLabel creates a new label on the specified repository.
// //
// GitHub API docs: https://developer.github.com/v3/issues/labels/#create-a-label // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#create-a-label
func (s *IssuesService) CreateLabel(ctx context.Context, owner string, repo string, label *Label) (*Label, *Response, error) { func (s *IssuesService) CreateLabel(ctx context.Context, owner string, repo string, label *Label) (*Label, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/labels", owner, repo) u := fmt.Sprintf("repos/%v/%v/labels", owner, repo)
req, err := s.client.NewRequest("POST", u, label) req, err := s.client.NewRequest("POST", u, label)
@ -89,7 +89,7 @@ func (s *IssuesService) CreateLabel(ctx context.Context, owner string, repo stri
// EditLabel edits a label. // EditLabel edits a label.
// //
// GitHub API docs: https://developer.github.com/v3/issues/labels/#update-a-label // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#update-a-label
func (s *IssuesService) EditLabel(ctx context.Context, owner string, repo string, name string, label *Label) (*Label, *Response, error) { func (s *IssuesService) EditLabel(ctx context.Context, owner string, repo string, name string, label *Label) (*Label, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/labels/%v", owner, repo, name) u := fmt.Sprintf("repos/%v/%v/labels/%v", owner, repo, name)
req, err := s.client.NewRequest("PATCH", u, label) req, err := s.client.NewRequest("PATCH", u, label)
@ -108,7 +108,7 @@ func (s *IssuesService) EditLabel(ctx context.Context, owner string, repo string
// DeleteLabel deletes a label. // DeleteLabel deletes a label.
// //
// GitHub API docs: https://developer.github.com/v3/issues/labels/#delete-a-label // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#delete-a-label
func (s *IssuesService) DeleteLabel(ctx context.Context, owner string, repo string, name string) (*Response, error) { func (s *IssuesService) DeleteLabel(ctx context.Context, owner string, repo string, name string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/labels/%v", owner, repo, name) u := fmt.Sprintf("repos/%v/%v/labels/%v", owner, repo, name)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -120,7 +120,7 @@ func (s *IssuesService) DeleteLabel(ctx context.Context, owner string, repo stri
// ListLabelsByIssue lists all labels for an issue. // ListLabelsByIssue lists all labels for an issue.
// //
// GitHub API docs: https://developer.github.com/v3/issues/labels/#list-labels-for-an-issue // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#list-labels-for-an-issue
func (s *IssuesService) ListLabelsByIssue(ctx context.Context, owner string, repo string, number int, opts *ListOptions) ([]*Label, *Response, error) { func (s *IssuesService) ListLabelsByIssue(ctx context.Context, owner string, repo string, number int, opts *ListOptions) ([]*Label, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/labels", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/issues/%d/labels", owner, repo, number)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -144,7 +144,7 @@ func (s *IssuesService) ListLabelsByIssue(ctx context.Context, owner string, rep
// AddLabelsToIssue adds labels to an issue. // AddLabelsToIssue adds labels to an issue.
// //
// GitHub API docs: https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#add-labels-to-an-issue
func (s *IssuesService) AddLabelsToIssue(ctx context.Context, owner string, repo string, number int, labels []string) ([]*Label, *Response, error) { func (s *IssuesService) AddLabelsToIssue(ctx context.Context, owner string, repo string, number int, labels []string) ([]*Label, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/labels", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/issues/%d/labels", owner, repo, number)
req, err := s.client.NewRequest("POST", u, labels) req, err := s.client.NewRequest("POST", u, labels)
@ -163,7 +163,7 @@ func (s *IssuesService) AddLabelsToIssue(ctx context.Context, owner string, repo
// RemoveLabelForIssue removes a label for an issue. // RemoveLabelForIssue removes a label for an issue.
// //
// GitHub API docs: https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#remove-a-label-from-an-issue
func (s *IssuesService) RemoveLabelForIssue(ctx context.Context, owner string, repo string, number int, label string) (*Response, error) { func (s *IssuesService) RemoveLabelForIssue(ctx context.Context, owner string, repo string, number int, label string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/labels/%v", owner, repo, number, label) u := fmt.Sprintf("repos/%v/%v/issues/%d/labels/%v", owner, repo, number, label)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -176,7 +176,7 @@ func (s *IssuesService) RemoveLabelForIssue(ctx context.Context, owner string, r
// ReplaceLabelsForIssue replaces all labels for an issue. // ReplaceLabelsForIssue replaces all labels for an issue.
// //
// GitHub API docs: https://developer.github.com/v3/issues/labels/#set-labels-for-an-issue // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#set-labels-for-an-issue
func (s *IssuesService) ReplaceLabelsForIssue(ctx context.Context, owner string, repo string, number int, labels []string) ([]*Label, *Response, error) { func (s *IssuesService) ReplaceLabelsForIssue(ctx context.Context, owner string, repo string, number int, labels []string) ([]*Label, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/labels", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/issues/%d/labels", owner, repo, number)
req, err := s.client.NewRequest("PUT", u, labels) req, err := s.client.NewRequest("PUT", u, labels)
@ -195,7 +195,7 @@ func (s *IssuesService) ReplaceLabelsForIssue(ctx context.Context, owner string,
// RemoveLabelsForIssue removes all labels for an issue. // RemoveLabelsForIssue removes all labels for an issue.
// //
// GitHub API docs: https://developer.github.com/v3/issues/labels/#remove-all-labels-from-an-issue // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#remove-all-labels-from-an-issue
func (s *IssuesService) RemoveLabelsForIssue(ctx context.Context, owner string, repo string, number int) (*Response, error) { func (s *IssuesService) RemoveLabelsForIssue(ctx context.Context, owner string, repo string, number int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/labels", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/issues/%d/labels", owner, repo, number)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -208,7 +208,7 @@ func (s *IssuesService) RemoveLabelsForIssue(ctx context.Context, owner string,
// ListLabelsForMilestone lists labels for every issue in a milestone. // ListLabelsForMilestone lists labels for every issue in a milestone.
// //
// GitHub API docs: https://developer.github.com/v3/issues/labels/#list-labels-for-issues-in-a-milestone // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#list-labels-for-issues-in-a-milestone
func (s *IssuesService) ListLabelsForMilestone(ctx context.Context, owner string, repo string, number int, opts *ListOptions) ([]*Label, *Response, error) { func (s *IssuesService) ListLabelsForMilestone(ctx context.Context, owner string, repo string, number int, opts *ListOptions) ([]*Label, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/milestones/%d/labels", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/milestones/%d/labels", owner, repo, number)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)

View file

@ -55,7 +55,7 @@ type MilestoneListOptions struct {
// ListMilestones lists all milestones for a repository. // ListMilestones lists all milestones for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/issues/milestones/#list-milestones // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#list-milestones
func (s *IssuesService) ListMilestones(ctx context.Context, owner string, repo string, opts *MilestoneListOptions) ([]*Milestone, *Response, error) { func (s *IssuesService) ListMilestones(ctx context.Context, owner string, repo string, opts *MilestoneListOptions) ([]*Milestone, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/milestones", owner, repo) u := fmt.Sprintf("repos/%v/%v/milestones", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -79,7 +79,7 @@ func (s *IssuesService) ListMilestones(ctx context.Context, owner string, repo s
// GetMilestone gets a single milestone. // GetMilestone gets a single milestone.
// //
// GitHub API docs: https://developer.github.com/v3/issues/milestones/#get-a-milestone // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#get-a-milestone
func (s *IssuesService) GetMilestone(ctx context.Context, owner string, repo string, number int) (*Milestone, *Response, error) { func (s *IssuesService) GetMilestone(ctx context.Context, owner string, repo string, number int) (*Milestone, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/milestones/%d", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/milestones/%d", owner, repo, number)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -98,7 +98,7 @@ func (s *IssuesService) GetMilestone(ctx context.Context, owner string, repo str
// CreateMilestone creates a new milestone on the specified repository. // CreateMilestone creates a new milestone on the specified repository.
// //
// GitHub API docs: https://developer.github.com/v3/issues/milestones/#create-a-milestone // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#create-a-milestone
func (s *IssuesService) CreateMilestone(ctx context.Context, owner string, repo string, milestone *Milestone) (*Milestone, *Response, error) { func (s *IssuesService) CreateMilestone(ctx context.Context, owner string, repo string, milestone *Milestone) (*Milestone, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/milestones", owner, repo) u := fmt.Sprintf("repos/%v/%v/milestones", owner, repo)
req, err := s.client.NewRequest("POST", u, milestone) req, err := s.client.NewRequest("POST", u, milestone)
@ -117,7 +117,7 @@ func (s *IssuesService) CreateMilestone(ctx context.Context, owner string, repo
// EditMilestone edits a milestone. // EditMilestone edits a milestone.
// //
// GitHub API docs: https://developer.github.com/v3/issues/milestones/#update-a-milestone // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#update-a-milestone
func (s *IssuesService) EditMilestone(ctx context.Context, owner string, repo string, number int, milestone *Milestone) (*Milestone, *Response, error) { func (s *IssuesService) EditMilestone(ctx context.Context, owner string, repo string, number int, milestone *Milestone) (*Milestone, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/milestones/%d", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/milestones/%d", owner, repo, number)
req, err := s.client.NewRequest("PATCH", u, milestone) req, err := s.client.NewRequest("PATCH", u, milestone)
@ -136,7 +136,7 @@ func (s *IssuesService) EditMilestone(ctx context.Context, owner string, repo st
// DeleteMilestone deletes a milestone. // DeleteMilestone deletes a milestone.
// //
// GitHub API docs: https://developer.github.com/v3/issues/milestones/#delete-a-milestone // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#delete-a-milestone
func (s *IssuesService) DeleteMilestone(ctx context.Context, owner string, repo string, number int) (*Response, error) { func (s *IssuesService) DeleteMilestone(ctx context.Context, owner string, repo string, number int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/milestones/%d", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/milestones/%d", owner, repo, number)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)

View file

@ -15,7 +15,7 @@ import (
// Timeline represents an event that occurred around an Issue or Pull Request. // Timeline represents an event that occurred around an Issue or Pull Request.
// //
// It is similar to an IssueEvent but may contain more information. // It is similar to an IssueEvent but may contain more information.
// GitHub API docs: https://developer.github.com/v3/issues/timeline/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/timeline/
type Timeline struct { type Timeline struct {
ID *int64 `json:"id,omitempty"` ID *int64 `json:"id,omitempty"`
URL *string `json:"url,omitempty"` URL *string `json:"url,omitempty"`
@ -81,6 +81,9 @@ type Timeline struct {
// reopened // reopened
// The issue was reopened by the actor. // The issue was reopened by the actor.
// //
// reviewed
// The pull request was reviewed.
//
// subscribed // subscribed
// The actor subscribed to receive notifications for an issue. // The actor subscribed to receive notifications for an issue.
// //
@ -118,6 +121,10 @@ type Timeline struct {
// Only provided for 'renamed' events. // Only provided for 'renamed' events.
Rename *Rename `json:"rename,omitempty"` Rename *Rename `json:"rename,omitempty"`
ProjectCard *ProjectCard `json:"project_card,omitempty"` ProjectCard *ProjectCard `json:"project_card,omitempty"`
// The state of a submitted review. Can be one of: 'commented',
// 'changes_requested' or 'approved'.
// Only provided for 'reviewed' events.
State *string `json:"state,omitempty"`
} }
// Source represents a reference's source. // Source represents a reference's source.
@ -131,7 +138,7 @@ type Source struct {
// ListIssueTimeline lists events for the specified issue. // ListIssueTimeline lists events for the specified issue.
// //
// GitHub API docs: https://developer.github.com/v3/issues/timeline/#list-timeline-events-for-an-issue // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#list-timeline-events-for-an-issue
func (s *IssuesService) ListIssueTimeline(ctx context.Context, owner, repo string, number int, opts *ListOptions) ([]*Timeline, *Response, error) { func (s *IssuesService) ListIssueTimeline(ctx context.Context, owner, repo string, number int, opts *ListOptions) ([]*Timeline, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%v/timeline", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/issues/%v/timeline", owner, repo, number)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)

View file

@ -13,7 +13,7 @@ import (
// LicensesService handles communication with the license related // LicensesService handles communication with the license related
// methods of the GitHub API. // methods of the GitHub API.
// //
// GitHub API docs: https://developer.github.com/v3/licenses/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/licenses/
type LicensesService service type LicensesService service
// RepositoryLicense represents the license for a repository. // RepositoryLicense represents the license for a repository.
@ -60,7 +60,7 @@ func (l License) String() string {
// List popular open source licenses. // List popular open source licenses.
// //
// GitHub API docs: https://developer.github.com/v3/licenses/#list-all-licenses // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/licenses/#list-all-licenses
func (s *LicensesService) List(ctx context.Context) ([]*License, *Response, error) { func (s *LicensesService) List(ctx context.Context) ([]*License, *Response, error) {
req, err := s.client.NewRequest("GET", "licenses", nil) req, err := s.client.NewRequest("GET", "licenses", nil)
if err != nil { if err != nil {
@ -78,7 +78,7 @@ func (s *LicensesService) List(ctx context.Context) ([]*License, *Response, erro
// Get extended metadata for one license. // Get extended metadata for one license.
// //
// GitHub API docs: https://developer.github.com/v3/licenses/#get-a-license // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/licenses/#get-a-license
func (s *LicensesService) Get(ctx context.Context, licenseName string) (*License, *Response, error) { func (s *LicensesService) Get(ctx context.Context, licenseName string) (*License, *Response, error) {
u := fmt.Sprintf("licenses/%s", licenseName) u := fmt.Sprintf("licenses/%s", licenseName)

View file

@ -19,6 +19,7 @@ import (
"fmt" "fmt"
"hash" "hash"
"io/ioutil" "io/ioutil"
"mime"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
@ -30,8 +31,10 @@ const (
// sha256Prefix and sha512Prefix are provided for future compatibility. // sha256Prefix and sha512Prefix are provided for future compatibility.
sha256Prefix = "sha256" sha256Prefix = "sha256"
sha512Prefix = "sha512" sha512Prefix = "sha512"
// signatureHeader is the GitHub header key used to pass the HMAC hexdigest. // sha1SignatureHeader is the GitHub header key used to pass the HMAC-SHA1 hexdigest.
signatureHeader = "X-Hub-Signature" 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 is the GitHub header key used to pass the event type.
eventTypeHeader = "X-Github-Event" eventTypeHeader = "X-Github-Event"
// deliveryIDHeader is the GitHub header key used to pass the unique ID for the webhook event. // deliveryIDHeader is the GitHub header key used to pass the unique ID for the webhook event.
@ -44,6 +47,7 @@ var (
"check_run": "CheckRunEvent", "check_run": "CheckRunEvent",
"check_suite": "CheckSuiteEvent", "check_suite": "CheckSuiteEvent",
"commit_comment": "CommitCommentEvent", "commit_comment": "CommitCommentEvent",
"content_reference": "ContentReferenceEvent",
"create": "CreateEvent", "create": "CreateEvent",
"delete": "DeleteEvent", "delete": "DeleteEvent",
"deploy_key": "DeployKeyEvent", "deploy_key": "DeployKeyEvent",
@ -71,9 +75,10 @@ var (
"project_card": "ProjectCardEvent", "project_card": "ProjectCardEvent",
"project_column": "ProjectColumnEvent", "project_column": "ProjectColumnEvent",
"public": "PublicEvent", "public": "PublicEvent",
"pull_request": "PullRequestEvent",
"pull_request_review": "PullRequestReviewEvent", "pull_request_review": "PullRequestReviewEvent",
"pull_request_review_comment": "PullRequestReviewCommentEvent", "pull_request_review_comment": "PullRequestReviewCommentEvent",
"pull_request": "PullRequestEvent", "pull_request_target": "PullRequestTargetEvent",
"push": "PushEvent", "push": "PushEvent",
"repository": "RepositoryEvent", "repository": "RepositoryEvent",
"repository_dispatch": "RepositoryDispatchEvent", "repository_dispatch": "RepositoryDispatchEvent",
@ -85,6 +90,8 @@ var (
"team_add": "TeamAddEvent", "team_add": "TeamAddEvent",
"user": "UserEvent", "user": "UserEvent",
"watch": "WatchEvent", "watch": "WatchEvent",
"workflow_dispatch": "WorkflowDispatchEvent",
"workflow_run": "WorkflowRunEvent",
} }
) )
@ -151,7 +158,14 @@ func messageMAC(signature string) ([]byte, func() hash.Hash, error) {
func ValidatePayload(r *http.Request, secretToken []byte) (payload []byte, err error) { func ValidatePayload(r *http.Request, secretToken []byte) (payload []byte, err error) {
var body []byte // Raw body that GitHub uses to calculate the signature. var body []byte // Raw body that GitHub uses to calculate the signature.
switch ct := r.Header.Get("Content-Type"); ct { ct := r.Header.Get("Content-Type")
mediatype, _, err := mime.ParseMediaType(ct)
if err != nil {
mediatype = ""
}
switch mediatype {
case "application/json": case "application/json":
var err error var err error
if body, err = ioutil.ReadAll(r.Body); err != nil { if body, err = ioutil.ReadAll(r.Body); err != nil {
@ -187,7 +201,10 @@ func ValidatePayload(r *http.Request, secretToken []byte) (payload []byte, err e
// Only validate the signature if a secret token exists. This is intended for // 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. // local development only and all webhooks should ideally set up a secret token.
if len(secretToken) > 0 { if len(secretToken) > 0 {
sig := r.Header.Get(signatureHeader) sig := r.Header.Get(sha256SignatureHeader)
if sig == "" {
sig = r.Header.Get(sha1SignatureHeader)
}
if err := ValidateSignature(sig, body, secretToken); err != nil { if err := ValidateSignature(sig, body, secretToken); err != nil {
return nil, err return nil, err
} }
@ -215,14 +232,14 @@ func ValidateSignature(signature string, payload, secretToken []byte) error {
// WebHookType returns the event type of webhook request r. // WebHookType returns the event type of webhook request r.
// //
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#webhook-headers // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/hooks/#webhook-headers
func WebHookType(r *http.Request) string { 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. // DeliveryID returns the unique delivery ID of webhook request r.
// //
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#webhook-headers // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/hooks/#webhook-headers
func DeliveryID(r *http.Request) string { func DeliveryID(r *http.Request) string {
return r.Header.Get(deliveryIDHeader) return r.Header.Get(deliveryIDHeader)
} }

View file

@ -16,7 +16,7 @@ import (
// MigrationService provides access to the migration related functions // MigrationService provides access to the migration related functions
// in the GitHub API. // in the GitHub API.
// //
// GitHub API docs: https://developer.github.com/v3/migration/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migration/
type MigrationService service type MigrationService service
// Migration represents a GitHub migration (archival). // Migration represents a GitHub migration (archival).
@ -74,7 +74,7 @@ type startMigration struct {
// StartMigration starts the generation of a migration archive. // StartMigration starts the generation of a migration archive.
// repos is a slice of repository names to migrate. // repos is a slice of repository names to migrate.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/orgs/#start-an-organization-migration // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#start-an-organization-migration
func (s *MigrationService) StartMigration(ctx context.Context, org string, repos []string, opts *MigrationOptions) (*Migration, *Response, error) { func (s *MigrationService) StartMigration(ctx context.Context, org string, repos []string, opts *MigrationOptions) (*Migration, *Response, error) {
u := fmt.Sprintf("orgs/%v/migrations", org) u := fmt.Sprintf("orgs/%v/migrations", org)
@ -103,7 +103,7 @@ func (s *MigrationService) StartMigration(ctx context.Context, org string, repos
// ListMigrations lists the most recent migrations. // ListMigrations lists the most recent migrations.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/orgs/#list-organization-migrations // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#list-organization-migrations
func (s *MigrationService) ListMigrations(ctx context.Context, org string, opts *ListOptions) ([]*Migration, *Response, error) { func (s *MigrationService) ListMigrations(ctx context.Context, org string, opts *ListOptions) ([]*Migration, *Response, error) {
u := fmt.Sprintf("orgs/%v/migrations", org) u := fmt.Sprintf("orgs/%v/migrations", org)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -131,7 +131,7 @@ func (s *MigrationService) ListMigrations(ctx context.Context, org string, opts
// MigrationStatus gets the status of a specific migration archive. // MigrationStatus gets the status of a specific migration archive.
// id is the migration ID. // id is the migration ID.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/orgs/#get-an-organization-migration-status // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#get-an-organization-migration-status
func (s *MigrationService) MigrationStatus(ctx context.Context, org string, id int64) (*Migration, *Response, error) { func (s *MigrationService) MigrationStatus(ctx context.Context, org string, id int64) (*Migration, *Response, error) {
u := fmt.Sprintf("orgs/%v/migrations/%v", org, id) u := fmt.Sprintf("orgs/%v/migrations/%v", org, id)
@ -155,7 +155,7 @@ func (s *MigrationService) MigrationStatus(ctx context.Context, org string, id i
// MigrationArchiveURL fetches a migration archive URL. // MigrationArchiveURL fetches a migration archive URL.
// id is the migration ID. // id is the migration ID.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/orgs/#download-an-organization-migration-archive // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#download-an-organization-migration-archive
func (s *MigrationService) MigrationArchiveURL(ctx context.Context, org string, id int64) (url string, err error) { func (s *MigrationService) MigrationArchiveURL(ctx context.Context, org string, id int64) (url string, err error) {
u := fmt.Sprintf("orgs/%v/migrations/%v/archive", org, id) u := fmt.Sprintf("orgs/%v/migrations/%v/archive", org, id)
@ -192,7 +192,7 @@ func (s *MigrationService) MigrationArchiveURL(ctx context.Context, org string,
// DeleteMigration deletes a previous migration archive. // DeleteMigration deletes a previous migration archive.
// id is the migration ID. // id is the migration ID.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/orgs/#delete-an-organization-migration-archive // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#delete-an-organization-migration-archive
func (s *MigrationService) DeleteMigration(ctx context.Context, org string, id int64) (*Response, error) { func (s *MigrationService) DeleteMigration(ctx context.Context, org string, id int64) (*Response, error) {
u := fmt.Sprintf("orgs/%v/migrations/%v/archive", org, id) u := fmt.Sprintf("orgs/%v/migrations/%v/archive", org, id)
@ -212,7 +212,7 @@ func (s *MigrationService) DeleteMigration(ctx context.Context, org string, id i
// You should unlock each migrated repository and delete them when the migration // You should unlock each migrated repository and delete them when the migration
// is complete and you no longer need the source data. // is complete and you no longer need the source data.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/orgs/#unlock-an-organization-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#unlock-an-organization-repository
func (s *MigrationService) UnlockRepo(ctx context.Context, org string, id int64, repo string) (*Response, error) { func (s *MigrationService) UnlockRepo(ctx context.Context, org string, id int64, repo string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/migrations/%v/repos/%v/lock", org, id, repo) u := fmt.Sprintf("orgs/%v/migrations/%v/repos/%v/lock", org, id, repo)

View file

@ -115,7 +115,7 @@ func (i Import) String() string {
// SourceImportAuthor identifies an author imported from a source repository. // SourceImportAuthor identifies an author imported from a source repository.
// //
// GitHub API docs: https://developer.github.com/v3/migration/source_imports/#get-commit-authors // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migration/source_imports/#get-commit-authors
type SourceImportAuthor struct { type SourceImportAuthor struct {
ID *int64 `json:"id,omitempty"` ID *int64 `json:"id,omitempty"`
RemoteID *string `json:"remote_id,omitempty"` RemoteID *string `json:"remote_id,omitempty"`
@ -132,7 +132,7 @@ func (a SourceImportAuthor) String() string {
// LargeFile identifies a file larger than 100MB found during a repository import. // LargeFile identifies a file larger than 100MB found during a repository import.
// //
// GitHub API docs: https://developer.github.com/v3/migration/source_imports/#get-large-files // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migration/source_imports/#get-large-files
type LargeFile struct { type LargeFile struct {
RefName *string `json:"ref_name,omitempty"` RefName *string `json:"ref_name,omitempty"`
Path *string `json:"path,omitempty"` Path *string `json:"path,omitempty"`
@ -146,7 +146,7 @@ func (f LargeFile) String() string {
// StartImport initiates a repository import. // StartImport initiates a repository import.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/source_imports/#start-an-import // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#start-an-import
func (s *MigrationService) StartImport(ctx context.Context, owner, repo string, in *Import) (*Import, *Response, error) { func (s *MigrationService) StartImport(ctx context.Context, owner, repo string, in *Import) (*Import, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/import", owner, repo) u := fmt.Sprintf("repos/%v/%v/import", owner, repo)
req, err := s.client.NewRequest("PUT", u, in) req, err := s.client.NewRequest("PUT", u, in)
@ -165,7 +165,7 @@ func (s *MigrationService) StartImport(ctx context.Context, owner, repo string,
// ImportProgress queries for the status and progress of an ongoing repository import. // ImportProgress queries for the status and progress of an ongoing repository import.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/source_imports/#get-an-import-status // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#get-an-import-status
func (s *MigrationService) ImportProgress(ctx context.Context, owner, repo string) (*Import, *Response, error) { func (s *MigrationService) ImportProgress(ctx context.Context, owner, repo string) (*Import, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/import", owner, repo) u := fmt.Sprintf("repos/%v/%v/import", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -184,7 +184,7 @@ func (s *MigrationService) ImportProgress(ctx context.Context, owner, repo strin
// UpdateImport initiates a repository import. // UpdateImport initiates a repository import.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/source_imports/#update-an-import // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#update-an-import
func (s *MigrationService) UpdateImport(ctx context.Context, owner, repo string, in *Import) (*Import, *Response, error) { func (s *MigrationService) UpdateImport(ctx context.Context, owner, repo string, in *Import) (*Import, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/import", owner, repo) u := fmt.Sprintf("repos/%v/%v/import", owner, repo)
req, err := s.client.NewRequest("PATCH", u, in) req, err := s.client.NewRequest("PATCH", u, in)
@ -213,7 +213,7 @@ func (s *MigrationService) UpdateImport(ctx context.Context, owner, repo string,
// This method and MapCommitAuthor allow you to provide correct Git author // This method and MapCommitAuthor allow you to provide correct Git author
// information. // information.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/source_imports/#get-commit-authors // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#get-commit-authors
func (s *MigrationService) CommitAuthors(ctx context.Context, owner, repo string) ([]*SourceImportAuthor, *Response, error) { func (s *MigrationService) CommitAuthors(ctx context.Context, owner, repo string) ([]*SourceImportAuthor, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/import/authors", owner, repo) u := fmt.Sprintf("repos/%v/%v/import/authors", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -234,7 +234,7 @@ func (s *MigrationService) CommitAuthors(ctx context.Context, owner, repo string
// application can continue updating authors any time before you push new // application can continue updating authors any time before you push new
// commits to the repository. // commits to the repository.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/source_imports/#map-a-commit-author // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#map-a-commit-author
func (s *MigrationService) MapCommitAuthor(ctx context.Context, owner, repo string, id int64, author *SourceImportAuthor) (*SourceImportAuthor, *Response, error) { func (s *MigrationService) MapCommitAuthor(ctx context.Context, owner, repo string, id int64, author *SourceImportAuthor) (*SourceImportAuthor, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/import/authors/%v", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/import/authors/%v", owner, repo, id)
req, err := s.client.NewRequest("PATCH", u, author) req, err := s.client.NewRequest("PATCH", u, author)
@ -255,7 +255,7 @@ func (s *MigrationService) MapCommitAuthor(ctx context.Context, owner, repo stri
// files larger than 100MB. Only the UseLFS field on the provided Import is // files larger than 100MB. Only the UseLFS field on the provided Import is
// used. // used.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/source_imports/#update-git-lfs-preference // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#update-git-lfs-preference
func (s *MigrationService) SetLFSPreference(ctx context.Context, owner, repo string, in *Import) (*Import, *Response, error) { func (s *MigrationService) SetLFSPreference(ctx context.Context, owner, repo string, in *Import) (*Import, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/import/lfs", owner, repo) u := fmt.Sprintf("repos/%v/%v/import/lfs", owner, repo)
req, err := s.client.NewRequest("PATCH", u, in) req, err := s.client.NewRequest("PATCH", u, in)
@ -274,7 +274,7 @@ func (s *MigrationService) SetLFSPreference(ctx context.Context, owner, repo str
// LargeFiles lists files larger than 100MB found during the import. // LargeFiles lists files larger than 100MB found during the import.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/source_imports/#get-large-files // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#get-large-files
func (s *MigrationService) LargeFiles(ctx context.Context, owner, repo string) ([]*LargeFile, *Response, error) { func (s *MigrationService) LargeFiles(ctx context.Context, owner, repo string) ([]*LargeFile, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/import/large_files", owner, repo) u := fmt.Sprintf("repos/%v/%v/import/large_files", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -293,7 +293,7 @@ func (s *MigrationService) LargeFiles(ctx context.Context, owner, repo string) (
// CancelImport stops an import for a repository. // CancelImport stops an import for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/source_imports/#cancel-an-import // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#cancel-an-import
func (s *MigrationService) CancelImport(ctx context.Context, owner, repo string) (*Response, error) { func (s *MigrationService) CancelImport(ctx context.Context, owner, repo string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/import", owner, repo) u := fmt.Sprintf("repos/%v/%v/import", owner, repo)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)

View file

@ -67,7 +67,7 @@ type startUserMigration struct {
// StartUserMigration starts the generation of a migration archive. // StartUserMigration starts the generation of a migration archive.
// repos is a slice of repository names to migrate. // repos is a slice of repository names to migrate.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/users/#start-a-user-migration // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#start-a-user-migration
func (s *MigrationService) StartUserMigration(ctx context.Context, repos []string, opts *UserMigrationOptions) (*UserMigration, *Response, error) { func (s *MigrationService) StartUserMigration(ctx context.Context, repos []string, opts *UserMigrationOptions) (*UserMigration, *Response, error) {
u := "user/migrations" u := "user/migrations"
@ -96,7 +96,7 @@ func (s *MigrationService) StartUserMigration(ctx context.Context, repos []strin
// ListUserMigrations lists the most recent migrations. // ListUserMigrations lists the most recent migrations.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/users/#list-user-migrations // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#list-user-migrations
func (s *MigrationService) ListUserMigrations(ctx context.Context) ([]*UserMigration, *Response, error) { func (s *MigrationService) ListUserMigrations(ctx context.Context) ([]*UserMigration, *Response, error) {
u := "user/migrations" u := "user/migrations"
@ -120,7 +120,7 @@ func (s *MigrationService) ListUserMigrations(ctx context.Context) ([]*UserMigra
// UserMigrationStatus gets the status of a specific migration archive. // UserMigrationStatus gets the status of a specific migration archive.
// id is the migration ID. // id is the migration ID.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/users/#get-a-user-migration-status // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#get-a-user-migration-status
func (s *MigrationService) UserMigrationStatus(ctx context.Context, id int64) (*UserMigration, *Response, error) { func (s *MigrationService) UserMigrationStatus(ctx context.Context, id int64) (*UserMigration, *Response, error) {
u := fmt.Sprintf("user/migrations/%v", id) u := fmt.Sprintf("user/migrations/%v", id)
@ -144,7 +144,7 @@ func (s *MigrationService) UserMigrationStatus(ctx context.Context, id int64) (*
// UserMigrationArchiveURL gets the URL for a specific migration archive. // UserMigrationArchiveURL gets the URL for a specific migration archive.
// id is the migration ID. // id is the migration ID.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/users/#download-a-user-migration-archive // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#download-a-user-migration-archive
func (s *MigrationService) UserMigrationArchiveURL(ctx context.Context, id int64) (string, error) { func (s *MigrationService) UserMigrationArchiveURL(ctx context.Context, id int64) (string, error) {
url := fmt.Sprintf("user/migrations/%v/archive", id) url := fmt.Sprintf("user/migrations/%v/archive", id)
@ -178,7 +178,7 @@ func (s *MigrationService) UserMigrationArchiveURL(ctx context.Context, id int64
// DeleteUserMigration will delete a previous migration archive. // DeleteUserMigration will delete a previous migration archive.
// id is the migration ID. // id is the migration ID.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/users/#delete-a-user-migration-archive // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#delete-a-user-migration-archive
func (s *MigrationService) DeleteUserMigration(ctx context.Context, id int64) (*Response, error) { func (s *MigrationService) DeleteUserMigration(ctx context.Context, id int64) (*Response, error) {
url := fmt.Sprintf("user/migrations/%v/archive", id) url := fmt.Sprintf("user/migrations/%v/archive", id)
@ -198,7 +198,7 @@ func (s *MigrationService) DeleteUserMigration(ctx context.Context, id int64) (*
// You should unlock each migrated repository and delete them when the migration // You should unlock each migrated repository and delete them when the migration
// is complete and you no longer need the source data. // is complete and you no longer need the source data.
// //
// GitHub API docs: https://developer.github.com/v3/migrations/users/#unlock-a-user-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations/#unlock-a-user-repository
func (s *MigrationService) UnlockUserRepo(ctx context.Context, id int64, repo string) (*Response, error) { func (s *MigrationService) UnlockUserRepo(ctx context.Context, id int64, repo string) (*Response, error) {
url := fmt.Sprintf("user/migrations/%v/repos/%v/lock", id, repo) url := fmt.Sprintf("user/migrations/%v/repos/%v/lock", id, repo)

View file

@ -39,7 +39,7 @@ type markdownRequest struct {
// Markdown renders an arbitrary Markdown document. // Markdown renders an arbitrary Markdown document.
// //
// GitHub API docs: https://developer.github.com/v3/markdown/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/markdown/
func (c *Client) Markdown(ctx context.Context, text string, opts *MarkdownOptions) (string, *Response, error) { func (c *Client) Markdown(ctx context.Context, text string, opts *MarkdownOptions) (string, *Response, error) {
request := &markdownRequest{Text: String(text)} request := &markdownRequest{Text: String(text)}
if opts != nil { if opts != nil {
@ -67,7 +67,7 @@ func (c *Client) Markdown(ctx context.Context, text string, opts *MarkdownOption
// ListEmojis returns the emojis available to use on GitHub. // ListEmojis returns the emojis available to use on GitHub.
// //
// GitHub API docs: https://developer.github.com/v3/emojis/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/emojis/
func (c *Client) ListEmojis(ctx context.Context) (map[string]string, *Response, error) { func (c *Client) ListEmojis(ctx context.Context) (map[string]string, *Response, error) {
req, err := c.NewRequest("GET", "emojis", nil) req, err := c.NewRequest("GET", "emojis", nil)
if err != nil { if err != nil {
@ -97,7 +97,7 @@ func (c *CodeOfConduct) String() string {
// ListCodesOfConduct returns all codes of conduct. // ListCodesOfConduct returns all codes of conduct.
// //
// GitHub API docs: https://developer.github.com/v3/codes_of_conduct/#list-all-codes-of-conduct // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/codes_of_conduct/#list-all-codes-of-conduct
func (c *Client) ListCodesOfConduct(ctx context.Context) ([]*CodeOfConduct, *Response, error) { func (c *Client) ListCodesOfConduct(ctx context.Context) ([]*CodeOfConduct, *Response, error) {
req, err := c.NewRequest("GET", "codes_of_conduct", nil) req, err := c.NewRequest("GET", "codes_of_conduct", nil)
if err != nil { if err != nil {
@ -118,7 +118,7 @@ func (c *Client) ListCodesOfConduct(ctx context.Context) ([]*CodeOfConduct, *Res
// GetCodeOfConduct returns an individual code of conduct. // GetCodeOfConduct returns an individual code of conduct.
// //
// https://developer.github.com/v3/codes_of_conduct/#get-an-individual-code-of-conduct // https://docs.github.com/en/free-pro-team@latest/rest/reference/codes_of_conduct/#get-an-individual-code-of-conduct
func (c *Client) GetCodeOfConduct(ctx context.Context, key string) (*CodeOfConduct, *Response, error) { func (c *Client) GetCodeOfConduct(ctx context.Context, key string) (*CodeOfConduct, *Response, error) {
u := fmt.Sprintf("codes_of_conduct/%s", key) u := fmt.Sprintf("codes_of_conduct/%s", key)
req, err := c.NewRequest("GET", u, nil) req, err := c.NewRequest("GET", u, nil)
@ -162,13 +162,21 @@ type APIMeta struct {
// An Array of IP addresses specifying the addresses that source imports // An Array of IP addresses specifying the addresses that source imports
// will originate from on GitHub.com. // will originate from on GitHub.com.
Importer []string `json:"importer,omitempty"` Importer []string `json:"importer,omitempty"`
// An array of IP addresses in CIDR format specifying the IP addresses
// GitHub Actions will originate from.
Actions []string `json:"actions,omitempty"`
// An array of IP addresses in CIDR format specifying the IP addresses
// Dependabot will originate from.
Dependabot []string `json:"dependabot,omitempty"`
} }
// APIMeta returns information about GitHub.com, the service. Or, if you access // APIMeta returns information about GitHub.com, the service. Or, if you access
// this endpoint on your organizations GitHub Enterprise installation, this // this endpoint on your organizations GitHub Enterprise installation, this
// endpoint provides information about that installation. // endpoint provides information about that installation.
// //
// GitHub API docs: https://developer.github.com/v3/meta/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/meta#get-github-meta-information
func (c *Client) APIMeta(ctx context.Context) (*APIMeta, *Response, error) { func (c *Client) APIMeta(ctx context.Context) (*APIMeta, *Response, error) {
req, err := c.NewRequest("GET", "meta", nil) req, err := c.NewRequest("GET", "meta", nil)
if err != nil { if err != nil {

View file

@ -14,7 +14,7 @@ import (
// OrganizationsService provides access to the organization related functions // OrganizationsService provides access to the organization related functions
// in the GitHub API. // in the GitHub API.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/
type OrganizationsService service type OrganizationsService service
// Organization represents a GitHub organization account. // Organization represents a GitHub organization account.
@ -73,6 +73,13 @@ type Organization struct {
// operation and does not consider 'internal' repositories during 'get' operation // operation and does not consider 'internal' repositories during 'get' operation
MembersAllowedRepositoryCreationType *string `json:"members_allowed_repository_creation_type,omitempty"` MembersAllowedRepositoryCreationType *string `json:"members_allowed_repository_creation_type,omitempty"`
// MembersCanCreatePages toggles whether organization members can create GitHub Pages sites.
MembersCanCreatePages *bool `json:"members_can_create_pages,omitempty"`
// MembersCanCreatePublicPages toggles whether organization members can create public GitHub Pages sites.
MembersCanCreatePublicPages *bool `json:"members_can_create_public_pages,omitempty"`
// MembersCanCreatePrivatePages toggles whether organization members can create private GitHub Pages sites.
MembersCanCreatePrivatePages *bool `json:"members_can_create_private_pages,omitempty"`
// API URLs // API URLs
URL *string `json:"url,omitempty"` URL *string `json:"url,omitempty"`
EventsURL *string `json:"events_url,omitempty"` EventsURL *string `json:"events_url,omitempty"`
@ -125,7 +132,7 @@ type OrganizationsListOptions struct {
// listing the next set of organizations, use the ID of the last-returned organization // listing the next set of organizations, use the ID of the last-returned organization
// as the opts.Since parameter for the next call. // as the opts.Since parameter for the next call.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/#list-organizations // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#list-organizations
func (s *OrganizationsService) ListAll(ctx context.Context, opts *OrganizationsListOptions) ([]*Organization, *Response, error) { func (s *OrganizationsService) ListAll(ctx context.Context, opts *OrganizationsListOptions) ([]*Organization, *Response, error) {
u, err := addOptions("organizations", opts) u, err := addOptions("organizations", opts)
if err != nil { if err != nil {
@ -148,8 +155,8 @@ func (s *OrganizationsService) ListAll(ctx context.Context, opts *OrganizationsL
// List the organizations for a user. Passing the empty string will list // List the organizations for a user. Passing the empty string will list
// organizations for the authenticated user. // organizations for the authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/#oauth-scope-requirements // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#list-organizations-for-the-authenticated-user
// GitHub API docs: https://developer.github.com/v3/orgs/#list-organizations-for-a-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#list-organizations-for-a-user
func (s *OrganizationsService) List(ctx context.Context, user string, opts *ListOptions) ([]*Organization, *Response, error) { func (s *OrganizationsService) List(ctx context.Context, user string, opts *ListOptions) ([]*Organization, *Response, error) {
var u string var u string
if user != "" { if user != "" {
@ -178,7 +185,7 @@ func (s *OrganizationsService) List(ctx context.Context, user string, opts *List
// Get fetches an organization by name. // Get fetches an organization by name.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/#get-an-organization // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#get-an-organization
func (s *OrganizationsService) Get(ctx context.Context, org string) (*Organization, *Response, error) { func (s *OrganizationsService) Get(ctx context.Context, org string) (*Organization, *Response, error) {
u := fmt.Sprintf("orgs/%v", org) u := fmt.Sprintf("orgs/%v", org)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -219,7 +226,7 @@ func (s *OrganizationsService) GetByID(ctx context.Context, id int64) (*Organiza
// Edit an organization. // Edit an organization.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/#members_can_create_repositories // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#update-an-organization
func (s *OrganizationsService) Edit(ctx context.Context, name string, org *Organization) (*Organization, *Response, error) { func (s *OrganizationsService) Edit(ctx context.Context, name string, org *Organization) (*Organization, *Response, error) {
u := fmt.Sprintf("orgs/%v", name) u := fmt.Sprintf("orgs/%v", name)
req, err := s.client.NewRequest("PATCH", u, org) req, err := s.client.NewRequest("PATCH", u, org)
@ -241,7 +248,7 @@ func (s *OrganizationsService) Edit(ctx context.Context, name string, org *Organ
// ListInstallations lists installations for an organization. // ListInstallations lists installations for an organization.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/#list-app-installations-for-an-organization // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#list-app-installations-for-an-organization
func (s *OrganizationsService) ListInstallations(ctx context.Context, org string, opts *ListOptions) (*OrganizationInstallations, *Response, error) { func (s *OrganizationsService) ListInstallations(ctx context.Context, org string, opts *ListOptions) (*OrganizationInstallations, *Response, error) {
u := fmt.Sprintf("orgs/%v/installations", org) u := fmt.Sprintf("orgs/%v/installations", org)
@ -255,9 +262,6 @@ func (s *OrganizationsService) ListInstallations(ctx context.Context, org string
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeIntegrationPreview)
result := new(OrganizationInstallations) result := new(OrganizationInstallations)
resp, err := s.client.Do(ctx, req, result) resp, err := s.client.Do(ctx, req, result)
if err != nil { if err != nil {

View file

@ -0,0 +1,58 @@
// 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"
)
// ActionsAllowed represents selected actions that are allowed in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#get-allowed-actions-for-an-organization
type ActionsAllowed struct {
GithubOwnedAllowed *bool `json:"github_owned_allowed,omitempty"`
VerifiedAllowed *bool `json:"verified_allowed,omitempty"`
PatternsAllowed []string `json:"patterns_allowed,omitempty"`
}
func (a ActionsAllowed) String() string {
return Stringify(a)
}
// GetActionsAllowed gets the actions that are allowed in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#get-allowed-actions-for-an-organization
func (s *OrganizationsService) GetActionsAllowed(ctx context.Context, org string) (*ActionsAllowed, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/permissions/selected-actions", org)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
actionsAllowed := new(ActionsAllowed)
resp, err := s.client.Do(ctx, req, actionsAllowed)
if err != nil {
return nil, resp, err
}
return actionsAllowed, resp, nil
}
// EditActionsAllowed sets the actions that are allowed in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#set-allowed-actions-for-an-organization
func (s *OrganizationsService) EditActionsAllowed(ctx context.Context, org string, actionsAllowed ActionsAllowed) (*ActionsAllowed, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/permissions/selected-actions", org)
req, err := s.client.NewRequest("PUT", u, actionsAllowed)
if err != nil {
return nil, nil, err
}
p := new(ActionsAllowed)
resp, err := s.client.Do(ctx, req, p)
return p, resp, err
}

View file

@ -0,0 +1,58 @@
// 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"
)
// ActionsPermissions represents a policy for repositories and allowed actions in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#permissions
type ActionsPermissions struct {
EnabledRepositories *string `json:"enabled_repositories,omitempty"`
AllowedActions *string `json:"allowed_actions,omitempty"`
SelectedActionsURL *string `json:"selected_actions_url,omitempty"`
}
func (a ActionsPermissions) String() string {
return Stringify(a)
}
// GetActionsPermissions gets the GitHub Actions permissions policy for repositories and allowed actions in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#get-github-actions-permissions-for-an-organization
func (s *OrganizationsService) GetActionsPermissions(ctx context.Context, org string) (*ActionsPermissions, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/permissions", org)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
permissions := new(ActionsPermissions)
resp, err := s.client.Do(ctx, req, permissions)
if err != nil {
return nil, resp, err
}
return permissions, resp, nil
}
// EditActionsPermissions sets the permissions policy for repositories and allowed actions in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/actions#set-github-actions-permissions-for-an-organization
func (s *OrganizationsService) EditActionsPermissions(ctx context.Context, org string, actionsPermissions ActionsPermissions) (*ActionsPermissions, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/permissions", org)
req, err := s.client.NewRequest("PUT", u, actionsPermissions)
if err != nil {
return nil, nil, err
}
p := new(ActionsPermissions)
resp, err := s.client.Do(ctx, req, p)
return p, resp, err
}

View file

@ -0,0 +1,113 @@
// 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"
)
// GetAuditLogOptions sets up optional parameters to query audit-log endpoint.
type GetAuditLogOptions struct {
Phrase *string `json:"phrase,omitempty"` // A search phrase. (Optional.)
Include *string `json:"include,omitempty"` // Event type includes. Can be one of "web", "git", "all". Default: "web". (Optional.)
Order *string `json:"order,omitempty"` // The order of audit log events. Can be one of "asc" or "desc". Default: "desc". (Optional.)
ListCursorOptions
}
// HookConfig describes metadata about a webhook configuration.
type HookConfig struct {
ContentType *string `json:"content_type,omitempty"`
InsecureSSL *string `json:"insecure_ssl,omitempty"`
URL *string `json:"url,omitempty"`
}
// AuditEntry describes the fields that may be represented by various audit-log "action" entries.
// For a list of actions see - https://docs.github.com/en/github/setting-up-and-managing-organizations-and-teams/reviewing-the-audit-log-for-your-organization#audit-log-actions
type AuditEntry struct {
Action *string `json:"action,omitempty"` // The name of the action that was performed, for example `user.login` or `repo.create`.
Active *bool `json:"active,omitempty"`
ActiveWas *bool `json:"active_was,omitempty"`
Actor *string `json:"actor,omitempty"` // The actor who performed the action.
BlockedUser *string `json:"blocked_user,omitempty"`
Business *string `json:"business,omitempty"`
CancelledAt *Timestamp `json:"cancelled_at,omitempty"`
CompletedAt *Timestamp `json:"completed_at,omitempty"`
Conclusion *string `json:"conclusion,omitempty"`
Config *HookConfig `json:"config,omitempty"`
ConfigWas *HookConfig `json:"config_was,omitempty"`
ContentType *string `json:"content_type,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
DeployKeyFingerprint *string `json:"deploy_key_fingerprint,omitempty"`
DocumentID *string `json:"_document_id,omitempty"`
Emoji *string `json:"emoji,omitempty"`
EnvironmentName *string `json:"environment_name,omitempty"`
Event *string `json:"event,omitempty"`
Events []string `json:"events,omitempty"`
EventsWere []string `json:"events_were,omitempty"`
Explanation *string `json:"explanation,omitempty"`
Fingerprint *string `json:"fingerprint,omitempty"`
HeadBranch *string `json:"head_branch,omitempty"`
HeadSHA *string `json:"head_sha,omitempty"`
HookID *int64 `json:"hook_id,omitempty"`
IsHostedRunner *bool `json:"is_hosted_runner,omitempty"`
JobName *string `json:"job_name,omitempty"`
LimitedAvailability *bool `json:"limited_availability,omitempty"`
Message *string `json:"message,omitempty"`
Name *string `json:"name,omitempty"`
OldUser *string `json:"old_user,omitempty"`
OpenSSHPublicKey *string `json:"openssh_public_key,omitempty"`
Org *string `json:"org,omitempty"`
PreviousVisibility *string `json:"previous_visibility,omitempty"`
ReadOnly *string `json:"read_only,omitempty"`
Repo *string `json:"repo,omitempty"`
Repository *string `json:"repository,omitempty"`
RepositoryPublic *bool `json:"repository_public,omitempty"`
RunnerGroupID *string `json:"runner_group_id,omitempty"`
RunnerGroupName *string `json:"runner_group_name,omitempty"`
RunnerID *string `json:"runner_id,omitempty"`
RunnerLabels []string `json:"runner_labels,omitempty"`
RunnerName *string `json:"runner_name,omitempty"`
SecretsPassed []string `json:"secrets_passed,omitempty"`
SourceVersion *string `json:"source_version,omitempty"`
StartedAt *Timestamp `json:"started_at,omitempty"`
TargetLogin *string `json:"target_login,omitempty"`
TargetVersion *string `json:"target_version,omitempty"`
Team *string `json:"team,omitempty"`
Timestamp *Timestamp `json:"@timestamp,omitempty"` // The time the audit log event occurred, given as a [Unix timestamp](http://en.wikipedia.org/wiki/Unix_time).
TransportProtocolName *string `json:"transport_protocol_name,omitempty"` // A human readable name for the protocol (for example, HTTP or SSH) used to transfer Git data.
TransportProtocol *int `json:"transport_protocol,omitempty"` // The type of protocol (for example, HTTP=1 or SSH=2) used to transfer Git data.
TriggerID *int64 `json:"trigger_id,omitempty"`
User *string `json:"user,omitempty"` // The user that was affected by the action performed (if available).
Visibility *string `json:"visibility,omitempty"` // The repository visibility, for example `public` or `private`.
WorkflowID *int64 `json:"workflow_id,omitempty"`
WorkflowRunID *int64 `json:"workflow_run_id,omitempty"`
}
// GetAuditLog gets the audit-log entries for an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/orgs#get-the-audit-log-for-an-organization
func (s *OrganizationsService) GetAuditLog(ctx context.Context, org string, opts *GetAuditLogOptions) ([]*AuditEntry, *Response, error) {
u := fmt.Sprintf("orgs/%v/audit-log", 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 auditEntries []*AuditEntry
resp, err := s.client.Do(ctx, req, &auditEntries)
if err != nil {
return nil, resp, err
}
return auditEntries, resp, nil
}

View file

@ -12,7 +12,7 @@ import (
// ListHooks lists all Hooks for the specified organization. // ListHooks lists all Hooks for the specified organization.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#list-organization-webhooks // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#list-organization-webhooks
func (s *OrganizationsService) ListHooks(ctx context.Context, org string, opts *ListOptions) ([]*Hook, *Response, error) { func (s *OrganizationsService) ListHooks(ctx context.Context, org string, opts *ListOptions) ([]*Hook, *Response, error) {
u := fmt.Sprintf("orgs/%v/hooks", org) u := fmt.Sprintf("orgs/%v/hooks", org)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -36,7 +36,7 @@ func (s *OrganizationsService) ListHooks(ctx context.Context, org string, opts *
// GetHook returns a single specified Hook. // GetHook returns a single specified Hook.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#get-an-organization-webhook // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#get-an-organization-webhook
func (s *OrganizationsService) GetHook(ctx context.Context, org string, id int64) (*Hook, *Response, error) { func (s *OrganizationsService) GetHook(ctx context.Context, org string, id int64) (*Hook, *Response, error) {
u := fmt.Sprintf("orgs/%v/hooks/%d", org, id) u := fmt.Sprintf("orgs/%v/hooks/%d", org, id)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -54,7 +54,7 @@ func (s *OrganizationsService) GetHook(ctx context.Context, org string, id int64
// Note that only a subset of the hook fields are used and hook must // Note that only a subset of the hook fields are used and hook must
// not be nil. // not be nil.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#create-an-organization-webhook // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#create-an-organization-webhook
func (s *OrganizationsService) CreateHook(ctx context.Context, org string, hook *Hook) (*Hook, *Response, error) { func (s *OrganizationsService) CreateHook(ctx context.Context, org string, hook *Hook) (*Hook, *Response, error) {
u := fmt.Sprintf("orgs/%v/hooks", org) u := fmt.Sprintf("orgs/%v/hooks", org)
@ -81,7 +81,7 @@ func (s *OrganizationsService) CreateHook(ctx context.Context, org string, hook
// EditHook updates a specified Hook. // EditHook updates a specified Hook.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#update-an-organization-webhook // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#update-an-organization-webhook
func (s *OrganizationsService) EditHook(ctx context.Context, org string, id int64, hook *Hook) (*Hook, *Response, error) { func (s *OrganizationsService) EditHook(ctx context.Context, org string, id int64, hook *Hook) (*Hook, *Response, error) {
u := fmt.Sprintf("orgs/%v/hooks/%d", org, id) u := fmt.Sprintf("orgs/%v/hooks/%d", org, id)
req, err := s.client.NewRequest("PATCH", u, hook) req, err := s.client.NewRequest("PATCH", u, hook)
@ -95,7 +95,7 @@ func (s *OrganizationsService) EditHook(ctx context.Context, org string, id int6
// PingHook triggers a 'ping' event to be sent to the Hook. // PingHook triggers a 'ping' event to be sent to the Hook.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#ping-an-organization-webhook // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#ping-an-organization-webhook
func (s *OrganizationsService) PingHook(ctx context.Context, org string, id int64) (*Response, error) { func (s *OrganizationsService) PingHook(ctx context.Context, org string, id int64) (*Response, error) {
u := fmt.Sprintf("orgs/%v/hooks/%d/pings", org, id) u := fmt.Sprintf("orgs/%v/hooks/%d/pings", org, id)
req, err := s.client.NewRequest("POST", u, nil) req, err := s.client.NewRequest("POST", u, nil)
@ -107,7 +107,7 @@ func (s *OrganizationsService) PingHook(ctx context.Context, org string, id int6
// DeleteHook deletes a specified Hook. // DeleteHook deletes a specified Hook.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#delete-an-organization-webhook // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#delete-an-organization-webhook
func (s *OrganizationsService) DeleteHook(ctx context.Context, org string, id int64) (*Response, error) { func (s *OrganizationsService) DeleteHook(ctx context.Context, org string, id int64) (*Response, error) {
u := fmt.Sprintf("orgs/%v/hooks/%d", org, id) u := fmt.Sprintf("orgs/%v/hooks/%d", org, id)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)

View file

@ -71,8 +71,8 @@ type ListMembersOptions struct {
// user is an owner of the organization, this will return both concealed and // user is an owner of the organization, this will return both concealed and
// public members, otherwise it will only return public members. // public members, otherwise it will only return public members.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/members/#list-organization-members // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#list-organization-members
// GitHub API docs: https://developer.github.com/v3/orgs/members/#list-public-organization-members // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#list-public-organization-members
func (s *OrganizationsService) ListMembers(ctx context.Context, org string, opts *ListMembersOptions) ([]*User, *Response, error) { func (s *OrganizationsService) ListMembers(ctx context.Context, org string, opts *ListMembersOptions) ([]*User, *Response, error) {
var u string var u string
if opts != nil && opts.PublicOnly { if opts != nil && opts.PublicOnly {
@ -101,7 +101,7 @@ func (s *OrganizationsService) ListMembers(ctx context.Context, org string, opts
// IsMember checks if a user is a member of an organization. // IsMember checks if a user is a member of an organization.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/members/#check-organization-membership-for-a-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#check-organization-membership-for-a-user
func (s *OrganizationsService) IsMember(ctx context.Context, org, user string) (bool, *Response, error) { func (s *OrganizationsService) IsMember(ctx context.Context, org, user string) (bool, *Response, error) {
u := fmt.Sprintf("orgs/%v/members/%v", org, user) u := fmt.Sprintf("orgs/%v/members/%v", org, user)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -116,7 +116,7 @@ func (s *OrganizationsService) IsMember(ctx context.Context, org, user string) (
// IsPublicMember checks if a user is a public member of an organization. // IsPublicMember checks if a user is a public member of an organization.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/members/#check-public-organization-membership-for-a-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#check-public-organization-membership-for-a-user
func (s *OrganizationsService) IsPublicMember(ctx context.Context, org, user string) (bool, *Response, error) { func (s *OrganizationsService) IsPublicMember(ctx context.Context, org, user string) (bool, *Response, error) {
u := fmt.Sprintf("orgs/%v/public_members/%v", org, user) u := fmt.Sprintf("orgs/%v/public_members/%v", org, user)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -131,7 +131,7 @@ func (s *OrganizationsService) IsPublicMember(ctx context.Context, org, user str
// RemoveMember removes a user from all teams of an organization. // RemoveMember removes a user from all teams of an organization.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/members/#remove-an-organization-member // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#remove-an-organization-member
func (s *OrganizationsService) RemoveMember(ctx context.Context, org, user string) (*Response, error) { func (s *OrganizationsService) RemoveMember(ctx context.Context, org, user string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/members/%v", org, user) u := fmt.Sprintf("orgs/%v/members/%v", org, user)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -145,7 +145,7 @@ func (s *OrganizationsService) RemoveMember(ctx context.Context, org, user strin
// PublicizeMembership publicizes a user's membership in an organization. (A // PublicizeMembership publicizes a user's membership in an organization. (A
// user cannot publicize the membership for another user.) // user cannot publicize the membership for another user.)
// //
// GitHub API docs: https://developer.github.com/v3/orgs/members/#set-public-organization-membership-for-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#set-public-organization-membership-for-the-authenticated-user
func (s *OrganizationsService) PublicizeMembership(ctx context.Context, org, user string) (*Response, error) { func (s *OrganizationsService) PublicizeMembership(ctx context.Context, org, user string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/public_members/%v", org, user) u := fmt.Sprintf("orgs/%v/public_members/%v", org, user)
req, err := s.client.NewRequest("PUT", u, nil) req, err := s.client.NewRequest("PUT", u, nil)
@ -158,7 +158,7 @@ func (s *OrganizationsService) PublicizeMembership(ctx context.Context, org, use
// ConcealMembership conceals a user's membership in an organization. // ConcealMembership conceals a user's membership in an organization.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/members/#remove-public-organization-membership-for-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#remove-public-organization-membership-for-the-authenticated-user
func (s *OrganizationsService) ConcealMembership(ctx context.Context, org, user string) (*Response, error) { func (s *OrganizationsService) ConcealMembership(ctx context.Context, org, user string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/public_members/%v", org, user) u := fmt.Sprintf("orgs/%v/public_members/%v", org, user)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -181,7 +181,7 @@ type ListOrgMembershipsOptions struct {
// ListOrgMemberships lists the organization memberships for the authenticated user. // ListOrgMemberships lists the organization memberships for the authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/members/#list-organization-memberships-for-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#list-organization-memberships-for-the-authenticated-user
func (s *OrganizationsService) ListOrgMemberships(ctx context.Context, opts *ListOrgMembershipsOptions) ([]*Membership, *Response, error) { func (s *OrganizationsService) ListOrgMemberships(ctx context.Context, opts *ListOrgMembershipsOptions) ([]*Membership, *Response, error) {
u := "user/memberships/orgs" u := "user/memberships/orgs"
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -207,8 +207,8 @@ func (s *OrganizationsService) ListOrgMemberships(ctx context.Context, opts *Lis
// Passing an empty string for user will get the membership for the // Passing an empty string for user will get the membership for the
// authenticated user. // authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/members/#get-an-organization-membership-for-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#get-an-organization-membership-for-the-authenticated-user
// GitHub API docs: https://developer.github.com/v3/orgs/members/#get-organization-membership-for-a-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#get-organization-membership-for-a-user
func (s *OrganizationsService) GetOrgMembership(ctx context.Context, user, org string) (*Membership, *Response, error) { func (s *OrganizationsService) GetOrgMembership(ctx context.Context, user, org string) (*Membership, *Response, error) {
var u string var u string
if user != "" { if user != "" {
@ -235,8 +235,8 @@ func (s *OrganizationsService) GetOrgMembership(ctx context.Context, user, org s
// Passing an empty string for user will edit the membership for the // Passing an empty string for user will edit the membership for the
// authenticated user. // authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/members/#update-an-organization-membership-for-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#update-an-organization-membership-for-the-authenticated-user
// GitHub API docs: https://developer.github.com/v3/orgs/members/#set-organization-membership-for-a-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#set-organization-membership-for-a-user
func (s *OrganizationsService) EditOrgMembership(ctx context.Context, user, org string, membership *Membership) (*Membership, *Response, error) { func (s *OrganizationsService) EditOrgMembership(ctx context.Context, user, org string, membership *Membership) (*Membership, *Response, error) {
var u, method string var u, method string
if user != "" { if user != "" {
@ -264,7 +264,7 @@ func (s *OrganizationsService) EditOrgMembership(ctx context.Context, user, org
// RemoveOrgMembership removes user from the specified organization. If the // RemoveOrgMembership removes user from the specified organization. If the
// user has been invited to the organization, this will cancel their invitation. // user has been invited to the organization, this will cancel their invitation.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/members/#remove-organization-membership-for-a-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#remove-organization-membership-for-a-user
func (s *OrganizationsService) RemoveOrgMembership(ctx context.Context, user, org string) (*Response, error) { func (s *OrganizationsService) RemoveOrgMembership(ctx context.Context, user, org string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/memberships/%v", org, user) u := fmt.Sprintf("orgs/%v/memberships/%v", org, user)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -277,7 +277,7 @@ func (s *OrganizationsService) RemoveOrgMembership(ctx context.Context, user, or
// ListPendingOrgInvitations returns a list of pending invitations. // ListPendingOrgInvitations returns a list of pending invitations.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/members/#list-pending-organization-invitations // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#list-pending-organization-invitations
func (s *OrganizationsService) ListPendingOrgInvitations(ctx context.Context, org string, opts *ListOptions) ([]*Invitation, *Response, error) { func (s *OrganizationsService) ListPendingOrgInvitations(ctx context.Context, org string, opts *ListOptions) ([]*Invitation, *Response, error) {
u := fmt.Sprintf("orgs/%v/invitations", org) u := fmt.Sprintf("orgs/%v/invitations", org)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -322,7 +322,7 @@ type CreateOrgInvitationOptions struct {
// In order to create invitations in an organization, // In order to create invitations in an organization,
// the authenticated user must be an organization owner. // the authenticated user must be an organization owner.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/members/#create-an-organization-invitation // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#create-an-organization-invitation
func (s *OrganizationsService) CreateOrgInvitation(ctx context.Context, org string, opts *CreateOrgInvitationOptions) (*Invitation, *Response, error) { func (s *OrganizationsService) CreateOrgInvitation(ctx context.Context, org string, opts *CreateOrgInvitationOptions) (*Invitation, *Response, error) {
u := fmt.Sprintf("orgs/%v/invitations", org) u := fmt.Sprintf("orgs/%v/invitations", org)
@ -342,7 +342,7 @@ func (s *OrganizationsService) CreateOrgInvitation(ctx context.Context, org stri
// ListOrgInvitationTeams lists all teams associated with an invitation. In order to see invitations in an organization, // ListOrgInvitationTeams lists all teams associated with an invitation. In order to see invitations in an organization,
// the authenticated user must be an organization owner. // the authenticated user must be an organization owner.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/members/#list-organization-invitation-teams // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#list-organization-invitation-teams
func (s *OrganizationsService) ListOrgInvitationTeams(ctx context.Context, org, invitationID string, opts *ListOptions) ([]*Team, *Response, error) { func (s *OrganizationsService) ListOrgInvitationTeams(ctx context.Context, org, invitationID string, opts *ListOptions) ([]*Team, *Response, error) {
u := fmt.Sprintf("orgs/%v/invitations/%v/teams", org, invitationID) u := fmt.Sprintf("orgs/%v/invitations/%v/teams", org, invitationID)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -362,3 +362,27 @@ func (s *OrganizationsService) ListOrgInvitationTeams(ctx context.Context, org,
} }
return orgInvitationTeams, resp, nil return orgInvitationTeams, resp, nil
} }
// ListFailedOrgInvitations returns a list of failed inviatations.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/orgs#list-failed-organization-invitations
func (s *OrganizationsService) ListFailedOrgInvitations(ctx context.Context, org string, opts *ListOptions) ([]*Invitation, *Response, error) {
u := fmt.Sprintf("orgs/%v/failed_invitations", 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 failedInvitations []*Invitation
resp, err := s.client.Do(ctx, req, &failedInvitations)
if err != nil {
return nil, resp, err
}
return failedInvitations, resp, nil
}

View file

@ -27,7 +27,7 @@ type ListOutsideCollaboratorsOptions struct {
// Warning: The API may change without advance notice during the preview period. // Warning: The API may change without advance notice during the preview period.
// Preview features are not supported for production use. // Preview features are not supported for production use.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/outside_collaborators/#list-outside-collaborators-for-an-organization // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#list-outside-collaborators-for-an-organization
func (s *OrganizationsService) ListOutsideCollaborators(ctx context.Context, org string, opts *ListOutsideCollaboratorsOptions) ([]*User, *Response, error) { func (s *OrganizationsService) ListOutsideCollaborators(ctx context.Context, org string, opts *ListOutsideCollaboratorsOptions) ([]*User, *Response, error) {
u := fmt.Sprintf("orgs/%v/outside_collaborators", org) u := fmt.Sprintf("orgs/%v/outside_collaborators", org)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -52,7 +52,7 @@ func (s *OrganizationsService) ListOutsideCollaborators(ctx context.Context, org
// RemoveOutsideCollaborator removes a user from the list of outside collaborators; // RemoveOutsideCollaborator removes a user from the list of outside collaborators;
// consequently, removing them from all the organization's repositories. // consequently, removing them from all the organization's repositories.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/outside_collaborators/#remove-outside-collaborator-from-an-organization // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#remove-outside-collaborator-from-an-organization
func (s *OrganizationsService) RemoveOutsideCollaborator(ctx context.Context, org string, user string) (*Response, error) { func (s *OrganizationsService) RemoveOutsideCollaborator(ctx context.Context, org string, user string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/outside_collaborators/%v", org, user) u := fmt.Sprintf("orgs/%v/outside_collaborators/%v", org, user)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -69,7 +69,7 @@ func (s *OrganizationsService) RemoveOutsideCollaborator(ctx context.Context, or
// Responses for converting a non-member or the last owner to an outside collaborator // Responses for converting a non-member or the last owner to an outside collaborator
// are listed in GitHub API docs. // are listed in GitHub API docs.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/outside_collaborators/#convert-an-organization-member-to-outside-collaborator // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#convert-an-organization-member-to-outside-collaborator
func (s *OrganizationsService) ConvertMemberToOutsideCollaborator(ctx context.Context, org string, user string) (*Response, error) { func (s *OrganizationsService) ConvertMemberToOutsideCollaborator(ctx context.Context, org string, user string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/outside_collaborators/%v", org, user) u := fmt.Sprintf("orgs/%v/outside_collaborators/%v", org, user)
req, err := s.client.NewRequest("PUT", u, nil) req, err := s.client.NewRequest("PUT", u, nil)

View file

@ -12,7 +12,7 @@ import (
// ListProjects lists the projects for an organization. // ListProjects lists the projects for an organization.
// //
// GitHub API docs: https://developer.github.com/v3/projects/#list-organization-projects // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#list-organization-projects
func (s *OrganizationsService) ListProjects(ctx context.Context, org string, opts *ProjectListOptions) ([]*Project, *Response, error) { func (s *OrganizationsService) ListProjects(ctx context.Context, org string, opts *ProjectListOptions) ([]*Project, *Response, error) {
u := fmt.Sprintf("orgs/%v/projects", org) u := fmt.Sprintf("orgs/%v/projects", org)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -39,7 +39,7 @@ func (s *OrganizationsService) ListProjects(ctx context.Context, org string, opt
// CreateProject creates a GitHub Project for the specified organization. // CreateProject creates a GitHub Project for the specified organization.
// //
// GitHub API docs: https://developer.github.com/v3/projects/#create-an-organization-project // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#create-an-organization-project
func (s *OrganizationsService) CreateProject(ctx context.Context, org string, opts *ProjectOptions) (*Project, *Response, error) { func (s *OrganizationsService) CreateProject(ctx context.Context, org string, opts *ProjectOptions) (*Project, *Response, error) {
u := fmt.Sprintf("orgs/%v/projects", org) u := fmt.Sprintf("orgs/%v/projects", org)
req, err := s.client.NewRequest("POST", u, opts) req, err := s.client.NewRequest("POST", u, opts)

View file

@ -12,7 +12,7 @@ import (
// ListBlockedUsers lists all the users blocked by an organization. // ListBlockedUsers lists all the users blocked by an organization.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/blocking/#list-users-blocked-by-an-organization // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#list-users-blocked-by-an-organization
func (s *OrganizationsService) ListBlockedUsers(ctx context.Context, org string, opts *ListOptions) ([]*User, *Response, error) { func (s *OrganizationsService) ListBlockedUsers(ctx context.Context, org string, opts *ListOptions) ([]*User, *Response, error) {
u := fmt.Sprintf("orgs/%v/blocks", org) u := fmt.Sprintf("orgs/%v/blocks", org)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -39,7 +39,7 @@ func (s *OrganizationsService) ListBlockedUsers(ctx context.Context, org string,
// IsBlocked reports whether specified user is blocked from an organization. // IsBlocked reports whether specified user is blocked from an organization.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/blocking/#check-if-a-user-is-blocked-by-an-organization // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#check-if-a-user-is-blocked-by-an-organization
func (s *OrganizationsService) IsBlocked(ctx context.Context, org string, user string) (bool, *Response, error) { func (s *OrganizationsService) IsBlocked(ctx context.Context, org string, user string) (bool, *Response, error) {
u := fmt.Sprintf("orgs/%v/blocks/%v", org, user) u := fmt.Sprintf("orgs/%v/blocks/%v", org, user)
@ -58,7 +58,7 @@ func (s *OrganizationsService) IsBlocked(ctx context.Context, org string, user s
// BlockUser blocks specified user from an organization. // BlockUser blocks specified user from an organization.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/blocking/#block-a-user-from-an-organization // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#block-a-user-from-an-organization
func (s *OrganizationsService) BlockUser(ctx context.Context, org string, user string) (*Response, error) { func (s *OrganizationsService) BlockUser(ctx context.Context, org string, user string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/blocks/%v", org, user) u := fmt.Sprintf("orgs/%v/blocks/%v", org, user)
@ -75,7 +75,7 @@ func (s *OrganizationsService) BlockUser(ctx context.Context, org string, user s
// UnblockUser unblocks specified user from an organization. // UnblockUser unblocks specified user from an organization.
// //
// GitHub API docs: https://developer.github.com/v3/orgs/blocking/#unblock-a-user-from-an-organization // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs/#unblock-a-user-from-an-organization
func (s *OrganizationsService) UnblockUser(ctx context.Context, org string, user string) (*Response, error) { func (s *OrganizationsService) UnblockUser(ctx context.Context, org string, user string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/blocks/%v", org, user) u := fmt.Sprintf("orgs/%v/blocks/%v", org, user)

View file

@ -13,7 +13,7 @@ import (
// ProjectsService provides access to the projects functions in the // ProjectsService provides access to the projects functions in the
// GitHub API. // GitHub API.
// //
// GitHub API docs: https://developer.github.com/v3/projects/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/
type ProjectsService service type ProjectsService service
// Project represents a GitHub Project. // Project represents a GitHub Project.
@ -41,7 +41,7 @@ func (p Project) String() string {
// GetProject gets a GitHub Project for a repo. // GetProject gets a GitHub Project for a repo.
// //
// GitHub API docs: https://developer.github.com/v3/projects/#get-a-project // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#get-a-project
func (s *ProjectsService) GetProject(ctx context.Context, id int64) (*Project, *Response, error) { func (s *ProjectsService) GetProject(ctx context.Context, id int64) (*Project, *Response, error) {
u := fmt.Sprintf("projects/%v", id) u := fmt.Sprintf("projects/%v", id)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -88,7 +88,7 @@ type ProjectOptions struct {
// UpdateProject updates a repository project. // UpdateProject updates a repository project.
// //
// GitHub API docs: https://developer.github.com/v3/projects/#update-a-project // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#update-a-project
func (s *ProjectsService) UpdateProject(ctx context.Context, id int64, opts *ProjectOptions) (*Project, *Response, error) { func (s *ProjectsService) UpdateProject(ctx context.Context, id int64, opts *ProjectOptions) (*Project, *Response, error) {
u := fmt.Sprintf("projects/%v", id) u := fmt.Sprintf("projects/%v", id)
req, err := s.client.NewRequest("PATCH", u, opts) req, err := s.client.NewRequest("PATCH", u, opts)
@ -110,7 +110,7 @@ func (s *ProjectsService) UpdateProject(ctx context.Context, id int64, opts *Pro
// DeleteProject deletes a GitHub Project from a repository. // DeleteProject deletes a GitHub Project from a repository.
// //
// GitHub API docs: https://developer.github.com/v3/projects/#delete-a-project // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#delete-a-project
func (s *ProjectsService) DeleteProject(ctx context.Context, id int64) (*Response, error) { func (s *ProjectsService) DeleteProject(ctx context.Context, id int64) (*Response, error) {
u := fmt.Sprintf("projects/%v", id) u := fmt.Sprintf("projects/%v", id)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -126,7 +126,7 @@ func (s *ProjectsService) DeleteProject(ctx context.Context, id int64) (*Respons
// ProjectColumn represents a column of a GitHub Project. // ProjectColumn represents a column of a GitHub Project.
// //
// GitHub API docs: https://developer.github.com/v3/repos/projects/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/projects/
type ProjectColumn struct { type ProjectColumn struct {
ID *int64 `json:"id,omitempty"` ID *int64 `json:"id,omitempty"`
Name *string `json:"name,omitempty"` Name *string `json:"name,omitempty"`
@ -140,7 +140,7 @@ type ProjectColumn struct {
// ListProjectColumns lists the columns of a GitHub Project for a repo. // ListProjectColumns lists the columns of a GitHub Project for a repo.
// //
// GitHub API docs: https://developer.github.com/v3/projects/columns/#list-project-columns // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#list-project-columns
func (s *ProjectsService) ListProjectColumns(ctx context.Context, projectID int64, opts *ListOptions) ([]*ProjectColumn, *Response, error) { func (s *ProjectsService) ListProjectColumns(ctx context.Context, projectID int64, opts *ListOptions) ([]*ProjectColumn, *Response, error) {
u := fmt.Sprintf("projects/%v/columns", projectID) u := fmt.Sprintf("projects/%v/columns", projectID)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -167,7 +167,7 @@ func (s *ProjectsService) ListProjectColumns(ctx context.Context, projectID int6
// GetProjectColumn gets a column of a GitHub Project for a repo. // GetProjectColumn gets a column of a GitHub Project for a repo.
// //
// GitHub API docs: https://developer.github.com/v3/projects/columns/#get-a-project-column // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#get-a-project-column
func (s *ProjectsService) GetProjectColumn(ctx context.Context, id int64) (*ProjectColumn, *Response, error) { func (s *ProjectsService) GetProjectColumn(ctx context.Context, id int64) (*ProjectColumn, *Response, error) {
u := fmt.Sprintf("projects/columns/%v", id) u := fmt.Sprintf("projects/columns/%v", id)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -197,7 +197,7 @@ type ProjectColumnOptions struct {
// CreateProjectColumn creates a column for the specified (by number) project. // CreateProjectColumn creates a column for the specified (by number) project.
// //
// GitHub API docs: https://developer.github.com/v3/projects/columns/#create-a-project-column // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#create-a-project-column
func (s *ProjectsService) CreateProjectColumn(ctx context.Context, projectID int64, opts *ProjectColumnOptions) (*ProjectColumn, *Response, error) { func (s *ProjectsService) CreateProjectColumn(ctx context.Context, projectID int64, opts *ProjectColumnOptions) (*ProjectColumn, *Response, error) {
u := fmt.Sprintf("projects/%v/columns", projectID) u := fmt.Sprintf("projects/%v/columns", projectID)
req, err := s.client.NewRequest("POST", u, opts) req, err := s.client.NewRequest("POST", u, opts)
@ -219,7 +219,7 @@ func (s *ProjectsService) CreateProjectColumn(ctx context.Context, projectID int
// UpdateProjectColumn updates a column of a GitHub Project. // UpdateProjectColumn updates a column of a GitHub Project.
// //
// GitHub API docs: https://developer.github.com/v3/projects/columns/#update-a-project-column // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#update-an-existing-project-column
func (s *ProjectsService) UpdateProjectColumn(ctx context.Context, columnID int64, opts *ProjectColumnOptions) (*ProjectColumn, *Response, error) { func (s *ProjectsService) UpdateProjectColumn(ctx context.Context, columnID int64, opts *ProjectColumnOptions) (*ProjectColumn, *Response, error) {
u := fmt.Sprintf("projects/columns/%v", columnID) u := fmt.Sprintf("projects/columns/%v", columnID)
req, err := s.client.NewRequest("PATCH", u, opts) req, err := s.client.NewRequest("PATCH", u, opts)
@ -241,7 +241,7 @@ func (s *ProjectsService) UpdateProjectColumn(ctx context.Context, columnID int6
// DeleteProjectColumn deletes a column from a GitHub Project. // DeleteProjectColumn deletes a column from a GitHub Project.
// //
// GitHub API docs: https://developer.github.com/v3/projects/columns/#delete-a-project-column // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#delete-a-project-column
func (s *ProjectsService) DeleteProjectColumn(ctx context.Context, columnID int64) (*Response, error) { func (s *ProjectsService) DeleteProjectColumn(ctx context.Context, columnID int64) (*Response, error) {
u := fmt.Sprintf("projects/columns/%v", columnID) u := fmt.Sprintf("projects/columns/%v", columnID)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -265,7 +265,7 @@ type ProjectColumnMoveOptions struct {
// MoveProjectColumn moves a column within a GitHub Project. // MoveProjectColumn moves a column within a GitHub Project.
// //
// GitHub API docs: https://developer.github.com/v3/projects/columns/#move-a-project-column // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#move-a-project-column
func (s *ProjectsService) MoveProjectColumn(ctx context.Context, columnID int64, opts *ProjectColumnMoveOptions) (*Response, error) { func (s *ProjectsService) MoveProjectColumn(ctx context.Context, columnID int64, opts *ProjectColumnMoveOptions) (*Response, error) {
u := fmt.Sprintf("projects/columns/%v/moves", columnID) u := fmt.Sprintf("projects/columns/%v/moves", columnID)
req, err := s.client.NewRequest("POST", u, opts) req, err := s.client.NewRequest("POST", u, opts)
@ -281,7 +281,7 @@ func (s *ProjectsService) MoveProjectColumn(ctx context.Context, columnID int64,
// ProjectCard represents a card in a column of a GitHub Project. // ProjectCard represents a card in a column of a GitHub Project.
// //
// GitHub API docs: https://developer.github.com/v3/projects/cards/#get-a-project-card // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/cards/#get-a-project-card
type ProjectCard struct { type ProjectCard struct {
URL *string `json:"url,omitempty"` URL *string `json:"url,omitempty"`
ColumnURL *string `json:"column_url,omitempty"` ColumnURL *string `json:"column_url,omitempty"`
@ -316,7 +316,7 @@ type ProjectCardListOptions struct {
// ListProjectCards lists the cards in a column of a GitHub Project. // ListProjectCards lists the cards in a column of a GitHub Project.
// //
// GitHub API docs: https://developer.github.com/v3/projects/cards/#list-project-cards // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#list-project-cards
func (s *ProjectsService) ListProjectCards(ctx context.Context, columnID int64, opts *ProjectCardListOptions) ([]*ProjectCard, *Response, error) { func (s *ProjectsService) ListProjectCards(ctx context.Context, columnID int64, opts *ProjectCardListOptions) ([]*ProjectCard, *Response, error) {
u := fmt.Sprintf("projects/columns/%v/cards", columnID) u := fmt.Sprintf("projects/columns/%v/cards", columnID)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -343,7 +343,7 @@ func (s *ProjectsService) ListProjectCards(ctx context.Context, columnID int64,
// GetProjectCard gets a card in a column of a GitHub Project. // GetProjectCard gets a card in a column of a GitHub Project.
// //
// GitHub API docs: https://developer.github.com/v3/projects/cards/#get-a-project-card // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#get-a-project-card
func (s *ProjectsService) GetProjectCard(ctx context.Context, cardID int64) (*ProjectCard, *Response, error) { func (s *ProjectsService) GetProjectCard(ctx context.Context, cardID int64) (*ProjectCard, *Response, error) {
u := fmt.Sprintf("projects/columns/cards/%v", cardID) u := fmt.Sprintf("projects/columns/cards/%v", cardID)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -381,7 +381,7 @@ type ProjectCardOptions struct {
// CreateProjectCard creates a card in the specified column of a GitHub Project. // CreateProjectCard creates a card in the specified column of a GitHub Project.
// //
// GitHub API docs: https://developer.github.com/v3/projects/cards/#create-a-project-card // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#create-a-project-card
func (s *ProjectsService) CreateProjectCard(ctx context.Context, columnID int64, opts *ProjectCardOptions) (*ProjectCard, *Response, error) { func (s *ProjectsService) CreateProjectCard(ctx context.Context, columnID int64, opts *ProjectCardOptions) (*ProjectCard, *Response, error) {
u := fmt.Sprintf("projects/columns/%v/cards", columnID) u := fmt.Sprintf("projects/columns/%v/cards", columnID)
req, err := s.client.NewRequest("POST", u, opts) req, err := s.client.NewRequest("POST", u, opts)
@ -403,7 +403,7 @@ func (s *ProjectsService) CreateProjectCard(ctx context.Context, columnID int64,
// UpdateProjectCard updates a card of a GitHub Project. // UpdateProjectCard updates a card of a GitHub Project.
// //
// GitHub API docs: https://developer.github.com/v3/projects/cards/#update-a-project-card // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#update-an-existing-project-card
func (s *ProjectsService) UpdateProjectCard(ctx context.Context, cardID int64, opts *ProjectCardOptions) (*ProjectCard, *Response, error) { func (s *ProjectsService) UpdateProjectCard(ctx context.Context, cardID int64, opts *ProjectCardOptions) (*ProjectCard, *Response, error) {
u := fmt.Sprintf("projects/columns/cards/%v", cardID) u := fmt.Sprintf("projects/columns/cards/%v", cardID)
req, err := s.client.NewRequest("PATCH", u, opts) req, err := s.client.NewRequest("PATCH", u, opts)
@ -425,7 +425,7 @@ func (s *ProjectsService) UpdateProjectCard(ctx context.Context, cardID int64, o
// DeleteProjectCard deletes a card from a GitHub Project. // DeleteProjectCard deletes a card from a GitHub Project.
// //
// GitHub API docs: https://developer.github.com/v3/projects/cards/#delete-a-project-card // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#delete-a-project-card
func (s *ProjectsService) DeleteProjectCard(ctx context.Context, cardID int64) (*Response, error) { func (s *ProjectsService) DeleteProjectCard(ctx context.Context, cardID int64) (*Response, error) {
u := fmt.Sprintf("projects/columns/cards/%v", cardID) u := fmt.Sprintf("projects/columns/cards/%v", cardID)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -453,7 +453,7 @@ type ProjectCardMoveOptions struct {
// MoveProjectCard moves a card within a GitHub Project. // MoveProjectCard moves a card within a GitHub Project.
// //
// GitHub API docs: https://developer.github.com/v3/projects/cards/#move-a-project-card // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#move-a-project-card
func (s *ProjectsService) MoveProjectCard(ctx context.Context, cardID int64, opts *ProjectCardMoveOptions) (*Response, error) { func (s *ProjectsService) MoveProjectCard(ctx context.Context, cardID int64, opts *ProjectCardMoveOptions) (*Response, error) {
u := fmt.Sprintf("projects/columns/cards/%v/moves", cardID) u := fmt.Sprintf("projects/columns/cards/%v/moves", cardID)
req, err := s.client.NewRequest("POST", u, opts) req, err := s.client.NewRequest("POST", u, opts)
@ -483,7 +483,7 @@ type ProjectCollaboratorOptions struct {
// AddProjectCollaborator adds a collaborator to an organization project and sets // AddProjectCollaborator adds a collaborator to an organization project and sets
// their permission level. You must be an organization owner or a project admin to add a collaborator. // their permission level. You must be an organization owner or a project admin to add a collaborator.
// //
// GitHub API docs: https://developer.github.com/v3/projects/collaborators/#add-project-collaborator // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#add-project-collaborator
func (s *ProjectsService) AddProjectCollaborator(ctx context.Context, id int64, username string, opts *ProjectCollaboratorOptions) (*Response, error) { func (s *ProjectsService) AddProjectCollaborator(ctx context.Context, id int64, username string, opts *ProjectCollaboratorOptions) (*Response, error) {
u := fmt.Sprintf("projects/%v/collaborators/%v", id, username) u := fmt.Sprintf("projects/%v/collaborators/%v", id, username)
req, err := s.client.NewRequest("PUT", u, opts) req, err := s.client.NewRequest("PUT", u, opts)
@ -500,7 +500,7 @@ func (s *ProjectsService) AddProjectCollaborator(ctx context.Context, id int64,
// RemoveProjectCollaborator removes a collaborator from an organization project. // RemoveProjectCollaborator removes a collaborator from an organization project.
// You must be an organization owner or a project admin to remove a collaborator. // You must be an organization owner or a project admin to remove a collaborator.
// //
// GitHub API docs: https://developer.github.com/v3/projects/collaborators/#remove-project-collaborator // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#remove-user-as-a-collaborator
func (s *ProjectsService) RemoveProjectCollaborator(ctx context.Context, id int64, username string) (*Response, error) { func (s *ProjectsService) RemoveProjectCollaborator(ctx context.Context, id int64, username string) (*Response, error) {
u := fmt.Sprintf("projects/%v/collaborators/%v", id, username) u := fmt.Sprintf("projects/%v/collaborators/%v", id, username)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -536,7 +536,7 @@ type ListCollaboratorOptions struct {
// with access through default organization permissions, and organization owners. You must be an // with access through default organization permissions, and organization owners. You must be an
// organization owner or a project admin to list collaborators. // organization owner or a project admin to list collaborators.
// //
// GitHub API docs: https://developer.github.com/v3/projects/collaborators/#list-project-collaborators // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#list-project-collaborators
func (s *ProjectsService) ListProjectCollaborators(ctx context.Context, id int64, opts *ListCollaboratorOptions) ([]*User, *Response, error) { func (s *ProjectsService) ListProjectCollaborators(ctx context.Context, id int64, opts *ListCollaboratorOptions) ([]*User, *Response, error) {
u := fmt.Sprintf("projects/%v/collaborators", id) u := fmt.Sprintf("projects/%v/collaborators", id)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -574,7 +574,7 @@ type ProjectPermissionLevel struct {
// project. Possible values for the permission key: "admin", "write", "read", "none". // project. Possible values for the permission key: "admin", "write", "read", "none".
// You must be an organization owner or a project admin to review a user's permission level. // You must be an organization owner or a project admin to review a user's permission level.
// //
// GitHub API docs: https://developer.github.com/v3/projects/collaborators/#get-project-permission-for-a-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#get-project-permission-for-a-user
func (s *ProjectsService) ReviewProjectCollaboratorPermission(ctx context.Context, id int64, username string) (*ProjectPermissionLevel, *Response, error) { func (s *ProjectsService) ReviewProjectCollaboratorPermission(ctx context.Context, id int64, username string) (*ProjectPermissionLevel, *Response, error) {
u := fmt.Sprintf("projects/%v/collaborators/%v/permission", id, username) u := fmt.Sprintf("projects/%v/collaborators/%v/permission", id, username)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)

View file

@ -9,63 +9,71 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"strings"
"time" "time"
) )
// PullRequestsService handles communication with the pull request related // PullRequestsService handles communication with the pull request related
// methods of the GitHub API. // methods of the GitHub API.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/
type PullRequestsService service type PullRequestsService service
// PullRequestAutoMerge represents the "auto_merge" response for a PullRequest.
type PullRequestAutoMerge struct {
EnabledBy *User `json:"enabled_by,omitempty"`
MergeMethod *string `json:"merge_method,omitempty"`
CommitTitle *string `json:"commit_title,omitempty"`
CommitMessage *string `json:"commit_message,omitempty"`
}
// PullRequest represents a GitHub pull request on a repository. // PullRequest represents a GitHub pull request on a repository.
type PullRequest struct { type PullRequest struct {
ID *int64 `json:"id,omitempty"` ID *int64 `json:"id,omitempty"`
Number *int `json:"number,omitempty"` Number *int `json:"number,omitempty"`
State *string `json:"state,omitempty"` State *string `json:"state,omitempty"`
Locked *bool `json:"locked,omitempty"` Locked *bool `json:"locked,omitempty"`
Title *string `json:"title,omitempty"` Title *string `json:"title,omitempty"`
Body *string `json:"body,omitempty"` Body *string `json:"body,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"` CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"` UpdatedAt *time.Time `json:"updated_at,omitempty"`
ClosedAt *time.Time `json:"closed_at,omitempty"` ClosedAt *time.Time `json:"closed_at,omitempty"`
MergedAt *time.Time `json:"merged_at,omitempty"` MergedAt *time.Time `json:"merged_at,omitempty"`
Labels []*Label `json:"labels,omitempty"` Labels []*Label `json:"labels,omitempty"`
User *User `json:"user,omitempty"` User *User `json:"user,omitempty"`
Draft *bool `json:"draft,omitempty"` Draft *bool `json:"draft,omitempty"`
Merged *bool `json:"merged,omitempty"` Merged *bool `json:"merged,omitempty"`
Mergeable *bool `json:"mergeable,omitempty"` Mergeable *bool `json:"mergeable,omitempty"`
MergeableState *string `json:"mergeable_state,omitempty"` MergeableState *string `json:"mergeable_state,omitempty"`
MergedBy *User `json:"merged_by,omitempty"` MergedBy *User `json:"merged_by,omitempty"`
MergeCommitSHA *string `json:"merge_commit_sha,omitempty"` MergeCommitSHA *string `json:"merge_commit_sha,omitempty"`
Rebaseable *bool `json:"rebaseable,omitempty"` Rebaseable *bool `json:"rebaseable,omitempty"`
Comments *int `json:"comments,omitempty"` Comments *int `json:"comments,omitempty"`
Commits *int `json:"commits,omitempty"` Commits *int `json:"commits,omitempty"`
Additions *int `json:"additions,omitempty"` Additions *int `json:"additions,omitempty"`
Deletions *int `json:"deletions,omitempty"` Deletions *int `json:"deletions,omitempty"`
ChangedFiles *int `json:"changed_files,omitempty"` ChangedFiles *int `json:"changed_files,omitempty"`
URL *string `json:"url,omitempty"` URL *string `json:"url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"` HTMLURL *string `json:"html_url,omitempty"`
IssueURL *string `json:"issue_url,omitempty"` IssueURL *string `json:"issue_url,omitempty"`
StatusesURL *string `json:"statuses_url,omitempty"` StatusesURL *string `json:"statuses_url,omitempty"`
DiffURL *string `json:"diff_url,omitempty"` DiffURL *string `json:"diff_url,omitempty"`
PatchURL *string `json:"patch_url,omitempty"` PatchURL *string `json:"patch_url,omitempty"`
CommitsURL *string `json:"commits_url,omitempty"` CommitsURL *string `json:"commits_url,omitempty"`
CommentsURL *string `json:"comments_url,omitempty"` CommentsURL *string `json:"comments_url,omitempty"`
ReviewCommentsURL *string `json:"review_comments_url,omitempty"` ReviewCommentsURL *string `json:"review_comments_url,omitempty"`
ReviewCommentURL *string `json:"review_comment_url,omitempty"` ReviewCommentURL *string `json:"review_comment_url,omitempty"`
ReviewComments *int `json:"review_comments,omitempty"` ReviewComments *int `json:"review_comments,omitempty"`
Assignee *User `json:"assignee,omitempty"` Assignee *User `json:"assignee,omitempty"`
Assignees []*User `json:"assignees,omitempty"` Assignees []*User `json:"assignees,omitempty"`
Milestone *Milestone `json:"milestone,omitempty"` Milestone *Milestone `json:"milestone,omitempty"`
MaintainerCanModify *bool `json:"maintainer_can_modify,omitempty"` MaintainerCanModify *bool `json:"maintainer_can_modify,omitempty"`
AuthorAssociation *string `json:"author_association,omitempty"` AuthorAssociation *string `json:"author_association,omitempty"`
NodeID *string `json:"node_id,omitempty"` NodeID *string `json:"node_id,omitempty"`
RequestedReviewers []*User `json:"requested_reviewers,omitempty"` RequestedReviewers []*User `json:"requested_reviewers,omitempty"`
AutoMerge *PullRequestAutoMerge `json:"auto_merge,omitempty"`
// RequestedTeams is populated as part of the PullRequestEvent. // RequestedTeams is populated as part of the PullRequestEvent.
// See, https://developer.github.com/v3/activity/events/types/#pullrequestevent for an example. // See, https://docs.github.com/en/developers/webhooks-and-events/github-event-types#pullrequestevent for an example.
RequestedTeams []*Team `json:"requested_teams,omitempty"` RequestedTeams []*Team `json:"requested_teams,omitempty"`
Links *PRLinks `json:"_links,omitempty"` Links *PRLinks `json:"_links,omitempty"`
@ -81,12 +89,12 @@ func (p PullRequest) String() string {
return Stringify(p) return Stringify(p)
} }
// PRLink represents a single link object from Github pull request _links. // PRLink represents a single link object from GitHub pull request _links.
type PRLink struct { type PRLink struct {
HRef *string `json:"href,omitempty"` HRef *string `json:"href,omitempty"`
} }
// PRLinks represents the "_links" object in a Github pull request. // PRLinks represents the "_links" object in a GitHub pull request.
type PRLinks struct { type PRLinks struct {
Self *PRLink `json:"self,omitempty"` Self *PRLink `json:"self,omitempty"`
HTML *PRLink `json:"html,omitempty"` HTML *PRLink `json:"html,omitempty"`
@ -135,7 +143,7 @@ type PullRequestListOptions struct {
// List the pull requests for the specified repository. // List the pull requests for the specified repository.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/#list-pull-requests // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#list-pull-requests
func (s *PullRequestsService) List(ctx context.Context, owner string, repo string, opts *PullRequestListOptions) ([]*PullRequest, *Response, error) { func (s *PullRequestsService) List(ctx context.Context, owner string, repo string, opts *PullRequestListOptions) ([]*PullRequest, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls", owner, repo) u := fmt.Sprintf("repos/%v/%v/pulls", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -148,10 +156,6 @@ func (s *PullRequestsService) List(ctx context.Context, owner string, repo strin
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept header when this API fully launches.
acceptHeaders := []string{mediaTypeLockReasonPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
var pulls []*PullRequest var pulls []*PullRequest
resp, err := s.client.Do(ctx, req, &pulls) resp, err := s.client.Do(ctx, req, &pulls)
if err != nil { if err != nil {
@ -165,7 +169,7 @@ func (s *PullRequestsService) List(ctx context.Context, owner string, repo strin
// //
// The results will include open and closed pull requests. // The results will include open and closed pull requests.
// //
// GitHub API docs: https://developer.github.com/v3/repos/commits/#list-pull-requests-associated-with-a-commit // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-pull-requests-associated-with-a-commit
func (s *PullRequestsService) ListPullRequestsWithCommit(ctx context.Context, owner, repo, sha string, opts *PullRequestListOptions) ([]*PullRequest, *Response, error) { func (s *PullRequestsService) ListPullRequestsWithCommit(ctx context.Context, owner, repo, sha string, opts *PullRequestListOptions) ([]*PullRequest, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v/pulls", owner, repo, sha) u := fmt.Sprintf("repos/%v/%v/commits/%v/pulls", owner, repo, sha)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -179,8 +183,7 @@ func (s *PullRequestsService) ListPullRequestsWithCommit(ctx context.Context, ow
} }
// TODO: remove custom Accept header when this API fully launches. // TODO: remove custom Accept header when this API fully launches.
acceptHeaders := []string{mediaTypeListPullsOrBranchesForCommitPreview, mediaTypeLockReasonPreview} req.Header.Set("Accept", mediaTypeListPullsOrBranchesForCommitPreview)
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
var pulls []*PullRequest var pulls []*PullRequest
resp, err := s.client.Do(ctx, req, &pulls) resp, err := s.client.Do(ctx, req, &pulls)
if err != nil { if err != nil {
@ -192,7 +195,7 @@ func (s *PullRequestsService) ListPullRequestsWithCommit(ctx context.Context, ow
// Get a single pull request. // Get a single pull request.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/#get-a-pull-request // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#get-a-pull-request
func (s *PullRequestsService) Get(ctx context.Context, owner string, repo string, number int) (*PullRequest, *Response, error) { func (s *PullRequestsService) Get(ctx context.Context, owner string, repo string, number int) (*PullRequest, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/pulls/%d", owner, repo, number)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -200,10 +203,6 @@ func (s *PullRequestsService) Get(ctx context.Context, owner string, repo string
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept header when this API fully launches.
acceptHeaders := []string{mediaTypeLockReasonPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
pull := new(PullRequest) pull := new(PullRequest)
resp, err := s.client.Do(ctx, req, pull) resp, err := s.client.Do(ctx, req, pull)
if err != nil { if err != nil {
@ -215,7 +214,7 @@ func (s *PullRequestsService) Get(ctx context.Context, owner string, repo string
// GetRaw gets a single pull request in raw (diff or patch) format. // GetRaw gets a single pull request in raw (diff or patch) format.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/#get-a-pull-request // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#get-a-pull-request
func (s *PullRequestsService) GetRaw(ctx context.Context, owner string, repo string, number int, opts RawOptions) (string, *Response, error) { func (s *PullRequestsService) GetRaw(ctx context.Context, owner string, repo string, number int, opts RawOptions) (string, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/pulls/%d", owner, repo, number)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -254,7 +253,7 @@ type NewPullRequest struct {
// Create a new pull request on the specified repository. // Create a new pull request on the specified repository.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/#create-a-pull-request // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#create-a-pull-request
func (s *PullRequestsService) Create(ctx context.Context, owner string, repo string, pull *NewPullRequest) (*PullRequest, *Response, error) { func (s *PullRequestsService) Create(ctx context.Context, owner string, repo string, pull *NewPullRequest) (*PullRequest, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls", owner, repo) u := fmt.Sprintf("repos/%v/%v/pulls", owner, repo)
req, err := s.client.NewRequest("POST", u, pull) req, err := s.client.NewRequest("POST", u, pull)
@ -293,7 +292,7 @@ type PullRequestBranchUpdateResponse struct {
// A follow up request, after a delay of a second or so, should result // A follow up request, after a delay of a second or so, should result
// in a successful request. // in a successful request.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/#update-a-pull-request-branch // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#update-a-pull-request-branch
func (s *PullRequestsService) UpdateBranch(ctx context.Context, owner, repo string, number int, opts *PullRequestBranchUpdateOptions) (*PullRequestBranchUpdateResponse, *Response, error) { func (s *PullRequestsService) UpdateBranch(ctx context.Context, owner, repo string, number int, opts *PullRequestBranchUpdateOptions) (*PullRequestBranchUpdateResponse, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/update-branch", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/pulls/%d/update-branch", owner, repo, number)
@ -328,7 +327,7 @@ type pullRequestUpdate struct {
// The following fields are editable: Title, Body, State, Base.Ref and MaintainerCanModify. // The following fields are editable: Title, Body, State, Base.Ref and MaintainerCanModify.
// Base.Ref updates the base branch of the pull request. // Base.Ref updates the base branch of the pull request.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/#update-a-pull-request // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#update-a-pull-request
func (s *PullRequestsService) Edit(ctx context.Context, owner string, repo string, number int, pull *PullRequest) (*PullRequest, *Response, error) { func (s *PullRequestsService) Edit(ctx context.Context, owner string, repo string, number int, pull *PullRequest) (*PullRequest, *Response, error) {
if pull == nil { if pull == nil {
return nil, nil, fmt.Errorf("pull must be provided") return nil, nil, fmt.Errorf("pull must be provided")
@ -354,10 +353,6 @@ func (s *PullRequestsService) Edit(ctx context.Context, owner string, repo strin
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept header when this API fully launches.
acceptHeaders := []string{mediaTypeLockReasonPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
p := new(PullRequest) p := new(PullRequest)
resp, err := s.client.Do(ctx, req, p) resp, err := s.client.Do(ctx, req, p)
if err != nil { if err != nil {
@ -369,7 +364,7 @@ func (s *PullRequestsService) Edit(ctx context.Context, owner string, repo strin
// ListCommits lists the commits in a pull request. // ListCommits lists the commits in a pull request.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/#list-commits-on-a-pull-request // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#list-commits-on-a-pull-request
func (s *PullRequestsService) ListCommits(ctx context.Context, owner string, repo string, number int, opts *ListOptions) ([]*RepositoryCommit, *Response, error) { func (s *PullRequestsService) ListCommits(ctx context.Context, owner string, repo string, number int, opts *ListOptions) ([]*RepositoryCommit, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/commits", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/pulls/%d/commits", owner, repo, number)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -393,7 +388,7 @@ func (s *PullRequestsService) ListCommits(ctx context.Context, owner string, rep
// ListFiles lists the files in a pull request. // ListFiles lists the files in a pull request.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/#list-pull-requests-files // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#list-pull-requests-files
func (s *PullRequestsService) ListFiles(ctx context.Context, owner string, repo string, number int, opts *ListOptions) ([]*CommitFile, *Response, error) { func (s *PullRequestsService) ListFiles(ctx context.Context, owner string, repo string, number int, opts *ListOptions) ([]*CommitFile, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/files", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/pulls/%d/files", owner, repo, number)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -417,7 +412,7 @@ func (s *PullRequestsService) ListFiles(ctx context.Context, owner string, repo
// IsMerged checks if a pull request has been merged. // IsMerged checks if a pull request has been merged.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/#check-if-a-pull-request-has-been-merged // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#check-if-a-pull-request-has-been-merged
func (s *PullRequestsService) IsMerged(ctx context.Context, owner string, repo string, number int) (bool, *Response, error) { func (s *PullRequestsService) IsMerged(ctx context.Context, owner string, repo string, number int) (bool, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/merge", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/pulls/%d/merge", owner, repo, number)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -444,27 +439,36 @@ type PullRequestOptions struct {
// The merge method to use. Possible values include: "merge", "squash", and "rebase" with the default being merge. (Optional.) // The merge method to use. Possible values include: "merge", "squash", and "rebase" with the default being merge. (Optional.)
MergeMethod string MergeMethod string
// If false, an empty string commit message will use the default commit message. If true, an empty string commit message will be used.
DontDefaultIfBlank bool
} }
type pullRequestMergeRequest struct { type pullRequestMergeRequest struct {
CommitMessage string `json:"commit_message,omitempty"` CommitMessage *string `json:"commit_message,omitempty"`
CommitTitle string `json:"commit_title,omitempty"` CommitTitle string `json:"commit_title,omitempty"`
MergeMethod string `json:"merge_method,omitempty"` MergeMethod string `json:"merge_method,omitempty"`
SHA string `json:"sha,omitempty"` SHA string `json:"sha,omitempty"`
} }
// Merge a pull request. // Merge a pull request.
// commitMessage is an extra detail to append to automatic commit message. // commitMessage is an extra detail to append to automatic commit message.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/#merge-a-pull-request // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#merge-a-pull-request
func (s *PullRequestsService) Merge(ctx context.Context, owner string, repo string, number int, commitMessage string, options *PullRequestOptions) (*PullRequestMergeResult, *Response, error) { func (s *PullRequestsService) Merge(ctx context.Context, owner string, repo string, number int, commitMessage string, options *PullRequestOptions) (*PullRequestMergeResult, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/merge", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/pulls/%d/merge", owner, repo, number)
pullRequestBody := &pullRequestMergeRequest{CommitMessage: commitMessage} pullRequestBody := &pullRequestMergeRequest{}
if commitMessage != "" {
pullRequestBody.CommitMessage = &commitMessage
}
if options != nil { if options != nil {
pullRequestBody.CommitTitle = options.CommitTitle pullRequestBody.CommitTitle = options.CommitTitle
pullRequestBody.MergeMethod = options.MergeMethod pullRequestBody.MergeMethod = options.MergeMethod
pullRequestBody.SHA = options.SHA pullRequestBody.SHA = options.SHA
if options.DontDefaultIfBlank && commitMessage == "" {
pullRequestBody.CommitMessage = &commitMessage
}
} }
req, err := s.client.NewRequest("PUT", u, pullRequestBody) req, err := s.client.NewRequest("PUT", u, pullRequestBody)
if err != nil { if err != nil {

View file

@ -66,9 +66,9 @@ type PullRequestListCommentsOptions struct {
// pull request number of 0 will return all comments on all pull requests for // pull request number of 0 will return all comments on all pull requests for
// the repository. // the repository.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/comments/#list-review-comments-on-a-pull-request // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#list-review-comments-on-a-pull-request
// GitHub API docs: https://developer.github.com/v3/pulls/comments/#list-review-comments-in-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#list-review-comments-in-a-repository
func (s *PullRequestsService) ListComments(ctx context.Context, owner string, repo string, number int, opts *PullRequestListCommentsOptions) ([]*PullRequestComment, *Response, error) { func (s *PullRequestsService) ListComments(ctx context.Context, owner, repo string, number int, opts *PullRequestListCommentsOptions) ([]*PullRequestComment, *Response, error) {
var u string var u string
if number == 0 { if number == 0 {
u = fmt.Sprintf("repos/%v/%v/pulls/comments", owner, repo) u = fmt.Sprintf("repos/%v/%v/pulls/comments", owner, repo)
@ -100,8 +100,8 @@ func (s *PullRequestsService) ListComments(ctx context.Context, owner string, re
// GetComment fetches the specified pull request comment. // GetComment fetches the specified pull request comment.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/comments/#get-a-review-comment-for-a-pull-request // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#get-a-review-comment-for-a-pull-request
func (s *PullRequestsService) GetComment(ctx context.Context, owner string, repo string, commentID int64) (*PullRequestComment, *Response, error) { func (s *PullRequestsService) GetComment(ctx context.Context, owner, repo string, commentID int64) (*PullRequestComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, commentID) u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, commentID)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
@ -123,8 +123,8 @@ func (s *PullRequestsService) GetComment(ctx context.Context, owner string, repo
// CreateComment creates a new comment on the specified pull request. // CreateComment creates a new comment on the specified pull request.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/comments/#create-a-review-comment-for-a-pull-request // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#create-a-review-comment-for-a-pull-request
func (s *PullRequestsService) CreateComment(ctx context.Context, owner string, repo string, number int, comment *PullRequestComment) (*PullRequestComment, *Response, error) { func (s *PullRequestsService) CreateComment(ctx context.Context, owner, repo string, number int, comment *PullRequestComment) (*PullRequestComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/comments", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/pulls/%d/comments", owner, repo, number)
req, err := s.client.NewRequest("POST", u, comment) req, err := s.client.NewRequest("POST", u, comment)
if err != nil { if err != nil {
@ -145,8 +145,8 @@ func (s *PullRequestsService) CreateComment(ctx context.Context, owner string, r
// CreateCommentInReplyTo creates a new comment as a reply to an existing pull request comment. // CreateCommentInReplyTo creates a new comment as a reply to an existing pull request comment.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/comments/#create-a-review-comment-for-a-pull-request // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#create-a-review-comment-for-a-pull-request
func (s *PullRequestsService) CreateCommentInReplyTo(ctx context.Context, owner string, repo string, number int, body string, commentID int64) (*PullRequestComment, *Response, error) { func (s *PullRequestsService) CreateCommentInReplyTo(ctx context.Context, owner, repo string, number int, body string, commentID int64) (*PullRequestComment, *Response, error) {
comment := &struct { comment := &struct {
Body string `json:"body,omitempty"` Body string `json:"body,omitempty"`
InReplyTo int64 `json:"in_reply_to,omitempty"` InReplyTo int64 `json:"in_reply_to,omitempty"`
@ -172,8 +172,8 @@ func (s *PullRequestsService) CreateCommentInReplyTo(ctx context.Context, owner
// EditComment updates a pull request comment. // EditComment updates a pull request comment.
// A non-nil comment.Body must be provided. Other comment fields should be left nil. // A non-nil comment.Body must be provided. Other comment fields should be left nil.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/comments/#update-a-review-comment-for-a-pull-request // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#update-a-review-comment-for-a-pull-request
func (s *PullRequestsService) EditComment(ctx context.Context, owner string, repo string, commentID int64, comment *PullRequestComment) (*PullRequestComment, *Response, error) { func (s *PullRequestsService) EditComment(ctx context.Context, owner, repo string, commentID int64, comment *PullRequestComment) (*PullRequestComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, commentID) u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, commentID)
req, err := s.client.NewRequest("PATCH", u, comment) req, err := s.client.NewRequest("PATCH", u, comment)
if err != nil { if err != nil {
@ -191,8 +191,8 @@ func (s *PullRequestsService) EditComment(ctx context.Context, owner string, rep
// DeleteComment deletes a pull request comment. // DeleteComment deletes a pull request comment.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/comments/#delete-a-review-comment-for-a-pull-request // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#delete-a-review-comment-for-a-pull-request
func (s *PullRequestsService) DeleteComment(ctx context.Context, owner string, repo string, commentID int64) (*Response, error) { func (s *PullRequestsService) DeleteComment(ctx context.Context, owner, repo string, commentID int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, commentID) u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, commentID)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil { if err != nil {

View file

@ -25,7 +25,7 @@ type Reviewers struct {
// RequestReviewers creates a review request for the provided reviewers for the specified pull request. // RequestReviewers creates a review request for the provided reviewers for the specified pull request.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/review_requests/#request-reviewers-for-a-pull-request // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#request-reviewers-for-a-pull-request
func (s *PullRequestsService) RequestReviewers(ctx context.Context, owner, repo string, number int, reviewers ReviewersRequest) (*PullRequest, *Response, error) { func (s *PullRequestsService) RequestReviewers(ctx context.Context, owner, repo string, number int, reviewers ReviewersRequest) (*PullRequest, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/pulls/%d/requested_reviewers", owner, repo, number) u := fmt.Sprintf("repos/%s/%s/pulls/%d/requested_reviewers", owner, repo, number)
req, err := s.client.NewRequest("POST", u, &reviewers) req, err := s.client.NewRequest("POST", u, &reviewers)
@ -44,7 +44,7 @@ func (s *PullRequestsService) RequestReviewers(ctx context.Context, owner, repo
// ListReviewers lists reviewers whose reviews have been requested on the specified pull request. // ListReviewers lists reviewers whose reviews have been requested on the specified pull request.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/review_requests/#list-requested-reviewers-for-a-pull-request // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#list-requested-reviewers-for-a-pull-request
func (s *PullRequestsService) ListReviewers(ctx context.Context, owner, repo string, number int, opts *ListOptions) (*Reviewers, *Response, error) { func (s *PullRequestsService) ListReviewers(ctx context.Context, owner, repo string, number int, opts *ListOptions) (*Reviewers, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/requested_reviewers", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/pulls/%d/requested_reviewers", owner, repo, number)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -68,7 +68,7 @@ func (s *PullRequestsService) ListReviewers(ctx context.Context, owner, repo str
// RemoveReviewers removes the review request for the provided reviewers for the specified pull request. // RemoveReviewers removes the review request for the provided reviewers for the specified pull request.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/review_requests/#remove-requested-reviewers-from-a-pull-request // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#remove-requested-reviewers-from-a-pull-request
func (s *PullRequestsService) RemoveReviewers(ctx context.Context, owner, repo string, number int, reviewers ReviewersRequest) (*Response, error) { func (s *PullRequestsService) RemoveReviewers(ctx context.Context, owner, repo string, number int, reviewers ReviewersRequest) (*Response, error) {
u := fmt.Sprintf("repos/%s/%s/pulls/%d/requested_reviewers", owner, repo, number) u := fmt.Sprintf("repos/%s/%s/pulls/%d/requested_reviewers", owner, repo, number)
req, err := s.client.NewRequest("DELETE", u, &reviewers) req, err := s.client.NewRequest("DELETE", u, &reviewers)

View file

@ -64,7 +64,7 @@ func (r PullRequestReviewRequest) String() string {
return Stringify(r) return Stringify(r)
} }
func (r PullRequestReviewRequest) isComfortFadePreview() (bool, error) { func (r *PullRequestReviewRequest) isComfortFadePreview() (bool, error) {
var isCF *bool var isCF *bool
for _, comment := range r.Comments { for _, comment := range r.Comments {
if comment == nil { if comment == nil {
@ -101,11 +101,7 @@ func (r PullRequestReviewDismissalRequest) String() string {
// ListReviews lists all reviews on the specified pull request. // ListReviews lists all reviews on the specified pull request.
// //
// TODO: Follow up with GitHub support about an issue with this method's // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#list-reviews-for-a-pull-request
// 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://developer.github.com/v3/pulls/reviews/#list-reviews-for-a-pull-request
func (s *PullRequestsService) ListReviews(ctx context.Context, owner, repo string, number int, opts *ListOptions) ([]*PullRequestReview, *Response, error) { func (s *PullRequestsService) ListReviews(ctx context.Context, owner, repo string, number int, opts *ListOptions) ([]*PullRequestReview, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews", owner, repo, number)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -133,7 +129,7 @@ func (s *PullRequestsService) ListReviews(ctx context.Context, owner, repo strin
// returned error format and remove this comment once it's fixed. // returned error format and remove this comment once it's fixed.
// Read more about it here - https://github.com/google/go-github/issues/540 // Read more about it here - https://github.com/google/go-github/issues/540
// //
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#get-a-review-for-a-pull-request // 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) { 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) u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d", owner, repo, number, reviewID)
@ -157,7 +153,7 @@ func (s *PullRequestsService) GetReview(ctx context.Context, owner, repo string,
// returned error format and remove this comment once it's fixed. // returned error format and remove this comment once it's fixed.
// Read more about it here - https://github.com/google/go-github/issues/540 // Read more about it here - https://github.com/google/go-github/issues/540
// //
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#delete-a-pending-review-for-a-pull-request // 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) { 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) u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d", owner, repo, number, reviewID)
@ -181,7 +177,7 @@ func (s *PullRequestsService) DeletePendingReview(ctx context.Context, owner, re
// returned error format and remove this comment once it's fixed. // returned error format and remove this comment once it's fixed.
// Read more about it here - https://github.com/google/go-github/issues/540 // Read more about it here - https://github.com/google/go-github/issues/540
// //
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#list-comments-for-a-pull-request-review // 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) { 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) u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d/comments", owner, repo, number, reviewID)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -209,7 +205,7 @@ func (s *PullRequestsService) ListReviewComments(ctx context.Context, owner, rep
// returned error format and remove this comment once it's fixed. // returned error format and remove this comment once it's fixed.
// Read more about it here - https://github.com/google/go-github/issues/540 // Read more about it here - https://github.com/google/go-github/issues/540
// //
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#create-a-review-for-a-pull-request // 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. // In order to use multi-line comments, you must use the "comfort fade" preview.
// This replaces the use of the "Position" field in comments with 4 new fields: // This replaces the use of the "Position" field in comments with 4 new fields:
@ -270,7 +266,7 @@ func (s *PullRequestsService) CreateReview(ctx context.Context, owner, repo stri
// UpdateReview updates the review summary on the specified pull request. // UpdateReview updates the review summary on the specified pull request.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#update-a-review-for-a-pull-request // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls/#update-a-review-for-a-pull-request
func (s *PullRequestsService) UpdateReview(ctx context.Context, owner, repo string, number int, reviewID int64, body string) (*PullRequestReview, *Response, error) { func (s *PullRequestsService) UpdateReview(ctx context.Context, owner, repo string, number int, reviewID int64, body string) (*PullRequestReview, *Response, error) {
opts := &struct { opts := &struct {
Body string `json:"body"` Body string `json:"body"`
@ -297,7 +293,7 @@ func (s *PullRequestsService) UpdateReview(ctx context.Context, owner, repo stri
// returned error format and remove this comment once it's fixed. // returned error format and remove this comment once it's fixed.
// Read more about it here - https://github.com/google/go-github/issues/540 // Read more about it here - https://github.com/google/go-github/issues/540
// //
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#submit-a-review-for-a-pull-request // 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) { 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) u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d/events", owner, repo, number, reviewID)
@ -321,7 +317,7 @@ func (s *PullRequestsService) SubmitReview(ctx context.Context, owner, repo stri
// returned error format and remove this comment once it's fixed. // returned error format and remove this comment once it's fixed.
// Read more about it here - https://github.com/google/go-github/issues/540 // Read more about it here - https://github.com/google/go-github/issues/540
// //
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#dismiss-a-review-for-a-pull-request // 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) { 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) u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d/dismissals", owner, repo, number, reviewID)

View file

@ -14,7 +14,7 @@ import (
// ReactionsService provides access to the reactions-related functions in the // ReactionsService provides access to the reactions-related functions in the
// GitHub API. // GitHub API.
// //
// GitHub API docs: https://developer.github.com/v3/reactions/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/
type ReactionsService service type ReactionsService service
// Reaction represents a GitHub reaction. // Reaction represents a GitHub reaction.
@ -25,7 +25,7 @@ type Reaction struct {
NodeID *string `json:"node_id,omitempty"` NodeID *string `json:"node_id,omitempty"`
// Content is the type of reaction. // Content is the type of reaction.
// Possible values are: // Possible values are:
// "+1", "-1", "laugh", "confused", "heart", "hooray". // "+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", or "eyes".
Content *string `json:"content,omitempty"` Content *string `json:"content,omitempty"`
} }
@ -38,6 +38,8 @@ type Reactions struct {
Confused *int `json:"confused,omitempty"` Confused *int `json:"confused,omitempty"`
Heart *int `json:"heart,omitempty"` Heart *int `json:"heart,omitempty"`
Hooray *int `json:"hooray,omitempty"` Hooray *int `json:"hooray,omitempty"`
Rocket *int `json:"rocket,omitempty"`
Eyes *int `json:"eyes,omitempty"`
URL *string `json:"url,omitempty"` URL *string `json:"url,omitempty"`
} }
@ -58,7 +60,7 @@ type ListCommentReactionOptions struct {
// ListCommentReactions lists the reactions for a commit comment. // ListCommentReactions lists the reactions for a commit comment.
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#list-reactions-for-a-commit-comment
func (s *ReactionsService) ListCommentReactions(ctx context.Context, owner, repo string, id int64, opts *ListCommentReactionOptions) ([]*Reaction, *Response, error) { func (s *ReactionsService) ListCommentReactions(ctx context.Context, owner, repo string, id int64, opts *ListCommentReactionOptions) ([]*Reaction, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions", owner, repo, id)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -86,9 +88,9 @@ func (s *ReactionsService) ListCommentReactions(ctx context.Context, owner, repo
// CreateCommentReaction creates a reaction for a commit comment. // CreateCommentReaction creates a reaction for a commit comment.
// Note that if you have already created a reaction of type content, the // Note that if you have already created a reaction of type content, the
// previously created reaction will be returned with Status: 200 OK. // previously created reaction will be returned with Status: 200 OK.
// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray". // The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", or "eyes".
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-a-commit-comment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#create-reaction-for-a-commit-comment
func (s *ReactionsService) CreateCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) { func (s *ReactionsService) CreateCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions", owner, repo, id)
@ -112,7 +114,7 @@ func (s *ReactionsService) CreateCommentReaction(ctx context.Context, owner, rep
// DeleteCommentReaction deletes the reaction for a commit comment. // DeleteCommentReaction deletes the reaction for a commit comment.
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#delete-a-commit-comment-reaction // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#delete-a-commit-comment-reaction
func (s *ReactionsService) DeleteCommentReaction(ctx context.Context, owner, repo string, commentID, reactionID int64) (*Response, error) { func (s *ReactionsService) DeleteCommentReaction(ctx context.Context, owner, repo string, commentID, reactionID int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions/%v", owner, repo, commentID, reactionID) u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions/%v", owner, repo, commentID, reactionID)
@ -121,7 +123,7 @@ func (s *ReactionsService) DeleteCommentReaction(ctx context.Context, owner, rep
// DeleteCommentReactionByID deletes the reaction for a commit comment by repository ID. // DeleteCommentReactionByID deletes the reaction for a commit comment by repository ID.
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#delete-a-commit-comment-reaction // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#delete-a-commit-comment-reaction
func (s *ReactionsService) DeleteCommentReactionByID(ctx context.Context, repoID, commentID, reactionID int64) (*Response, error) { func (s *ReactionsService) DeleteCommentReactionByID(ctx context.Context, repoID, commentID, reactionID int64) (*Response, error) {
u := fmt.Sprintf("repositories/%v/comments/%v/reactions/%v", repoID, commentID, reactionID) u := fmt.Sprintf("repositories/%v/comments/%v/reactions/%v", repoID, commentID, reactionID)
@ -130,7 +132,7 @@ func (s *ReactionsService) DeleteCommentReactionByID(ctx context.Context, repoID
// ListIssueReactions lists the reactions for an issue. // ListIssueReactions lists the reactions for an issue.
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#list-reactions-for-an-issue // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#list-reactions-for-an-issue
func (s *ReactionsService) ListIssueReactions(ctx context.Context, owner, repo string, number int, opts *ListOptions) ([]*Reaction, *Response, error) { func (s *ReactionsService) ListIssueReactions(ctx context.Context, owner, repo string, number int, opts *ListOptions) ([]*Reaction, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%v/reactions", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/issues/%v/reactions", owner, repo, number)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -158,9 +160,9 @@ func (s *ReactionsService) ListIssueReactions(ctx context.Context, owner, repo s
// CreateIssueReaction creates a reaction for an issue. // CreateIssueReaction creates a reaction for an issue.
// Note that if you have already created a reaction of type content, the // Note that if you have already created a reaction of type content, the
// previously created reaction will be returned with Status: 200 OK. // previously created reaction will be returned with Status: 200 OK.
// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray". // The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", or "eyes".
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-an-issue // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#create-reaction-for-an-issue
func (s *ReactionsService) CreateIssueReaction(ctx context.Context, owner, repo string, number int, content string) (*Reaction, *Response, error) { func (s *ReactionsService) CreateIssueReaction(ctx context.Context, owner, repo string, number int, content string) (*Reaction, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%v/reactions", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/issues/%v/reactions", owner, repo, number)
@ -184,7 +186,7 @@ func (s *ReactionsService) CreateIssueReaction(ctx context.Context, owner, repo
// DeleteIssueReaction deletes the reaction to an issue. // DeleteIssueReaction deletes the reaction to an issue.
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#delete-an-issue-reaction // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#delete-an-issue-reaction
func (s *ReactionsService) DeleteIssueReaction(ctx context.Context, owner, repo string, issueNumber int, reactionID int64) (*Response, error) { func (s *ReactionsService) DeleteIssueReaction(ctx context.Context, owner, repo string, issueNumber int, reactionID int64) (*Response, error) {
url := fmt.Sprintf("repos/%v/%v/issues/%v/reactions/%v", owner, repo, issueNumber, reactionID) url := fmt.Sprintf("repos/%v/%v/issues/%v/reactions/%v", owner, repo, issueNumber, reactionID)
@ -193,7 +195,7 @@ func (s *ReactionsService) DeleteIssueReaction(ctx context.Context, owner, repo
// DeleteIssueReactionByID deletes the reaction to an issue by repository ID. // DeleteIssueReactionByID deletes the reaction to an issue by repository ID.
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#delete-an-issue-reaction // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#delete-an-issue-reaction
func (s *ReactionsService) DeleteIssueReactionByID(ctx context.Context, repoID, issueNumber int, reactionID int64) (*Response, error) { func (s *ReactionsService) DeleteIssueReactionByID(ctx context.Context, repoID, issueNumber int, reactionID int64) (*Response, error) {
url := fmt.Sprintf("repositories/%v/issues/%v/reactions/%v", repoID, issueNumber, reactionID) url := fmt.Sprintf("repositories/%v/issues/%v/reactions/%v", repoID, issueNumber, reactionID)
@ -202,7 +204,7 @@ func (s *ReactionsService) DeleteIssueReactionByID(ctx context.Context, repoID,
// ListIssueCommentReactions lists the reactions for an issue comment. // ListIssueCommentReactions lists the reactions for an issue comment.
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#list-reactions-for-an-issue-comment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#list-reactions-for-an-issue-comment
func (s *ReactionsService) ListIssueCommentReactions(ctx context.Context, owner, repo string, id int64, opts *ListOptions) ([]*Reaction, *Response, error) { func (s *ReactionsService) ListIssueCommentReactions(ctx context.Context, owner, repo string, id int64, opts *ListOptions) ([]*Reaction, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/comments/%v/reactions", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/issues/comments/%v/reactions", owner, repo, id)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -230,9 +232,9 @@ func (s *ReactionsService) ListIssueCommentReactions(ctx context.Context, owner,
// CreateIssueCommentReaction creates a reaction for an issue comment. // CreateIssueCommentReaction creates a reaction for an issue comment.
// Note that if you have already created a reaction of type content, the // Note that if you have already created a reaction of type content, the
// previously created reaction will be returned with Status: 200 OK. // previously created reaction will be returned with Status: 200 OK.
// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray". // The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", or "eyes".
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-an-issue-comment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#create-reaction-for-an-issue-comment
func (s *ReactionsService) CreateIssueCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) { func (s *ReactionsService) CreateIssueCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/comments/%v/reactions", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/issues/comments/%v/reactions", owner, repo, id)
@ -256,7 +258,7 @@ func (s *ReactionsService) CreateIssueCommentReaction(ctx context.Context, owner
// DeleteIssueCommentReaction deletes the reaction to an issue comment. // DeleteIssueCommentReaction deletes the reaction to an issue comment.
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#delete-an-issue-comment-reaction // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#delete-an-issue-comment-reaction
func (s *ReactionsService) DeleteIssueCommentReaction(ctx context.Context, owner, repo string, commentID, reactionID int64) (*Response, error) { func (s *ReactionsService) DeleteIssueCommentReaction(ctx context.Context, owner, repo string, commentID, reactionID int64) (*Response, error) {
url := fmt.Sprintf("repos/%v/%v/issues/comments/%v/reactions/%v", owner, repo, commentID, reactionID) url := fmt.Sprintf("repos/%v/%v/issues/comments/%v/reactions/%v", owner, repo, commentID, reactionID)
@ -265,7 +267,7 @@ func (s *ReactionsService) DeleteIssueCommentReaction(ctx context.Context, owner
// DeleteIssueCommentReactionByID deletes the reaction to an issue comment by repository ID. // DeleteIssueCommentReactionByID deletes the reaction to an issue comment by repository ID.
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#delete-an-issue-comment-reaction // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#delete-an-issue-comment-reaction
func (s *ReactionsService) DeleteIssueCommentReactionByID(ctx context.Context, repoID, commentID, reactionID int64) (*Response, error) { func (s *ReactionsService) DeleteIssueCommentReactionByID(ctx context.Context, repoID, commentID, reactionID int64) (*Response, error) {
url := fmt.Sprintf("repositories/%v/issues/comments/%v/reactions/%v", repoID, commentID, reactionID) url := fmt.Sprintf("repositories/%v/issues/comments/%v/reactions/%v", repoID, commentID, reactionID)
@ -274,7 +276,7 @@ func (s *ReactionsService) DeleteIssueCommentReactionByID(ctx context.Context, r
// ListPullRequestCommentReactions lists the reactions for a pull request review comment. // ListPullRequestCommentReactions lists the reactions for a pull request review comment.
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#list-reactions-for-a-pull-request-review-comment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#list-reactions-for-a-pull-request-review-comment
func (s *ReactionsService) ListPullRequestCommentReactions(ctx context.Context, owner, repo string, id int64, opts *ListOptions) ([]*Reaction, *Response, error) { func (s *ReactionsService) ListPullRequestCommentReactions(ctx context.Context, owner, repo string, id int64, opts *ListOptions) ([]*Reaction, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/comments/%v/reactions", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/pulls/comments/%v/reactions", owner, repo, id)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -302,9 +304,9 @@ func (s *ReactionsService) ListPullRequestCommentReactions(ctx context.Context,
// CreatePullRequestCommentReaction creates a reaction for a pull request review comment. // CreatePullRequestCommentReaction creates a reaction for a pull request review comment.
// Note that if you have already created a reaction of type content, the // Note that if you have already created a reaction of type content, the
// previously created reaction will be returned with Status: 200 OK. // previously created reaction will be returned with Status: 200 OK.
// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray". // The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", or "eyes".
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-a-pull-request-review-comment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#create-reaction-for-a-pull-request-review-comment
func (s *ReactionsService) CreatePullRequestCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) { func (s *ReactionsService) CreatePullRequestCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/comments/%v/reactions", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/pulls/comments/%v/reactions", owner, repo, id)
@ -328,7 +330,7 @@ func (s *ReactionsService) CreatePullRequestCommentReaction(ctx context.Context,
// DeletePullRequestCommentReaction deletes the reaction to a pull request review comment. // DeletePullRequestCommentReaction deletes the reaction to a pull request review comment.
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#delete-a-pull-request-comment-reaction // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#delete-a-pull-request-comment-reaction
func (s *ReactionsService) DeletePullRequestCommentReaction(ctx context.Context, owner, repo string, commentID, reactionID int64) (*Response, error) { func (s *ReactionsService) DeletePullRequestCommentReaction(ctx context.Context, owner, repo string, commentID, reactionID int64) (*Response, error) {
url := fmt.Sprintf("repos/%v/%v/pulls/comments/%v/reactions/%v", owner, repo, commentID, reactionID) url := fmt.Sprintf("repos/%v/%v/pulls/comments/%v/reactions/%v", owner, repo, commentID, reactionID)
@ -337,7 +339,7 @@ func (s *ReactionsService) DeletePullRequestCommentReaction(ctx context.Context,
// DeletePullRequestCommentReactionByID deletes the reaction to a pull request review comment by repository ID. // DeletePullRequestCommentReactionByID deletes the reaction to a pull request review comment by repository ID.
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#delete-a-pull-request-comment-reaction // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#delete-a-pull-request-comment-reaction
func (s *ReactionsService) DeletePullRequestCommentReactionByID(ctx context.Context, repoID, commentID, reactionID int64) (*Response, error) { func (s *ReactionsService) DeletePullRequestCommentReactionByID(ctx context.Context, repoID, commentID, reactionID int64) (*Response, error) {
url := fmt.Sprintf("repositories/%v/pulls/comments/%v/reactions/%v", repoID, commentID, reactionID) url := fmt.Sprintf("repositories/%v/pulls/comments/%v/reactions/%v", repoID, commentID, reactionID)
@ -346,7 +348,7 @@ func (s *ReactionsService) DeletePullRequestCommentReactionByID(ctx context.Cont
// ListTeamDiscussionReactions lists the reactions for a team discussion. // ListTeamDiscussionReactions lists the reactions for a team discussion.
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#list-reactions-for-a-team-discussion-legacy // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#list-reactions-for-a-team-discussion-legacy
func (s *ReactionsService) ListTeamDiscussionReactions(ctx context.Context, teamID int64, discussionNumber int, opts *ListOptions) ([]*Reaction, *Response, error) { func (s *ReactionsService) ListTeamDiscussionReactions(ctx context.Context, teamID int64, discussionNumber int, opts *ListOptions) ([]*Reaction, *Response, error) {
u := fmt.Sprintf("teams/%v/discussions/%v/reactions", teamID, discussionNumber) u := fmt.Sprintf("teams/%v/discussions/%v/reactions", teamID, discussionNumber)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -371,9 +373,9 @@ func (s *ReactionsService) ListTeamDiscussionReactions(ctx context.Context, team
} }
// CreateTeamDiscussionReaction creates a reaction for a team discussion. // CreateTeamDiscussionReaction creates a reaction for a team discussion.
// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray". // The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", or "eyes".
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-a-team-discussion-legacy // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#create-reaction-for-a-team-discussion-legacy
func (s *ReactionsService) CreateTeamDiscussionReaction(ctx context.Context, teamID int64, discussionNumber int, content string) (*Reaction, *Response, error) { func (s *ReactionsService) CreateTeamDiscussionReaction(ctx context.Context, teamID int64, discussionNumber int, content string) (*Reaction, *Response, error) {
u := fmt.Sprintf("teams/%v/discussions/%v/reactions", teamID, discussionNumber) u := fmt.Sprintf("teams/%v/discussions/%v/reactions", teamID, discussionNumber)
@ -396,7 +398,7 @@ func (s *ReactionsService) CreateTeamDiscussionReaction(ctx context.Context, tea
// DeleteTeamDiscussionReaction deletes the reaction to a team discussion. // DeleteTeamDiscussionReaction deletes the reaction to a team discussion.
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#delete-team-discussion-reaction // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#delete-team-discussion-reaction
func (s *ReactionsService) DeleteTeamDiscussionReaction(ctx context.Context, org, teamSlug string, discussionNumber int, reactionID int64) (*Response, error) { func (s *ReactionsService) DeleteTeamDiscussionReaction(ctx context.Context, org, teamSlug string, discussionNumber int, reactionID int64) (*Response, error) {
url := fmt.Sprintf("orgs/%v/teams/%v/discussions/%v/reactions/%v", org, teamSlug, discussionNumber, reactionID) url := fmt.Sprintf("orgs/%v/teams/%v/discussions/%v/reactions/%v", org, teamSlug, discussionNumber, reactionID)
@ -405,7 +407,7 @@ func (s *ReactionsService) DeleteTeamDiscussionReaction(ctx context.Context, org
// DeleteTeamDiscussionReactionByOrgIDAndTeamID deletes the reaction to a team discussion by organization ID and team ID. // DeleteTeamDiscussionReactionByOrgIDAndTeamID deletes the reaction to a team discussion by organization ID and team ID.
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#delete-team-discussion-reaction // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#delete-team-discussion-reaction
func (s *ReactionsService) DeleteTeamDiscussionReactionByOrgIDAndTeamID(ctx context.Context, orgID, teamID, discussionNumber int, reactionID int64) (*Response, error) { func (s *ReactionsService) DeleteTeamDiscussionReactionByOrgIDAndTeamID(ctx context.Context, orgID, teamID, discussionNumber int, reactionID int64) (*Response, error) {
url := fmt.Sprintf("organizations/%v/team/%v/discussions/%v/reactions/%v", orgID, teamID, discussionNumber, reactionID) url := fmt.Sprintf("organizations/%v/team/%v/discussions/%v/reactions/%v", orgID, teamID, discussionNumber, reactionID)
@ -414,7 +416,7 @@ func (s *ReactionsService) DeleteTeamDiscussionReactionByOrgIDAndTeamID(ctx cont
// ListTeamDiscussionCommentReactions lists the reactions for a team discussion comment. // ListTeamDiscussionCommentReactions lists the reactions for a team discussion comment.
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#list-reactions-for-a-team-discussion-comment-legacy // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#list-reactions-for-a-team-discussion-comment-legacy
func (s *ReactionsService) ListTeamDiscussionCommentReactions(ctx context.Context, teamID int64, discussionNumber, commentNumber int, opts *ListOptions) ([]*Reaction, *Response, error) { func (s *ReactionsService) ListTeamDiscussionCommentReactions(ctx context.Context, teamID int64, discussionNumber, commentNumber int, opts *ListOptions) ([]*Reaction, *Response, error) {
u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v/reactions", teamID, discussionNumber, commentNumber) u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v/reactions", teamID, discussionNumber, commentNumber)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -432,15 +434,15 @@ func (s *ReactionsService) ListTeamDiscussionCommentReactions(ctx context.Contex
var m []*Reaction var m []*Reaction
resp, err := s.client.Do(ctx, req, &m) resp, err := s.client.Do(ctx, req, &m)
if err != nil { if err != nil {
return nil, nil, err return nil, resp, err
} }
return m, resp, nil return m, resp, nil
} }
// CreateTeamDiscussionCommentReaction creates a reaction for a team discussion comment. // CreateTeamDiscussionCommentReaction creates a reaction for a team discussion comment.
// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray". // The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", or "eyes".
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-a-team-discussion-comment-legacy // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#create-reaction-for-a-team-discussion-comment-legacy
func (s *ReactionsService) CreateTeamDiscussionCommentReaction(ctx context.Context, teamID int64, discussionNumber, commentNumber int, content string) (*Reaction, *Response, error) { func (s *ReactionsService) CreateTeamDiscussionCommentReaction(ctx context.Context, teamID int64, discussionNumber, commentNumber int, content string) (*Reaction, *Response, error) {
u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v/reactions", teamID, discussionNumber, commentNumber) u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v/reactions", teamID, discussionNumber, commentNumber)
@ -463,7 +465,7 @@ func (s *ReactionsService) CreateTeamDiscussionCommentReaction(ctx context.Conte
// DeleteTeamDiscussionCommentReaction deletes the reaction to a team discussion comment. // DeleteTeamDiscussionCommentReaction deletes the reaction to a team discussion comment.
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#delete-team-discussion-comment-reaction // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#delete-team-discussion-comment-reaction
func (s *ReactionsService) DeleteTeamDiscussionCommentReaction(ctx context.Context, org, teamSlug string, discussionNumber, commentNumber int, reactionID int64) (*Response, error) { func (s *ReactionsService) DeleteTeamDiscussionCommentReaction(ctx context.Context, org, teamSlug string, discussionNumber, commentNumber int, reactionID int64) (*Response, error) {
url := fmt.Sprintf("orgs/%v/teams/%v/discussions/%v/comments/%v/reactions/%v", org, teamSlug, discussionNumber, commentNumber, reactionID) url := fmt.Sprintf("orgs/%v/teams/%v/discussions/%v/comments/%v/reactions/%v", org, teamSlug, discussionNumber, commentNumber, reactionID)
@ -472,7 +474,7 @@ func (s *ReactionsService) DeleteTeamDiscussionCommentReaction(ctx context.Conte
// DeleteTeamDiscussionCommentReactionByOrgIDAndTeamID deletes the reaction to a team discussion comment by organization ID and team ID. // DeleteTeamDiscussionCommentReactionByOrgIDAndTeamID deletes the reaction to a team discussion comment by organization ID and team ID.
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#delete-team-discussion-comment-reaction // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions/#delete-team-discussion-comment-reaction
func (s *ReactionsService) DeleteTeamDiscussionCommentReactionByOrgIDAndTeamID(ctx context.Context, orgID, teamID, discussionNumber, commentNumber int, reactionID int64) (*Response, error) { func (s *ReactionsService) DeleteTeamDiscussionCommentReactionByOrgIDAndTeamID(ctx context.Context, orgID, teamID, discussionNumber, commentNumber int, reactionID int64) (*Response, error) {
url := fmt.Sprintf("organizations/%v/team/%v/discussions/%v/comments/%v/reactions/%v", orgID, teamID, discussionNumber, commentNumber, reactionID) url := fmt.Sprintf("organizations/%v/team/%v/discussions/%v/comments/%v/reactions/%v", orgID, teamID, discussionNumber, commentNumber, reactionID)

View file

@ -9,58 +9,61 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http"
"strings" "strings"
) )
// RepositoriesService handles communication with the repository related // RepositoriesService handles communication with the repository related
// methods of the GitHub API. // methods of the GitHub API.
// //
// GitHub API docs: https://developer.github.com/v3/repos/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/
type RepositoriesService service type RepositoriesService service
// Repository represents a GitHub repository. // Repository represents a GitHub repository.
type Repository struct { type Repository struct {
ID *int64 `json:"id,omitempty"` ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"` NodeID *string `json:"node_id,omitempty"`
Owner *User `json:"owner,omitempty"` Owner *User `json:"owner,omitempty"`
Name *string `json:"name,omitempty"` Name *string `json:"name,omitempty"`
FullName *string `json:"full_name,omitempty"` FullName *string `json:"full_name,omitempty"`
Description *string `json:"description,omitempty"` Description *string `json:"description,omitempty"`
Homepage *string `json:"homepage,omitempty"` Homepage *string `json:"homepage,omitempty"`
CodeOfConduct *CodeOfConduct `json:"code_of_conduct,omitempty"` CodeOfConduct *CodeOfConduct `json:"code_of_conduct,omitempty"`
DefaultBranch *string `json:"default_branch,omitempty"` DefaultBranch *string `json:"default_branch,omitempty"`
MasterBranch *string `json:"master_branch,omitempty"` MasterBranch *string `json:"master_branch,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"` CreatedAt *Timestamp `json:"created_at,omitempty"`
PushedAt *Timestamp `json:"pushed_at,omitempty"` PushedAt *Timestamp `json:"pushed_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"` UpdatedAt *Timestamp `json:"updated_at,omitempty"`
HTMLURL *string `json:"html_url,omitempty"` HTMLURL *string `json:"html_url,omitempty"`
CloneURL *string `json:"clone_url,omitempty"` CloneURL *string `json:"clone_url,omitempty"`
GitURL *string `json:"git_url,omitempty"` GitURL *string `json:"git_url,omitempty"`
MirrorURL *string `json:"mirror_url,omitempty"` MirrorURL *string `json:"mirror_url,omitempty"`
SSHURL *string `json:"ssh_url,omitempty"` SSHURL *string `json:"ssh_url,omitempty"`
SVNURL *string `json:"svn_url,omitempty"` SVNURL *string `json:"svn_url,omitempty"`
Language *string `json:"language,omitempty"` Language *string `json:"language,omitempty"`
Fork *bool `json:"fork,omitempty"` Fork *bool `json:"fork,omitempty"`
ForksCount *int `json:"forks_count,omitempty"` ForksCount *int `json:"forks_count,omitempty"`
NetworkCount *int `json:"network_count,omitempty"` NetworkCount *int `json:"network_count,omitempty"`
OpenIssuesCount *int `json:"open_issues_count,omitempty"` OpenIssuesCount *int `json:"open_issues_count,omitempty"`
StargazersCount *int `json:"stargazers_count,omitempty"` OpenIssues *int `json:"open_issues,omitempty"` // Deprecated: Replaced by OpenIssuesCount. For backward compatibility OpenIssues is still populated.
SubscribersCount *int `json:"subscribers_count,omitempty"` StargazersCount *int `json:"stargazers_count,omitempty"`
WatchersCount *int `json:"watchers_count,omitempty"` SubscribersCount *int `json:"subscribers_count,omitempty"`
Size *int `json:"size,omitempty"` WatchersCount *int `json:"watchers_count,omitempty"` // Deprecated: Replaced by StargazersCount. For backward compatibility WatchersCount is still populated.
AutoInit *bool `json:"auto_init,omitempty"` Watchers *int `json:"watchers,omitempty"` // Deprecated: Replaced by StargazersCount. For backward compatibility Watchers is still populated.
Parent *Repository `json:"parent,omitempty"` Size *int `json:"size,omitempty"`
Source *Repository `json:"source,omitempty"` AutoInit *bool `json:"auto_init,omitempty"`
TemplateRepository *Repository `json:"template_repository,omitempty"` Parent *Repository `json:"parent,omitempty"`
Organization *Organization `json:"organization,omitempty"` Source *Repository `json:"source,omitempty"`
Permissions *map[string]bool `json:"permissions,omitempty"` TemplateRepository *Repository `json:"template_repository,omitempty"`
AllowRebaseMerge *bool `json:"allow_rebase_merge,omitempty"` Organization *Organization `json:"organization,omitempty"`
AllowSquashMerge *bool `json:"allow_squash_merge,omitempty"` Permissions map[string]bool `json:"permissions,omitempty"`
AllowMergeCommit *bool `json:"allow_merge_commit,omitempty"` AllowRebaseMerge *bool `json:"allow_rebase_merge,omitempty"`
DeleteBranchOnMerge *bool `json:"delete_branch_on_merge,omitempty"` AllowSquashMerge *bool `json:"allow_squash_merge,omitempty"`
Topics []string `json:"topics,omitempty"` AllowMergeCommit *bool `json:"allow_merge_commit,omitempty"`
Archived *bool `json:"archived,omitempty"` DeleteBranchOnMerge *bool `json:"delete_branch_on_merge,omitempty"`
Disabled *bool `json:"disabled,omitempty"` Topics []string `json:"topics,omitempty"`
Archived *bool `json:"archived,omitempty"`
Disabled *bool `json:"disabled,omitempty"`
// Only provided when using RepositoriesService.Get while in preview // Only provided when using RepositoriesService.Get while in preview
License *License `json:"license,omitempty"` License *License `json:"license,omitempty"`
@ -119,7 +122,7 @@ type Repository struct {
TeamsURL *string `json:"teams_url,omitempty"` TeamsURL *string `json:"teams_url,omitempty"`
// TextMatches is only populated from search results that request text matches // TextMatches is only populated from search results that request text matches
// See: search.go and https://developer.github.com/v3/search/#text-match-metadata // See: search.go and https://docs.github.com/en/free-pro-team@latest/rest/reference/search/#text-match-metadata
TextMatches []*TextMatch `json:"text_matches,omitempty"` TextMatches []*TextMatch `json:"text_matches,omitempty"`
// Visibility is only used for Create and Edit endpoints. The visibility field // Visibility is only used for Create and Edit endpoints. The visibility field
@ -182,8 +185,8 @@ type RepositoryListOptions struct {
// List the repositories for a user. Passing the empty string will list // List the repositories for a user. Passing the empty string will list
// repositories for the authenticated user. // repositories for the authenticated user.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#list-repositories-for-a-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-repositories-for-the-authenticated-user
// GitHub API docs: https://developer.github.com/v3/repos/#list-repositories-for-the-authenticated-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-repositories-for-a-user
func (s *RepositoriesService) List(ctx context.Context, user string, opts *RepositoryListOptions) ([]*Repository, *Response, error) { func (s *RepositoriesService) List(ctx context.Context, user string, opts *RepositoryListOptions) ([]*Repository, *Response, error) {
var u string var u string
if user != "" { if user != "" {
@ -202,7 +205,7 @@ func (s *RepositoriesService) List(ctx context.Context, user string, opts *Repos
} }
// TODO: remove custom Accept headers when APIs fully launch. // TODO: remove custom Accept headers when APIs fully launch.
acceptHeaders := []string{mediaTypeTopicsPreview} acceptHeaders := []string{mediaTypeTopicsPreview, mediaTypeRepositoryVisibilityPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
var repos []*Repository var repos []*Repository
@ -234,7 +237,7 @@ type RepositoryListByOrgOptions struct {
// ListByOrg lists the repositories for an organization. // ListByOrg lists the repositories for an organization.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#list-organization-repositories // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-organization-repositories
func (s *RepositoriesService) ListByOrg(ctx context.Context, org string, opts *RepositoryListByOrgOptions) ([]*Repository, *Response, error) { func (s *RepositoriesService) ListByOrg(ctx context.Context, org string, opts *RepositoryListByOrgOptions) ([]*Repository, *Response, error) {
u := fmt.Sprintf("orgs/%v/repos", org) u := fmt.Sprintf("orgs/%v/repos", org)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -248,7 +251,7 @@ func (s *RepositoriesService) ListByOrg(ctx context.Context, org string, opts *R
} }
// TODO: remove custom Accept headers when APIs fully launch. // TODO: remove custom Accept headers when APIs fully launch.
acceptHeaders := []string{mediaTypeTopicsPreview} acceptHeaders := []string{mediaTypeTopicsPreview, mediaTypeRepositoryVisibilityPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
var repos []*Repository var repos []*Repository
@ -269,7 +272,7 @@ type RepositoryListAllOptions struct {
// ListAll lists all GitHub repositories in the order that they were created. // ListAll lists all GitHub repositories in the order that they were created.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#list-public-repositories // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-public-repositories
func (s *RepositoriesService) ListAll(ctx context.Context, opts *RepositoryListAllOptions) ([]*Repository, *Response, error) { func (s *RepositoriesService) ListAll(ctx context.Context, opts *RepositoryListAllOptions) ([]*Repository, *Response, error) {
u, err := addOptions("repositories", opts) u, err := addOptions("repositories", opts)
if err != nil { if err != nil {
@ -327,8 +330,13 @@ type createRepoRequest struct {
// Note that only a subset of the repo fields are used and repo must // Note that only a subset of the repo fields are used and repo must
// not be nil. // not be nil.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#create-a-repository-for-the-authenticated-user // Also note that this method will return the response without actually
// GitHub API docs: https://developer.github.com/v3/repos/#create-an-organization-repository // waiting for GitHub to finish creating the repository and letting the
// changes propagate throughout its servers. You may set up a loop with
// exponential back-off to verify repository's creation.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#create-a-repository-for-the-authenticated-user
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#create-an-organization-repository
func (s *RepositoriesService) Create(ctx context.Context, org string, repo *Repository) (*Repository, *Response, error) { func (s *RepositoriesService) Create(ctx context.Context, org string, repo *Repository) (*Repository, *Response, error) {
var u string var u string
if org != "" { if org != "" {
@ -380,12 +388,13 @@ type TemplateRepoRequest struct {
Owner *string `json:"owner,omitempty"` Owner *string `json:"owner,omitempty"`
Description *string `json:"description,omitempty"` Description *string `json:"description,omitempty"`
Private *bool `json:"private,omitempty"` IncludeAllBranches *bool `json:"include_all_branches,omitempty"`
Private *bool `json:"private,omitempty"`
} }
// CreateFromTemplate generates a repository from a template. // CreateFromTemplate generates a repository from a template.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#create-a-repository-using-a-template // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#create-a-repository-using-a-template
func (s *RepositoriesService) CreateFromTemplate(ctx context.Context, templateOwner, templateRepo string, templateRepoReq *TemplateRepoRequest) (*Repository, *Response, error) { func (s *RepositoriesService) CreateFromTemplate(ctx context.Context, templateOwner, templateRepo string, templateRepoReq *TemplateRepoRequest) (*Repository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/generate", templateOwner, templateRepo) u := fmt.Sprintf("repos/%v/%v/generate", templateOwner, templateRepo)
@ -406,7 +415,7 @@ func (s *RepositoriesService) CreateFromTemplate(ctx context.Context, templateOw
// Get fetches a repository. // Get fetches a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#get-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-a-repository
func (s *RepositoriesService) Get(ctx context.Context, owner, repo string) (*Repository, *Response, error) { func (s *RepositoriesService) Get(ctx context.Context, owner, repo string) (*Repository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v", owner, repo) u := fmt.Sprintf("repos/%v/%v", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -415,7 +424,7 @@ func (s *RepositoriesService) Get(ctx context.Context, owner, repo string) (*Rep
} }
// TODO: remove custom Accept header when the license support fully launches // TODO: remove custom Accept header when the license support fully launches
// https://developer.github.com/v3/licenses/#get-a-repositorys-license // https://docs.github.com/en/free-pro-team@latest/rest/reference/licenses/#get-a-repositorys-license
acceptHeaders := []string{ acceptHeaders := []string{
mediaTypeCodesOfConductPreview, mediaTypeCodesOfConductPreview,
mediaTypeTopicsPreview, mediaTypeTopicsPreview,
@ -435,7 +444,7 @@ func (s *RepositoriesService) Get(ctx context.Context, owner, repo string) (*Rep
// GetCodeOfConduct gets the contents of a repository's code of conduct. // GetCodeOfConduct gets the contents of a repository's code of conduct.
// //
// GitHub API docs: https://developer.github.com/v3/codes_of_conduct/#get-the-code-of-conduct-for-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/codes-of-conduct/#get-the-code-of-conduct-for-a-repository
func (s *RepositoriesService) GetCodeOfConduct(ctx context.Context, owner, repo string) (*CodeOfConduct, *Response, error) { func (s *RepositoriesService) GetCodeOfConduct(ctx context.Context, owner, repo string) (*CodeOfConduct, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/community/code_of_conduct", owner, repo) u := fmt.Sprintf("repos/%v/%v/community/code_of_conduct", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -476,7 +485,7 @@ func (s *RepositoriesService) GetByID(ctx context.Context, id int64) (*Repositor
// Edit updates a repository. // Edit updates a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#update-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#update-a-repository
func (s *RepositoriesService) Edit(ctx context.Context, owner, repo string, repository *Repository) (*Repository, *Response, error) { func (s *RepositoriesService) Edit(ctx context.Context, owner, repo string, repository *Repository) (*Repository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v", owner, repo) u := fmt.Sprintf("repos/%v/%v", owner, repo)
req, err := s.client.NewRequest("PATCH", u, repository) req, err := s.client.NewRequest("PATCH", u, repository)
@ -497,7 +506,7 @@ func (s *RepositoriesService) Edit(ctx context.Context, owner, repo string, repo
// Delete a repository. // Delete a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#delete-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#delete-a-repository
func (s *RepositoriesService) Delete(ctx context.Context, owner, repo string) (*Response, error) { func (s *RepositoriesService) Delete(ctx context.Context, owner, repo string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v", owner, repo) u := fmt.Sprintf("repos/%v/%v", owner, repo)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -529,6 +538,8 @@ type Contributor struct {
Type *string `json:"type,omitempty"` Type *string `json:"type,omitempty"`
SiteAdmin *bool `json:"site_admin,omitempty"` SiteAdmin *bool `json:"site_admin,omitempty"`
Contributions *int `json:"contributions,omitempty"` Contributions *int `json:"contributions,omitempty"`
Name *string `json:"name,omitempty"`
Email *string `json:"email,omitempty"`
} }
// ListContributorsOptions specifies the optional parameters to the // ListContributorsOptions specifies the optional parameters to the
@ -542,7 +553,7 @@ type ListContributorsOptions struct {
// GetVulnerabilityAlerts checks if vulnerability alerts are enabled for a repository. // GetVulnerabilityAlerts checks if vulnerability alerts are enabled for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#check-if-vulnerability-alerts-are-enabled-for-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#check-if-vulnerability-alerts-are-enabled-for-a-repository
func (s *RepositoriesService) GetVulnerabilityAlerts(ctx context.Context, owner, repository string) (bool, *Response, error) { func (s *RepositoriesService) GetVulnerabilityAlerts(ctx context.Context, owner, repository string) (bool, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/vulnerability-alerts", owner, repository) u := fmt.Sprintf("repos/%v/%v/vulnerability-alerts", owner, repository)
@ -562,7 +573,7 @@ func (s *RepositoriesService) GetVulnerabilityAlerts(ctx context.Context, owner,
// EnableVulnerabilityAlerts enables vulnerability alerts and the dependency graph for a repository. // EnableVulnerabilityAlerts enables vulnerability alerts and the dependency graph for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#enable-vulnerability-alerts // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#enable-vulnerability-alerts
func (s *RepositoriesService) EnableVulnerabilityAlerts(ctx context.Context, owner, repository string) (*Response, error) { func (s *RepositoriesService) EnableVulnerabilityAlerts(ctx context.Context, owner, repository string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/vulnerability-alerts", owner, repository) u := fmt.Sprintf("repos/%v/%v/vulnerability-alerts", owner, repository)
@ -579,7 +590,7 @@ func (s *RepositoriesService) EnableVulnerabilityAlerts(ctx context.Context, own
// DisableVulnerabilityAlerts disables vulnerability alerts and the dependency graph for a repository. // DisableVulnerabilityAlerts disables vulnerability alerts and the dependency graph for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#disable-vulnerability-alerts // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#disable-vulnerability-alerts
func (s *RepositoriesService) DisableVulnerabilityAlerts(ctx context.Context, owner, repository string) (*Response, error) { func (s *RepositoriesService) DisableVulnerabilityAlerts(ctx context.Context, owner, repository string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/vulnerability-alerts", owner, repository) u := fmt.Sprintf("repos/%v/%v/vulnerability-alerts", owner, repository)
@ -596,7 +607,7 @@ func (s *RepositoriesService) DisableVulnerabilityAlerts(ctx context.Context, ow
// EnableAutomatedSecurityFixes enables the automated security fixes for a repository. // EnableAutomatedSecurityFixes enables the automated security fixes for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#enable-automated-security-fixes // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#enable-automated-security-fixes
func (s *RepositoriesService) EnableAutomatedSecurityFixes(ctx context.Context, owner, repository string) (*Response, error) { func (s *RepositoriesService) EnableAutomatedSecurityFixes(ctx context.Context, owner, repository string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/automated-security-fixes", owner, repository) u := fmt.Sprintf("repos/%v/%v/automated-security-fixes", owner, repository)
@ -613,7 +624,7 @@ func (s *RepositoriesService) EnableAutomatedSecurityFixes(ctx context.Context,
// DisableAutomatedSecurityFixes disables vulnerability alerts and the dependency graph for a repository. // DisableAutomatedSecurityFixes disables vulnerability alerts and the dependency graph for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#disable-automated-security-fixes // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#disable-automated-security-fixes
func (s *RepositoriesService) DisableAutomatedSecurityFixes(ctx context.Context, owner, repository string) (*Response, error) { func (s *RepositoriesService) DisableAutomatedSecurityFixes(ctx context.Context, owner, repository string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/automated-security-fixes", owner, repository) u := fmt.Sprintf("repos/%v/%v/automated-security-fixes", owner, repository)
@ -630,7 +641,7 @@ func (s *RepositoriesService) DisableAutomatedSecurityFixes(ctx context.Context,
// ListContributors lists contributors for a repository. // ListContributors lists contributors for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#list-repository-contributors // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-repository-contributors
func (s *RepositoriesService) ListContributors(ctx context.Context, owner string, repository string, opts *ListContributorsOptions) ([]*Contributor, *Response, error) { func (s *RepositoriesService) ListContributors(ctx context.Context, owner string, repository string, opts *ListContributorsOptions) ([]*Contributor, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/contributors", owner, repository) u := fmt.Sprintf("repos/%v/%v/contributors", owner, repository)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -646,7 +657,7 @@ func (s *RepositoriesService) ListContributors(ctx context.Context, owner string
var contributor []*Contributor var contributor []*Contributor
resp, err := s.client.Do(ctx, req, &contributor) resp, err := s.client.Do(ctx, req, &contributor)
if err != nil { if err != nil {
return nil, nil, err return nil, resp, err
} }
return contributor, resp, nil return contributor, resp, nil
@ -661,7 +672,7 @@ func (s *RepositoriesService) ListContributors(ctx context.Context, owner string
// "Python": 7769 // "Python": 7769
// } // }
// //
// GitHub API docs: https://developer.github.com/v3/repos/#list-repository-languages // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-repository-languages
func (s *RepositoriesService) ListLanguages(ctx context.Context, owner string, repo string) (map[string]int, *Response, error) { func (s *RepositoriesService) ListLanguages(ctx context.Context, owner string, repo string) (map[string]int, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/languages", owner, repo) u := fmt.Sprintf("repos/%v/%v/languages", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -680,7 +691,7 @@ func (s *RepositoriesService) ListLanguages(ctx context.Context, owner string, r
// ListTeams lists the teams for the specified repository. // ListTeams lists the teams for the specified repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#list-repository-teams // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-repository-teams
func (s *RepositoriesService) ListTeams(ctx context.Context, owner string, repo string, opts *ListOptions) ([]*Team, *Response, error) { func (s *RepositoriesService) ListTeams(ctx context.Context, owner string, repo string, opts *ListOptions) ([]*Team, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/teams", owner, repo) u := fmt.Sprintf("repos/%v/%v/teams", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -712,7 +723,7 @@ type RepositoryTag struct {
// ListTags lists tags for the specified repository. // ListTags lists tags for the specified repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#list-repository-tags // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-repository-tags
func (s *RepositoriesService) ListTags(ctx context.Context, owner string, repo string, opts *ListOptions) ([]*RepositoryTag, *Response, error) { func (s *RepositoriesService) ListTags(ctx context.Context, owner string, repo string, opts *ListOptions) ([]*RepositoryTag, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/tags", owner, repo) u := fmt.Sprintf("repos/%v/%v/tags", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -743,13 +754,14 @@ type Branch struct {
// Protection represents a repository branch's protection. // Protection represents a repository branch's protection.
type Protection struct { type Protection struct {
RequiredStatusChecks *RequiredStatusChecks `json:"required_status_checks"` RequiredStatusChecks *RequiredStatusChecks `json:"required_status_checks"`
RequiredPullRequestReviews *PullRequestReviewsEnforcement `json:"required_pull_request_reviews"` RequiredPullRequestReviews *PullRequestReviewsEnforcement `json:"required_pull_request_reviews"`
EnforceAdmins *AdminEnforcement `json:"enforce_admins"` EnforceAdmins *AdminEnforcement `json:"enforce_admins"`
Restrictions *BranchRestrictions `json:"restrictions"` Restrictions *BranchRestrictions `json:"restrictions"`
RequireLinearHistory *RequireLinearHistory `json:"required_linear_history"` RequireLinearHistory *RequireLinearHistory `json:"required_linear_history"`
AllowForcePushes *AllowForcePushes `json:"allow_force_pushes"` AllowForcePushes *AllowForcePushes `json:"allow_force_pushes"`
AllowDeletions *AllowDeletions `json:"allow_deletions"` AllowDeletions *AllowDeletions `json:"allow_deletions"`
RequiredConversationResolution *RequiredConversationResolution `json:"required_conversation_resolution"`
} }
// ProtectionRequest represents a request to create/edit a branch's protection. // ProtectionRequest represents a request to create/edit a branch's protection.
@ -826,7 +838,7 @@ type PullRequestReviewsEnforcementUpdate struct {
RequiredApprovingReviewCount int `json:"required_approving_review_count"` RequiredApprovingReviewCount int `json:"required_approving_review_count"`
} }
// RequireLinearHistory represents the configuration to enfore branches with no merge commit. // RequireLinearHistory represents the configuration to enforce branches with no merge commit.
type RequireLinearHistory struct { type RequireLinearHistory struct {
Enabled bool `json:"enabled"` Enabled bool `json:"enabled"`
} }
@ -841,6 +853,11 @@ type AllowForcePushes struct {
Enabled bool `json:"enabled"` Enabled bool `json:"enabled"`
} }
// RequiredConversationResolution, if enabled, requires all comments on the pull request to be resolved before it can be merged to a protected branch.
type RequiredConversationResolution struct {
Enabled bool `json:"enabled"`
}
// AdminEnforcement represents the configuration to enforce required status checks for repository administrators. // AdminEnforcement represents the configuration to enforce required status checks for repository administrators.
type AdminEnforcement struct { type AdminEnforcement struct {
URL *string `json:"url,omitempty"` URL *string `json:"url,omitempty"`
@ -900,7 +917,7 @@ type SignaturesProtectedBranch struct {
// ListBranches lists branches for the specified repository. // ListBranches lists branches for the specified repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#list-branches // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-branches
func (s *RepositoriesService) ListBranches(ctx context.Context, owner string, repo string, opts *BranchListOptions) ([]*Branch, *Response, error) { func (s *RepositoriesService) ListBranches(ctx context.Context, owner string, repo string, opts *BranchListOptions) ([]*Branch, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches", owner, repo) u := fmt.Sprintf("repos/%v/%v/branches", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -913,9 +930,6 @@ func (s *RepositoriesService) ListBranches(ctx context.Context, owner string, re
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept header when this API fully launches
req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
var branches []*Branch var branches []*Branch
resp, err := s.client.Do(ctx, req, &branches) resp, err := s.client.Do(ctx, req, &branches)
if err != nil { if err != nil {
@ -927,29 +941,55 @@ func (s *RepositoriesService) ListBranches(ctx context.Context, owner string, re
// GetBranch gets the specified branch for a repository. // GetBranch gets the specified branch for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#get-a-branch // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-a-branch
func (s *RepositoriesService) GetBranch(ctx context.Context, owner, repo, branch string) (*Branch, *Response, error) { func (s *RepositoriesService) GetBranch(ctx context.Context, owner, repo, branch string, followRedirects bool) (*Branch, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v", owner, repo, branch)
req, err := s.client.NewRequest("GET", u, nil)
resp, err := s.getBranchFromURL(ctx, u, followRedirects)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
defer resp.Body.Close()
// TODO: remove custom Accept header when this API fully launches if resp.StatusCode != http.StatusOK {
req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) return nil, newResponse(resp), fmt.Errorf("unexpected status code: %s", resp.Status)
b := new(Branch)
resp, err := s.client.Do(ctx, req, b)
if err != nil {
return nil, resp, err
} }
return b, resp, nil b := new(Branch)
err = json.NewDecoder(resp.Body).Decode(b)
return b, newResponse(resp), err
}
func (s *RepositoriesService) getBranchFromURL(ctx context.Context, u string, followRedirects bool) (*http.Response, error) {
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
var resp *http.Response
// Use http.DefaultTransport if no custom Transport is configured
req = withContext(ctx, req)
if s.client.client.Transport == nil {
resp, err = http.DefaultTransport.RoundTrip(req)
} else {
resp, err = s.client.client.Transport.RoundTrip(req)
}
if err != nil {
return nil, err
}
// If redirect response is returned, follow it
if followRedirects && resp.StatusCode == http.StatusMovedPermanently {
resp.Body.Close()
u = resp.Header.Get("Location")
resp, err = s.getBranchFromURL(ctx, u, false)
}
return resp, err
} }
// GetBranchProtection gets the protection of a given branch. // GetBranchProtection gets the protection of a given branch.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#get-branch-protection // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-branch-protection
func (s *RepositoriesService) GetBranchProtection(ctx context.Context, owner, repo, branch string) (*Protection, *Response, error) { func (s *RepositoriesService) GetBranchProtection(ctx context.Context, owner, repo, branch string) (*Protection, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection", owner, repo, branch)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -971,7 +1011,7 @@ func (s *RepositoriesService) GetBranchProtection(ctx context.Context, owner, re
// GetRequiredStatusChecks gets the required status checks for a given protected branch. // GetRequiredStatusChecks gets the required status checks for a given protected branch.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#get-status-checks-protection // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-status-checks-protection
func (s *RepositoriesService) GetRequiredStatusChecks(ctx context.Context, owner, repo, branch string) (*RequiredStatusChecks, *Response, error) { func (s *RepositoriesService) GetRequiredStatusChecks(ctx context.Context, owner, repo, branch string) (*RequiredStatusChecks, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_status_checks", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_status_checks", owner, repo, branch)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -979,9 +1019,6 @@ func (s *RepositoriesService) GetRequiredStatusChecks(ctx context.Context, owner
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept header when this API fully launches
req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
p := new(RequiredStatusChecks) p := new(RequiredStatusChecks)
resp, err := s.client.Do(ctx, req, p) resp, err := s.client.Do(ctx, req, p)
if err != nil { if err != nil {
@ -993,7 +1030,7 @@ func (s *RepositoriesService) GetRequiredStatusChecks(ctx context.Context, owner
// ListRequiredStatusChecksContexts lists the required status checks contexts for a given protected branch. // ListRequiredStatusChecksContexts lists the required status checks contexts for a given protected branch.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#get-all-status-check-contexts // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-all-status-check-contexts
func (s *RepositoriesService) ListRequiredStatusChecksContexts(ctx context.Context, owner, repo, branch string) (contexts []string, resp *Response, err error) { func (s *RepositoriesService) ListRequiredStatusChecksContexts(ctx context.Context, owner, repo, branch string) (contexts []string, resp *Response, err error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_status_checks/contexts", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_status_checks/contexts", owner, repo, branch)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -1001,9 +1038,6 @@ func (s *RepositoriesService) ListRequiredStatusChecksContexts(ctx context.Conte
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept header when this API fully launches
req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
resp, err = s.client.Do(ctx, req, &contexts) resp, err = s.client.Do(ctx, req, &contexts)
if err != nil { if err != nil {
return nil, resp, err return nil, resp, err
@ -1014,7 +1048,7 @@ func (s *RepositoriesService) ListRequiredStatusChecksContexts(ctx context.Conte
// UpdateBranchProtection updates the protection of a given branch. // UpdateBranchProtection updates the protection of a given branch.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#update-branch-protection // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#update-branch-protection
func (s *RepositoriesService) UpdateBranchProtection(ctx context.Context, owner, repo, branch string, preq *ProtectionRequest) (*Protection, *Response, error) { func (s *RepositoriesService) UpdateBranchProtection(ctx context.Context, owner, repo, branch string, preq *ProtectionRequest) (*Protection, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection", owner, repo, branch)
req, err := s.client.NewRequest("PUT", u, preq) req, err := s.client.NewRequest("PUT", u, preq)
@ -1036,7 +1070,7 @@ func (s *RepositoriesService) UpdateBranchProtection(ctx context.Context, owner,
// RemoveBranchProtection removes the protection of a given branch. // RemoveBranchProtection removes the protection of a given branch.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#delete-branch-protection // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#delete-branch-protection
func (s *RepositoriesService) RemoveBranchProtection(ctx context.Context, owner, repo, branch string) (*Response, error) { func (s *RepositoriesService) RemoveBranchProtection(ctx context.Context, owner, repo, branch string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection", owner, repo, branch)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -1044,15 +1078,12 @@ func (s *RepositoriesService) RemoveBranchProtection(ctx context.Context, owner,
return nil, err return nil, err
} }
// TODO: remove custom Accept header when this API fully launches
req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
return s.client.Do(ctx, req, nil) return s.client.Do(ctx, req, nil)
} }
// GetSignaturesProtectedBranch gets required signatures of protected branch. // GetSignaturesProtectedBranch gets required signatures of protected branch.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#get-commit-signature-protection // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-commit-signature-protection
func (s *RepositoriesService) GetSignaturesProtectedBranch(ctx context.Context, owner, repo, branch string) (*SignaturesProtectedBranch, *Response, error) { func (s *RepositoriesService) GetSignaturesProtectedBranch(ctx context.Context, owner, repo, branch string) (*SignaturesProtectedBranch, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_signatures", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_signatures", owner, repo, branch)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -1075,7 +1106,7 @@ func (s *RepositoriesService) GetSignaturesProtectedBranch(ctx context.Context,
// RequireSignaturesOnProtectedBranch makes signed commits required on a protected branch. // RequireSignaturesOnProtectedBranch makes signed commits required on a protected branch.
// It requires admin access and branch protection to be enabled. // It requires admin access and branch protection to be enabled.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#create-commit-signature-protection // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#create-commit-signature-protection
func (s *RepositoriesService) RequireSignaturesOnProtectedBranch(ctx context.Context, owner, repo, branch string) (*SignaturesProtectedBranch, *Response, error) { func (s *RepositoriesService) RequireSignaturesOnProtectedBranch(ctx context.Context, owner, repo, branch string) (*SignaturesProtectedBranch, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_signatures", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_signatures", owner, repo, branch)
req, err := s.client.NewRequest("POST", u, nil) req, err := s.client.NewRequest("POST", u, nil)
@ -1097,7 +1128,7 @@ func (s *RepositoriesService) RequireSignaturesOnProtectedBranch(ctx context.Con
// OptionalSignaturesOnProtectedBranch removes required signed commits on a given branch. // OptionalSignaturesOnProtectedBranch removes required signed commits on a given branch.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#delete-commit-signature-protection // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#delete-commit-signature-protection
func (s *RepositoriesService) OptionalSignaturesOnProtectedBranch(ctx context.Context, owner, repo, branch string) (*Response, error) { func (s *RepositoriesService) OptionalSignaturesOnProtectedBranch(ctx context.Context, owner, repo, branch string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_signatures", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_signatures", owner, repo, branch)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -1113,7 +1144,7 @@ func (s *RepositoriesService) OptionalSignaturesOnProtectedBranch(ctx context.Co
// UpdateRequiredStatusChecks updates the required status checks for a given protected branch. // UpdateRequiredStatusChecks updates the required status checks for a given protected branch.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#update-status-check-potection // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#update-status-check-protection
func (s *RepositoriesService) UpdateRequiredStatusChecks(ctx context.Context, owner, repo, branch string, sreq *RequiredStatusChecksRequest) (*RequiredStatusChecks, *Response, error) { func (s *RepositoriesService) UpdateRequiredStatusChecks(ctx context.Context, owner, repo, branch string, sreq *RequiredStatusChecksRequest) (*RequiredStatusChecks, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_status_checks", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_status_checks", owner, repo, branch)
req, err := s.client.NewRequest("PATCH", u, sreq) req, err := s.client.NewRequest("PATCH", u, sreq)
@ -1130,9 +1161,22 @@ func (s *RepositoriesService) UpdateRequiredStatusChecks(ctx context.Context, ow
return sc, resp, nil return sc, resp, nil
} }
// RemoveRequiredStatusChecks removes the required status checks for a given protected branch.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#remove-status-check-protection
func (s *RepositoriesService) RemoveRequiredStatusChecks(ctx context.Context, owner, repo, branch string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_status_checks", owner, repo, branch)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// License gets the contents of a repository's license if one is detected. // License gets the contents of a repository's license if one is detected.
// //
// GitHub API docs: https://developer.github.com/v3/licenses/#get-the-license-for-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/licenses/#get-the-license-for-a-repository
func (s *RepositoriesService) License(ctx context.Context, owner, repo string) (*RepositoryLicense, *Response, error) { func (s *RepositoriesService) License(ctx context.Context, owner, repo string) (*RepositoryLicense, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/license", owner, repo) u := fmt.Sprintf("repos/%v/%v/license", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -1151,7 +1195,7 @@ func (s *RepositoriesService) License(ctx context.Context, owner, repo string) (
// GetPullRequestReviewEnforcement gets pull request review enforcement of a protected branch. // GetPullRequestReviewEnforcement gets pull request review enforcement of a protected branch.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#get-pull-request-review-protection // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-pull-request-review-protection
func (s *RepositoriesService) GetPullRequestReviewEnforcement(ctx context.Context, owner, repo, branch string) (*PullRequestReviewsEnforcement, *Response, error) { func (s *RepositoriesService) GetPullRequestReviewEnforcement(ctx context.Context, owner, repo, branch string) (*PullRequestReviewsEnforcement, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_pull_request_reviews", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_pull_request_reviews", owner, repo, branch)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -1174,7 +1218,7 @@ func (s *RepositoriesService) GetPullRequestReviewEnforcement(ctx context.Contex
// UpdatePullRequestReviewEnforcement patches pull request review enforcement of a protected branch. // UpdatePullRequestReviewEnforcement patches pull request review enforcement of a protected branch.
// It requires admin access and branch protection to be enabled. // It requires admin access and branch protection to be enabled.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#update-pull-request-review-protection // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#update-pull-request-review-protection
func (s *RepositoriesService) UpdatePullRequestReviewEnforcement(ctx context.Context, owner, repo, branch string, patch *PullRequestReviewsEnforcementUpdate) (*PullRequestReviewsEnforcement, *Response, error) { func (s *RepositoriesService) UpdatePullRequestReviewEnforcement(ctx context.Context, owner, repo, branch string, patch *PullRequestReviewsEnforcementUpdate) (*PullRequestReviewsEnforcement, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_pull_request_reviews", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_pull_request_reviews", owner, repo, branch)
req, err := s.client.NewRequest("PATCH", u, patch) req, err := s.client.NewRequest("PATCH", u, patch)
@ -1197,7 +1241,7 @@ func (s *RepositoriesService) UpdatePullRequestReviewEnforcement(ctx context.Con
// DisableDismissalRestrictions disables dismissal restrictions of a protected branch. // DisableDismissalRestrictions disables dismissal restrictions of a protected branch.
// It requires admin access and branch protection to be enabled. // It requires admin access and branch protection to be enabled.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#update-pull-request-review-protection // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#update-pull-request-review-protection
func (s *RepositoriesService) DisableDismissalRestrictions(ctx context.Context, owner, repo, branch string) (*PullRequestReviewsEnforcement, *Response, error) { func (s *RepositoriesService) DisableDismissalRestrictions(ctx context.Context, owner, repo, branch string) (*PullRequestReviewsEnforcement, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_pull_request_reviews", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_pull_request_reviews", owner, repo, branch)
@ -1224,7 +1268,7 @@ func (s *RepositoriesService) DisableDismissalRestrictions(ctx context.Context,
// RemovePullRequestReviewEnforcement removes pull request enforcement of a protected branch. // RemovePullRequestReviewEnforcement removes pull request enforcement of a protected branch.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#delete-pull-request-review-protection // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#delete-pull-request-review-protection
func (s *RepositoriesService) RemovePullRequestReviewEnforcement(ctx context.Context, owner, repo, branch string) (*Response, error) { func (s *RepositoriesService) RemovePullRequestReviewEnforcement(ctx context.Context, owner, repo, branch string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_pull_request_reviews", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_pull_request_reviews", owner, repo, branch)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -1232,15 +1276,12 @@ func (s *RepositoriesService) RemovePullRequestReviewEnforcement(ctx context.Con
return nil, err return nil, err
} }
// TODO: remove custom Accept header when this API fully launches
req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
return s.client.Do(ctx, req, nil) return s.client.Do(ctx, req, nil)
} }
// GetAdminEnforcement gets admin enforcement information of a protected branch. // GetAdminEnforcement gets admin enforcement information of a protected branch.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#get-admin-branch-protection // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-admin-branch-protection
func (s *RepositoriesService) GetAdminEnforcement(ctx context.Context, owner, repo, branch string) (*AdminEnforcement, *Response, error) { func (s *RepositoriesService) GetAdminEnforcement(ctx context.Context, owner, repo, branch string) (*AdminEnforcement, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/enforce_admins", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/enforce_admins", owner, repo, branch)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -1248,9 +1289,6 @@ func (s *RepositoriesService) GetAdminEnforcement(ctx context.Context, owner, re
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept header when this API fully launches
req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
r := new(AdminEnforcement) r := new(AdminEnforcement)
resp, err := s.client.Do(ctx, req, r) resp, err := s.client.Do(ctx, req, r)
if err != nil { if err != nil {
@ -1263,7 +1301,7 @@ func (s *RepositoriesService) GetAdminEnforcement(ctx context.Context, owner, re
// AddAdminEnforcement adds admin enforcement to a protected branch. // AddAdminEnforcement adds admin enforcement to a protected branch.
// It requires admin access and branch protection to be enabled. // It requires admin access and branch protection to be enabled.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#set-admin-branch-protection // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#set-admin-branch-protection
func (s *RepositoriesService) AddAdminEnforcement(ctx context.Context, owner, repo, branch string) (*AdminEnforcement, *Response, error) { func (s *RepositoriesService) AddAdminEnforcement(ctx context.Context, owner, repo, branch string) (*AdminEnforcement, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/enforce_admins", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/enforce_admins", owner, repo, branch)
req, err := s.client.NewRequest("POST", u, nil) req, err := s.client.NewRequest("POST", u, nil)
@ -1271,9 +1309,6 @@ func (s *RepositoriesService) AddAdminEnforcement(ctx context.Context, owner, re
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept header when this API fully launches
req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
r := new(AdminEnforcement) r := new(AdminEnforcement)
resp, err := s.client.Do(ctx, req, r) resp, err := s.client.Do(ctx, req, r)
if err != nil { if err != nil {
@ -1285,7 +1320,7 @@ func (s *RepositoriesService) AddAdminEnforcement(ctx context.Context, owner, re
// RemoveAdminEnforcement removes admin enforcement from a protected branch. // RemoveAdminEnforcement removes admin enforcement from a protected branch.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#delete-admin-branch-protection // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#delete-admin-branch-protection
func (s *RepositoriesService) RemoveAdminEnforcement(ctx context.Context, owner, repo, branch string) (*Response, error) { func (s *RepositoriesService) RemoveAdminEnforcement(ctx context.Context, owner, repo, branch string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/enforce_admins", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/enforce_admins", owner, repo, branch)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -1293,9 +1328,6 @@ func (s *RepositoriesService) RemoveAdminEnforcement(ctx context.Context, owner,
return nil, err return nil, err
} }
// TODO: remove custom Accept header when this API fully launches
req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
return s.client.Do(ctx, req, nil) return s.client.Do(ctx, req, nil)
} }
@ -1306,7 +1338,7 @@ type repositoryTopics struct {
// ListAllTopics lists topics for a repository. // ListAllTopics lists topics for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#get-all-repository-topics // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-all-repository-topics
func (s *RepositoriesService) ListAllTopics(ctx context.Context, owner, repo string) ([]string, *Response, error) { func (s *RepositoriesService) ListAllTopics(ctx context.Context, owner, repo string) ([]string, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/topics", owner, repo) u := fmt.Sprintf("repos/%v/%v/topics", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -1328,7 +1360,7 @@ func (s *RepositoriesService) ListAllTopics(ctx context.Context, owner, repo str
// ReplaceAllTopics replaces topics for a repository. // ReplaceAllTopics replaces topics for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#replace-all-repository-topics // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#replace-all-repository-topics
func (s *RepositoriesService) ReplaceAllTopics(ctx context.Context, owner, repo string, topics []string) ([]string, *Response, error) { func (s *RepositoriesService) ReplaceAllTopics(ctx context.Context, owner, repo string, topics []string) ([]string, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/topics", owner, repo) u := fmt.Sprintf("repos/%v/%v/topics", owner, repo)
t := &repositoryTopics{ t := &repositoryTopics{
@ -1354,10 +1386,10 @@ func (s *RepositoriesService) ReplaceAllTopics(ctx context.Context, owner, repo
return t.Names, resp, nil return t.Names, resp, nil
} }
// ListApps lists the Github apps that have push access to a given protected branch. // ListApps lists the GitHub apps that have push access to a given protected branch.
// It requires the Github apps to have `write` access to the `content` permission. // It requires the GitHub apps to have `write` access to the `content` permission.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#list-apps-with-access-to-the-protected-branch // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-apps-with-access-to-the-protected-branch
func (s *RepositoriesService) ListApps(ctx context.Context, owner, repo, branch string) ([]*App, *Response, error) { func (s *RepositoriesService) ListApps(ctx context.Context, owner, repo, branch string) ([]*App, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, branch)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -1376,11 +1408,11 @@ func (s *RepositoriesService) ListApps(ctx context.Context, owner, repo, branch
// ReplaceAppRestrictions replaces the apps that have push access to a given protected branch. // ReplaceAppRestrictions replaces the apps that have push access to a given protected branch.
// It removes all apps that previously had push access and grants push access to the new list of apps. // It removes all apps that previously had push access and grants push access to the new list of apps.
// It requires the Github apps to have `write` access to the `content` permission. // It requires the GitHub apps to have `write` access to the `content` permission.
// //
// Note: The list of users, apps, and teams in total is limited to 100 items. // Note: The list of users, apps, and teams in total is limited to 100 items.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#set-app-access-restrictions // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#set-app-access-restrictions
func (s *RepositoriesService) ReplaceAppRestrictions(ctx context.Context, owner, repo, branch string, slug []string) ([]*App, *Response, error) { func (s *RepositoriesService) ReplaceAppRestrictions(ctx context.Context, owner, repo, branch string, slug []string) ([]*App, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, branch)
req, err := s.client.NewRequest("PUT", u, slug) req, err := s.client.NewRequest("PUT", u, slug)
@ -1391,18 +1423,18 @@ func (s *RepositoriesService) ReplaceAppRestrictions(ctx context.Context, owner,
var apps []*App var apps []*App
resp, err := s.client.Do(ctx, req, &apps) resp, err := s.client.Do(ctx, req, &apps)
if err != nil { if err != nil {
return nil, nil, err return nil, resp, err
} }
return apps, resp, nil return apps, resp, nil
} }
// AddAppRestrictions grants the specified apps push access to a given protected branch. // AddAppRestrictions grants the specified apps push access to a given protected branch.
// It requires the Github apps to have `write` access to the `content` permission. // It requires the GitHub apps to have `write` access to the `content` permission.
// //
// Note: The list of users, apps, and teams in total is limited to 100 items. // Note: The list of users, apps, and teams in total is limited to 100 items.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#add-app-access-restrictions // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#add-app-access-restrictions
func (s *RepositoriesService) AddAppRestrictions(ctx context.Context, owner, repo, branch string, slug []string) ([]*App, *Response, error) { func (s *RepositoriesService) AddAppRestrictions(ctx context.Context, owner, repo, branch string, slug []string) ([]*App, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, branch)
req, err := s.client.NewRequest("POST", u, slug) req, err := s.client.NewRequest("POST", u, slug)
@ -1413,18 +1445,18 @@ func (s *RepositoriesService) AddAppRestrictions(ctx context.Context, owner, rep
var apps []*App var apps []*App
resp, err := s.client.Do(ctx, req, &apps) resp, err := s.client.Do(ctx, req, &apps)
if err != nil { if err != nil {
return nil, nil, err return nil, resp, err
} }
return apps, resp, nil return apps, resp, nil
} }
// RemoveAppRestrictions removes the ability of an app to push to this branch. // RemoveAppRestrictions removes the ability of an app to push to this branch.
// It requires the Github apps to have `write` access to the `content` permission. // It requires the GitHub apps to have `write` access to the `content` permission.
// //
// Note: The list of users, apps, and teams in total is limited to 100 items. // Note: The list of users, apps, and teams in total is limited to 100 items.
// //
// GitHub API docs: https://developer.github.com/v3/repos/branches/#remove-app-access-restrictions // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#remove-app-access-restrictions
func (s *RepositoriesService) RemoveAppRestrictions(ctx context.Context, owner, repo, branch string, slug []string) ([]*App, *Response, error) { func (s *RepositoriesService) RemoveAppRestrictions(ctx context.Context, owner, repo, branch string, slug []string) ([]*App, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, branch) u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, branch)
req, err := s.client.NewRequest("DELETE", u, slug) req, err := s.client.NewRequest("DELETE", u, slug)
@ -1435,7 +1467,7 @@ func (s *RepositoriesService) RemoveAppRestrictions(ctx context.Context, owner,
var apps []*App var apps []*App
resp, err := s.client.Do(ctx, req, &apps) resp, err := s.client.Do(ctx, req, &apps)
if err != nil { if err != nil {
return nil, nil, err return nil, resp, err
} }
return apps, resp, nil return apps, resp, nil
@ -1455,7 +1487,7 @@ type TransferRequest struct {
// A follow up request, after a delay of a second or so, should result // A follow up request, after a delay of a second or so, should result
// in a successful request. // in a successful request.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#transfer-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#transfer-a-repository
func (s *RepositoriesService) Transfer(ctx context.Context, owner, repo string, transfer TransferRequest) (*Repository, *Response, error) { func (s *RepositoriesService) Transfer(ctx context.Context, owner, repo string, transfer TransferRequest) (*Repository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/transfer", owner, repo) u := fmt.Sprintf("repos/%v/%v/transfer", owner, repo)
@ -1484,7 +1516,7 @@ type DispatchRequestOptions struct {
// Dispatch triggers a repository_dispatch event in a GitHub Actions workflow. // Dispatch triggers a repository_dispatch event in a GitHub Actions workflow.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#create-a-repository-dispatch-event // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#create-a-repository-dispatch-event
func (s *RepositoriesService) Dispatch(ctx context.Context, owner, repo string, opts DispatchRequestOptions) (*Repository, *Response, error) { func (s *RepositoriesService) Dispatch(ctx context.Context, owner, repo string, opts DispatchRequestOptions) (*Repository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/dispatches", owner, repo) u := fmt.Sprintf("repos/%v/%v/dispatches", owner, repo)

View file

@ -27,7 +27,7 @@ type ListCollaboratorsOptions struct {
} }
// CollaboratorInvitation represents an invitation created when adding a collaborator. // CollaboratorInvitation represents an invitation created when adding a collaborator.
// GitHub API docs: https://developer.github.com/v3/repos/collaborators/#response-when-a-new-invitation-is-created // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/collaborators/#response-when-a-new-invitation-is-created
type CollaboratorInvitation struct { type CollaboratorInvitation struct {
ID *int64 `json:"id,omitempty"` ID *int64 `json:"id,omitempty"`
Repo *Repository `json:"repository,omitempty"` Repo *Repository `json:"repository,omitempty"`
@ -41,7 +41,7 @@ type CollaboratorInvitation struct {
// ListCollaborators lists the GitHub users that have access to the repository. // ListCollaborators lists the GitHub users that have access to the repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/collaborators/#list-repository-collaborators // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-repository-collaborators
func (s *RepositoriesService) ListCollaborators(ctx context.Context, owner, repo string, opts *ListCollaboratorsOptions) ([]*User, *Response, error) { func (s *RepositoriesService) ListCollaborators(ctx context.Context, owner, repo string, opts *ListCollaboratorsOptions) ([]*User, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/collaborators", owner, repo) u := fmt.Sprintf("repos/%v/%v/collaborators", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -68,7 +68,7 @@ func (s *RepositoriesService) ListCollaborators(ctx context.Context, owner, repo
// Note: This will return false if the user is not a collaborator OR the user // Note: This will return false if the user is not a collaborator OR the user
// is not a GitHub user. // is not a GitHub user.
// //
// GitHub API docs: https://developer.github.com/v3/repos/collaborators/#check-if-a-user-is-a-repository-collaborator // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#check-if-a-user-is-a-repository-collaborator
func (s *RepositoriesService) IsCollaborator(ctx context.Context, owner, repo, user string) (bool, *Response, error) { func (s *RepositoriesService) IsCollaborator(ctx context.Context, owner, repo, user string) (bool, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/collaborators/%v", owner, repo, user) u := fmt.Sprintf("repos/%v/%v/collaborators/%v", owner, repo, user)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -91,7 +91,7 @@ type RepositoryPermissionLevel struct {
} }
// GetPermissionLevel retrieves the specific permission level a collaborator has for a given repository. // GetPermissionLevel retrieves the specific permission level a collaborator has for a given repository.
// GitHub API docs: https://developer.github.com/v3/repos/collaborators/#get-repository-permissions-for-a-user // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-repository-permissions-for-a-user
func (s *RepositoriesService) GetPermissionLevel(ctx context.Context, owner, repo, user string) (*RepositoryPermissionLevel, *Response, error) { func (s *RepositoriesService) GetPermissionLevel(ctx context.Context, owner, repo, user string) (*RepositoryPermissionLevel, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/collaborators/%v/permission", owner, repo, user) u := fmt.Sprintf("repos/%v/%v/collaborators/%v/permission", owner, repo, user)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -125,7 +125,7 @@ type RepositoryAddCollaboratorOptions struct {
// AddCollaborator sends an invitation to the specified GitHub user // AddCollaborator sends an invitation to the specified GitHub user
// to become a collaborator to the given repo. // to become a collaborator to the given repo.
// //
// GitHub API docs: https://developer.github.com/v3/repos/collaborators/#add-a-repository-collaborator // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#add-a-repository-collaborator
func (s *RepositoriesService) AddCollaborator(ctx context.Context, owner, repo, user string, opts *RepositoryAddCollaboratorOptions) (*CollaboratorInvitation, *Response, error) { func (s *RepositoriesService) AddCollaborator(ctx context.Context, owner, repo, user string, opts *RepositoryAddCollaboratorOptions) (*CollaboratorInvitation, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/collaborators/%v", owner, repo, user) u := fmt.Sprintf("repos/%v/%v/collaborators/%v", owner, repo, user)
req, err := s.client.NewRequest("PUT", u, opts) req, err := s.client.NewRequest("PUT", u, opts)
@ -143,7 +143,7 @@ func (s *RepositoriesService) AddCollaborator(ctx context.Context, owner, repo,
// RemoveCollaborator removes the specified GitHub user as collaborator from the given repo. // RemoveCollaborator removes the specified GitHub user as collaborator from the given repo.
// Note: Does not return error if a valid user that is not a collaborator is removed. // Note: Does not return error if a valid user that is not a collaborator is removed.
// //
// GitHub API docs: https://developer.github.com/v3/repos/collaborators/#remove-a-repository-collaborator // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#remove-a-repository-collaborator
func (s *RepositoriesService) RemoveCollaborator(ctx context.Context, owner, repo, user string) (*Response, error) { func (s *RepositoriesService) RemoveCollaborator(ctx context.Context, owner, repo, user string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/collaborators/%v", owner, repo, user) u := fmt.Sprintf("repos/%v/%v/collaborators/%v", owner, repo, user)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)

View file

@ -36,7 +36,7 @@ func (r RepositoryComment) String() string {
// ListComments lists all the comments for the repository. // ListComments lists all the comments for the repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-commit-comments-for-a-repository
func (s *RepositoriesService) ListComments(ctx context.Context, owner, repo string, opts *ListOptions) ([]*RepositoryComment, *Response, error) { func (s *RepositoriesService) ListComments(ctx context.Context, owner, repo string, opts *ListOptions) ([]*RepositoryComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments", owner, repo) u := fmt.Sprintf("repos/%v/%v/comments", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -63,7 +63,7 @@ func (s *RepositoriesService) ListComments(ctx context.Context, owner, repo stri
// ListCommitComments lists all the comments for a given commit SHA. // ListCommitComments lists all the comments for a given commit SHA.
// //
// GitHub API docs: https://developer.github.com/v3/repos/comments/#list-commit-comments // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-commit-comments
func (s *RepositoriesService) ListCommitComments(ctx context.Context, owner, repo, sha string, opts *ListOptions) ([]*RepositoryComment, *Response, error) { func (s *RepositoriesService) ListCommitComments(ctx context.Context, owner, repo, sha string, opts *ListOptions) ([]*RepositoryComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v/comments", owner, repo, sha) u := fmt.Sprintf("repos/%v/%v/commits/%v/comments", owner, repo, sha)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -91,7 +91,7 @@ func (s *RepositoriesService) ListCommitComments(ctx context.Context, owner, rep
// CreateComment creates a comment for the given commit. // CreateComment creates a comment for the given commit.
// Note: GitHub allows for comments to be created for non-existing files and positions. // Note: GitHub allows for comments to be created for non-existing files and positions.
// //
// GitHub API docs: https://developer.github.com/v3/repos/comments/#create-a-commit-comment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#create-a-commit-comment
func (s *RepositoriesService) CreateComment(ctx context.Context, owner, repo, sha string, comment *RepositoryComment) (*RepositoryComment, *Response, error) { func (s *RepositoriesService) CreateComment(ctx context.Context, owner, repo, sha string, comment *RepositoryComment) (*RepositoryComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v/comments", owner, repo, sha) u := fmt.Sprintf("repos/%v/%v/commits/%v/comments", owner, repo, sha)
req, err := s.client.NewRequest("POST", u, comment) req, err := s.client.NewRequest("POST", u, comment)
@ -110,7 +110,7 @@ func (s *RepositoriesService) CreateComment(ctx context.Context, owner, repo, sh
// GetComment gets a single comment from a repository. // GetComment gets a single comment from a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/comments/#get-a-commit-comment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-a-commit-comment
func (s *RepositoriesService) GetComment(ctx context.Context, owner, repo string, id int64) (*RepositoryComment, *Response, error) { func (s *RepositoriesService) GetComment(ctx context.Context, owner, repo string, id int64) (*RepositoryComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -132,7 +132,7 @@ func (s *RepositoriesService) GetComment(ctx context.Context, owner, repo string
// UpdateComment updates the body of a single comment. // UpdateComment updates the body of a single comment.
// //
// GitHub API docs: https://developer.github.com/v3/repos/comments/#update-a-commit-comment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#update-a-commit-comment
func (s *RepositoriesService) UpdateComment(ctx context.Context, owner, repo string, id int64, comment *RepositoryComment) (*RepositoryComment, *Response, error) { func (s *RepositoriesService) UpdateComment(ctx context.Context, owner, repo string, id int64, comment *RepositoryComment) (*RepositoryComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id)
req, err := s.client.NewRequest("PATCH", u, comment) req, err := s.client.NewRequest("PATCH", u, comment)
@ -151,7 +151,7 @@ func (s *RepositoriesService) UpdateComment(ctx context.Context, owner, repo str
// DeleteComment deletes a single comment from a repository. // DeleteComment deletes a single comment from a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/comments/#delete-a-commit-comment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#delete-a-commit-comment
func (s *RepositoriesService) DeleteComment(ctx context.Context, owner, repo string, id int64) (*Response, error) { func (s *RepositoriesService) DeleteComment(ctx context.Context, owner, repo string, id int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)

View file

@ -9,6 +9,7 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"net/url"
"time" "time"
) )
@ -123,7 +124,7 @@ type BranchCommit struct {
// ListCommits lists the commits of a repository. // ListCommits lists the commits of a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/commits/#list-commits // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-commits
func (s *RepositoriesService) ListCommits(ctx context.Context, owner, repo string, opts *CommitsListOptions) ([]*RepositoryCommit, *Response, error) { func (s *RepositoriesService) ListCommits(ctx context.Context, owner, repo string, opts *CommitsListOptions) ([]*RepositoryCommit, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits", owner, repo) u := fmt.Sprintf("repos/%v/%v/commits", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -147,8 +148,8 @@ func (s *RepositoriesService) ListCommits(ctx context.Context, owner, repo strin
// GetCommit fetches the specified commit, including all details about it. // GetCommit fetches the specified commit, including all details about it.
// //
// GitHub API docs: https://developer.github.com/v3/repos/commits/#get-a-single-commit // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-a-single-commit
// GitHub API docs: https://developer.github.com/v3/repos/commits/#get-a-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) (*RepositoryCommit, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v", owner, repo, sha) u := fmt.Sprintf("repos/%v/%v/commits/%v", owner, repo, sha)
@ -168,7 +169,7 @@ func (s *RepositoriesService) GetCommit(ctx context.Context, owner, repo, sha st
// GetCommitRaw fetches the specified commit in raw (diff or patch) format. // GetCommitRaw fetches the specified commit in raw (diff or patch) format.
// //
// GitHub API docs: https://developer.github.com/v3/repos/commits/#get-a-commit // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-a-commit
func (s *RepositoriesService) GetCommitRaw(ctx context.Context, owner string, repo string, sha string, opts RawOptions) (string, *Response, error) { func (s *RepositoriesService) GetCommitRaw(ctx context.Context, owner string, repo string, sha string, opts RawOptions) (string, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v", owner, repo, sha) u := fmt.Sprintf("repos/%v/%v/commits/%v", owner, repo, sha)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -197,7 +198,7 @@ func (s *RepositoriesService) GetCommitRaw(ctx context.Context, owner string, re
// GetCommitSHA1 gets the SHA-1 of a commit reference. If a last-known SHA1 is // GetCommitSHA1 gets the SHA-1 of a commit reference. If a last-known SHA1 is
// supplied and no new commits have occurred, a 304 Unmodified response is returned. // supplied and no new commits have occurred, a 304 Unmodified response is returned.
// //
// GitHub API docs: https://developer.github.com/v3/repos/commits/#get-a-commit // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-a-commit
func (s *RepositoriesService) GetCommitSHA1(ctx context.Context, owner, repo, ref, lastSHA string) (string, *Response, error) { func (s *RepositoriesService) GetCommitSHA1(ctx context.Context, owner, repo, ref, lastSHA string) (string, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v", owner, repo, refURLEscape(ref)) u := fmt.Sprintf("repos/%v/%v/commits/%v", owner, repo, refURLEscape(ref))
@ -221,11 +222,13 @@ func (s *RepositoriesService) GetCommitSHA1(ctx context.Context, owner, repo, re
} }
// CompareCommits compares a range of commits with each other. // CompareCommits compares a range of commits with each other.
// todo: support media formats - https://github.com/google/go-github/issues/6
// //
// GitHub API docs: https://developer.github.com/v3/repos/commits/#compare-two-commits // 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) (*CommitsComparison, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/compare/%v...%v", owner, repo, base, head) escapedBase := url.QueryEscape(base)
escapedHead := url.QueryEscape(head)
u := fmt.Sprintf("repos/%v/%v/compare/%v...%v", owner, repo, escapedBase, escapedHead)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
@ -241,10 +244,46 @@ func (s *RepositoriesService) CompareCommits(ctx context.Context, owner, repo st
return comp, resp, nil return comp, resp, nil
} }
// CompareCommitsRaw compares a range of commits with each other in raw (diff or patch) format.
//
// Both "base" and "head" must be branch names in "repo".
// To compare branches across other repositories in the same network as "repo",
// use the format "<USERNAME>:branch".
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#compare-two-commits
func (s *RepositoriesService) CompareCommitsRaw(ctx context.Context, owner, repo, base, head string, opts RawOptions) (string, *Response, error) {
escapedBase := url.QueryEscape(base)
escapedHead := url.QueryEscape(head)
u := fmt.Sprintf("repos/%v/%v/compare/%v...%v", owner, repo, escapedBase, escapedHead)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return "", nil, err
}
switch opts.Type {
case Diff:
req.Header.Set("Accept", mediaTypeV3Diff)
case Patch:
req.Header.Set("Accept", mediaTypeV3Patch)
default:
return "", nil, fmt.Errorf("unsupported raw type %d", opts.Type)
}
var buf bytes.Buffer
resp, err := s.client.Do(ctx, req, &buf)
if err != nil {
return "", resp, err
}
return buf.String(), resp, nil
}
// ListBranchesHeadCommit gets all branches where the given commit SHA is the HEAD, // ListBranchesHeadCommit gets all branches where the given commit SHA is the HEAD,
// or latest commit for the branch. // or latest commit for the branch.
// //
// GitHub API docs: https://developer.github.com/v3/repos/commits/#list-branches-for-head-commit // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-branches-for-head-commit
func (s *RepositoriesService) ListBranchesHeadCommit(ctx context.Context, owner, repo, sha string) ([]*BranchCommit, *Response, error) { func (s *RepositoriesService) ListBranchesHeadCommit(ctx context.Context, owner, repo, sha string) ([]*BranchCommit, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v/branches-where-head", owner, repo, sha) u := fmt.Sprintf("repos/%v/%v/commits/%v/branches-where-head", owner, repo, sha)

View file

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

View file

@ -4,7 +4,7 @@
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Repository contents API methods. // Repository contents API methods.
// GitHub API docs: https://developer.github.com/v3/repos/contents/ // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/contents/
package github package github
@ -18,6 +18,7 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"path" "path"
"strings"
) )
// RepositoryContent represents a file or directory in a github repository. // RepositoryContent represents a file or directory in a github repository.
@ -94,7 +95,7 @@ func (r *RepositoryContent) GetContent() (string, error) {
// GetReadme gets the Readme file for the repository. // GetReadme gets the Readme file for the repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/contents/#get-a-repository-readme // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-a-repository-readme
func (s *RepositoriesService) GetReadme(ctx context.Context, owner, repo string, opts *RepositoryContentGetOptions) (*RepositoryContent, *Response, error) { func (s *RepositoriesService) GetReadme(ctx context.Context, owner, repo string, opts *RepositoryContentGetOptions) (*RepositoryContent, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/readme", owner, repo) u := fmt.Sprintf("repos/%v/%v/readme", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -117,26 +118,60 @@ func (s *RepositoriesService) GetReadme(ctx context.Context, owner, repo string,
// specified file. This function will work with files of any size, as opposed // specified file. This function will work with files of any size, as opposed
// to GetContents which is limited to 1 Mb files. It is the caller's // to GetContents which is limited to 1 Mb files. It is the caller's
// responsibility to close the ReadCloser. // responsibility to close the ReadCloser.
func (s *RepositoriesService) DownloadContents(ctx context.Context, owner, repo, filepath string, opts *RepositoryContentGetOptions) (io.ReadCloser, error) { //
// It is possible for the download to result in a failed response when the
// returned error is nil. Callers should check the returned Response status
// code to verify the content is from a successful response.
func (s *RepositoriesService) DownloadContents(ctx context.Context, owner, repo, filepath string, opts *RepositoryContentGetOptions) (io.ReadCloser, *Response, error) {
dir := path.Dir(filepath) dir := path.Dir(filepath)
filename := path.Base(filepath) filename := path.Base(filepath)
_, dirContents, _, err := s.GetContents(ctx, owner, repo, dir, opts) _, dirContents, resp, err := s.GetContents(ctx, owner, repo, dir, opts)
if err != nil { if err != nil {
return nil, err return nil, resp, err
} }
for _, contents := range dirContents { for _, contents := range dirContents {
if *contents.Name == filename { if *contents.Name == filename {
if contents.DownloadURL == nil || *contents.DownloadURL == "" { if contents.DownloadURL == nil || *contents.DownloadURL == "" {
return nil, fmt.Errorf("No download link found for %s", filepath) return nil, resp, fmt.Errorf("No download link found for %s", filepath)
} }
resp, err := s.client.client.Get(*contents.DownloadURL) dlResp, err := s.client.client.Get(*contents.DownloadURL)
if err != nil { if err != nil {
return nil, err return nil, &Response{Response: dlResp}, err
} }
return resp.Body, nil return dlResp.Body, &Response{Response: dlResp}, nil
} }
} }
return nil, 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
// returns the RepositoryContent of the requested file. This additional data
// is useful for future operations involving the requested file. For merely
// reading the content of a file, DownloadContents is perfectly adequate.
//
// It is possible for the download to result in a failed response when the
// returned error is nil. Callers should check the returned Response status
// code to verify the content is from a successful response.
func (s *RepositoriesService) DownloadContentsWithMeta(ctx context.Context, owner, repo, filepath string, opts *RepositoryContentGetOptions) (io.ReadCloser, *RepositoryContent, *Response, error) {
dir := path.Dir(filepath)
filename := path.Base(filepath)
_, dirContents, resp, err := s.GetContents(ctx, owner, repo, dir, opts)
if err != nil {
return nil, nil, resp, err
}
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)
}
dlResp, err := s.client.client.Get(*contents.DownloadURL)
if err != nil {
return nil, contents, &Response{Response: dlResp}, err
}
return dlResp.Body, contents, &Response{Response: dlResp}, nil
}
}
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 // GetContents can return either the metadata and content of a single file
@ -146,9 +181,9 @@ func (s *RepositoriesService) DownloadContents(ctx context.Context, owner, repo,
// as possible, both result types will be returned but only one will contain a // as possible, both result types will be returned but only one will contain a
// value and the other will be nil. // value and the other will be nil.
// //
// GitHub API docs: https://developer.github.com/v3/repos/contents/#get-repository-content // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-repository-content
func (s *RepositoriesService) GetContents(ctx context.Context, owner, repo, path string, opts *RepositoryContentGetOptions) (fileContent *RepositoryContent, directoryContent []*RepositoryContent, resp *Response, err error) { func (s *RepositoriesService) GetContents(ctx context.Context, owner, repo, path string, opts *RepositoryContentGetOptions) (fileContent *RepositoryContent, directoryContent []*RepositoryContent, resp *Response, err error) {
escapedPath := (&url.URL{Path: path}).String() escapedPath := (&url.URL{Path: strings.TrimSuffix(path, "/")}).String()
u := fmt.Sprintf("repos/%s/%s/contents/%s", owner, repo, escapedPath) u := fmt.Sprintf("repos/%s/%s/contents/%s", owner, repo, escapedPath)
u, err = addOptions(u, opts) u, err = addOptions(u, opts)
if err != nil { if err != nil {
@ -177,7 +212,7 @@ func (s *RepositoriesService) GetContents(ctx context.Context, owner, repo, path
// CreateFile creates a new file in a repository at the given path and returns // CreateFile creates a new file in a repository at the given path and returns
// the commit and file metadata. // the commit and file metadata.
// //
// GitHub API docs: https://developer.github.com/v3/repos/contents/#create-or-update-file-contents // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#create-or-update-file-contents
func (s *RepositoriesService) CreateFile(ctx context.Context, owner, repo, path string, opts *RepositoryContentFileOptions) (*RepositoryContentResponse, *Response, error) { func (s *RepositoriesService) CreateFile(ctx context.Context, owner, repo, path string, opts *RepositoryContentFileOptions) (*RepositoryContentResponse, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/contents/%s", owner, repo, path) u := fmt.Sprintf("repos/%s/%s/contents/%s", owner, repo, path)
req, err := s.client.NewRequest("PUT", u, opts) req, err := s.client.NewRequest("PUT", u, opts)
@ -195,7 +230,7 @@ func (s *RepositoriesService) CreateFile(ctx context.Context, owner, repo, path
// UpdateFile updates a file in a repository at the given path and returns the // UpdateFile updates a file in a repository at the given path and returns the
// commit and file metadata. Requires the blob SHA of the file being updated. // commit and file metadata. Requires the blob SHA of the file being updated.
// //
// GitHub API docs: https://developer.github.com/v3/repos/contents/#create-or-update-file-contents // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#create-or-update-file-contents
func (s *RepositoriesService) UpdateFile(ctx context.Context, owner, repo, path string, opts *RepositoryContentFileOptions) (*RepositoryContentResponse, *Response, error) { func (s *RepositoriesService) UpdateFile(ctx context.Context, owner, repo, path string, opts *RepositoryContentFileOptions) (*RepositoryContentResponse, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/contents/%s", owner, repo, path) u := fmt.Sprintf("repos/%s/%s/contents/%s", owner, repo, path)
req, err := s.client.NewRequest("PUT", u, opts) req, err := s.client.NewRequest("PUT", u, opts)
@ -213,7 +248,7 @@ func (s *RepositoriesService) UpdateFile(ctx context.Context, owner, repo, path
// DeleteFile deletes a file from a repository and returns the commit. // DeleteFile deletes a file from a repository and returns the commit.
// Requires the blob SHA of the file to be deleted. // Requires the blob SHA of the file to be deleted.
// //
// GitHub API docs: https://developer.github.com/v3/repos/contents/#delete-a-file // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#delete-a-file
func (s *RepositoriesService) DeleteFile(ctx context.Context, owner, repo, path string, opts *RepositoryContentFileOptions) (*RepositoryContentResponse, *Response, error) { func (s *RepositoriesService) DeleteFile(ctx context.Context, owner, repo, path string, opts *RepositoryContentFileOptions) (*RepositoryContentResponse, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/contents/%s", owner, repo, path) u := fmt.Sprintf("repos/%s/%s/contents/%s", owner, repo, path)
req, err := s.client.NewRequest("DELETE", u, opts) req, err := s.client.NewRequest("DELETE", u, opts)
@ -243,7 +278,7 @@ const (
// repository. The archiveFormat can be specified by either the github.Tarball // repository. The archiveFormat can be specified by either the github.Tarball
// or github.Zipball constant. // or github.Zipball constant.
// //
// GitHub API docs: https://developer.github.com/v3/repos/contents/#get-archive-link // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/contents/#get-archive-link
func (s *RepositoriesService) GetArchiveLink(ctx context.Context, owner, repo string, archiveformat ArchiveFormat, opts *RepositoryContentGetOptions, followRedirects bool) (*url.URL, *Response, error) { func (s *RepositoriesService) GetArchiveLink(ctx context.Context, owner, repo string, archiveformat ArchiveFormat, opts *RepositoryContentGetOptions, followRedirects bool) (*url.URL, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/%s", owner, repo, archiveformat) u := fmt.Sprintf("repos/%s/%s/%s", owner, repo, archiveformat)
if opts != nil && opts.Ref != "" { if opts != nil && opts.Ref != "" {

View file

@ -63,7 +63,7 @@ type DeploymentsListOptions struct {
// ListDeployments lists the deployments of a repository. // ListDeployments lists the deployments of a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/deployments/#list-deployments // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-deployments
func (s *RepositoriesService) ListDeployments(ctx context.Context, owner, repo string, opts *DeploymentsListOptions) ([]*Deployment, *Response, error) { func (s *RepositoriesService) ListDeployments(ctx context.Context, owner, repo string, opts *DeploymentsListOptions) ([]*Deployment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/deployments", owner, repo) u := fmt.Sprintf("repos/%v/%v/deployments", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -87,7 +87,7 @@ func (s *RepositoriesService) ListDeployments(ctx context.Context, owner, repo s
// GetDeployment returns a single deployment of a repository. // GetDeployment returns a single deployment of a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/deployments/#get-a-deployment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-a-deployment
func (s *RepositoriesService) GetDeployment(ctx context.Context, owner, repo string, deploymentID int64) (*Deployment, *Response, error) { func (s *RepositoriesService) GetDeployment(ctx context.Context, owner, repo string, deploymentID int64) (*Deployment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/deployments/%v", owner, repo, deploymentID) u := fmt.Sprintf("repos/%v/%v/deployments/%v", owner, repo, deploymentID)
@ -107,7 +107,7 @@ func (s *RepositoriesService) GetDeployment(ctx context.Context, owner, repo str
// CreateDeployment creates a new deployment for a repository. // CreateDeployment creates a new deployment for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/deployments/#create-a-deployment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#create-a-deployment
func (s *RepositoriesService) CreateDeployment(ctx context.Context, owner, repo string, request *DeploymentRequest) (*Deployment, *Response, error) { func (s *RepositoriesService) CreateDeployment(ctx context.Context, owner, repo string, request *DeploymentRequest) (*Deployment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/deployments", owner, repo) u := fmt.Sprintf("repos/%v/%v/deployments", owner, repo)
@ -131,7 +131,7 @@ func (s *RepositoriesService) CreateDeployment(ctx context.Context, owner, repo
// DeleteDeployment deletes an existing deployment for a repository. // DeleteDeployment deletes an existing deployment for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/deployments/#delete-a-deployment // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#delete-a-deployment
func (s *RepositoriesService) DeleteDeployment(ctx context.Context, owner, repo string, deploymentID int64) (*Response, error) { func (s *RepositoriesService) DeleteDeployment(ctx context.Context, owner, repo string, deploymentID int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/deployments/%v", owner, repo, deploymentID) u := fmt.Sprintf("repos/%v/%v/deployments/%v", owner, repo, deploymentID)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -175,7 +175,7 @@ type DeploymentStatusRequest struct {
// ListDeploymentStatuses lists the statuses of a given deployment of a repository. // ListDeploymentStatuses lists the statuses of a given deployment of a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/deployments/#list-deployment-statuses // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-deployment-statuses
func (s *RepositoriesService) ListDeploymentStatuses(ctx context.Context, owner, repo string, deployment int64, opts *ListOptions) ([]*DeploymentStatus, *Response, error) { func (s *RepositoriesService) ListDeploymentStatuses(ctx context.Context, owner, repo string, deployment int64, opts *ListOptions) ([]*DeploymentStatus, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/deployments/%v/statuses", owner, repo, deployment) u := fmt.Sprintf("repos/%v/%v/deployments/%v/statuses", owner, repo, deployment)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -203,7 +203,7 @@ func (s *RepositoriesService) ListDeploymentStatuses(ctx context.Context, owner,
// GetDeploymentStatus returns a single deployment status of a repository. // GetDeploymentStatus returns a single deployment status of a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/deployments/#get-a-deployment-status // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-a-deployment-status
func (s *RepositoriesService) GetDeploymentStatus(ctx context.Context, owner, repo string, deploymentID, deploymentStatusID int64) (*DeploymentStatus, *Response, error) { func (s *RepositoriesService) GetDeploymentStatus(ctx context.Context, owner, repo string, deploymentID, deploymentStatusID int64) (*DeploymentStatus, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/deployments/%v/statuses/%v", owner, repo, deploymentID, deploymentStatusID) u := fmt.Sprintf("repos/%v/%v/deployments/%v/statuses/%v", owner, repo, deploymentID, deploymentStatusID)
@ -227,7 +227,7 @@ func (s *RepositoriesService) GetDeploymentStatus(ctx context.Context, owner, re
// CreateDeploymentStatus creates a new status for a deployment. // CreateDeploymentStatus creates a new status for a deployment.
// //
// GitHub API docs: https://developer.github.com/v3/repos/deployments/#create-a-deployment-status // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#create-a-deployment-status
func (s *RepositoriesService) CreateDeploymentStatus(ctx context.Context, owner, repo string, deployment int64, request *DeploymentStatusRequest) (*DeploymentStatus, *Response, error) { func (s *RepositoriesService) CreateDeploymentStatus(ctx context.Context, owner, repo string, deployment int64, request *DeploymentStatusRequest) (*DeploymentStatus, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/deployments/%v/statuses", owner, repo, deployment) u := fmt.Sprintf("repos/%v/%v/deployments/%v/statuses", owner, repo, deployment)

View file

@ -0,0 +1,191 @@
// 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"
)
// Environment represents a single environment in a repository.
type Environment struct {
Owner *string `json:"owner,omitempty"`
Repo *string `json:"repo,omitempty"`
EnvironmentName *string `json:"environment_name,omitempty"`
WaitTimer *int `json:"wait_timer,omitempty"`
Reviewers []*EnvReviewers `json:"reviewers,omitempty"`
DeploymentBranchPolicy *BranchPolicy `json:"deployment_branch_policy,omitempty"`
// Return/response only values
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
Name *string `json:"name,omitempty"`
URL *string `json:"url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
ProtectionRules []*ProtectionRule `json:"protection_rules,omitempty"`
}
// EnvReviewers represents a single environment reviewer entry.
type EnvReviewers struct {
Type *string `json:"type,omitempty"`
ID *int64 `json:"id,omitempty"`
}
// BranchPolicy represents the options for whether a branch deployment policy is applied to this environment.
type BranchPolicy struct {
ProtectedBranches *bool `json:"protected_branches,omitempty"`
CustomBranchPolicies *bool `json:"custom_branch_policies,omitempty"`
}
// EnvResponse represents the slightly different format of response that comes back when you list an environment.
type EnvResponse struct {
TotalCount *int `json:"total_count,omitempty"`
Environments []*Environment `json:"environments,omitempty"`
}
// ProtectionRule represents a single protection rule applied to the environment.
type ProtectionRule struct {
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
Type *string `json:"type,omitempty"`
WaitTimer *int `json:"wait_timer,omitempty"`
Reviewers []*RequiredReviewer `json:"reviewers,omitempty"`
}
// RequiredReviewer represents a required reviewer.
type RequiredReviewer struct {
Type *string `json:"type,omitempty"`
Reviewer interface{} `json:"reviewer,omitempty"`
}
// UnmarshalJSON implements the json.Unmarshaler interface.
// This helps us handle the fact that RequiredReviewer can have either a User or Team type reviewer field.
func (r *RequiredReviewer) UnmarshalJSON(data []byte) error {
type aliasReviewer RequiredReviewer
var reviewer aliasReviewer
if err := json.Unmarshal(data, &reviewer); err != nil {
return err
}
r.Type = reviewer.Type
switch *reviewer.Type {
case "User":
reviewer.Reviewer = &User{}
if err := json.Unmarshal(data, &reviewer); err != nil {
return err
}
r.Reviewer = reviewer.Reviewer
case "Team":
reviewer.Reviewer = &Team{}
if err := json.Unmarshal(data, &reviewer); err != nil {
return err
}
r.Reviewer = reviewer.Reviewer
default:
r.Type = nil
r.Reviewer = nil
return fmt.Errorf("reviewer.Type is %T, not a string of 'User' or 'Team', unable to unmarshal", reviewer.Type)
}
return nil
}
// ListEnvironments lists all environments for a repository.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/repos#get-all-environments
func (s *RepositoriesService) ListEnvironments(ctx context.Context, owner, repo string) (*EnvResponse, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/environments", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var list *EnvResponse
resp, err := s.client.Do(ctx, req, &list)
if err != nil {
return nil, resp, err
}
return list, resp, nil
}
// GetEnvironment get a single environment for a repository.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/repos#get-an-environment
func (s *RepositoriesService) GetEnvironment(ctx context.Context, owner, repo, name string) (*Environment, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/environments/%s", owner, repo, name)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var env *Environment
resp, err := s.client.Do(ctx, req, &env)
if err != nil {
return nil, resp, err
}
return env, resp, nil
}
// MarshalJSON implements the json.Marshaler interface.
// As the only way to clear a WaitTimer is to set it to 0, a missing WaitTimer object should default to 0, not null.
func (c *CreateUpdateEnvironment) MarshalJSON() ([]byte, error) {
type Alias CreateUpdateEnvironment
if c.WaitTimer == nil {
c.WaitTimer = Int(0)
}
return json.Marshal(&struct {
*Alias
}{
Alias: (*Alias)(c),
})
}
// CreateUpdateEnvironment represents the fields required for the create/update operation
// following the Create/Update release example.
// See https://github.com/google/go-github/issues/992 for more information.
// Removed omitempty here as the API expects null values for reviewers and deployment_branch_policy to clear them.
type CreateUpdateEnvironment struct {
WaitTimer *int `json:"wait_timer"`
Reviewers []*EnvReviewers `json:"reviewers"`
DeploymentBranchPolicy *BranchPolicy `json:"deployment_branch_policy"`
}
// CreateUpdateEnvironment create or update a new environment for a repository.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/repos#create-or-update-an-environment
func (s *RepositoriesService) CreateUpdateEnvironment(ctx context.Context, owner, repo, name string, environment *CreateUpdateEnvironment) (*Environment, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/environments/%s", owner, repo, name)
req, err := s.client.NewRequest("PUT", u, environment)
if err != nil {
return nil, nil, err
}
e := new(Environment)
resp, err := s.client.Do(ctx, req, e)
if err != nil {
return nil, resp, err
}
return e, resp, nil
}
// DeleteEnvironment delete an environment from a repository.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/repos#delete-an-environment
func (s *RepositoriesService) DeleteEnvironment(ctx context.Context, owner, repo, name string) (*Response, error) {
u := fmt.Sprintf("repos/%s/%s/environments/%s", owner, repo, name)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}

View file

@ -24,7 +24,7 @@ type RepositoryListForksOptions struct {
// ListForks lists the forks of the specified repository. // ListForks lists the forks of the specified repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/forks/#list-forks // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-forks
func (s *RepositoriesService) ListForks(ctx context.Context, owner, repo string, opts *RepositoryListForksOptions) ([]*Repository, *Response, error) { func (s *RepositoriesService) ListForks(ctx context.Context, owner, repo string, opts *RepositoryListForksOptions) ([]*Repository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/forks", owner, repo) u := fmt.Sprintf("repos/%v/%v/forks", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -65,7 +65,7 @@ type RepositoryCreateForkOptions struct {
// A follow up request, after a delay of a second or so, should result // A follow up request, after a delay of a second or so, should result
// in a successful request. // in a successful request.
// //
// GitHub API docs: https://developer.github.com/v3/repos/forks/#create-a-fork // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#create-a-fork
func (s *RepositoriesService) CreateFork(ctx context.Context, owner, repo string, opts *RepositoryCreateForkOptions) (*Repository, *Response, error) { func (s *RepositoriesService) CreateFork(ctx context.Context, owner, repo string, opts *RepositoryCreateForkOptions) (*Repository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/forks", owner, repo) u := fmt.Sprintf("repos/%v/%v/forks", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)

View file

@ -19,18 +19,21 @@ import (
// //
// GitHub API docs: https://help.github.com/articles/post-receive-hooks // GitHub API docs: https://help.github.com/articles/post-receive-hooks
type WebHookPayload struct { type WebHookPayload struct {
After *string `json:"after,omitempty"` Action *string `json:"action,omitempty"`
Before *string `json:"before,omitempty"` After *string `json:"after,omitempty"`
Commits []*WebHookCommit `json:"commits,omitempty"` Before *string `json:"before,omitempty"`
Compare *string `json:"compare,omitempty"` Commits []*WebHookCommit `json:"commits,omitempty"`
Created *bool `json:"created,omitempty"` Compare *string `json:"compare,omitempty"`
Deleted *bool `json:"deleted,omitempty"` Created *bool `json:"created,omitempty"`
Forced *bool `json:"forced,omitempty"` Deleted *bool `json:"deleted,omitempty"`
HeadCommit *WebHookCommit `json:"head_commit,omitempty"` Forced *bool `json:"forced,omitempty"`
Pusher *User `json:"pusher,omitempty"` HeadCommit *WebHookCommit `json:"head_commit,omitempty"`
Ref *string `json:"ref,omitempty"` Installation *Installation `json:"installation,omitempty"`
Repo *Repository `json:"repository,omitempty"` Organization *Organization `json:"organization,omitempty"`
Sender *User `json:"sender,omitempty"` Pusher *User `json:"pusher,omitempty"`
Ref *string `json:"ref,omitempty"`
Repo *Repository `json:"repository,omitempty"`
Sender *User `json:"sender,omitempty"`
} }
func (w WebHookPayload) String() string { func (w WebHookPayload) String() string {
@ -69,10 +72,15 @@ func (w WebHookAuthor) String() string {
// Hook represents a GitHub (web and service) hook for a repository. // Hook represents a GitHub (web and service) hook for a repository.
type Hook struct { type Hook struct {
CreatedAt *time.Time `json:"created_at,omitempty"` CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"` UpdatedAt *time.Time `json:"updated_at,omitempty"`
URL *string `json:"url,omitempty"` URL *string `json:"url,omitempty"`
ID *int64 `json:"id,omitempty"` ID *int64 `json:"id,omitempty"`
Type *string `json:"type,omitempty"`
Name *string `json:"name,omitempty"`
TestURL *string `json:"test_url,omitempty"`
PingURL *string `json:"ping_url,omitempty"`
LastResponse map[string]interface{} `json:"last_response,omitempty"`
// Only the following fields are used when creating a hook. // Only the following fields are used when creating a hook.
// Config is required. // Config is required.
@ -104,7 +112,7 @@ type createHookRequest struct {
// Note that only a subset of the hook fields are used and hook must // Note that only a subset of the hook fields are used and hook must
// not be nil. // not be nil.
// //
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#create-a-repository-webhook // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#create-a-repository-webhook
func (s *RepositoriesService) CreateHook(ctx context.Context, owner, repo string, hook *Hook) (*Hook, *Response, error) { func (s *RepositoriesService) CreateHook(ctx context.Context, owner, repo string, hook *Hook) (*Hook, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks", owner, repo) u := fmt.Sprintf("repos/%v/%v/hooks", owner, repo)
@ -131,7 +139,7 @@ func (s *RepositoriesService) CreateHook(ctx context.Context, owner, repo string
// ListHooks lists all Hooks for the specified repository. // ListHooks lists all Hooks for the specified repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#list-repository-webhooks // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-repository-webhooks
func (s *RepositoriesService) ListHooks(ctx context.Context, owner, repo string, opts *ListOptions) ([]*Hook, *Response, error) { func (s *RepositoriesService) ListHooks(ctx context.Context, owner, repo string, opts *ListOptions) ([]*Hook, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks", owner, repo) u := fmt.Sprintf("repos/%v/%v/hooks", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -155,7 +163,7 @@ func (s *RepositoriesService) ListHooks(ctx context.Context, owner, repo string,
// GetHook returns a single specified Hook. // GetHook returns a single specified Hook.
// //
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#get-a-repository-webhook // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-a-repository-webhook
func (s *RepositoriesService) GetHook(ctx context.Context, owner, repo string, id int64) (*Hook, *Response, error) { func (s *RepositoriesService) GetHook(ctx context.Context, owner, repo string, id int64) (*Hook, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -173,7 +181,7 @@ func (s *RepositoriesService) GetHook(ctx context.Context, owner, repo string, i
// EditHook updates a specified Hook. // EditHook updates a specified Hook.
// //
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#update-a-repository-webhook // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#update-a-repository-webhook
func (s *RepositoriesService) EditHook(ctx context.Context, owner, repo string, id int64, hook *Hook) (*Hook, *Response, error) { func (s *RepositoriesService) EditHook(ctx context.Context, owner, repo string, id int64, hook *Hook) (*Hook, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id)
req, err := s.client.NewRequest("PATCH", u, hook) req, err := s.client.NewRequest("PATCH", u, hook)
@ -191,7 +199,7 @@ func (s *RepositoriesService) EditHook(ctx context.Context, owner, repo string,
// DeleteHook deletes a specified Hook. // DeleteHook deletes a specified Hook.
// //
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#delete-a-repository-webhook // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#delete-a-repository-webhook
func (s *RepositoriesService) DeleteHook(ctx context.Context, owner, repo string, id int64) (*Response, error) { func (s *RepositoriesService) DeleteHook(ctx context.Context, owner, repo string, id int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -203,7 +211,7 @@ func (s *RepositoriesService) DeleteHook(ctx context.Context, owner, repo string
// PingHook triggers a 'ping' event to be sent to the Hook. // PingHook triggers a 'ping' event to be sent to the Hook.
// //
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#ping-a-repository-webhook // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#ping-a-repository-webhook
func (s *RepositoriesService) PingHook(ctx context.Context, owner, repo string, id int64) (*Response, error) { func (s *RepositoriesService) PingHook(ctx context.Context, owner, repo string, id int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%d/pings", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/hooks/%d/pings", owner, repo, id)
req, err := s.client.NewRequest("POST", u, nil) req, err := s.client.NewRequest("POST", u, nil)
@ -215,7 +223,7 @@ func (s *RepositoriesService) PingHook(ctx context.Context, owner, repo string,
// TestHook triggers a test Hook by github. // TestHook triggers a test Hook by github.
// //
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#test-the-push-repository-webhook // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#test-the-push-repository-webhook
func (s *RepositoriesService) TestHook(ctx context.Context, owner, repo string, id int64) (*Response, error) { func (s *RepositoriesService) TestHook(ctx context.Context, owner, repo string, id int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%d/tests", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/hooks/%d/tests", owner, repo, id)
req, err := s.client.NewRequest("POST", u, nil) req, err := s.client.NewRequest("POST", u, nil)

View file

@ -27,7 +27,7 @@ type RepositoryInvitation struct {
// ListInvitations lists all currently-open repository invitations. // ListInvitations lists all currently-open repository invitations.
// //
// GitHub API docs: https://developer.github.com/v3/repos/invitations/#list-repository-invitations // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-repository-invitations
func (s *RepositoriesService) ListInvitations(ctx context.Context, owner, repo string, opts *ListOptions) ([]*RepositoryInvitation, *Response, error) { func (s *RepositoriesService) ListInvitations(ctx context.Context, owner, repo string, opts *ListOptions) ([]*RepositoryInvitation, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/invitations", owner, repo) u := fmt.Sprintf("repos/%v/%v/invitations", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -51,7 +51,7 @@ func (s *RepositoriesService) ListInvitations(ctx context.Context, owner, repo s
// DeleteInvitation deletes a repository invitation. // DeleteInvitation deletes a repository invitation.
// //
// GitHub API docs: https://developer.github.com/v3/repos/invitations/#delete-a-repository-invitation // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#delete-a-repository-invitation
func (s *RepositoriesService) DeleteInvitation(ctx context.Context, owner, repo string, invitationID int64) (*Response, error) { func (s *RepositoriesService) DeleteInvitation(ctx context.Context, owner, repo string, invitationID int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/invitations/%v", owner, repo, invitationID) u := fmt.Sprintf("repos/%v/%v/invitations/%v", owner, repo, invitationID)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -68,7 +68,7 @@ func (s *RepositoriesService) DeleteInvitation(ctx context.Context, owner, repo
// permissions represents the permissions that the associated user will have // permissions represents the permissions that the associated user will have
// on the repository. Possible values are: "read", "write", "admin". // on the repository. Possible values are: "read", "write", "admin".
// //
// GitHub API docs: https://developer.github.com/v3/repos/invitations/#update-a-repository-invitation // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#update-a-repository-invitation
func (s *RepositoriesService) UpdateInvitation(ctx context.Context, owner, repo string, invitationID int64, permissions string) (*RepositoryInvitation, *Response, error) { func (s *RepositoriesService) UpdateInvitation(ctx context.Context, owner, repo string, invitationID int64, permissions string) (*RepositoryInvitation, *Response, error) {
opts := &struct { opts := &struct {
Permissions string `json:"permissions"` Permissions string `json:"permissions"`

View file

@ -14,7 +14,7 @@ import (
// ListKeys lists the deploy keys for a repository. // ListKeys lists the deploy keys for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/keys/#list-deploy-keys // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-deploy-keys
func (s *RepositoriesService) ListKeys(ctx context.Context, owner string, repo string, opts *ListOptions) ([]*Key, *Response, error) { func (s *RepositoriesService) ListKeys(ctx context.Context, owner string, repo string, opts *ListOptions) ([]*Key, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/keys", owner, repo) u := fmt.Sprintf("repos/%v/%v/keys", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -38,7 +38,7 @@ func (s *RepositoriesService) ListKeys(ctx context.Context, owner string, repo s
// GetKey fetches a single deploy key. // GetKey fetches a single deploy key.
// //
// GitHub API docs: https://developer.github.com/v3/repos/keys/#get-a-deploy-key // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-a-deploy-key
func (s *RepositoriesService) GetKey(ctx context.Context, owner string, repo string, id int64) (*Key, *Response, error) { func (s *RepositoriesService) GetKey(ctx context.Context, owner string, repo string, id int64) (*Key, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/keys/%v", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/keys/%v", owner, repo, id)
@ -58,7 +58,7 @@ func (s *RepositoriesService) GetKey(ctx context.Context, owner string, repo str
// CreateKey adds a deploy key for a repository. // CreateKey adds a deploy key for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/keys/#create-a-deploy-key // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#create-a-deploy-key
func (s *RepositoriesService) CreateKey(ctx context.Context, owner string, repo string, key *Key) (*Key, *Response, error) { func (s *RepositoriesService) CreateKey(ctx context.Context, owner string, repo string, key *Key) (*Key, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/keys", owner, repo) u := fmt.Sprintf("repos/%v/%v/keys", owner, repo)
@ -78,7 +78,7 @@ func (s *RepositoriesService) CreateKey(ctx context.Context, owner string, repo
// DeleteKey deletes a deploy key. // DeleteKey deletes a deploy key.
// //
// GitHub API docs: https://developer.github.com/v3/repos/keys/#delete-a-deploy-key // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#delete-a-deploy-key
func (s *RepositoriesService) DeleteKey(ctx context.Context, owner string, repo string, id int64) (*Response, error) { func (s *RepositoriesService) DeleteKey(ctx context.Context, owner string, repo string, id int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/keys/%v", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/keys/%v", owner, repo, id)

View file

@ -20,7 +20,7 @@ type RepositoryMergeRequest struct {
// Merge a branch in the specified repository. // Merge a branch in the specified repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/merging/#merge-a-branch // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#merge-a-branch
func (s *RepositoriesService) Merge(ctx context.Context, owner, repo string, request *RepositoryMergeRequest) (*RepositoryCommit, *Response, error) { func (s *RepositoriesService) Merge(ctx context.Context, owner, repo string, request *RepositoryMergeRequest) (*RepositoryCommit, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/merges", owner, repo) u := fmt.Sprintf("repos/%v/%v/merges", owner, repo)
req, err := s.client.NewRequest("POST", u, request) req, err := s.client.NewRequest("POST", u, request)

View file

@ -51,7 +51,7 @@ type createPagesRequest struct {
// EnablePages enables GitHub Pages for the named repo. // EnablePages enables GitHub Pages for the named repo.
// //
// GitHub API docs: https://developer.github.com/v3/repos/pages/#create-a-github-pages-site // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#create-a-github-pages-site
func (s *RepositoriesService) EnablePages(ctx context.Context, owner, repo string, pages *Pages) (*Pages, *Response, error) { func (s *RepositoriesService) EnablePages(ctx context.Context, owner, repo string, pages *Pages) (*Pages, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pages", owner, repo) u := fmt.Sprintf("repos/%v/%v/pages", owner, repo)
@ -87,7 +87,7 @@ type PagesUpdate struct {
// UpdatePages updates GitHub Pages for the named repo. // UpdatePages updates GitHub Pages for the named repo.
// //
// GitHub API docs: https://developer.github.com/v3/repos/pages/#update-information-about-a-github-pages-site // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#update-information-about-a-github-pages-site
func (s *RepositoriesService) UpdatePages(ctx context.Context, owner, repo string, opts *PagesUpdate) (*Response, error) { func (s *RepositoriesService) UpdatePages(ctx context.Context, owner, repo string, opts *PagesUpdate) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/pages", owner, repo) u := fmt.Sprintf("repos/%v/%v/pages", owner, repo)
@ -106,7 +106,7 @@ func (s *RepositoriesService) UpdatePages(ctx context.Context, owner, repo strin
// DisablePages disables GitHub Pages for the named repo. // DisablePages disables GitHub Pages for the named repo.
// //
// GitHub API docs: https://developer.github.com/v3/repos/pages/#delete-a-github-pages-site // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#delete-a-github-pages-site
func (s *RepositoriesService) DisablePages(ctx context.Context, owner, repo string) (*Response, error) { func (s *RepositoriesService) DisablePages(ctx context.Context, owner, repo string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/pages", owner, repo) u := fmt.Sprintf("repos/%v/%v/pages", owner, repo)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -122,7 +122,7 @@ func (s *RepositoriesService) DisablePages(ctx context.Context, owner, repo stri
// GetPagesInfo fetches information about a GitHub Pages site. // GetPagesInfo fetches information about a GitHub Pages site.
// //
// GitHub API docs: https://developer.github.com/v3/repos/pages/#get-a-github-pages-site // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-a-github-pages-site
func (s *RepositoriesService) GetPagesInfo(ctx context.Context, owner, repo string) (*Pages, *Response, error) { func (s *RepositoriesService) GetPagesInfo(ctx context.Context, owner, repo string) (*Pages, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pages", owner, repo) u := fmt.Sprintf("repos/%v/%v/pages", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -141,7 +141,7 @@ func (s *RepositoriesService) GetPagesInfo(ctx context.Context, owner, repo stri
// ListPagesBuilds lists the builds for a GitHub Pages site. // ListPagesBuilds lists the builds for a GitHub Pages site.
// //
// GitHub API docs: https://developer.github.com/v3/repos/pages/#list-github-pages-builds // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-github-pages-builds
func (s *RepositoriesService) ListPagesBuilds(ctx context.Context, owner, repo string, opts *ListOptions) ([]*PagesBuild, *Response, error) { func (s *RepositoriesService) ListPagesBuilds(ctx context.Context, owner, repo string, opts *ListOptions) ([]*PagesBuild, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pages/builds", owner, repo) u := fmt.Sprintf("repos/%v/%v/pages/builds", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -165,7 +165,7 @@ func (s *RepositoriesService) ListPagesBuilds(ctx context.Context, owner, repo s
// GetLatestPagesBuild fetches the latest build information for a GitHub pages site. // GetLatestPagesBuild fetches the latest build information for a GitHub pages site.
// //
// GitHub API docs: https://developer.github.com/v3/repos/pages/#get-latest-pages-build // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-latest-pages-build
func (s *RepositoriesService) GetLatestPagesBuild(ctx context.Context, owner, repo string) (*PagesBuild, *Response, error) { func (s *RepositoriesService) GetLatestPagesBuild(ctx context.Context, owner, repo string) (*PagesBuild, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pages/builds/latest", owner, repo) u := fmt.Sprintf("repos/%v/%v/pages/builds/latest", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -184,7 +184,7 @@ func (s *RepositoriesService) GetLatestPagesBuild(ctx context.Context, owner, re
// GetPageBuild fetches the specific build information for a GitHub pages site. // GetPageBuild fetches the specific build information for a GitHub pages site.
// //
// GitHub API docs: https://developer.github.com/v3/repos/pages/#get-github-pages-build // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-github-pages-build
func (s *RepositoriesService) GetPageBuild(ctx context.Context, owner, repo string, id int64) (*PagesBuild, *Response, error) { func (s *RepositoriesService) GetPageBuild(ctx context.Context, owner, repo string, id int64) (*PagesBuild, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pages/builds/%v", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/pages/builds/%v", owner, repo, id)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -203,7 +203,7 @@ func (s *RepositoriesService) GetPageBuild(ctx context.Context, owner, repo stri
// RequestPageBuild requests a build of a GitHub Pages site without needing to push new commit. // RequestPageBuild requests a build of a GitHub Pages site without needing to push new commit.
// //
// GitHub API docs: https://developer.github.com/v3/repos/pages/#request-a-github-pages-build // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#request-a-github-pages-build
func (s *RepositoriesService) RequestPageBuild(ctx context.Context, owner, repo string) (*PagesBuild, *Response, error) { func (s *RepositoriesService) RequestPageBuild(ctx context.Context, owner, repo string) (*PagesBuild, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pages/builds", owner, repo) u := fmt.Sprintf("repos/%v/%v/pages/builds", owner, repo)
req, err := s.client.NewRequest("POST", u, nil) req, err := s.client.NewRequest("POST", u, nil)

View file

@ -21,7 +21,7 @@ type ProjectListOptions struct {
// ListProjects lists the projects for a repo. // ListProjects lists the projects for a repo.
// //
// GitHub API docs: https://developer.github.com/v3/projects/#list-repository-projects // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#list-repository-projects
func (s *RepositoriesService) ListProjects(ctx context.Context, owner, repo string, opts *ProjectListOptions) ([]*Project, *Response, error) { func (s *RepositoriesService) ListProjects(ctx context.Context, owner, repo string, opts *ProjectListOptions) ([]*Project, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/projects", owner, repo) u := fmt.Sprintf("repos/%v/%v/projects", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -48,7 +48,7 @@ func (s *RepositoriesService) ListProjects(ctx context.Context, owner, repo stri
// CreateProject creates a GitHub Project for the specified repository. // CreateProject creates a GitHub Project for the specified repository.
// //
// GitHub API docs: https://developer.github.com/v3/projects/#create-a-repository-project // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#create-a-repository-project
func (s *RepositoriesService) CreateProject(ctx context.Context, owner, repo string, opts *ProjectOptions) (*Project, *Response, error) { func (s *RepositoriesService) CreateProject(ctx context.Context, owner, repo string, opts *ProjectOptions) (*Project, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/projects", owner, repo) u := fmt.Sprintf("repos/%v/%v/projects", owner, repo)
req, err := s.client.NewRequest("POST", u, opts) req, err := s.client.NewRequest("POST", u, opts)

View file

@ -19,12 +19,13 @@ import (
// RepositoryRelease represents a GitHub release in a repository. // RepositoryRelease represents a GitHub release in a repository.
type RepositoryRelease struct { type RepositoryRelease struct {
TagName *string `json:"tag_name,omitempty"` TagName *string `json:"tag_name,omitempty"`
TargetCommitish *string `json:"target_commitish,omitempty"` TargetCommitish *string `json:"target_commitish,omitempty"`
Name *string `json:"name,omitempty"` Name *string `json:"name,omitempty"`
Body *string `json:"body,omitempty"` Body *string `json:"body,omitempty"`
Draft *bool `json:"draft,omitempty"` Draft *bool `json:"draft,omitempty"`
Prerelease *bool `json:"prerelease,omitempty"` Prerelease *bool `json:"prerelease,omitempty"`
DiscussionCategoryName *string `json:"discussion_category_name,omitempty"`
// The following fields are not used in CreateRelease or EditRelease: // The following fields are not used in CreateRelease or EditRelease:
ID *int64 `json:"id,omitempty"` ID *int64 `json:"id,omitempty"`
@ -68,7 +69,7 @@ func (r ReleaseAsset) String() string {
// ListReleases lists the releases for a repository. // ListReleases lists the releases for a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/releases/#list-releases // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-releases
func (s *RepositoriesService) ListReleases(ctx context.Context, owner, repo string, opts *ListOptions) ([]*RepositoryRelease, *Response, error) { func (s *RepositoriesService) ListReleases(ctx context.Context, owner, repo string, opts *ListOptions) ([]*RepositoryRelease, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases", owner, repo) u := fmt.Sprintf("repos/%s/%s/releases", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -91,7 +92,7 @@ func (s *RepositoriesService) ListReleases(ctx context.Context, owner, repo stri
// GetRelease fetches a single release. // GetRelease fetches a single release.
// //
// GitHub API docs: https://developer.github.com/v3/repos/releases/#get-a-release // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-a-release
func (s *RepositoriesService) GetRelease(ctx context.Context, owner, repo string, id int64) (*RepositoryRelease, *Response, error) { func (s *RepositoriesService) GetRelease(ctx context.Context, owner, repo string, id int64) (*RepositoryRelease, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/%d", owner, repo, id) u := fmt.Sprintf("repos/%s/%s/releases/%d", owner, repo, id)
return s.getSingleRelease(ctx, u) return s.getSingleRelease(ctx, u)
@ -99,7 +100,7 @@ func (s *RepositoriesService) GetRelease(ctx context.Context, owner, repo string
// GetLatestRelease fetches the latest published release for the repository. // GetLatestRelease fetches the latest published release for the repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/releases/#get-the-latest-release // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-the-latest-release
func (s *RepositoriesService) GetLatestRelease(ctx context.Context, owner, repo string) (*RepositoryRelease, *Response, error) { func (s *RepositoriesService) GetLatestRelease(ctx context.Context, owner, repo string) (*RepositoryRelease, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/latest", owner, repo) u := fmt.Sprintf("repos/%s/%s/releases/latest", owner, repo)
return s.getSingleRelease(ctx, u) return s.getSingleRelease(ctx, u)
@ -107,7 +108,7 @@ func (s *RepositoriesService) GetLatestRelease(ctx context.Context, owner, repo
// GetReleaseByTag fetches a release with the specified tag. // GetReleaseByTag fetches a release with the specified tag.
// //
// GitHub API docs: https://developer.github.com/v3/repos/releases/#get-a-release-by-tag-name // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-a-release-by-tag-name
func (s *RepositoriesService) GetReleaseByTag(ctx context.Context, owner, repo, tag string) (*RepositoryRelease, *Response, error) { func (s *RepositoriesService) GetReleaseByTag(ctx context.Context, owner, repo, tag string) (*RepositoryRelease, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/tags/%s", owner, repo, tag) u := fmt.Sprintf("repos/%s/%s/releases/tags/%s", owner, repo, tag)
return s.getSingleRelease(ctx, u) return s.getSingleRelease(ctx, u)
@ -134,12 +135,13 @@ func (s *RepositoriesService) getSingleRelease(ctx context.Context, url string)
// See https://github.com/google/go-github/issues/992 for more // See https://github.com/google/go-github/issues/992 for more
// information. // information.
type repositoryReleaseRequest struct { type repositoryReleaseRequest struct {
TagName *string `json:"tag_name,omitempty"` TagName *string `json:"tag_name,omitempty"`
TargetCommitish *string `json:"target_commitish,omitempty"` TargetCommitish *string `json:"target_commitish,omitempty"`
Name *string `json:"name,omitempty"` Name *string `json:"name,omitempty"`
Body *string `json:"body,omitempty"` Body *string `json:"body,omitempty"`
Draft *bool `json:"draft,omitempty"` Draft *bool `json:"draft,omitempty"`
Prerelease *bool `json:"prerelease,omitempty"` Prerelease *bool `json:"prerelease,omitempty"`
DiscussionCategoryName *string `json:"discussion_category_name,omitempty"`
} }
// CreateRelease adds a new release for a repository. // CreateRelease adds a new release for a repository.
@ -147,17 +149,18 @@ type repositoryReleaseRequest struct {
// Note that only a subset of the release fields are used. // Note that only a subset of the release fields are used.
// See RepositoryRelease for more information. // See RepositoryRelease for more information.
// //
// GitHub API docs: https://developer.github.com/v3/repos/releases/#create-a-release // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#create-a-release
func (s *RepositoriesService) CreateRelease(ctx context.Context, owner, repo string, release *RepositoryRelease) (*RepositoryRelease, *Response, error) { func (s *RepositoriesService) CreateRelease(ctx context.Context, owner, repo string, release *RepositoryRelease) (*RepositoryRelease, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases", owner, repo) u := fmt.Sprintf("repos/%s/%s/releases", owner, repo)
releaseReq := &repositoryReleaseRequest{ releaseReq := &repositoryReleaseRequest{
TagName: release.TagName, TagName: release.TagName,
TargetCommitish: release.TargetCommitish, TargetCommitish: release.TargetCommitish,
Name: release.Name, Name: release.Name,
Body: release.Body, Body: release.Body,
Draft: release.Draft, Draft: release.Draft,
Prerelease: release.Prerelease, Prerelease: release.Prerelease,
DiscussionCategoryName: release.DiscussionCategoryName,
} }
req, err := s.client.NewRequest("POST", u, releaseReq) req, err := s.client.NewRequest("POST", u, releaseReq)
@ -178,17 +181,18 @@ func (s *RepositoriesService) CreateRelease(ctx context.Context, owner, repo str
// Note that only a subset of the release fields are used. // Note that only a subset of the release fields are used.
// See RepositoryRelease for more information. // See RepositoryRelease for more information.
// //
// GitHub API docs: https://developer.github.com/v3/repos/releases/#update-a-release // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#update-a-release
func (s *RepositoriesService) EditRelease(ctx context.Context, owner, repo string, id int64, release *RepositoryRelease) (*RepositoryRelease, *Response, error) { func (s *RepositoriesService) EditRelease(ctx context.Context, owner, repo string, id int64, release *RepositoryRelease) (*RepositoryRelease, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/%d", owner, repo, id) u := fmt.Sprintf("repos/%s/%s/releases/%d", owner, repo, id)
releaseReq := &repositoryReleaseRequest{ releaseReq := &repositoryReleaseRequest{
TagName: release.TagName, TagName: release.TagName,
TargetCommitish: release.TargetCommitish, TargetCommitish: release.TargetCommitish,
Name: release.Name, Name: release.Name,
Body: release.Body, Body: release.Body,
Draft: release.Draft, Draft: release.Draft,
Prerelease: release.Prerelease, Prerelease: release.Prerelease,
DiscussionCategoryName: release.DiscussionCategoryName,
} }
req, err := s.client.NewRequest("PATCH", u, releaseReq) req, err := s.client.NewRequest("PATCH", u, releaseReq)
@ -206,7 +210,7 @@ func (s *RepositoriesService) EditRelease(ctx context.Context, owner, repo strin
// DeleteRelease delete a single release from a repository. // DeleteRelease delete a single release from a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/releases/#delete-a-release // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#delete-a-release
func (s *RepositoriesService) DeleteRelease(ctx context.Context, owner, repo string, id int64) (*Response, error) { func (s *RepositoriesService) DeleteRelease(ctx context.Context, owner, repo string, id int64) (*Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/%d", owner, repo, id) u := fmt.Sprintf("repos/%s/%s/releases/%d", owner, repo, id)
@ -219,7 +223,7 @@ func (s *RepositoriesService) DeleteRelease(ctx context.Context, owner, repo str
// ListReleaseAssets lists the release's assets. // ListReleaseAssets lists the release's assets.
// //
// GitHub API docs: https://developer.github.com/v3/repos/releases/#list-release-assets // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-release-assets
func (s *RepositoriesService) ListReleaseAssets(ctx context.Context, owner, repo string, id int64, opts *ListOptions) ([]*ReleaseAsset, *Response, error) { func (s *RepositoriesService) ListReleaseAssets(ctx context.Context, owner, repo string, id int64, opts *ListOptions) ([]*ReleaseAsset, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/%d/assets", owner, repo, id) u := fmt.Sprintf("repos/%s/%s/releases/%d/assets", owner, repo, id)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -242,7 +246,7 @@ func (s *RepositoriesService) ListReleaseAssets(ctx context.Context, owner, repo
// GetReleaseAsset fetches a single release asset. // GetReleaseAsset fetches a single release asset.
// //
// GitHub API docs: https://developer.github.com/v3/repos/releases/#get-a-release-asset // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-a-release-asset
func (s *RepositoriesService) GetReleaseAsset(ctx context.Context, owner, repo string, id int64) (*ReleaseAsset, *Response, error) { func (s *RepositoriesService) GetReleaseAsset(ctx context.Context, owner, repo string, id int64) (*ReleaseAsset, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/assets/%d", owner, repo, id) u := fmt.Sprintf("repos/%s/%s/releases/assets/%d", owner, repo, id)
@ -271,7 +275,7 @@ func (s *RepositoriesService) GetReleaseAsset(ctx context.Context, owner, repo s
// exist, but it's possible to pass any http.Client. If nil is passed the // exist, but it's possible to pass any http.Client. If nil is passed the
// redirectURL will be returned instead. // redirectURL will be returned instead.
// //
// GitHub API docs: https://developer.github.com/v3/repos/releases/#get-a-release-asset // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-a-release-asset
func (s *RepositoriesService) DownloadReleaseAsset(ctx context.Context, owner, repo string, id int64, followRedirectsClient *http.Client) (rc io.ReadCloser, redirectURL string, err error) { func (s *RepositoriesService) DownloadReleaseAsset(ctx context.Context, owner, repo string, id int64, followRedirectsClient *http.Client) (rc io.ReadCloser, redirectURL string, err error) {
u := fmt.Sprintf("repos/%s/%s/releases/assets/%d", owner, repo, id) u := fmt.Sprintf("repos/%s/%s/releases/assets/%d", owner, repo, id)
@ -333,7 +337,7 @@ func (s *RepositoriesService) downloadReleaseAssetFromURL(ctx context.Context, f
// EditReleaseAsset edits a repository release asset. // EditReleaseAsset edits a repository release asset.
// //
// GitHub API docs: https://developer.github.com/v3/repos/releases/#update-a-release-asset // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#update-a-release-asset
func (s *RepositoriesService) EditReleaseAsset(ctx context.Context, owner, repo string, id int64, release *ReleaseAsset) (*ReleaseAsset, *Response, error) { func (s *RepositoriesService) EditReleaseAsset(ctx context.Context, owner, repo string, id int64, release *ReleaseAsset) (*ReleaseAsset, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/assets/%d", owner, repo, id) u := fmt.Sprintf("repos/%s/%s/releases/assets/%d", owner, repo, id)
@ -352,7 +356,7 @@ func (s *RepositoriesService) EditReleaseAsset(ctx context.Context, owner, repo
// DeleteReleaseAsset delete a single release asset from a repository. // DeleteReleaseAsset delete a single release asset from a repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/releases/#delete-a-release-asset // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#delete-a-release-asset
func (s *RepositoriesService) DeleteReleaseAsset(ctx context.Context, owner, repo string, id int64) (*Response, error) { func (s *RepositoriesService) DeleteReleaseAsset(ctx context.Context, owner, repo string, id int64) (*Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/assets/%d", owner, repo, id) u := fmt.Sprintf("repos/%s/%s/releases/assets/%d", owner, repo, id)
@ -366,7 +370,7 @@ func (s *RepositoriesService) DeleteReleaseAsset(ctx context.Context, owner, rep
// UploadReleaseAsset creates an asset by uploading a file into a release repository. // UploadReleaseAsset creates an asset by uploading a file into a release repository.
// To upload assets that cannot be represented by an os.File, call NewUploadRequest directly. // To upload assets that cannot be represented by an os.File, call NewUploadRequest directly.
// //
// GitHub API docs: https://developer.github.com/v3/repos/releases/#upload-a-release-asset // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#upload-a-release-asset
func (s *RepositoriesService) UploadReleaseAsset(ctx context.Context, owner, repo string, id int64, opts *UploadOptions, file *os.File) (*ReleaseAsset, *Response, error) { func (s *RepositoriesService) UploadReleaseAsset(ctx context.Context, owner, repo string, id int64, opts *UploadOptions, file *os.File) (*ReleaseAsset, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/%d/assets", owner, repo, id) u := fmt.Sprintf("repos/%s/%s/releases/%d/assets", owner, repo, id)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)

View file

@ -45,7 +45,7 @@ func (w WeeklyStats) String() string {
// it is now computing the requested statistics. A follow up request, after a // it is now computing the requested statistics. A follow up request, after a
// delay of a second or so, should result in a successful request. // delay of a second or so, should result in a successful request.
// //
// GitHub API docs: https://developer.github.com/v3/repos/statistics/#get-all-contributor-commit-activity // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-all-contributor-commit-activity
func (s *RepositoriesService) ListContributorsStats(ctx context.Context, owner, repo string) ([]*ContributorStats, *Response, error) { func (s *RepositoriesService) ListContributorsStats(ctx context.Context, owner, repo string) ([]*ContributorStats, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/stats/contributors", owner, repo) u := fmt.Sprintf("repos/%v/%v/stats/contributors", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -84,7 +84,7 @@ func (w WeeklyCommitActivity) String() string {
// it is now computing the requested statistics. A follow up request, after a // it is now computing the requested statistics. A follow up request, after a
// delay of a second or so, should result in a successful request. // delay of a second or so, should result in a successful request.
// //
// GitHub API docs: https://developer.github.com/v3/repos/statistics/#get-the-last-year-of-commit-activity // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-the-last-year-of-commit-activity
func (s *RepositoriesService) ListCommitActivity(ctx context.Context, owner, repo string) ([]*WeeklyCommitActivity, *Response, error) { func (s *RepositoriesService) ListCommitActivity(ctx context.Context, owner, repo string) ([]*WeeklyCommitActivity, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/stats/commit_activity", owner, repo) u := fmt.Sprintf("repos/%v/%v/stats/commit_activity", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -111,7 +111,7 @@ func (s *RepositoriesService) ListCommitActivity(ctx context.Context, owner, rep
// it is now computing the requested statistics. A follow up request, after a // it is now computing the requested statistics. A follow up request, after a
// delay of a second or so, should result in a successful request. // delay of a second or so, should result in a successful request.
// //
// GitHub API docs: https://developer.github.com/v3/repos/statistics/#get-the-weekly-commit-activity // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-the-weekly-commit-activity
func (s *RepositoriesService) ListCodeFrequency(ctx context.Context, owner, repo string) ([]*WeeklyStats, *Response, error) { func (s *RepositoriesService) ListCodeFrequency(ctx context.Context, owner, repo string) ([]*WeeklyStats, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/stats/code_frequency", owner, repo) u := fmt.Sprintf("repos/%v/%v/stats/code_frequency", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -164,7 +164,7 @@ func (r RepositoryParticipation) String() string {
// it is now computing the requested statistics. A follow up request, after a // it is now computing the requested statistics. A follow up request, after a
// delay of a second or so, should result in a successful request. // delay of a second or so, should result in a successful request.
// //
// GitHub API docs: https://developer.github.com/v3/repos/statistics/#get-the-weekly-commit-count // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-the-weekly-commit-count
func (s *RepositoriesService) ListParticipation(ctx context.Context, owner, repo string) (*RepositoryParticipation, *Response, error) { func (s *RepositoriesService) ListParticipation(ctx context.Context, owner, repo string) (*RepositoryParticipation, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/stats/participation", owner, repo) u := fmt.Sprintf("repos/%v/%v/stats/participation", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -197,7 +197,7 @@ type PunchCard struct {
// it is now computing the requested statistics. A follow up request, after a // it is now computing the requested statistics. A follow up request, after a
// delay of a second or so, should result in a successful request. // delay of a second or so, should result in a successful request.
// //
// GitHub API docs: https://developer.github.com/v3/repos/statistics/#get-the-hourly-commit-count-for-each-day // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-the-hourly-commit-count-for-each-day
func (s *RepositoriesService) ListPunchCard(ctx context.Context, owner, repo string) ([]*PunchCard, *Response, error) { func (s *RepositoriesService) ListPunchCard(ctx context.Context, owner, repo string) ([]*PunchCard, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/stats/punch_card", owner, repo) u := fmt.Sprintf("repos/%v/%v/stats/punch_card", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)

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