Update go-github

This commit is contained in:
Miguel de la Cruz 2020-09-24 11:13:52 +02:00
parent a13a0ec949
commit da89cad164
115 changed files with 4785 additions and 1606 deletions

View file

@ -6,7 +6,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"github.com/google/go-github/v29/github" "github.com/google/go-github/v32/github"
jira "gopkg.in/andygrunwald/go-jira.v1" jira "gopkg.in/andygrunwald/go-jira.v1"
"git.ctrlz.es/mgdelacroix/campaigner/model" "git.ctrlz.es/mgdelacroix/campaigner/model"

View file

@ -11,7 +11,7 @@ import (
"git.ctrlz.es/mgdelacroix/campaigner/model" "git.ctrlz.es/mgdelacroix/campaigner/model"
"github.com/StevenACoffman/j2m" "github.com/StevenACoffman/j2m"
"github.com/google/go-github/v29/github" "github.com/google/go-github/v32/github"
"golang.org/x/oauth2" "golang.org/x/oauth2"
) )
@ -92,6 +92,8 @@ func (a *App) PublishNextInGithub(dryRun bool) (bool, error) {
return false, err return false, err
} }
// ToDo: print here the newly created issue
if !dryRun { if !dryRun {
if err := a.UpdateJiraAfterGithub(ticket); err != nil { if err := a.UpdateJiraAfterGithub(ticket); err != nil {
fmt.Fprintf(os.Stderr, "error updating Jira info for %s after publishing in Github\n", ticket.JiraLink) fmt.Fprintf(os.Stderr, "error updating Jira info for %s after publishing in Github\n", ticket.JiraLink)

2
go.mod
View file

@ -6,7 +6,7 @@ require (
github.com/StevenACoffman/j2m v0.0.0-20190826163711-7d8d00c99217 github.com/StevenACoffman/j2m v0.0.0-20190826163711-7d8d00c99217
github.com/fatih/color v1.9.0 github.com/fatih/color v1.9.0
github.com/fatih/structs v1.1.0 // indirect github.com/fatih/structs v1.1.0 // indirect
github.com/google/go-github/v29 v29.0.3 github.com/google/go-github/v32 v32.1.0
github.com/spf13/cobra v0.0.6 github.com/spf13/cobra v0.0.6
github.com/trivago/tgo v1.0.7 // indirect github.com/trivago/tgo v1.0.7 // indirect
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be

4
go.sum
View file

@ -40,8 +40,8 @@ github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-github/v29 v29.0.3 h1:IktKCTwU//aFHnpA+2SLIi7Oo9uhAzgsdZNbcAqhgdc= github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II=
github.com/google/go-github/v29 v29.0.3/go.mod h1:CHKiKKPHJ0REzfwc14QMklvtHwCveD0PxlMjLlzAM5E= github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
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/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=

View file

@ -1,132 +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"
)
// PublicKey represents the public key that should be used to encrypt secrets.
type PublicKey struct {
KeyID *string `json:"key_id"`
Key *string `json:"key"`
}
// GetPublicKey gets a public key that should be used for secret encryption.
//
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#get-your-public-key
func (s *ActionsService) GetPublicKey(ctx context.Context, owner, repo string) (*PublicKey, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/secrets/public-key", owner, repo)
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.
type Secret struct {
Name string `json:"name"`
CreatedAt Timestamp `json:"created_at"`
UpdatedAt Timestamp `json:"updated_at"`
}
// Secrets represents one item from the ListSecrets response.
type Secrets struct {
TotalCount int `json:"total_count"`
Secrets []*Secret `json:"secrets"`
}
// ListSecrets lists all secrets available in a repository
// without revealing their encrypted values.
//
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#list-secrets-for-a-repository
func (s *ActionsService) ListSecrets(ctx context.Context, owner, repo string, opts *ListOptions) (*Secrets, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/actions/secrets", 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
}
secrets := new(Secrets)
resp, err := s.client.Do(ctx, req, &secrets)
if err != nil {
return nil, resp, err
}
return secrets, resp, nil
}
// GetSecret gets a single secret without revealing its encrypted value.
//
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#get-a-secret
func (s *ActionsService) GetSecret(ctx context.Context, owner, repo, name string) (*Secret, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/secrets/%v", owner, repo, name)
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
}
// EncryptedSecret represents a secret that is encrypted using a public key.
//
// The value of EncryptedValue must be your secret, encrypted with
// LibSodium (see documentation here: https://libsodium.gitbook.io/doc/bindings_for_other_languages)
// using the public key retrieved using the GetPublicKey method.
type EncryptedSecret struct {
Name string `json:"-"`
KeyID string `json:"key_id"`
EncryptedValue string `json:"encrypted_value"`
}
// CreateOrUpdateSecret creates or updates a secret with an encrypted value.
//
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#create-or-update-a-secret-for-a-repository
func (s *ActionsService) CreateOrUpdateSecret(ctx context.Context, owner, repo string, eSecret *EncryptedSecret) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/secrets/%v", owner, repo, eSecret.Name)
req, err := s.client.NewRequest("PUT", u, eSecret)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// DeleteSecret deletes a secret in a repository using the secret name.
//
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#delete-a-secret-from-a-repository
func (s *ActionsService) DeleteSecret(ctx context.Context, owner, repo, name string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/secrets/%v", 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

@ -1,88 +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"`
NodeID string `json:"node_id"`
Name string `json:"name"`
Path string `json:"path"`
State string `json:"state"`
CreatedAt Timestamp `json:"created_at"`
UpdatedAt Timestamp `json:"updated_at"`
URL string `json:"url"`
HTMLURL string `json:"html_url"`
BadgeURL string `json:"badge_url"`
}
// Workflows represents a slice of repository action workflows.
type Workflows struct {
TotalCount int `json:"total_count"`
Workflows []*Workflow `json:"workflows"`
}
// 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
}

View file

@ -1,43 +0,0 @@
// Copyright 2019 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"
// createOrgRequest is a subset of Organization and is used internally
// by CreateOrg to pass only the known fields for the endpoint.
type createOrgRequest struct {
Login *string `json:"login,omitempty"`
Admin *string `json:"admin,omitempty"`
}
// CreateOrg creates a new organization in GitHub Enterprise.
//
// Note that only a subset of the org fields are used and org must
// not be nil.
//
// GitHub Enterprise API docs: https://developer.github.com/enterprise/v3/enterprise-admin/orgs/#create-an-organization
func (s *AdminService) CreateOrg(ctx context.Context, org *Organization, admin string) (*Organization, *Response, error) {
u := "admin/organizations"
orgReq := &createOrgRequest{
Login: org.Login,
Admin: &admin,
}
req, err := s.client.NewRequest("POST", u, orgReq)
if err != nil {
return nil, nil, err
}
o := new(Organization)
resp, err := s.client.Do(ctx, req, o)
if err != nil {
return nil, resp, err
}
return o, resp, nil
}

View file

@ -1,140 +0,0 @@
// Copyright 2018 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"
)
// DiscussionComment represents a GitHub dicussion in a team.
type DiscussionComment struct {
Author *User `json:"author,omitempty"`
Body *string `json:"body,omitempty"`
BodyHTML *string `json:"body_html,omitempty"`
BodyVersion *string `json:"body_version,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
LastEditedAt *Timestamp `json:"last_edited_at,omitempty"`
DiscussionURL *string `json:"discussion_url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
NodeID *string `json:"node_id,omitempty"`
Number *int `json:"number,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
URL *string `json:"url,omitempty"`
Reactions *Reactions `json:"reactions,omitempty"`
}
func (c DiscussionComment) String() string {
return Stringify(c)
}
// DiscussionCommentListOptions specifies optional parameters to the
// TeamServices.ListComments method.
type DiscussionCommentListOptions struct {
// Sorts the discussion comments by the date they were created.
// Accepted values are asc and desc. Default is desc.
Direction string `url:"direction,omitempty"`
}
// ListComments lists all comments on a team discussion.
// Authenticated user must grant read:discussion scope.
//
// GitHub API docs: https://developer.github.com/v3/teams/discussion_comments/#list-comments
func (s *TeamsService) ListComments(ctx context.Context, teamID int64, discussionNumber int, options *DiscussionCommentListOptions) ([]*DiscussionComment, *Response, error) {
u := fmt.Sprintf("teams/%v/discussions/%v/comments", teamID, discussionNumber)
u, err := addOptions(u, options)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var comments []*DiscussionComment
resp, err := s.client.Do(ctx, req, &comments)
if err != nil {
return nil, resp, err
}
return comments, resp, nil
}
// GetComment gets a specific comment on a team discussion.
// Authenticated user must grant read:discussion scope.
//
// GitHub API docs: https://developer.github.com/v3/teams/discussion_comments/#get-a-single-comment
func (s *TeamsService) GetComment(ctx context.Context, teamID int64, discussionNumber, commentNumber int) (*DiscussionComment, *Response, error) {
u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v", teamID, discussionNumber, commentNumber)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
discussionComment := &DiscussionComment{}
resp, err := s.client.Do(ctx, req, discussionComment)
if err != nil {
return nil, resp, err
}
return discussionComment, resp, nil
}
// CreateComment creates a new discussion post on a team discussion.
// Authenticated user must grant write:discussion scope.
//
// GitHub API docs: https://developer.github.com/v3/teams/discussion_comments/#create-a-comment
func (s *TeamsService) CreateComment(ctx context.Context, teamID int64, discsusionNumber int, comment DiscussionComment) (*DiscussionComment, *Response, error) {
u := fmt.Sprintf("teams/%v/discussions/%v/comments", teamID, discsusionNumber)
req, err := s.client.NewRequest("POST", u, comment)
if err != nil {
return nil, nil, err
}
discussionComment := &DiscussionComment{}
resp, err := s.client.Do(ctx, req, discussionComment)
if err != nil {
return nil, resp, err
}
return discussionComment, resp, nil
}
// EditComment edits the body text of a discussion comment.
// Authenticated user must grant write:discussion scope.
// User is allowed to edit body of a comment only.
//
// GitHub API docs: https://developer.github.com/v3/teams/discussion_comments/#edit-a-comment
func (s *TeamsService) EditComment(ctx context.Context, teamID int64, discussionNumber, commentNumber int, comment DiscussionComment) (*DiscussionComment, *Response, error) {
u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v", teamID, discussionNumber, commentNumber)
req, err := s.client.NewRequest("PATCH", u, comment)
if err != nil {
return nil, nil, err
}
discussionComment := &DiscussionComment{}
resp, err := s.client.Do(ctx, req, discussionComment)
if err != nil {
return nil, resp, err
}
return discussionComment, resp, nil
}
// DeleteComment deletes a comment on a team discussion.
// Authenticated user must grant write:discussion scope.
//
// GitHub API docs: https://developer.github.com/v3/teams/discussion_comments/#delete-a-comment
func (s *TeamsService) DeleteComment(ctx context.Context, teamID int64, discussionNumber, commentNumber int) (*Response, error) {
u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v", teamID, discussionNumber, commentNumber)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}

View file

@ -1,145 +0,0 @@
// Copyright 2018 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"
)
// TeamDiscussion represents a GitHub dicussion in a team.
type TeamDiscussion struct {
Author *User `json:"author,omitempty"`
Body *string `json:"body,omitempty"`
BodyHTML *string `json:"body_html,omitempty"`
BodyVersion *string `json:"body_version,omitempty"`
CommentsCount *int `json:"comments_count,omitempty"`
CommentsURL *string `json:"comments_url,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
LastEditedAt *Timestamp `json:"last_edited_at,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
NodeID *string `json:"node_id,omitempty"`
Number *int `json:"number,omitempty"`
Pinned *bool `json:"pinned,omitempty"`
Private *bool `json:"private,omitempty"`
TeamURL *string `json:"team_url,omitempty"`
Title *string `json:"title,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
URL *string `json:"url,omitempty"`
Reactions *Reactions `json:"reactions,omitempty"`
}
func (d TeamDiscussion) String() string {
return Stringify(d)
}
// DiscussionListOptions specifies optional parameters to the
// TeamServices.ListDiscussions method.
type DiscussionListOptions struct {
// Sorts the discussion by the date they were created.
// Accepted values are asc and desc. Default is desc.
Direction string `url:"direction,omitempty"`
}
// ListDiscussions lists all discussions on team's page.
// Authenticated user must grant read:discussion scope.
//
// GitHub API docs: https://developer.github.com/v3/teams/discussions/#list-discussions
func (s *TeamsService) ListDiscussions(ctx context.Context, teamID int64, options *DiscussionListOptions) ([]*TeamDiscussion, *Response, error) {
u := fmt.Sprintf("teams/%v/discussions", teamID)
u, err := addOptions(u, options)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var teamDiscussions []*TeamDiscussion
resp, err := s.client.Do(ctx, req, &teamDiscussions)
if err != nil {
return nil, resp, err
}
return teamDiscussions, resp, nil
}
// GetDiscussion gets a specific discussion on a team's page.
// Authenticated user must grant read:discussion scope.
//
// GitHub API docs: https://developer.github.com/v3/teams/discussions/#get-a-single-discussion
func (s *TeamsService) GetDiscussion(ctx context.Context, teamID int64, discussionNumber int) (*TeamDiscussion, *Response, error) {
u := fmt.Sprintf("teams/%v/discussions/%v", teamID, discussionNumber)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
teamDiscussion := &TeamDiscussion{}
resp, err := s.client.Do(ctx, req, teamDiscussion)
if err != nil {
return nil, resp, err
}
return teamDiscussion, resp, nil
}
// CreateDiscussion creates a new discussion post on a team's page.
// Authenticated user must grant write:discussion scope.
//
// GitHub API docs: https://developer.github.com/v3/teams/discussions/#create-a-discussion
func (s *TeamsService) CreateDiscussion(ctx context.Context, teamID int64, discussion TeamDiscussion) (*TeamDiscussion, *Response, error) {
u := fmt.Sprintf("teams/%v/discussions", teamID)
req, err := s.client.NewRequest("POST", u, discussion)
if err != nil {
return nil, nil, err
}
teamDiscussion := &TeamDiscussion{}
resp, err := s.client.Do(ctx, req, teamDiscussion)
if err != nil {
return nil, resp, err
}
return teamDiscussion, resp, nil
}
// EditDiscussion edits the title and body text of a discussion post.
// Authenticated user must grant write:discussion scope.
// User is allowed to change Title and Body of a discussion only.
//
// GitHub API docs: https://developer.github.com/v3/teams/discussions/#edit-a-discussion
func (s *TeamsService) EditDiscussion(ctx context.Context, teamID int64, discussionNumber int, discussion TeamDiscussion) (*TeamDiscussion, *Response, error) {
u := fmt.Sprintf("teams/%v/discussions/%v", teamID, discussionNumber)
req, err := s.client.NewRequest("PATCH", u, discussion)
if err != nil {
return nil, nil, err
}
teamDiscussion := &TeamDiscussion{}
resp, err := s.client.Do(ctx, req, teamDiscussion)
if err != nil {
return nil, resp, err
}
return teamDiscussion, resp, nil
}
// DeleteDiscussion deletes a discussion from team's page.
// Authenticated user must grant write:discussion scope.
//
// GitHub API docs: https://developer.github.com/v3/teams/discussions/#delete-a-discussion
func (s *TeamsService) DeleteDiscussion(ctx context.Context, teamID int64, discussionNumber int) (*Response, error) {
u := fmt.Sprintf("teams/%v/discussions/%v", teamID, discussionNumber)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}

View file

@ -1,170 +0,0 @@
// Copyright 2018 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"
)
// TeamListTeamMembersOptions specifies the optional parameters to the
// TeamsService.ListTeamMembers method.
type TeamListTeamMembersOptions struct {
// Role filters members returned by their role in the team. Possible
// values are "all", "member", "maintainer". Default is "all".
Role string `url:"role,omitempty"`
ListOptions
}
// ListTeamMembers lists all of the users who are members of the specified
// team.
//
// GitHub API docs: https://developer.github.com/v3/teams/members/#list-team-members
func (s *TeamsService) ListTeamMembers(ctx context.Context, team int64, opts *TeamListTeamMembersOptions) ([]*User, *Response, error) {
u := fmt.Sprintf("teams/%v/members", team)
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 members []*User
resp, err := s.client.Do(ctx, req, &members)
if err != nil {
return nil, resp, err
}
return members, resp, nil
}
// IsTeamMember checks if a user is a member of the specified team.
//
// GitHub API docs: https://developer.github.com/v3/teams/members/#get-team-member
//
// Deprecated: This API has been marked as deprecated in the Github API docs,
// TeamsService.GetTeamMembership method should be used instead.
func (s *TeamsService) IsTeamMember(ctx context.Context, team int64, user string) (bool, *Response, error) {
u := fmt.Sprintf("teams/%v/members/%v", team, user)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return false, nil, err
}
resp, err := s.client.Do(ctx, req, nil)
member, err := parseBoolResponse(err)
return member, resp, err
}
// GetTeamMembership returns the membership status for a user in a team.
//
// GitHub API docs: https://developer.github.com/v3/teams/members/#get-team-membership
func (s *TeamsService) GetTeamMembership(ctx context.Context, team int64, user string) (*Membership, *Response, error) {
u := fmt.Sprintf("teams/%v/memberships/%v", team, user)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
t := new(Membership)
resp, err := s.client.Do(ctx, req, t)
if err != nil {
return nil, resp, err
}
return t, resp, nil
}
// TeamAddTeamMembershipOptions specifies the optional
// parameters to the TeamsService.AddTeamMembership method.
type TeamAddTeamMembershipOptions struct {
// Role specifies the role the user should have in the team. Possible
// values are:
// member - a normal member of the team
// maintainer - a team maintainer. Able to add/remove other team
// members, promote other team members to team
// maintainer, and edit the teams name and description
//
// Default value is "member".
Role string `json:"role,omitempty"`
}
// AddTeamMembership adds or invites a user to a team.
//
// In order to add a membership between a user and a team, the authenticated
// user must have 'admin' permissions to the team or be an owner of the
// organization that the team is associated with.
//
// If the user is already a part of the team's organization (meaning they're on
// at least one other team in the organization), this endpoint will add the
// user to the team.
//
// If the user is completely unaffiliated with the team's organization (meaning
// they're on none of the organization's teams), this endpoint will send an
// invitation to the user via email. This newly-created membership will be in
// the "pending" state until the user accepts the invitation, at which point
// the membership will transition to the "active" state and the user will be
// added as a member of the team.
//
// GitHub API docs: https://developer.github.com/v3/teams/members/#add-or-update-team-membership
func (s *TeamsService) AddTeamMembership(ctx context.Context, team int64, user string, opts *TeamAddTeamMembershipOptions) (*Membership, *Response, error) {
u := fmt.Sprintf("teams/%v/memberships/%v", team, user)
req, err := s.client.NewRequest("PUT", u, opts)
if err != nil {
return nil, nil, err
}
t := new(Membership)
resp, err := s.client.Do(ctx, req, t)
if err != nil {
return nil, resp, err
}
return t, resp, nil
}
// RemoveTeamMembership removes a user from a team.
//
// GitHub API docs: https://developer.github.com/v3/teams/members/#remove-team-membership
func (s *TeamsService) RemoveTeamMembership(ctx context.Context, team int64, user string) (*Response, error) {
u := fmt.Sprintf("teams/%v/memberships/%v", team, user)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// ListPendingTeamInvitations get pending invitaion list in team.
// Warning: The API may change without advance notice during the preview period.
// Preview features are not supported for production use.
//
// GitHub API docs: https://developer.github.com/v3/teams/members/#list-pending-team-invitations
func (s *TeamsService) ListPendingTeamInvitations(ctx context.Context, team int64, opts *ListOptions) ([]*Invitation, *Response, error) {
u := fmt.Sprintf("teams/%v/invitations", team)
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 pendingInvitations []*Invitation
resp, err := s.client.Do(ctx, req, &pendingInvitations)
if err != nil {
return nil, resp, err
}
return pendingInvitations, resp, nil
}

View file

@ -9,25 +9,30 @@
# their employer, as appropriate). # their employer, as appropriate).
178inaba <masahiro.furudate@gmail.com> 178inaba <masahiro.furudate@gmail.com>
2BFL <imqksl@gmail.com>
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>
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>
ajz01 <azdenek@yahoo.com>
Akeda Bagus <akeda@x-team.com> Akeda Bagus <akeda@x-team.com>
Akhil Mohan <akhilerm@gmail.com> Akhil Mohan <akhilerm@gmail.com>
Alec Thomas <alec@swapoff.org> 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>
Alexander Harkness <me@bearbin.net> Alexander Harkness <me@bearbin.net>
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>
Andreas Garnæs <https://github.com/andreas> Andreas Garnæs <https://github.com/andreas>
Andrew Ryabchun <aryabchun@mail.ua> Andrew Ryabchun <aryabchun@mail.ua>
Andy Grunwald <andygrunwald@gmail.com> Andy Grunwald <andygrunwald@gmail.com>
Andy Hume <andyhume@gmail.com> Andy Hume <andyhume@gmail.com>
Andy Lindeman <andy@lindeman.io> Andy Lindeman <andy@lindeman.io>
angie pinilla <angelinepinilla@gmail.com>
anjanashenoy <anjanashenoy1@gmail.com> 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>
@ -37,6 +42,7 @@ appilon <apilon@hashicorp.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>
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>
@ -51,6 +57,7 @@ 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>
Cami Diez <diezcami@gmail.com> Cami Diez <diezcami@gmail.com>
Carl Johnson <me@carlmjohnson.net>
Carlos Alexandro Becker <caarlos0@gmail.com> Carlos Alexandro Becker <caarlos0@gmail.com>
Carlos Tadeu Panato Junior <ctadeu@gmail.com> Carlos Tadeu Panato Junior <ctadeu@gmail.com>
chandresh-pancholi <chandreshpancholi007@gmail.com> chandresh-pancholi <chandreshpancholi007@gmail.com>
@ -148,9 +155,9 @@ Junya Kono <junya03dance@gmail.com>
Justin Abrahms <justin@abrah.ms> Justin Abrahms <justin@abrah.ms>
Jusung Lee <e.jusunglee@gmail.com> Jusung Lee <e.jusunglee@gmail.com>
jzhoucliqr <jzhou@cliqr.com> jzhoucliqr <jzhou@cliqr.com>
kadern0 <kaderno@gmail.com>
Katrina Owen <kytrinyx@github.com> Katrina Owen <kytrinyx@github.com>
Kautilya Tripathi <tripathi.kautilya@gmail.com> Kautilya Tripathi <tripathi.kautilya@gmail.com>
Kautilya Tripathi <tripathi.kautilya@gmail.com>
Keita Urashima <ursm@ursm.jp> Keita Urashima <ursm@ursm.jp>
Kevin Burke <kev@inburke.com> Kevin Burke <kev@inburke.com>
Konrad Malawski <konrad.malawski@project13.pl> Konrad Malawski <konrad.malawski@project13.pl>
@ -166,9 +173,11 @@ Luke Evers <me@lukevers.com>
Luke Kysow <lkysow@gmail.com> Luke Kysow <lkysow@gmail.com>
Luke Roberts <email@luke-roberts.co.uk> Luke Roberts <email@luke-roberts.co.uk>
Luke Young <luke@hydrantlabs.org> Luke Young <luke@hydrantlabs.org>
lynn [they] <lynncyrin@gmail.com>
Maksim Zhylinski <uzzable@gmail.com> Maksim Zhylinski <uzzable@gmail.com>
Mark Tareshawty <tarebyte@github.com> Mark Tareshawty <tarebyte@github.com>
Martin-Louis Bright <mlbright@gmail.com> Martin-Louis Bright <mlbright@gmail.com>
Martins Sipenko <martins.sipenko@gmail.com>
Marwan Sulaiman <marwan.sameer@gmail.com> Marwan Sulaiman <marwan.sameer@gmail.com>
Masayuki Izumi <m@izum.in> Masayuki Izumi <m@izum.in>
Mat Geist <matgeist@gmail.com> Mat Geist <matgeist@gmail.com>
@ -189,19 +198,23 @@ Nick Spragg <nick.spragg@bbc.co.uk>
Nikhita Raghunath <nikitaraghunath@gmail.com> Nikhita Raghunath <nikitaraghunath@gmail.com>
Noah Zoschke <noah+sso2@convox.com> Noah Zoschke <noah+sso2@convox.com>
ns-cweber <cweber@narrativescience.com> ns-cweber <cweber@narrativescience.com>
Oleg Kovalov <iamolegkovalov@gmail.com>
Ole Orhagen <ole.orhagen@northern.tech> Ole Orhagen <ole.orhagen@northern.tech>
Oleg Kovalov <iamolegkovalov@gmail.com>
Ondřej Kupka <ondra.cap@gmail.com> Ondřej Kupka <ondra.cap@gmail.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>
Parker Moore <parkrmoore@gmail.com> Parker Moore <parkrmoore@gmail.com>
parkhyukjun89 <park.hyukjun89@gmail.com> parkhyukjun89 <park.hyukjun89@gmail.com>
Patrick DeVivo <patrick.devivo@gmail.com>
Patrick Marabeas <patrick@marabeas.io>
Pavel Shtanko <pavel.shtanko@gmail.com> Pavel Shtanko <pavel.shtanko@gmail.com>
Pete Wagner <thepwagner@github.com> 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>
Pratik Mallya <pratik.mallya@gmail.com>
Qais Patankar <qaisjp@gmail.com>
Quang Le Hong <iamquang95@gmail.com> Quang Le Hong <iamquang95@gmail.com>
Quentin Leffray <fiahil@gmail.com> Quentin Leffray <fiahil@gmail.com>
Quinn Slack <qslack@qslack.com> Quinn Slack <qslack@qslack.com>
@ -211,9 +224,11 @@ Radliński Ignacy <radlinsk@student.agh.edu.pl>
Rajat Jindal <rajatjindal83@gmail.com> Rajat Jindal <rajatjindal83@gmail.com>
Rajendra arora <rajendraarora16@yahoo.com> Rajendra arora <rajendraarora16@yahoo.com>
Ranbir Singh <binkkatal.r@gmail.com> Ranbir Singh <binkkatal.r@gmail.com>
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.
Reinier Timmer <reinier.timmer@ah.nl>
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>
@ -221,6 +236,7 @@ Ronak Jain <ronakjain@outlook.in>
Ruben Vereecken <rubenvereecken@gmail.com> Ruben Vereecken <rubenvereecken@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>
Safwan Olaimat <safwan.olaimat@gmail.com> Safwan Olaimat <safwan.olaimat@gmail.com>
Sahil Dua <sahildua2305@gmail.com> Sahil Dua <sahildua2305@gmail.com>
saisi <saisi@users.noreply.github.com> saisi <saisi@users.noreply.github.com>
@ -246,6 +262,7 @@ 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>
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>
@ -261,8 +278,10 @@ Vaibhav Singh <vaibhav.singh.14cse@bml.edu.in>
Varadarajan Aravamudhan <varadaraajan@gmail.com> Varadarajan Aravamudhan <varadaraajan@gmail.com>
Victor Castell <victor@victorcastell.com> Victor Castell <victor@victorcastell.com>
Victor Vrantchan <vrancean+github@gmail.com> Victor Vrantchan <vrancean+github@gmail.com>
vikkyomkar <vikky.omkar@samsung.com>
Vlad Ungureanu <vladu@palantir.com> Vlad Ungureanu <vladu@palantir.com>
Wasim Thabraze <wasim@thabraze.me> Wasim Thabraze <wasim@thabraze.me>
Weslei Juan Moser Pereira <wesleimsr@gmail.com>
Will Maier <wcmaier@gmail.com> Will Maier <wcmaier@gmail.com>
Willem D'Haeseleer <dhwillem@gmail.com> Willem D'Haeseleer <dhwillem@gmail.com>
William Bailey <mail@williambailey.org.uk> William Bailey <mail@williambailey.org.uk>

View file

@ -0,0 +1,164 @@
// 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"
"net/http"
"net/url"
)
// Artifact reprents a GitHub artifact. Artifacts allow sharing
// data between jobs in a workflow and provide storage for data
// once a workflow is complete.
//
// GitHub API docs: https://developer.github.com/v3/actions/artifacts/
type Artifact struct {
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
Name *string `json:"name,omitempty"`
SizeInBytes *int64 `json:"size_in_bytes,omitempty"`
ArchiveDownloadURL *string `json:"archive_download_url,omitempty"`
Expired *bool `json:"expired,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
ExpiresAt *Timestamp `json:"expires_at,omitempty"`
}
// ArtifactList represents a list of GitHub artifacts.
//
// GitHub API docs: https://developer.github.com/v3/actions/artifacts/
type ArtifactList struct {
TotalCount *int64 `json:"total_count,omitempty"`
Artifacts []*Artifact `json:"artifacts,omitempty"`
}
// ListArtifacts lists all artifacts that belong to a repository.
//
// GitHub API docs: https://developer.github.com/v3/actions/artifacts/#list-artifacts-for-a-repository
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, 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
}
artifactList := new(ArtifactList)
resp, err := s.client.Do(ctx, req, artifactList)
if err != nil {
return nil, resp, err
}
return artifactList, resp, nil
}
// ListWorkflowRunArtifacts lists all artifacts that belong to a workflow run.
//
// GitHub API docs: https://developer.github.com/v3/actions/artifacts/#list-workflow-run-artifacts
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, 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
}
artifactList := new(ArtifactList)
resp, err := s.client.Do(ctx, req, artifactList)
if err != nil {
return nil, resp, err
}
return artifactList, resp, nil
}
// GetArtifact gets a specific artifact for a workflow run.
//
// GitHub API docs: https://developer.github.com/v3/actions/artifacts/#get-an-artifact
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)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
artifact := new(Artifact)
resp, err := s.client.Do(ctx, req, artifact)
if err != nil {
return nil, resp, err
}
return artifact, resp, nil
}
// 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
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)
resp, err := s.getDownloadArtifactFromURL(ctx, u, followRedirects)
if err != nil {
return nil, nil, err
}
if resp.StatusCode != http.StatusFound {
return nil, newResponse(resp), fmt.Errorf("unexpected status code: %s", resp.Status)
}
parsedURL, err := url.Parse(resp.Header.Get("Location"))
return parsedURL, newResponse(resp), nil
}
func (s *ActionsService) getDownloadArtifactFromURL(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
}
resp.Body.Close()
// If redirect response is returned, follow it
if followRedirects && resp.StatusCode == http.StatusMovedPermanently {
u = resp.Header.Get("Location")
resp, err = s.getDownloadArtifactFromURL(ctx, u, false)
}
return resp, err
}
// DeleteArtifact deletes a workflow run artifact.
//
// GitHub API docs: https://developer.github.com/v3/actions/artifacts/#delete-an-artifact
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)
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,277 @@
// 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"
)
// RunnerApplicationDownload represents a binary for the self-hosted runner application that can be downloaded.
type RunnerApplicationDownload struct {
OS *string `json:"os,omitempty"`
Architecture *string `json:"architecture,omitempty"`
DownloadURL *string `json:"download_url,omitempty"`
Filename *string `json:"filename,omitempty"`
}
// 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
func (s *ActionsService) ListRunnerApplicationDownloads(ctx context.Context, owner, repo string) ([]*RunnerApplicationDownload, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/runners/downloads", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var rads []*RunnerApplicationDownload
resp, err := s.client.Do(ctx, req, &rads)
if err != nil {
return nil, resp, err
}
return rads, resp, nil
}
// RegistrationToken represents a token that can be used to add a self-hosted runner to a repository.
type RegistrationToken struct {
Token *string `json:"token,omitempty"`
ExpiresAt *Timestamp `json:"expires_at,omitempty"`
}
// 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
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)
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
}
// Runner represents a self-hosted runner registered with a repository.
type Runner struct {
ID *int64 `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
OS *string `json:"os,omitempty"`
Status *string `json:"status,omitempty"`
}
// Runners represents a collection of self-hosted runners for a repository.
type Runners struct {
TotalCount int `json:"total_count"`
Runners []*Runner `json:"runners"`
}
// 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
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, 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
}
// 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
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)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
runner := new(Runner)
resp, err := s.client.Do(ctx, req, runner)
if err != nil {
return nil, resp, err
}
return runner, resp, nil
}
// RemoveToken represents a token that can be used to remove a self-hosted runner from a repository.
type RemoveToken struct {
Token *string `json:"token,omitempty"`
ExpiresAt *Timestamp `json:"expires_at,omitempty"`
}
// 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
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)
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {
return nil, nil, err
}
removeToken := new(RemoveToken)
resp, err := s.client.Do(ctx, req, removeToken)
if err != nil {
return nil, resp, err
}
return removeToken, resp, nil
}
// 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
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)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// 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
func (s *ActionsService) ListOrganizationRunnerApplicationDownloads(ctx context.Context, owner string) ([]*RunnerApplicationDownload, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runners/downloads", owner)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var rads []*RunnerApplicationDownload
resp, err := s.client.Do(ctx, req, &rads)
if err != nil {
return nil, resp, err
}
return rads, resp, nil
}
// 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
func (s *ActionsService) CreateOrganizationRegistrationToken(ctx context.Context, owner string) (*RegistrationToken, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runners/registration-token", owner)
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
}
// 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
func (s *ActionsService) ListOrganizationRunners(ctx context.Context, owner string, opts *ListOptions) (*Runners, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runners", 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
}
runners := &Runners{}
resp, err := s.client.Do(ctx, req, &runners)
if err != nil {
return nil, resp, err
}
return runners, resp, nil
}
// 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
func (s *ActionsService) GetOrganizationRunner(ctx context.Context, owner string, runnerID int64) (*Runner, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runners/%v", owner, runnerID)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
runner := new(Runner)
resp, err := s.client.Do(ctx, req, runner)
if err != nil {
return nil, resp, err
}
return runner, resp, nil
}
// 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
func (s *ActionsService) CreateOrganizationRemoveToken(ctx context.Context, owner string) (*RemoveToken, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runners/remove-token", owner)
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {
return nil, nil, err
}
removeToken := new(RemoveToken)
resp, err := s.client.Do(ctx, req, removeToken)
if err != nil {
return nil, resp, err
}
return removeToken, resp, nil
}
// 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
func (s *ActionsService) RemoveOrganizationRunner(ctx context.Context, owner string, runnerID int64) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/runners/%v", owner, 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,299 @@
// 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"
)
// PublicKey represents the public key that should be used to encrypt secrets.
type PublicKey struct {
KeyID *string `json:"key_id"`
Key *string `json:"key"`
}
// 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
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)
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
}
// 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
func (s *ActionsService) GetOrgPublicKey(ctx context.Context, org string) (*PublicKey, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/secrets/public-key", org)
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.
type Secret struct {
Name string `json:"name"`
CreatedAt Timestamp `json:"created_at"`
UpdatedAt Timestamp `json:"updated_at"`
Visibility string `json:"visibility,omitempty"`
SelectedRepositoriesURL string `json:"selected_repositories_url,omitempty"`
}
// Secrets represents one item from the ListSecrets response.
type Secrets struct {
TotalCount int `json:"total_count"`
Secrets []*Secret `json:"secrets"`
}
// ListRepoSecrets lists all secrets available in a repository
// without revealing their encrypted values.
//
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#list-repository-secrets
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, 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
}
// 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
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)
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
}
// SelectedRepoIDs are the repository IDs that have access to the secret.
type SelectedRepoIDs []int64
// EncryptedSecret represents a secret that is encrypted using a public key.
//
// The value of EncryptedValue must be your secret, encrypted with
// LibSodium (see documentation here: https://libsodium.gitbook.io/doc/bindings_for_other_languages)
// using the public key retrieved using the GetPublicKey method.
type EncryptedSecret struct {
Name string `json:"-"`
KeyID string `json:"key_id"`
EncryptedValue string `json:"encrypted_value"`
Visibility string `json:"visibility,omitempty"`
SelectedRepositoryIDs SelectedRepoIDs `json:"selected_repository_ids,omitempty"`
}
// 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
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)
req, err := s.client.NewRequest("PUT", u, eSecret)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// 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
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)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// ListOrgSecrets lists all secrets available in an organization
// without revealing their encrypted values.
//
// GitHub API docs: https://developer.github.com/v3/actions/secrets/#list-organization-secrets
func (s *ActionsService) ListOrgSecrets(ctx context.Context, org string, opts *ListOptions) (*Secrets, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/secrets", 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
}
secrets := new(Secrets)
resp, err := s.client.Do(ctx, req, &secrets)
if err != nil {
return nil, resp, err
}
return secrets, resp, nil
}
// 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
func (s *ActionsService) GetOrgSecret(ctx context.Context, org, name string) (*Secret, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/secrets/%v", org, name)
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
}
// 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
func (s *ActionsService) CreateOrUpdateOrgSecret(ctx context.Context, org string, eSecret *EncryptedSecret) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/secrets/%v", org, eSecret.Name)
req, err := s.client.NewRequest("PUT", u, eSecret)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// SelectedReposList represents the list of repositories selected for an organization secret.
type SelectedReposList struct {
TotalCount *int `json:"total_count,omitempty"`
Repositories []*Repository `json:"repositories,omitempty"`
}
// 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
func (s *ActionsService) ListSelectedReposForOrgSecret(ctx context.Context, org, name string) (*SelectedReposList, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/secrets/%v/repositories", org, name)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
result := new(SelectedReposList)
resp, err := s.client.Do(ctx, req, result)
if err != nil {
return nil, resp, err
}
return result, resp, nil
}
// 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
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)
type repoIDs struct {
SelectedIDs SelectedRepoIDs `json:"selected_repository_ids,omitempty"`
}
req, err := s.client.NewRequest("PUT", u, repoIDs{SelectedIDs: ids})
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// 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
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)
req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// 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
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)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// 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
func (s *ActionsService) DeleteOrgSecret(ctx context.Context, org, name string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/secrets/%v", org, name)
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,149 @@
// 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"
"net/http"
"net/url"
)
// TaskStep represents a single task step from a sequence of tasks of a job.
type TaskStep struct {
Name *string `json:"name,omitempty"`
Status *string `json:"status,omitempty"`
Conclusion *string `json:"conclusion,omitempty"`
Number *int64 `json:"number,omitempty"`
StartedAt *Timestamp `json:"started_at,omitempty"`
CompletedAt *Timestamp `json:"completed_at,omitempty"`
}
// WorkflowJob represents a repository action workflow job.
type WorkflowJob struct {
ID *int64 `json:"id,omitempty"`
RunID *int64 `json:"run_id,omitempty"`
RunURL *string `json:"run_url,omitempty"`
NodeID *string `json:"node_id,omitempty"`
HeadSHA *string `json:"head_sha,omitempty"`
URL *string `json:"url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
Status *string `json:"status,omitempty"`
Conclusion *string `json:"conclusion,omitempty"`
StartedAt *Timestamp `json:"started_at,omitempty"`
CompletedAt *Timestamp `json:"completed_at,omitempty"`
Name *string `json:"name,omitempty"`
Steps []*TaskStep `json:"steps,omitempty"`
CheckRunURL *string `json:"check_run_url,omitempty"`
}
// Jobs represents a slice of repository action workflow job.
type Jobs struct {
TotalCount *int `json:"total_count,omitempty"`
Jobs []*WorkflowJob `json:"jobs,omitempty"`
}
// ListWorkflowJobsOptions specifies optional parameters to ListWorkflowJobs.
type ListWorkflowJobsOptions struct {
// Filter specifies how jobs should be filtered by their completed_at timestamp.
// Possible values are:
// latest - Returns jobs from the most recent execution of the workflow run
// all - Returns all jobs for a workflow run, including from old executions of the workflow run
//
// Default value is "latest".
Filter string `url:"filter,omitempty"`
ListOptions
}
// 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
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, 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
}
jobs := new(Jobs)
resp, err := s.client.Do(ctx, req, &jobs)
if err != nil {
return nil, resp, err
}
return jobs, resp, nil
}
// 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
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)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
job := new(WorkflowJob)
resp, err := s.client.Do(ctx, req, job)
if err != nil {
return nil, resp, err
}
return job, resp, nil
}
// 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
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)
resp, err := s.getWorkflowLogsFromURL(ctx, u, followRedirects)
if err != nil {
return nil, nil, err
}
if resp.StatusCode != http.StatusFound {
return nil, newResponse(resp), fmt.Errorf("unexpected status code: %s", resp.Status)
}
parsedURL, err := url.Parse(resp.Header.Get("Location"))
return parsedURL, newResponse(resp), err
}
func (s *ActionsService) getWorkflowLogsFromURL(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
}
resp.Body.Close()
// If redirect response is returned, follow it
if followRedirects && resp.StatusCode == http.StatusMovedPermanently {
u = resp.Header.Get("Location")
resp, err = s.getWorkflowLogsFromURL(ctx, u, false)
}
return resp, err
}

View file

@ -0,0 +1,235 @@
// 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"
"net/http"
"net/url"
)
// WorkflowRun represents a repository action workflow run.
type WorkflowRun struct {
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
HeadBranch *string `json:"head_branch,omitempty"`
HeadSHA *string `json:"head_sha,omitempty"`
RunNumber *int `json:"run_number,omitempty"`
Event *string `json:"event,omitempty"`
Status *string `json:"status,omitempty"`
Conclusion *string `json:"conclusion,omitempty"`
WorkflowID *int64 `json:"workflow_id,omitempty"`
URL *string `json:"url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
PullRequests []*PullRequest `json:"pull_requests,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
JobsURL *string `json:"jobs_url,omitempty"`
LogsURL *string `json:"logs_url,omitempty"`
CheckSuiteURL *string `json:"check_suite_url,omitempty"`
ArtifactsURL *string `json:"artifacts_url,omitempty"`
CancelURL *string `json:"cancel_url,omitempty"`
RerunURL *string `json:"rerun_url,omitempty"`
HeadCommit *HeadCommit `json:"head_commit,omitempty"`
WorkflowURL *string `json:"workflow_url,omitempty"`
Repository *Repository `json:"repository,omitempty"`
HeadRepository *Repository `json:"head_repository,omitempty"`
}
// WorkflowRuns represents a slice of repository action workflow run.
type WorkflowRuns struct {
TotalCount *int `json:"total_count,omitempty"`
WorkflowRuns []*WorkflowRun `json:"workflow_runs,omitempty"`
}
// ListWorkflowRunsOptions specifies optional parameters to ListWorkflowRuns.
type ListWorkflowRunsOptions struct {
Actor string `url:"actor,omitempty"`
Branch string `url:"branch,omitempty"`
Event string `url:"event,omitempty"`
Status string `url:"status,omitempty"`
ListOptions
}
// WorkflowRunUsage represents a usage of a specific workflow run.
type WorkflowRunUsage struct {
Billable *WorkflowRunEnvironment `json:"billable,omitempty"`
RunDurationMS *int64 `json:"run_duration_ms,omitempty"`
}
// WorkflowRunEnvironment represents different runner environments available for a workflow run.
type WorkflowRunEnvironment struct {
Ubuntu *WorkflowRunBill `json:"UBUNTU,omitempty"`
MacOS *WorkflowRunBill `json:"MACOS,omitempty"`
Windows *WorkflowRunBill `json:"WINDOWS,omitempty"`
}
// WorkflowRunBill specifies billable time for a specific environment in a workflow run.
type WorkflowRunBill struct {
TotalMS *int64 `json:"total_ms,omitempty"`
Jobs *int `json:"jobs,omitempty"`
}
func (s *ActionsService) listWorkflowRuns(ctx context.Context, endpoint string, opts *ListWorkflowRunsOptions) (*WorkflowRuns, *Response, error) {
u, err := addOptions(endpoint, opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
runs := new(WorkflowRuns)
resp, err := s.client.Do(ctx, req, &runs)
if err != nil {
return nil, resp, err
}
return runs, resp, nil
}
// ListWorkflowRunsByID lists all workflow runs by workflow ID.
//
// GitHub API docs: https://developer.github.com/v3/actions/workflow-runs/#list-workflow-runs
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)
return s.listWorkflowRuns(ctx, u, opts)
}
// ListWorkflowRunsByFileName lists all workflow runs by workflow file name.
//
// GitHub API docs: https://developer.github.com/v3/actions/workflow-runs/#list-workflow-runs
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)
return s.listWorkflowRuns(ctx, u, opts)
}
// 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
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, 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
}
runs := new(WorkflowRuns)
resp, err := s.client.Do(ctx, req, &runs)
if err != nil {
return nil, resp, err
}
return runs, resp, nil
}
// GetWorkflowRunByID gets a specific workflow run by ID.
//
// GitHub API docs: https://developer.github.com/v3/actions/workflow-runs/#get-a-workflow-run
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)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
run := new(WorkflowRun)
resp, err := s.client.Do(ctx, req, run)
if err != nil {
return nil, resp, err
}
return run, resp, nil
}
// RerunWorkflow re-runs a workflow by ID.
//
// GitHub API docs: https://developer.github.com/v3/actions/workflow-runs/#re-run-a-workflow
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)
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// CancelWorkflowRunByID cancels a workflow run by ID.
//
// GitHub API docs: https://developer.github.com/v3/actions/workflow-runs/#cancel-a-workflow-run
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)
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// 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
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)
resp, err := s.getWorkflowLogsFromURL(ctx, u, followRedirects)
if err != nil {
return nil, nil, err
}
if resp.StatusCode != http.StatusFound {
return nil, newResponse(resp), fmt.Errorf("unexpected status code: %s", resp.Status)
}
parsedURL, err := url.Parse(resp.Header.Get("Location"))
return parsedURL, newResponse(resp), err
}
// DeleteWorkflowRunLogs deletes all logs for a workflow run.
//
// GitHub API docs: https://developer.github.com/v3/actions/workflow-runs/#delete-workflow-run-logs
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)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// 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
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)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
workflowRunUsage := new(WorkflowRunUsage)
resp, err := s.client.Do(ctx, req, workflowRunUsage)
if err != nil {
return nil, resp, err
}
return workflowRunUsage, resp, nil
}

View file

@ -0,0 +1,138 @@
// 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

@ -35,7 +35,7 @@ type Feeds struct {
CurrentUser *FeedLink `json:"current_user,omitempty"` CurrentUser *FeedLink `json:"current_user,omitempty"`
CurrentUserActor *FeedLink `json:"current_user_actor,omitempty"` CurrentUserActor *FeedLink `json:"current_user_actor,omitempty"`
CurrentUserOrganization *FeedLink `json:"current_user_organization,omitempty"` CurrentUserOrganization *FeedLink `json:"current_user_organization,omitempty"`
CurrentUserOrganizations []FeedLink `json:"current_user_organizations,omitempty"` CurrentUserOrganizations []*FeedLink `json:"current_user_organizations,omitempty"`
} `json:"_links,omitempty"` } `json:"_links,omitempty"`
} }

View file

@ -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/activity/events/#list-issue-events-for-a-repository // GitHub API docs: https://developer.github.com/v3/issues/events/#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)
@ -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-events-for-an-organization // GitHub API docs: https://developer.github.com/v3/activity/events/#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,7 +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-performed-by-a-user // GitHub API docs: https://developer.github.com/v3/activity/events/#list-events-for-the-authenticated-user
// GitHub API docs: https://developer.github.com/v3/activity/events/#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 {
@ -162,7 +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-that-a-user-has-received // GitHub API docs: https://developer.github.com/v3/activity/events/#list-events-received-by-the-authenticated-user
// GitHub API docs: https://developer.github.com/v3/activity/events/#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 {
@ -192,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-events-for-an-organization // GitHub API docs: https://developer.github.com/v3/activity/events/#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

@ -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-your-notifications // GitHub API docs: https://developer.github.com/v3/activity/notifications/#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-your-notifications-in-a-repository // GitHub API docs: https://developer.github.com/v3/activity/notifications/#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)
@ -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-notifications-as-read-in-a-repository // GitHub API docs: https://developer.github.com/v3/activity/notifications/#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/#view-a-single-thread // GitHub API docs: https://developer.github.com/v3/activity/notifications/#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)
@ -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 // GitHub API docs: https://developer.github.com/v3/activity/notifications/#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)

View file

@ -67,7 +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-being-starred // GitHub API docs: https://developer.github.com/v3/activity/starring/#list-repositories-starred-by-a-user
// GitHub API docs: https://developer.github.com/v3/activity/starring/#list-repositories-starred-by-the-authenticated-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 != "" {
@ -100,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-you-are-starring-a-repository // GitHub API docs: https://developer.github.com/v3/activity/starring/#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)
@ -114,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 // GitHub API docs: https://developer.github.com/v3/activity/starring/#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)
@ -126,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 // GitHub API docs: https://developer.github.com/v3/activity/starring/#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

@ -52,7 +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-being-watched // GitHub API docs: https://developer.github.com/v3/activity/watching/#list-repositories-watched-by-a-user
// GitHub API docs: https://developer.github.com/v3/activity/watching/#list-repositories-watched-by-the-authenticated-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 != "" {

View file

@ -0,0 +1,89 @@
// Copyright 2019 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"
)
// createOrgRequest is a subset of Organization and is used internally
// by CreateOrg to pass only the known fields for the endpoint.
type createOrgRequest struct {
Login *string `json:"login,omitempty"`
Admin *string `json:"admin,omitempty"`
}
// CreateOrg creates a new organization in GitHub Enterprise.
//
// Note that only a subset of the org fields are used and org must
// not be nil.
//
// GitHub Enterprise API docs: https://developer.github.com/enterprise/v3/enterprise-admin/orgs/#create-an-organization
func (s *AdminService) CreateOrg(ctx context.Context, org *Organization, admin string) (*Organization, *Response, error) {
u := "admin/organizations"
orgReq := &createOrgRequest{
Login: org.Login,
Admin: &admin,
}
req, err := s.client.NewRequest("POST", u, orgReq)
if err != nil {
return nil, nil, err
}
o := new(Organization)
resp, err := s.client.Do(ctx, req, o)
if err != nil {
return nil, resp, err
}
return o, resp, nil
}
// renameOrgRequest is a subset of Organization and is used internally
// by RenameOrg and RenameOrgByName to pass only the known fields for the endpoint.
type renameOrgRequest struct {
Login *string `json:"login,omitempty"`
}
// RenameOrgResponse is the response given when renaming an Organization.
type RenameOrgResponse struct {
Message *string `json:"message,omitempty"`
URL *string `json:"url,omitempty"`
}
// RenameOrg renames an organization in GitHub Enterprise.
//
// GitHub Enterprise API docs: https://developer.github.com/enterprise/v3/enterprise-admin/orgs/#rename-an-organization
func (s *AdminService) RenameOrg(ctx context.Context, org *Organization, newName string) (*RenameOrgResponse, *Response, error) {
return s.RenameOrgByName(ctx, *org.Login, newName)
}
// RenameOrgByName renames an organization in GitHub Enterprise using its current name.
//
// GitHub Enterprise API docs: https://developer.github.com/enterprise/v3/enterprise-admin/orgs/#rename-an-organization
func (s *AdminService) RenameOrgByName(ctx context.Context, org, newName string) (*RenameOrgResponse, *Response, error) {
u := fmt.Sprintf("admin/organizations/%v", org)
orgReq := &renameOrgRequest{
Login: &newName,
}
req, err := s.client.NewRequest("PATCH", u, orgReq)
if err != nil {
return nil, nil, err
}
o := new(RenameOrgResponse)
resp, err := s.client.Do(ctx, req, o)
if err != nil {
return nil, resp, err
}
return o, resp, nil
}

View file

@ -123,7 +123,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-a-single-github-app // GitHub API docs: https://developer.github.com/v3/apps/#get-the-authenticated-app
// GitHub API docs: https://developer.github.com/v3/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 != "" {
@ -151,7 +152,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 // GitHub API docs: https://developer.github.com/v3/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 {
@ -177,14 +178,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-a-single-installation // GitHub API docs: https://developer.github.com/v3/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/#list-installations-for-user // GitHub API docs: https://developer.github.com/v3/apps/installations/#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 {
@ -210,9 +211,54 @@ func (s *AppsService) ListUserInstallations(ctx context.Context, opts *ListOptio
return i.Installations, resp, nil return i.Installations, resp, nil
} }
// SuspendInstallation suspends the specified installation.
//
// GitHub API docs: https://developer.github.com/v3/apps/#suspend-an-app-installation
func (s *AppsService) SuspendInstallation(ctx context.Context, id int64) (*Response, error) {
u := fmt.Sprintf("app/installations/%v/suspended", id)
req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// UnsuspendInstallation unsuspends the specified installation.
//
// GitHub API docs: https://developer.github.com/v3/apps/#unsuspend-an-app-installation
func (s *AppsService) UnsuspendInstallation(ctx context.Context, id int64) (*Response, error) {
u := fmt.Sprintf("app/installations/%v/suspended", id)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// DeleteInstallation deletes the specified installation.
//
// GitHub API docs: https://developer.github.com/v3/apps/#delete-an-installation-for-the-authenticated-app
func (s *AppsService) DeleteInstallation(ctx context.Context, id int64) (*Response, error) {
u := fmt.Sprintf("app/installations/%v", id)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
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)
}
// CreateInstallationToken creates a new installation token. // CreateInstallationToken creates a new installation token.
// //
// GitHub API docs: https://developer.github.com/v3/apps/#create-a-new-installation-token // GitHub API docs: https://developer.github.com/v3/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)
@ -235,7 +281,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/#create-a-content-attachment // GitHub API docs: https://developer.github.com/v3/apps/installations/#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)}
@ -258,14 +304,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 // GitHub API docs: https://developer.github.com/v3/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 // GitHub API docs: https://developer.github.com/v3/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))
} }
@ -279,7 +325,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 // GitHub API docs: https://developer.github.com/v3/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))
} }

View file

@ -12,7 +12,7 @@ import (
// 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 // GitHub API docs: https://developer.github.com/v3/apps/installations/#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) ([]*Repository, *Response, error) {
u, err := addOptions("installation/repositories", opts) u, err := addOptions("installation/repositories", opts)
if err != nil { if err != nil {
@ -41,7 +41,7 @@ func (s *AppsService) ListRepos(ctx context.Context, opts *ListOptions) ([]*Repo
// 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-for-an-installation // GitHub API docs: https://developer.github.com/v3/apps/installations/#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) ([]*Repository, *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)
@ -70,7 +70,7 @@ func (s *AppsService) ListUserRepos(ctx context.Context, id int64, opts *ListOpt
// 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-repository-to-installation // GitHub API docs: https://developer.github.com/v3/apps/installations/#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)
@ -90,7 +90,7 @@ 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 docs: https://developer.github.com/v3/apps/installations/#remove-repository-from-installation // GitHub API docs: https://developer.github.com/v3/apps/installations/#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)
@ -104,14 +104,13 @@ func (s *AppsService) RemoveRepository(ctx context.Context, instID, repoID int64
// RevokeInstallationToken revokes an installation token. // RevokeInstallationToken revokes an installation token.
// //
// GitHub docs: https://developer.github.com/v3/apps/installations/#revoke-an-installation-token // GitHub API docs: https://developer.github.com/v3/apps/installations/#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)
if err != nil { if err != nil {
return nil, err return nil, err
} }
req.Header.Set("Accept", mediaTypeRevokeTokenPreview)
return s.client.Do(ctx, req, nil) return s.client.Do(ctx, req, nil)
} }

View file

@ -34,7 +34,7 @@ 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/apps/building-github-apps/creating-github-apps-from-a-manifest/#3-you-exchange-the-temporary-code-to-retrieve-the-app-configuration // GitHub API docs: https://developer.github.com/v3/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)

View file

@ -150,7 +150,8 @@ func (s *MarketplaceService) ListPlanAccountsForAccount(ctx context.Context, acc
// 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/#get-a-users-marketplace-purchases // GitHub API docs: https://developer.github.com/v3/apps/marketplace/#list-subscriptions-for-the-authenticated-user
// GitHub API docs: https://developer.github.com/v3/apps/marketplace/#list-subscriptions-for-the-authenticated-user-stubbed
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

@ -41,6 +41,7 @@ const (
ScopeReadGPGKey Scope = "read:gpg_key" ScopeReadGPGKey Scope = "read:gpg_key"
ScopeWriteGPGKey Scope = "write:gpg_key" ScopeWriteGPGKey Scope = "write:gpg_key"
ScopeAdminGPGKey Scope = "admin:gpg_key" ScopeAdminGPGKey Scope = "admin:gpg_key"
ScopeSecurityEvents Scope = "security_events"
) )
// AuthorizationsService handles communication with the authorization related // AuthorizationsService handles communication with the authorization related
@ -134,137 +135,6 @@ func (a AuthorizationUpdateRequest) String() string {
return Stringify(a) return Stringify(a)
} }
// List the authorizations for the authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#list-your-authorizations
func (s *AuthorizationsService) List(ctx context.Context, opts *ListOptions) ([]*Authorization, *Response, error) {
u := "authorizations"
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 auths []*Authorization
resp, err := s.client.Do(ctx, req, &auths)
if err != nil {
return nil, resp, err
}
return auths, resp, nil
}
// Get a single authorization.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#get-a-single-authorization
func (s *AuthorizationsService) Get(ctx context.Context, id int64) (*Authorization, *Response, error) {
u := fmt.Sprintf("authorizations/%d", id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
a := new(Authorization)
resp, err := s.client.Do(ctx, req, a)
if err != nil {
return nil, resp, err
}
return a, resp, nil
}
// Create a new authorization for the specified OAuth application.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization
func (s *AuthorizationsService) Create(ctx context.Context, auth *AuthorizationRequest) (*Authorization, *Response, error) {
u := "authorizations"
req, err := s.client.NewRequest("POST", u, auth)
if err != nil {
return nil, nil, err
}
a := new(Authorization)
resp, err := s.client.Do(ctx, req, a)
if err != nil {
return nil, resp, err
}
return a, resp, nil
}
// GetOrCreateForApp creates a new authorization for the specified OAuth
// application, only if an authorization for that application doesnt already
// exist for the user.
//
// If a new token is created, the HTTP status code will be "201 Created", and
// the returned Authorization.Token field will be populated. If an existing
// token is returned, the status code will be "200 OK" and the
// Authorization.Token field will be empty.
//
// clientID is the OAuth Client ID with which to create the token.
//
// GitHub API docs:
// https://developer.github.com/v3/oauth_authorizations/#get-or-create-an-authorization-for-a-specific-app
// https://developer.github.com/v3/oauth_authorizations/#get-or-create-an-authorization-for-a-specific-app-and-fingerprint
func (s *AuthorizationsService) GetOrCreateForApp(ctx context.Context, clientID string, auth *AuthorizationRequest) (*Authorization, *Response, error) {
var u string
if auth.Fingerprint == nil || *auth.Fingerprint == "" {
u = fmt.Sprintf("authorizations/clients/%v", clientID)
} else {
u = fmt.Sprintf("authorizations/clients/%v/%v", clientID, *auth.Fingerprint)
}
req, err := s.client.NewRequest("PUT", u, auth)
if err != nil {
return nil, nil, err
}
a := new(Authorization)
resp, err := s.client.Do(ctx, req, a)
if err != nil {
return nil, resp, err
}
return a, resp, nil
}
// Edit a single authorization.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#update-an-existing-authorization
func (s *AuthorizationsService) Edit(ctx context.Context, id int64, auth *AuthorizationUpdateRequest) (*Authorization, *Response, error) {
u := fmt.Sprintf("authorizations/%d", id)
req, err := s.client.NewRequest("PATCH", u, auth)
if err != nil {
return nil, nil, err
}
a := new(Authorization)
resp, err := s.client.Do(ctx, req, a)
if err != nil {
return nil, resp, err
}
return a, resp, nil
}
// Delete a single authorization.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#delete-an-authorization
func (s *AuthorizationsService) Delete(ctx context.Context, id int64) (*Response, error) {
u := fmt.Sprintf("authorizations/%d", id)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// Check if an OAuth token is valid for a specific app. // Check if an OAuth token is valid for a specific app.
// //
// Note that this operation requires the use of BasicAuth, but where the // Note that this operation requires the use of BasicAuth, but where the
@ -273,14 +143,19 @@ func (s *AuthorizationsService) Delete(ctx context.Context, id int64) (*Response
// //
// The returned Authorization.User field will be populated. // The returned Authorization.User field will be populated.
// //
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#check-an-authorization // GitHub API docs: https://developer.github.com/v3/apps/oauth_applications/#check-a-token
func (s *AuthorizationsService) Check(ctx context.Context, clientID string, token string) (*Authorization, *Response, error) { func (s *AuthorizationsService) Check(ctx context.Context, clientID, accessToken string) (*Authorization, *Response, error) {
u := fmt.Sprintf("applications/%v/tokens/%v", clientID, token) u := fmt.Sprintf("applications/%v/token", clientID)
req, err := s.client.NewRequest("GET", u, nil) reqBody := &struct {
AccessToken string `json:"access_token"`
}{AccessToken: accessToken}
req, err := s.client.NewRequest("POST", u, reqBody)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
req.Header.Set("Accept", mediaTypeOAuthAppPreview)
a := new(Authorization) a := new(Authorization)
resp, err := s.client.Do(ctx, req, a) resp, err := s.client.Do(ctx, req, a)
@ -301,14 +176,19 @@ func (s *AuthorizationsService) Check(ctx context.Context, clientID string, toke
// //
// The returned Authorization.User field will be populated. // The returned Authorization.User field will be populated.
// //
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#reset-an-authorization // GitHub API docs: https://developer.github.com/v3/apps/oauth_applications/#reset-a-token
func (s *AuthorizationsService) Reset(ctx context.Context, clientID string, token string) (*Authorization, *Response, error) { func (s *AuthorizationsService) Reset(ctx context.Context, clientID, accessToken string) (*Authorization, *Response, error) {
u := fmt.Sprintf("applications/%v/tokens/%v", clientID, token) u := fmt.Sprintf("applications/%v/token", clientID)
req, err := s.client.NewRequest("POST", u, nil) reqBody := &struct {
AccessToken string `json:"access_token"`
}{AccessToken: accessToken}
req, err := s.client.NewRequest("PATCH", u, reqBody)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
req.Header.Set("Accept", mediaTypeOAuthAppPreview)
a := new(Authorization) a := new(Authorization)
resp, err := s.client.Do(ctx, req, a) resp, err := s.client.Do(ctx, req, a)
@ -325,74 +205,40 @@ func (s *AuthorizationsService) Reset(ctx context.Context, clientID string, toke
// 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/oauth_authorizations/#revoke-an-authorization-for-an-application // GitHub API docs: https://developer.github.com/v3/apps/oauth_applications/#delete-an-app-token
func (s *AuthorizationsService) Revoke(ctx context.Context, clientID string, token string) (*Response, error) { func (s *AuthorizationsService) Revoke(ctx context.Context, clientID, accessToken string) (*Response, error) {
u := fmt.Sprintf("applications/%v/tokens/%v", clientID, token) u := fmt.Sprintf("applications/%v/token", clientID)
req, err := s.client.NewRequest("DELETE", u, nil) reqBody := &struct {
AccessToken string `json:"access_token"`
}{AccessToken: accessToken}
req, err := s.client.NewRequest("DELETE", u, reqBody)
if err != nil { if err != nil {
return nil, err return nil, err
} }
req.Header.Set("Accept", mediaTypeOAuthAppPreview)
return s.client.Do(ctx, req, nil) return s.client.Do(ctx, req, nil)
} }
// ListGrants lists the set of OAuth applications that have been granted
// access to a user's account. This will return one entry for each application
// that has been granted access to the account, regardless of the number of
// tokens an application has generated for the user.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#list-your-grants
func (s *AuthorizationsService) ListGrants(ctx context.Context, opts *ListOptions) ([]*Grant, *Response, error) {
u, err := addOptions("applications/grants", opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
grants := []*Grant{}
resp, err := s.client.Do(ctx, req, &grants)
if err != nil {
return nil, resp, err
}
return grants, resp, nil
}
// GetGrant gets a single OAuth application grant.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#get-a-single-grant
func (s *AuthorizationsService) GetGrant(ctx context.Context, id int64) (*Grant, *Response, error) {
u := fmt.Sprintf("applications/grants/%d", id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
grant := new(Grant)
resp, err := s.client.Do(ctx, req, grant)
if err != nil {
return nil, resp, err
}
return grant, resp, nil
}
// DeleteGrant deletes an OAuth application grant. Deleting an application's // DeleteGrant deletes an OAuth application grant. Deleting an application's
// 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/oauth_authorizations/#delete-a-grant // GitHub API docs: https://developer.github.com/v3/apps/oauth_applications/#delete-an-app-authorization
func (s *AuthorizationsService) DeleteGrant(ctx context.Context, id int64) (*Response, error) { func (s *AuthorizationsService) DeleteGrant(ctx context.Context, clientID, accessToken string) (*Response, error) {
u := fmt.Sprintf("applications/grants/%d", id) u := fmt.Sprintf("applications/%v/grant", clientID)
req, err := s.client.NewRequest("DELETE", u, nil)
reqBody := &struct {
AccessToken string `json:"access_token"`
}{AccessToken: accessToken}
req, err := s.client.NewRequest("DELETE", u, reqBody)
if err != nil { if err != nil {
return nil, err return nil, err
} }
req.Header.Set("Accept", mediaTypeOAuthAppPreview)
return s.client.Do(ctx, req, nil) return s.client.Do(ctx, req, nil)
} }

View file

@ -8,7 +8,6 @@ package github
import ( import (
"context" "context"
"fmt" "fmt"
"net/url"
) )
// ChecksService provides access to the Checks API in the // ChecksService provides access to the Checks API in the
@ -97,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-single-check-run // GitHub API docs: https://developer.github.com/v3/checks/runs/#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)
@ -118,7 +117,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-single-check-suite // GitHub API docs: https://developer.github.com/v3/checks/suites/#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)
@ -144,7 +143,7 @@ type CreateCheckRunOptions struct {
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.)
Conclusion *string `json:"conclusion,omitempty"` // Can be one of "success", "failure", "neutral", "cancelled", "timed_out", or "action_required". (Optional. Required if you provide a status of "completed".) Conclusion *string `json:"conclusion,omitempty"` // Can be one of "success", "failure", "neutral", "cancelled", "skipped", "timed_out", or "action_required". (Optional. Required if you provide a status of "completed".)
StartedAt *Timestamp `json:"started_at,omitempty"` // The time that the check run began. (Optional.) StartedAt *Timestamp `json:"started_at,omitempty"` // The time that the check run began. (Optional.)
CompletedAt *Timestamp `json:"completed_at,omitempty"` // The time the check completed. (Optional. Required if you provide conclusion.) CompletedAt *Timestamp `json:"completed_at,omitempty"` // The time the check completed. (Optional. Required if you provide conclusion.)
Output *CheckRunOutput `json:"output,omitempty"` // Provide descriptive details about the run. (Optional) Output *CheckRunOutput `json:"output,omitempty"` // Provide descriptive details about the run. (Optional)
@ -186,7 +185,7 @@ type UpdateCheckRunOptions struct {
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.)
Conclusion *string `json:"conclusion,omitempty"` // Can be one of "success", "failure", "neutral", "cancelled", "timed_out", or "action_required". (Optional. Required if you provide a status of "completed".) Conclusion *string `json:"conclusion,omitempty"` // Can be one of "success", "failure", "neutral", "cancelled", "skipped", "timed_out", or "action_required". (Optional. Required if you provide a status of "completed".)
CompletedAt *Timestamp `json:"completed_at,omitempty"` // The time the check completed. (Optional. Required if you provide conclusion.) CompletedAt *Timestamp `json:"completed_at,omitempty"` // The time the check completed. (Optional. Required if you provide conclusion.)
Output *CheckRunOutput `json:"output,omitempty"` // Provide descriptive details about the run. (Optional) Output *CheckRunOutput `json:"output,omitempty"` // Provide descriptive details about the run. (Optional)
Actions []*CheckRunAction `json:"actions,omitempty"` // Possible further actions the integrator can perform, which a user may trigger. (Optional.) Actions []*CheckRunAction `json:"actions,omitempty"` // Possible further actions the integrator can perform, which a user may trigger. (Optional.)
@ -215,7 +214,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-annotations-for-a-check-run // GitHub API docs: https://developer.github.com/v3/checks/runs/#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)
@ -256,9 +255,9 @@ 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-specific-ref // GitHub API docs: https://developer.github.com/v3/checks/runs/#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, url.QueryEscape(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)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -322,9 +321,9 @@ 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-specific-ref // GitHub API docs: https://developer.github.com/v3/checks/suites/#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, url.QueryEscape(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)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -370,7 +369,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/#set-preferences-for-check-suites-on-a-repository // GitHub API docs: https://developer.github.com/v3/checks/suites/#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)
@ -418,7 +417,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-check-suite // GitHub API docs: https://developer.github.com/v3/checks/suites/#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)

View file

@ -0,0 +1,117 @@
// 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"
"strconv"
"strings"
)
// CodeScanningService handles communication with the code scanning related
// methods of the GitHub API.
//
// GitHub API docs: https://developer.github.com/v3/code-scanning/
type CodeScanningService service
type Alert struct {
RuleID *string `json:"rule_id,omitempty"`
RuleSeverity *string `json:"rule_severity,omitempty"`
RuleDescription *string `json:"rule_description,omitempty"`
Tool *string `json:"tool,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
Open *bool `json:"open,omitempty"`
ClosedBy *User `json:"closed_by,omitempty"`
ClosedAt *Timestamp `json:"closed_at,omitempty"`
URL *string `json:"url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
}
// ID returns the ID associated with an alert. It is the number at the end of the security alert's URL.
func (a *Alert) ID() int64 {
if a == nil {
return 0
}
s := a.GetHTMLURL()
// Check for an ID to parse at the end of the url
if i := strings.LastIndex(s, "/"); i >= 0 {
s = s[i+1:]
}
// Return the alert ID as a 64-bit integer. Unable to convert or out of range returns 0.
id, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return 0
}
return id
}
// AlertListOptions specifies optional parameters to the CodeScanningService.ListAlerts
// method.
type AlertListOptions struct {
// State of the code scanning alerts to list. Set to closed to list only closed code scanning alerts. Default: open
State string `url:"state,omitempty"`
// Return code scanning alerts for a specific branch reference. The ref must be formatted as heads/<branch name>.
Ref string `url:"ref,omitempty"`
}
// ListAlertsForRepo lists code scanning alerts for a repository.
//
// Lists all open code scanning alerts for the default branch (usually master) and protected branches in a repository.
// 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.
//
// GitHub API docs: https://developer.github.com/v3/code-scanning/#list-code-scanning-alerts-for-a-repository
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, 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 alerts []*Alert
resp, err := s.client.Do(ctx, req, &alerts)
if err != nil {
return nil, resp, err
}
return alerts, resp, nil
}
// GetAlert gets a single code scanning alert for a repository.
//
// 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.
//
// 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
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)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
a := new(Alert)
resp, err := s.client.Do(ctx, req, a)
if err != nil {
return nil, resp, err
}
return a, resp, nil
}

View file

@ -8,7 +8,7 @@ Package github provides a client for using the GitHub API.
Usage: Usage:
import "github.com/google/go-github/v29/github" // with go modules enabled (GO111MODULE=on or outside GOPATH) import "github.com/google/go-github/v32/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

View file

@ -76,6 +76,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) {
payload = &OrganizationEvent{} payload = &OrganizationEvent{}
case "OrgBlockEvent": case "OrgBlockEvent":
payload = &OrgBlockEvent{} payload = &OrgBlockEvent{}
case "PackageEvent":
payload = &PackageEvent{}
case "PageBuildEvent": case "PageBuildEvent":
payload = &PageBuildEvent{} payload = &PageBuildEvent{}
case "PingEvent": case "PingEvent":

View file

@ -468,6 +468,22 @@ type OrgBlockEvent struct {
Installation *Installation `json:"installation,omitempty"` Installation *Installation `json:"installation,omitempty"`
} }
// PackageEvent represents activity related to GitHub Packages.
// The Webhook event name is "package".
//
// This event is triggered when a GitHub Package is published or updated.
//
// GitHub API docs: https://developer.github.com/webhooks/event-payloads/#package
type PackageEvent struct {
// Action is the action that was performed.
// Can be "published" or "updated".
Action *string `json:"action,omitempty"`
Package *Package `json:"package,omitempty"`
Repo *Repository `json:"repository,omitempty"`
Org *Organization `json:"organization,omitempty"`
Sender *User `json:"sender,omitempty"`
}
// PageBuildEvent represents an attempted build of a GitHub Pages site, whether // PageBuildEvent represents an attempted build of a GitHub Pages site, whether
// successful or not. // successful or not.
// The Webhook event name is "page_build". // The Webhook event name is "page_build".
@ -653,7 +669,7 @@ type PushEvent struct {
Head *string `json:"head,omitempty"` Head *string `json:"head,omitempty"`
Ref *string `json:"ref,omitempty"` Ref *string `json:"ref,omitempty"`
Size *int `json:"size,omitempty"` Size *int `json:"size,omitempty"`
Commits []PushEventCommit `json:"commits,omitempty"` Commits []*HeadCommit `json:"commits,omitempty"`
Before *string `json:"before,omitempty"` Before *string `json:"before,omitempty"`
DistinctSize *int `json:"distinct_size,omitempty"` DistinctSize *int `json:"distinct_size,omitempty"`
@ -665,7 +681,7 @@ type PushEvent struct {
BaseRef *string `json:"base_ref,omitempty"` BaseRef *string `json:"base_ref,omitempty"`
Compare *string `json:"compare,omitempty"` Compare *string `json:"compare,omitempty"`
Repo *PushEventRepository `json:"repository,omitempty"` Repo *PushEventRepository `json:"repository,omitempty"`
HeadCommit *PushEventCommit `json:"head_commit,omitempty"` HeadCommit *HeadCommit `json:"head_commit,omitempty"`
Pusher *User `json:"pusher,omitempty"` Pusher *User `json:"pusher,omitempty"`
Sender *User `json:"sender,omitempty"` Sender *User `json:"sender,omitempty"`
Installation *Installation `json:"installation,omitempty"` Installation *Installation `json:"installation,omitempty"`
@ -675,8 +691,8 @@ func (p PushEvent) String() string {
return Stringify(p) return Stringify(p)
} }
// PushEventCommit represents a git commit in a GitHub PushEvent. // HeadCommit represents a git commit in a GitHub PushEvent.
type PushEventCommit struct { type HeadCommit struct {
Message *string `json:"message,omitempty"` Message *string `json:"message,omitempty"`
Author *CommitAuthor `json:"author,omitempty"` Author *CommitAuthor `json:"author,omitempty"`
URL *string `json:"url,omitempty"` URL *string `json:"url,omitempty"`
@ -695,7 +711,7 @@ type PushEventCommit struct {
Modified []string `json:"modified,omitempty"` Modified []string `json:"modified,omitempty"`
} }
func (p PushEventCommit) String() string { func (p HeadCommit) String() string {
return Stringify(p) return Stringify(p)
} }
@ -819,6 +835,9 @@ type RepositoryVulnerabilityAlertEvent struct {
DismissReason *string `json:"dismiss_reason,omitempty"` DismissReason *string `json:"dismiss_reason,omitempty"`
DismissedAt *Timestamp `json:"dismissed_at,omitempty"` DismissedAt *Timestamp `json:"dismissed_at,omitempty"`
} `json:"alert,omitempty"` } `json:"alert,omitempty"`
//The repository of the vulnerable dependency.
Repository *Repository `json:"repository,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.

View file

@ -96,7 +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 // GitHub API docs: https://developer.github.com/v3/gists/#list-gists-for-a-user
// GitHub API docs: https://developer.github.com/v3/gists/#list-gists-for-the-authenticated-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 != "" {
@ -125,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-gists // GitHub API docs: https://developer.github.com/v3/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 {
@ -148,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-gists // GitHub API docs: https://developer.github.com/v3/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 {
@ -171,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-single-gist // GitHub API docs: https://developer.github.com/v3/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)
@ -190,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-specific-revision-of-a-gist // GitHub API docs: https://developer.github.com/v3/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)
@ -228,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/#edit-a-gist // GitHub API docs: https://developer.github.com/v3/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)

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-comments-on-a-gist // GitHub API docs: https://developer.github.com/v3/gists/comments/#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-single-comment // GitHub API docs: https://developer.github.com/v3/gists/comments/#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-comment // GitHub API docs: https://developer.github.com/v3/gists/comments/#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/#edit-a-comment // GitHub API docs: https://developer.github.com/v3/gists/comments/#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-comment // GitHub API docs: https://developer.github.com/v3/gists/comments/#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

@ -31,7 +31,7 @@ type Commit struct {
Committer *CommitAuthor `json:"committer,omitempty"` Committer *CommitAuthor `json:"committer,omitempty"`
Message *string `json:"message,omitempty"` Message *string `json:"message,omitempty"`
Tree *Tree `json:"tree,omitempty"` Tree *Tree `json:"tree,omitempty"`
Parents []Commit `json:"parents,omitempty"` Parents []*Commit `json:"parents,omitempty"`
Stats *CommitStats `json:"stats,omitempty"` Stats *CommitStats `json:"stats,omitempty"`
HTMLURL *string `json:"html_url,omitempty"` HTMLURL *string `json:"html_url,omitempty"`
URL *string `json:"url,omitempty"` URL *string `json:"url,omitempty"`

View file

@ -7,8 +7,6 @@ package github
import ( import (
"context" "context"
"encoding/json"
"errors"
"fmt" "fmt"
"net/url" "net/url"
"strings" "strings"
@ -49,16 +47,12 @@ type updateRefRequest struct {
Force *bool `json:"force"` Force *bool `json:"force"`
} }
// GetRef fetches a single Reference object for a given Git ref. // GetRef fetches a single reference in a repository.
// If there is no exact match, GetRef will return an error.
//
// Note: The GitHub API can return multiple matches.
// If you wish to use this functionality please use the GetRefs() method.
// //
// GitHub API docs: https://developer.github.com/v3/git/refs/#get-a-reference // GitHub API docs: https://developer.github.com/v3/git/refs/#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/refs/%v", owner, repo, url.QueryEscape(ref)) u := fmt.Sprintf("repos/%v/%v/git/ref/%v", owner, repo, refURLEscape(ref))
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
@ -66,82 +60,41 @@ func (s *GitService) GetRef(ctx context.Context, owner string, repo string, ref
r := new(Reference) r := new(Reference)
resp, err := s.client.Do(ctx, req, r) resp, err := s.client.Do(ctx, req, r)
if _, ok := err.(*json.UnmarshalTypeError); ok { if err != nil {
// Multiple refs, means there wasn't an exact match.
return nil, resp, errors.New("multiple matches found for this ref")
} else if _, ok := err.(*ErrorResponse); ok && resp.StatusCode == 404 {
// No ref, there was no match for the ref
return nil, resp, errors.New("no match found for this ref")
} else if err != nil {
return nil, resp, err return nil, resp, err
} }
return r, resp, nil return r, resp, nil
} }
// GetRefs fetches a slice of Reference objects for a given Git ref. // refURLEscape escapes every path segment of the given ref. Those must
// If there is an exact match, only that ref is returned. // not contain escaped "/" - as "%2F" - or github will not recognize it.
// If there is no exact match, GitHub returns all refs that start with ref. func refURLEscape(ref string) string {
// If returned error is nil, there will be at least 1 ref returned. parts := strings.Split(ref, "/")
// For example: for i, s := range parts {
// parts[i] = url.PathEscape(s)
// "heads/featureA" -> ["refs/heads/featureA"] // Exact match, single ref is returned.
// "heads/feature" -> ["refs/heads/featureA", "refs/heads/featureB"] // All refs that start with ref.
// "heads/notexist" -> [] // Returns an error.
//
// GitHub API docs: https://developer.github.com/v3/git/refs/#get-a-reference
func (s *GitService) GetRefs(ctx context.Context, owner string, repo string, ref string) ([]*Reference, *Response, error) {
ref = strings.TrimPrefix(ref, "refs/")
u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, url.QueryEscape(ref))
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
} }
return strings.Join(parts, "/")
var rawJSON json.RawMessage
resp, err := s.client.Do(ctx, req, &rawJSON)
if err != nil {
return nil, resp, err
}
// Prioritize the most common case: a single returned ref.
r := new(Reference)
singleUnmarshalError := json.Unmarshal(rawJSON, r)
if singleUnmarshalError == nil {
return []*Reference{r}, resp, nil
}
// Attempt to unmarshal multiple refs.
var rs []*Reference
multipleUnmarshalError := json.Unmarshal(rawJSON, &rs)
if multipleUnmarshalError == nil {
if len(rs) == 0 {
return nil, resp, fmt.Errorf("unexpected response from GitHub API: an array of refs with length 0")
}
return rs, resp, nil
}
return nil, resp, fmt.Errorf("unmarshalling failed for both single and multiple refs: %s and %s", singleUnmarshalError, multipleUnmarshalError)
} }
// ReferenceListOptions specifies optional parameters to the // ReferenceListOptions specifies optional parameters to the
// GitService.ListRefs method. // GitService.ListMatchingRefs method.
type ReferenceListOptions struct { type ReferenceListOptions struct {
Type string `url:"-"` Ref string `url:"-"`
ListOptions ListOptions
} }
// ListRefs lists all refs in a repository. // ListMatchingRefs lists references in a repository that match a supplied ref.
// Use an empty ref to list all references.
// //
// GitHub API docs: https://developer.github.com/v3/git/refs/#get-all-references // GitHub API docs: https://developer.github.com/v3/git/refs/#list-matching-references
func (s *GitService) ListRefs(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 u string var ref string
if opts != nil && opts.Type != "" { if opts != nil {
u = fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, opts.Type) ref = strings.TrimPrefix(opts.Ref, "refs/")
} else {
u = fmt.Sprintf("repos/%v/%v/git/refs", owner, repo)
} }
u := fmt.Sprintf("repos/%v/%v/git/matching-refs/%v", owner, repo, refURLEscape(ref))
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -212,7 +165,7 @@ func (s *GitService) UpdateRef(ctx context.Context, owner string, repo string, r
// GitHub API docs: https://developer.github.com/v3/git/refs/#delete-a-reference // GitHub API docs: https://developer.github.com/v3/git/refs/#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, url.QueryEscape(ref)) u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, refURLEscape(ref))
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

View file

@ -14,7 +14,7 @@ import (
// Tree represents a GitHub tree. // Tree represents a GitHub tree.
type Tree struct { type Tree struct {
SHA *string `json:"sha,omitempty"` SHA *string `json:"sha,omitempty"`
Entries []TreeEntry `json:"tree,omitempty"` Entries []*TreeEntry `json:"tree,omitempty"`
// Truncated is true if the number of items in the tree // Truncated is true if the number of items in the tree
// exceeded GitHub's maximum limit and the Entries were truncated // exceeded GitHub's maximum limit and the Entries were truncated
@ -125,7 +125,7 @@ type createTree struct {
// 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://developer.github.com/v3/git/trees/#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)
newEntries := make([]interface{}, 0, len(entries)) newEntries := make([]interface{}, 0, len(entries))

View file

@ -46,9 +46,6 @@ const (
// Media Type values to access preview APIs // Media Type values to access preview APIs
// https://developer.github.com/changes/2020-01-10-revoke-installation-token/
mediaTypeRevokeTokenPreview = "application/vnd.github.gambit-preview+json"
// https://developer.github.com/changes/2014-12-09-new-attributes-for-stars-api/ // https://developer.github.com/changes/2014-12-09-new-attributes-for-stars-api/
mediaTypeStarringPreview = "application/vnd.github.v3.star+json" mediaTypeStarringPreview = "application/vnd.github.v3.star+json"
@ -109,9 +106,6 @@ const (
// https://developer.github.com/changes/2018-12-18-interactions-preview/ // https://developer.github.com/changes/2018-12-18-interactions-preview/
mediaTypeInteractionRestrictionsPreview = "application/vnd.github.sombra-preview+json" mediaTypeInteractionRestrictionsPreview = "application/vnd.github.sombra-preview+json"
// https://developer.github.com/changes/2019-02-14-draft-pull-requests/
mediaTypeDraftPreview = "application/vnd.github.shadow-cat-preview+json"
// https://developer.github.com/changes/2019-03-14-enabling-disabling-pages/ // https://developer.github.com/changes/2019-03-14-enabling-disabling-pages/
mediaTypeEnablePagesAPIPreview = "application/vnd.github.switcheroo-preview+json" mediaTypeEnablePagesAPIPreview = "application/vnd.github.switcheroo-preview+json"
@ -135,6 +129,12 @@ const (
// https://developer.github.com/changes/2019-10-03-multi-line-comments/ // https://developer.github.com/changes/2019-10-03-multi-line-comments/
mediaTypeMultiLineCommentsPreview = "application/vnd.github.comfort-fade-preview+json" mediaTypeMultiLineCommentsPreview = "application/vnd.github.comfort-fade-preview+json"
// https://developer.github.com/changes/2019-11-05-deprecated-passwords-and-authorizations-api/
mediaTypeOAuthAppPreview = "application/vnd.github.doctor-strange-preview+json"
// https://developer.github.com/changes/2019-12-03-internal-visibility-changes/
mediaTypeRepositoryVisibilityPreview = "application/vnd.github.nebula-preview+json"
) )
// A Client manages communication with the GitHub API. // A Client manages communication with the GitHub API.
@ -165,6 +165,7 @@ type Client struct {
Apps *AppsService Apps *AppsService
Authorizations *AuthorizationsService Authorizations *AuthorizationsService
Checks *ChecksService Checks *ChecksService
CodeScanning *CodeScanningService
Gists *GistsService Gists *GistsService
Git *GitService Git *GitService
Gitignores *GitignoresService Gitignores *GitignoresService
@ -230,7 +231,7 @@ type RawOptions struct {
Type RawType Type RawType
} }
// addOptions adds the parameters in opt as URL query parameters to s. opt // addOptions adds the parameters in opts as URL query parameters to s. opts
// must be a struct whose fields may contain "url" tags. // must be a struct whose fields may contain "url" tags.
func addOptions(s string, opts interface{}) (string, error) { func addOptions(s string, opts interface{}) (string, error) {
v := reflect.ValueOf(opts) v := reflect.ValueOf(opts)
@ -271,6 +272,7 @@ func NewClient(httpClient *http.Client) *Client {
c.Apps = (*AppsService)(&c.common) c.Apps = (*AppsService)(&c.common)
c.Authorizations = (*AuthorizationsService)(&c.common) c.Authorizations = (*AuthorizationsService)(&c.common)
c.Checks = (*ChecksService)(&c.common) c.Checks = (*ChecksService)(&c.common)
c.CodeScanning = (*CodeScanningService)(&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)
@ -291,16 +293,18 @@ func NewClient(httpClient *http.Client) *Client {
} }
// NewEnterpriseClient returns a new GitHub API client with provided // NewEnterpriseClient returns a new GitHub API client with provided
// base URL and upload URL (often the same URL and is your GitHub Enterprise hostname). // base URL and upload URL (often is your GitHub Enterprise hostname).
// If either URL does not have the suffix "/api/v3/", it will be added automatically. // If the base URL does not have the suffix "/api/v3/", it will be added automatically.
// If a nil httpClient is provided, http.DefaultClient will be used. // If the upload URL does not have the suffix "/api/uploads", it will be added automatically.
// If a nil httpClient is provided, a new http.Client will be used.
// //
// Note that NewEnterpriseClient is a convenience helper only; // Note that NewEnterpriseClient is a convenience helper only;
// its behavior is equivalent to using NewClient, followed by setting // its behavior is equivalent to using NewClient, followed by setting
// the BaseURL and UploadURL fields. // the BaseURL and UploadURL fields.
// //
// Another important thing is that by default, the GitHub Enterprise URL format // Another important thing is that by default, the GitHub Enterprise URL format
// should be http(s)://[hostname]/api/v3 or you will always receive the 406 status code. // should be http(s)://[hostname]/api/v3/ or you will always receive the 406 status code.
// The upload URL format should be http(s)://[hostname]/api/uploads/.
func NewEnterpriseClient(baseURL, uploadURL string, httpClient *http.Client) (*Client, error) { func NewEnterpriseClient(baseURL, uploadURL string, httpClient *http.Client) (*Client, error) {
baseEndpoint, err := url.Parse(baseURL) baseEndpoint, err := url.Parse(baseURL)
if err != nil { if err != nil {
@ -320,8 +324,8 @@ 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/v3/") { if !strings.HasSuffix(uploadEndpoint.Path, "/api/uploads/") {
uploadEndpoint.Path += "api/v3/" uploadEndpoint.Path += "api/uploads/"
} }
c := NewClient(httpClient) c := NewClient(httpClient)
@ -918,6 +922,24 @@ func (c *Client) RateLimits(ctx context.Context) (*RateLimits, *Response, error)
return response.Resources, resp, nil return response.Resources, resp, nil
} }
func setCredentialsAsHeaders(req *http.Request, id, secret string) *http.Request {
// To set extra headers, we must make a copy of the Request so
// that we don't modify the Request we were given. This is required by the
// specification of http.RoundTripper.
//
// Since we are going to modify only req.Header here, we only need a deep copy
// of req.Header.
convertedRequest := new(http.Request)
*convertedRequest = *req
convertedRequest.Header = make(http.Header, len(req.Header))
for k, s := range req.Header {
convertedRequest.Header[k] = append([]string(nil), s...)
}
convertedRequest.SetBasicAuth(id, secret)
return convertedRequest
}
/* /*
UnauthenticatedRateLimitedTransport allows you to make unauthenticated calls UnauthenticatedRateLimitedTransport allows you to make unauthenticated calls
that need to use a higher rate limit associated with your OAuth application. that need to use a higher rate limit associated with your OAuth application.
@ -928,8 +950,8 @@ that need to use a higher rate limit associated with your OAuth application.
} }
client := github.NewClient(t.Client()) client := github.NewClient(t.Client())
This will append the querystring params client_id=xxx&client_secret=yyy to all This will add the client id and secret as a base64-encoded string in the format
requests. ClientID:ClientSecret and apply it as an "Authorization": "Basic" header.
See https://developer.github.com/v3/#unauthenticated-rate-limited-requests for See https://developer.github.com/v3/#unauthenticated-rate-limited-requests for
more information. more information.
@ -958,22 +980,7 @@ func (t *UnauthenticatedRateLimitedTransport) RoundTrip(req *http.Request) (*htt
return nil, errors.New("t.ClientSecret is empty") return nil, errors.New("t.ClientSecret is empty")
} }
// To set extra querystring params, we must make a copy of the Request so req2 := setCredentialsAsHeaders(req, t.ClientID, t.ClientSecret)
// that we don't modify the Request we were given. This is required by the
// specification of http.RoundTripper.
//
// Since we are going to modify only req.URL here, we only need a deep copy
// of req.URL.
req2 := new(http.Request)
*req2 = *req
req2.URL = new(url.URL)
*req2.URL = *req.URL
q := req2.URL.Query()
q.Set("client_id", t.ClientID)
q.Set("client_secret", t.ClientSecret)
req2.URL.RawQuery = q.Encode()
// Make the HTTP request. // Make the HTTP request.
return t.transport().RoundTrip(req2) return t.transport().RoundTrip(req2)
} }
@ -1007,20 +1014,7 @@ type BasicAuthTransport struct {
// RoundTrip implements the RoundTripper interface. // RoundTrip implements the RoundTripper interface.
func (t *BasicAuthTransport) RoundTrip(req *http.Request) (*http.Response, error) { func (t *BasicAuthTransport) RoundTrip(req *http.Request) (*http.Response, error) {
// To set extra headers, we must make a copy of the Request so req2 := setCredentialsAsHeaders(req, t.Username, t.Password)
// that we don't modify the Request we were given. This is required by the
// specification of http.RoundTripper.
//
// Since we are going to modify only req.Header here, we only need a deep copy
// of req.Header.
req2 := new(http.Request)
*req2 = *req
req2.Header = make(http.Header, len(req.Header))
for k, s := range req.Header {
req2.Header[k] = append([]string(nil), s...)
}
req2.SetBasicAuth(t.Username, t.Password)
if t.OTP != "" { if t.OTP != "" {
req2.Header.Set(headerOTP, t.OTP) req2.Header.Set(headerOTP, t.OTP)
} }

View file

@ -29,7 +29,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://developer.github.com/v3/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 {
return nil, nil, err return nil, nil, err
@ -46,8 +46,8 @@ func (s GitignoresService) List(ctx context.Context) ([]string, *Response, error
// Get a Gitignore by name. // Get a Gitignore by name.
// //
// GitHub API docs: https://developer.github.com/v3/gitignore/#get-a-single-template // GitHub API docs: https://developer.github.com/v3/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)
if err != nil { if err != nil {

View file

@ -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/#add-or-update-interaction-restrictions-for-an-organization // GitHub API docs: https://developer.github.com/v3/interactions/orgs/#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)

View file

@ -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/#add-or-update-interaction-restrictions-for-a-repository // GitHub API docs: https://developer.github.com/v3/interactions/repos/#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)

View file

@ -32,8 +32,9 @@ type Issue struct {
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"`
AuthorAssociation *string `json:"author_association,omitempty"`
User *User `json:"user,omitempty"` User *User `json:"user,omitempty"`
Labels []Label `json:"labels,omitempty"` Labels []*Label `json:"labels,omitempty"`
Assignee *User `json:"assignee,omitempty"` Assignee *User `json:"assignee,omitempty"`
Comments *int `json:"comments,omitempty"` Comments *int `json:"comments,omitempty"`
ClosedAt *time.Time `json:"closed_at,omitempty"` ClosedAt *time.Time `json:"closed_at,omitempty"`
@ -55,7 +56,7 @@ type Issue struct {
// 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://developer.github.com/v3/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.
// Possible values are: "off-topic", "too heated", "resolved", and "spam". // Possible values are: "off-topic", "too heated", "resolved", and "spam".
@ -128,7 +129,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 // GitHub API docs: https://developer.github.com/v3/issues/#list-issues-assigned-to-the-authenticated-user
// GitHub API docs: https://developer.github.com/v3/issues/#list-user-account-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 {
@ -142,7 +144,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-issues // GitHub API docs: https://developer.github.com/v3/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)
@ -214,7 +216,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-issues-for-a-repository // GitHub API docs: https://developer.github.com/v3/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)
@ -242,7 +244,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-a-single-issue // GitHub API docs: https://developer.github.com/v3/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)
@ -284,7 +286,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/#edit-an-issue // GitHub API docs: https://developer.github.com/v3/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)

View file

@ -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-assignee // GitHub API docs: https://developer.github.com/v3/issues/assignees/#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)

View file

@ -50,7 +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-comments-on-an-issue // GitHub API docs: https://developer.github.com/v3/issues/comments/#list-issue-comments
// GitHub API docs: https://developer.github.com/v3/issues/comments/#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 {
@ -82,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-a-single-comment // GitHub API docs: https://developer.github.com/v3/issues/comments/#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)
@ -105,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-a-comment // GitHub API docs: https://developer.github.com/v3/issues/comments/#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)
@ -124,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/#edit-a-comment // GitHub API docs: https://developer.github.com/v3/issues/comments/#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)
@ -142,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-a-comment // GitHub API docs: https://developer.github.com/v3/issues/comments/#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

@ -95,7 +95,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-events-for-an-issue // GitHub API docs: https://developer.github.com/v3/issues/events/#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)
@ -122,7 +122,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-events-for-a-repository // GitHub API docs: https://developer.github.com/v3/issues/events/#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 +146,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-a-single-event // GitHub API docs: https://developer.github.com/v3/issues/events/#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-all-labels-for-this-repository // GitHub API docs: https://developer.github.com/v3/issues/labels/#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-single-label // GitHub API docs: https://developer.github.com/v3/issues/labels/#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)
@ -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-on-an-issue // GitHub API docs: https://developer.github.com/v3/issues/labels/#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)
@ -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/#replace-all-labels-for-an-issue // GitHub API docs: https://developer.github.com/v3/issues/labels/#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)
@ -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/#get-labels-for-every-issue-in-a-milestone // GitHub API docs: https://developer.github.com/v3/issues/labels/#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-for-a-repository // GitHub API docs: https://developer.github.com/v3/issues/milestones/#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-single-milestone // GitHub API docs: https://developer.github.com/v3/issues/milestones/#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)

View file

@ -131,7 +131,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-events-for-an-issue // GitHub API docs: https://developer.github.com/v3/issues/timeline/#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

@ -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-an-individual-license // GitHub API docs: https://developer.github.com/v3/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

@ -50,6 +50,7 @@ var (
"deployment": "DeploymentEvent", "deployment": "DeploymentEvent",
"deployment_status": "DeploymentStatusEvent", "deployment_status": "DeploymentStatusEvent",
"fork": "ForkEvent", "fork": "ForkEvent",
"github_app_authorization": "GitHubAppAuthorizationEvent",
"gollum": "GollumEvent", "gollum": "GollumEvent",
"installation": "InstallationEvent", "installation": "InstallationEvent",
"installation_repositories": "InstallationRepositoriesEvent", "installation_repositories": "InstallationRepositoriesEvent",
@ -63,6 +64,7 @@ var (
"milestone": "MilestoneEvent", "milestone": "MilestoneEvent",
"organization": "OrganizationEvent", "organization": "OrganizationEvent",
"org_block": "OrgBlockEvent", "org_block": "OrgBlockEvent",
"package": "PackageEvent",
"page_build": "PageBuildEvent", "page_build": "PageBuildEvent",
"ping": "PingEvent", "ping": "PingEvent",
"project": "ProjectEvent", "project": "ProjectEvent",

View file

@ -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/migration/migrations/#start-a-migration // GitHub API docs: https://developer.github.com/v3/migrations/orgs/#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/#get-a-list-of-organization-migrations // GitHub API docs: https://developer.github.com/v3/migrations/orgs/#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/migration/migrations/#get-the-status-of-a-migration // GitHub API docs: https://developer.github.com/v3/migrations/orgs/#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/migration/migrations/#download-a-migration-archive // GitHub API docs: https://developer.github.com/v3/migrations/orgs/#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/migration/migrations/#delete-a-migration-archive // GitHub API docs: https://developer.github.com/v3/migrations/orgs/#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/migration/migrations/#unlock-a-repository // GitHub API docs: https://developer.github.com/v3/migrations/orgs/#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

@ -106,7 +106,7 @@ type Import struct {
// When the importer finds several projects or repositories at the // When the importer finds several projects or repositories at the
// provided URLs, this will identify the available choices. Call // provided URLs, this will identify the available choices. Call
// UpdateImport with the selected Import value. // UpdateImport with the selected Import value.
ProjectChoices []Import `json:"project_choices,omitempty"` ProjectChoices []*Import `json:"project_choices,omitempty"`
} }
func (i Import) String() string { func (i Import) String() string {
@ -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/migration/source_imports/#start-an-import // GitHub API docs: https://developer.github.com/v3/migrations/source_imports/#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/migration/source_imports/#get-import-progress // GitHub API docs: https://developer.github.com/v3/migrations/source_imports/#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/migration/source_imports/#update-existing-import // GitHub API docs: https://developer.github.com/v3/migrations/source_imports/#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/migration/source_imports/#get-commit-authors // GitHub API docs: https://developer.github.com/v3/migrations/source_imports/#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/migration/source_imports/#map-a-commit-author // GitHub API docs: https://developer.github.com/v3/migrations/source_imports/#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/migration/source_imports/#set-git-lfs-preference // GitHub API docs: https://developer.github.com/v3/migrations/source_imports/#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/migration/source_imports/#get-large-files // GitHub API docs: https://developer.github.com/v3/migrations/source_imports/#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/migration/source_imports/#cancel-an-import // GitHub API docs: https://developer.github.com/v3/migrations/source_imports/#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

@ -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/#get-a-list-of-user-migrations // GitHub API docs: https://developer.github.com/v3/migrations/users/#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-the-status-of-a-user-migration // GitHub API docs: https://developer.github.com/v3/migrations/users/#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)

View file

@ -29,6 +29,7 @@ type Organization struct {
Blog *string `json:"blog,omitempty"` Blog *string `json:"blog,omitempty"`
Location *string `json:"location,omitempty"` Location *string `json:"location,omitempty"`
Email *string `json:"email,omitempty"` Email *string `json:"email,omitempty"`
TwitterUsername *string `json:"twitter_username,omitempty"`
Description *string `json:"description,omitempty"` Description *string `json:"description,omitempty"`
PublicRepos *int `json:"public_repos,omitempty"` PublicRepos *int `json:"public_repos,omitempty"`
PublicGists *int `json:"public_gists,omitempty"` PublicGists *int `json:"public_gists,omitempty"`
@ -45,6 +46,9 @@ type Organization struct {
Type *string `json:"type,omitempty"` Type *string `json:"type,omitempty"`
Plan *Plan `json:"plan,omitempty"` Plan *Plan `json:"plan,omitempty"`
TwoFactorRequirementEnabled *bool `json:"two_factor_requirement_enabled,omitempty"` TwoFactorRequirementEnabled *bool `json:"two_factor_requirement_enabled,omitempty"`
IsVerified *bool `json:"is_verified,omitempty"`
HasOrganizationProjects *bool `json:"has_organization_projects,omitempty"`
HasRepositoryProjects *bool `json:"has_repository_projects,omitempty"`
// DefaultRepoPermission can be one of: "read", "write", "admin", or "none". (Default: "read"). // DefaultRepoPermission can be one of: "read", "write", "admin", or "none". (Default: "read").
// It is only used in OrganizationsService.Edit. // It is only used in OrganizationsService.Edit.
@ -121,7 +125,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-all-organizations // GitHub API docs: https://developer.github.com/v3/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 {
@ -144,7 +148,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/#list-user-organizations // GitHub API docs: https://developer.github.com/v3/orgs/#oauth-scope-requirements
// GitHub API docs: https://developer.github.com/v3/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 != "" {
@ -214,7 +219,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/#edit-an-organization // GitHub API docs: https://developer.github.com/v3/orgs/#members_can_create_repositories
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)
@ -236,7 +241,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-installations-for-an-organization // GitHub API docs: https://developer.github.com/v3/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)

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-hooks // GitHub API docs: https://developer.github.com/v3/orgs/hooks/#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-single-hook // GitHub API docs: https://developer.github.com/v3/orgs/hooks/#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-a-hook // GitHub API docs: https://developer.github.com/v3/orgs/hooks/#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/#edit-a-hook // GitHub API docs: https://developer.github.com/v3/orgs/hooks/#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-a-hook // GitHub API docs: https://developer.github.com/v3/orgs/hooks/#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-a-hook // GitHub API docs: https://developer.github.com/v3/orgs/hooks/#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,7 +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/#members-list // GitHub API docs: https://developer.github.com/v3/orgs/members/#list-organization-members
// GitHub API docs: https://developer.github.com/v3/orgs/members/#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 {
@ -100,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-membership // GitHub API docs: https://developer.github.com/v3/orgs/members/#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)
@ -115,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-membership // GitHub API docs: https://developer.github.com/v3/orgs/members/#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)
@ -130,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-a-member // GitHub API docs: https://developer.github.com/v3/orgs/members/#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)
@ -144,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/#publicize-a-users-membership // GitHub API docs: https://developer.github.com/v3/orgs/members/#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)
@ -157,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/#conceal-a-users-membership // GitHub API docs: https://developer.github.com/v3/orgs/members/#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)
@ -180,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-your-organization-memberships // GitHub API docs: https://developer.github.com/v3/orgs/members/#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)
@ -206,9 +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: // GitHub API docs: https://developer.github.com/v3/orgs/members/#get-an-organization-membership-for-the-authenticated-user
// https://developer.github.com/v3/orgs/members/#get-organization-membership // GitHub API docs: https://developer.github.com/v3/orgs/members/#get-organization-membership-for-a-user
// https://developer.github.com/v3/orgs/members/#get-your-organization-membership
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/#add-or-update-organization-membership // GitHub API docs: https://developer.github.com/v3/orgs/members/#update-an-organization-membership-for-the-authenticated-user
// GitHub API docs: https://developer.github.com/v3/orgs/members/#edit-your-organization-membership // GitHub API docs: https://developer.github.com/v3/orgs/members/#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 // GitHub API docs: https://developer.github.com/v3/orgs/members/#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)
@ -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.
// //
// https://developer.github.com/v3/orgs/members/#create-organization-invitation // GitHub API docs: https://developer.github.com/v3/orgs/members/#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)

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 // GitHub API docs: https://developer.github.com/v3/orgs/outside_collaborators/#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 // GitHub API docs: https://developer.github.com/v3/orgs/outside_collaborators/#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-member-to-outside-collaborator // GitHub API docs: https://developer.github.com/v3/orgs/outside_collaborators/#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 (
// 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-blocked-users // GitHub API docs: https://developer.github.com/v3/orgs/blocking/#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-whether-a-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
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 // GitHub API docs: https://developer.github.com/v3/orgs/blocking/#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 // GitHub API docs: https://developer.github.com/v3/orgs/blocking/#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

@ -0,0 +1,101 @@
// 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
// Package represents a GitHub package.
type Package struct {
ID *int64 `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
PackageType *string `json:"package_type,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
Owner *User `json:"owner,omitempty"`
PackageVersion *PackageVersion `json:"package_version,omitempty"`
Registry *PackageRegistry `json:"registry,omitempty"`
}
func (p Package) String() string {
return Stringify(p)
}
// PackageVersion represents a GitHub package version.
type PackageVersion struct {
ID *int64 `json:"id,omitempty"`
Version *string `json:"version,omitempty"`
Summary *string `json:"summary,omitempty"`
Body *string `json:"body,omitempty"`
BodyHTML *string `json:"body_html,omitempty"`
Release *PackageRelease `json:"release,omitempty"`
Manifest *string `json:"manifest,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
TagName *string `json:"tag_name,omitempty"`
TargetCommitish *string `json:"target_commitish,omitempty"`
TargetOID *string `json:"target_oid,omitempty"`
Draft *bool `json:"draft,omitempty"`
Prerelease *bool `json:"prerelease,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
PackageFiles []*PackageFile `json:"package_files,omitempty"`
Author *User `json:"author,omitempty"`
InstallationCommand *string `json:"installation_command,omitempty"`
}
func (pv PackageVersion) String() string {
return Stringify(pv)
}
// PackageRelease represents a GitHub package version release.
type PackageRelease struct {
URL *string `json:"url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
ID *int64 `json:"id,omitempty"`
TagName *string `json:"tag_name,omitempty"`
TargetCommitish *string `json:"target_commitish,omitempty"`
Name *string `json:"name,omitempty"`
Draft *bool `json:"draft,omitempty"`
Author *User `json:"author,omitempty"`
Prerelease *bool `json:"prerelease,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
PublishedAt *Timestamp `json:"published_at,omitempty"`
}
func (r PackageRelease) String() string {
return Stringify(r)
}
// PackageFile represents a GitHub package version release file.
type PackageFile struct {
DownloadURL *string `json:"download_url,omitempty"`
ID *int64 `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
SHA256 *string `json:"sha256,omitempty"`
SHA1 *string `json:"sha1,omitempty"`
MD5 *string `json:"md5,omitempty"`
ContentType *string `json:"content_type,omitempty"`
State *string `json:"state,omitempty"`
Author *User `json:"author,omitempty"`
Size *int64 `json:"size,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
}
func (pf PackageFile) String() string {
return Stringify(pf)
}
// PackageRegistry represents a GitHub package registry.
type PackageRegistry struct {
AboutURL *string `json:"about_url,omitempty"`
Name *string `json:"name,omitempty"`
Type *string `json:"type,omitempty"`
URL *string `json:"url,omitempty"`
Vendor *string `json:"vendor,omitempty"`
}
func (r PackageRegistry) String() string {
return Stringify(r)
}

View file

@ -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-user-as-a-collaborator // GitHub API docs: https://developer.github.com/v3/projects/collaborators/#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-user-as-a-collaborator // GitHub API docs: https://developer.github.com/v3/projects/collaborators/#remove-project-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-collaborators // GitHub API docs: https://developer.github.com/v3/projects/collaborators/#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/#review-a-users-permission-level // GitHub API docs: https://developer.github.com/v3/projects/collaborators/#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

@ -149,7 +149,7 @@ func (s *PullRequestsService) List(ctx context.Context, owner string, repo strin
} }
// TODO: remove custom Accept header when this API fully launches. // TODO: remove custom Accept header when this API fully launches.
acceptHeaders := []string{mediaTypeLockReasonPreview, mediaTypeDraftPreview} acceptHeaders := []string{mediaTypeLockReasonPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
var pulls []*PullRequest var pulls []*PullRequest
@ -165,7 +165,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-commit // GitHub API docs: https://developer.github.com/v3/repos/commits/#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,7 +179,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, mediaTypeDraftPreview, mediaTypeLockReasonPreview} acceptHeaders := []string{mediaTypeListPullsOrBranchesForCommitPreview, mediaTypeLockReasonPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) 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)
@ -192,7 +192,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-single-pull-request // GitHub API docs: https://developer.github.com/v3/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)
@ -201,7 +201,7 @@ func (s *PullRequestsService) Get(ctx context.Context, owner string, repo string
} }
// TODO: remove custom Accept header when this API fully launches. // TODO: remove custom Accept header when this API fully launches.
acceptHeaders := []string{mediaTypeLockReasonPreview, mediaTypeDraftPreview} acceptHeaders := []string{mediaTypeLockReasonPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
pull := new(PullRequest) pull := new(PullRequest)
@ -214,6 +214,8 @@ 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
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)
@ -260,10 +262,6 @@ func (s *PullRequestsService) Create(ctx context.Context, owner string, repo str
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept header when this API fully launches.
acceptHeaders := []string{mediaTypeDraftPreview}
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 {
@ -419,7 +417,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/#get-if-a-pull-request-has-been-merged // GitHub API docs: https://developer.github.com/v3/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)
@ -441,7 +439,7 @@ type PullRequestMergeResult struct {
// PullRequestOptions lets you define how a pull request will be merged. // PullRequestOptions lets you define how a pull request will be merged.
type PullRequestOptions struct { type PullRequestOptions struct {
CommitTitle string // Extra detail to append to automatic commit message. (Optional.) CommitTitle string // Title for the automatic commit message. (Optional.)
SHA string // SHA that pull request head must match to allow merge. (Optional.) SHA string // SHA that pull request head must match to allow merge. (Optional.)
// 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.)
@ -449,16 +447,16 @@ type PullRequestOptions struct {
} }
type pullRequestMergeRequest struct { type pullRequestMergeRequest struct {
CommitMessage string `json:"commit_message"` 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 Button™). // Merge a pull request.
// commitMessage is the title for the 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-merge-buttontrade // GitHub API docs: https://developer.github.com/v3/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)

View file

@ -66,7 +66,8 @@ 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-comments-on-a-pull-request // GitHub API docs: https://developer.github.com/v3/pulls/comments/#list-review-comments-on-a-pull-request
// GitHub API docs: https://developer.github.com/v3/pulls/comments/#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 string, repo string, number int, opts *PullRequestListCommentsOptions) ([]*PullRequestComment, *Response, error) {
var u string var u string
if number == 0 { if number == 0 {
@ -99,7 +100,7 @@ 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-single-comment // GitHub API docs: https://developer.github.com/v3/pulls/comments/#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 string, 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)
@ -122,7 +123,7 @@ 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-comment // GitHub API docs: https://developer.github.com/v3/pulls/comments/#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 string, 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)
@ -144,7 +145,7 @@ 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/#alternative-input // GitHub API docs: https://developer.github.com/v3/pulls/comments/#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 string, 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"`
@ -171,7 +172,7 @@ 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/#edit-a-comment // GitHub API docs: https://developer.github.com/v3/pulls/comments/#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 string, 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)
@ -190,7 +191,7 @@ 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-comment // GitHub API docs: https://developer.github.com/v3/pulls/comments/#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 string, 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)

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/#create-a-review-request // GitHub API docs: https://developer.github.com/v3/pulls/review_requests/#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-review-requests // GitHub API docs: https://developer.github.com/v3/pulls/review_requests/#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/#delete-a-review-request // GitHub API docs: https://developer.github.com/v3/pulls/review_requests/#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

@ -7,10 +7,13 @@ package github
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"time" "time"
) )
var ErrMixedCommentStyles = errors.New("cannot use both position and side/line form comments")
// PullRequestReview represents a review of a pull request. // PullRequestReview represents a review of a pull request.
type PullRequestReview struct { type PullRequestReview struct {
ID *int64 `json:"id,omitempty"` ID *int64 `json:"id,omitempty"`
@ -36,6 +39,12 @@ type DraftReviewComment struct {
Path *string `json:"path,omitempty"` Path *string `json:"path,omitempty"`
Position *int `json:"position,omitempty"` Position *int `json:"position,omitempty"`
Body *string `json:"body,omitempty"` Body *string `json:"body,omitempty"`
// The new comfort-fade-preview fields
StartSide *string `json:"start_side,omitempty"`
Side *string `json:"side,omitempty"`
StartLine *int `json:"start_line,omitempty"`
Line *int `json:"line,omitempty"`
} }
func (c DraftReviewComment) String() string { func (c DraftReviewComment) String() string {
@ -55,6 +64,32 @@ func (r PullRequestReviewRequest) String() string {
return Stringify(r) return Stringify(r)
} }
func (r PullRequestReviewRequest) isComfortFadePreview() (bool, error) {
var isCF *bool
for _, comment := range r.Comments {
if comment == nil {
continue
}
hasPos := comment.Position != nil
hasComfortFade := (comment.StartSide != nil) || (comment.Side != nil) ||
(comment.StartLine != nil) || (comment.Line != nil)
switch {
case hasPos && hasComfortFade:
return false, ErrMixedCommentStyles
case hasPos && isCF != nil && *isCF:
return false, ErrMixedCommentStyles
case hasComfortFade && isCF != nil && !*isCF:
return false, ErrMixedCommentStyles
}
isCF = &hasComfortFade
}
if isCF != nil {
return *isCF, nil
}
return false, nil
}
// PullRequestReviewDismissalRequest represents a request to dismiss a review. // PullRequestReviewDismissalRequest represents a request to dismiss a review.
type PullRequestReviewDismissalRequest struct { type PullRequestReviewDismissalRequest struct {
Message *string `json:"message,omitempty"` Message *string `json:"message,omitempty"`
@ -70,7 +105,7 @@ func (r PullRequestReviewDismissalRequest) String() 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/#list-reviews-on-a-pull-request // 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)
@ -98,7 +133,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-single-review // GitHub API docs: https://developer.github.com/v3/pulls/reviews/#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)
@ -122,7 +157,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 // GitHub API docs: https://developer.github.com/v3/pulls/reviews/#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)
@ -146,7 +181,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/#get-comments-for-a-single-review // GitHub API docs: https://developer.github.com/v3/pulls/reviews/#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)
@ -174,7 +209,39 @@ 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-pull-request-review // GitHub API docs: https://developer.github.com/v3/pulls/reviews/#create-a-review-for-a-pull-request
//
// 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:
// [Start]Side, and [Start]Line.
// These new fields must be used for ALL comments (including single-line),
// with the following restrictions (empirically observed, so subject to change).
//
// For single-line "comfort fade" comments, you must use:
//
// Path: &path, // as before
// Body: &body, // as before
// Side: &"RIGHT" (or "LEFT")
// Line: &123, // NOT THE SAME AS POSITION, this is an actual line number.
//
// If StartSide or StartLine is used with single-line comments, a 422 is returned.
//
// For multi-line "comfort fade" comments, you must use:
//
// Path: &path, // as before
// Body: &body, // as before
// StartSide: &"RIGHT" (or "LEFT")
// Side: &"RIGHT" (or "LEFT")
// StartLine: &120,
// Line: &125,
//
// Suggested edits are made by commenting on the lines to replace, and including the
// suggested edit in a block like this (it may be surrounded in non-suggestion markdown):
//
// ```suggestion
// Use this instead.
// It is waaaaaay better.
// ```
func (s *PullRequestsService) CreateReview(ctx context.Context, owner, repo string, number int, review *PullRequestReviewRequest) (*PullRequestReview, *Response, error) { func (s *PullRequestsService) CreateReview(ctx context.Context, owner, repo string, number int, review *PullRequestReviewRequest) (*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)
@ -183,6 +250,15 @@ func (s *PullRequestsService) CreateReview(ctx context.Context, owner, repo stri
return nil, nil, err return nil, nil, err
} }
// Detect which style of review comment is being used.
if isCF, err := review.isComfortFadePreview(); err != nil {
return nil, nil, err
} else if isCF {
// If the review comments are using the comfort fade preview fields,
// then pass the comfort fade header.
req.Header.Set("Accept", mediaTypeMultiLineCommentsPreview)
}
r := new(PullRequestReview) r := new(PullRequestReview)
resp, err := s.client.Do(ctx, req, r) resp, err := s.client.Do(ctx, req, r)
if err != nil { if err != nil {
@ -194,7 +270,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-pull-request-review // GitHub API docs: https://developer.github.com/v3/pulls/reviews/#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"`
@ -221,7 +297,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-pull-request-review // GitHub API docs: https://developer.github.com/v3/pulls/reviews/#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)
@ -245,7 +321,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-pull-request-review // GitHub API docs: https://developer.github.com/v3/pulls/reviews/#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

@ -8,6 +8,7 @@ package github
import ( import (
"context" "context"
"fmt" "fmt"
"net/http"
) )
// ReactionsService provides access to the reactions-related functions in the // ReactionsService provides access to the reactions-related functions in the
@ -88,7 +89,7 @@ func (s *ReactionsService) ListCommentReactions(ctx context.Context, owner, repo
// 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".
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-a-commit-comment // GitHub API docs: https://developer.github.com/v3/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)
body := &Reaction{Content: String(content)} body := &Reaction{Content: String(content)}
@ -109,6 +110,24 @@ func (s ReactionsService) CreateCommentReaction(ctx context.Context, owner, repo
return m, resp, nil return m, resp, nil
} }
// DeleteCommentReaction deletes the reaction for a commit comment.
//
// GitHub API docs: https://developer.github.com/v3/reactions/#delete-a-commit-comment-reaction
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)
return s.deleteReaction(ctx, u)
}
// 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
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)
return s.deleteReaction(ctx, u)
}
// 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://developer.github.com/v3/reactions/#list-reactions-for-an-issue
@ -142,7 +161,7 @@ func (s *ReactionsService) ListIssueReactions(ctx context.Context, owner, repo s
// 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".
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-an-issue // GitHub API docs: https://developer.github.com/v3/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)
body := &Reaction{Content: String(content)} body := &Reaction{Content: String(content)}
@ -163,6 +182,24 @@ func (s ReactionsService) CreateIssueReaction(ctx context.Context, owner, repo s
return m, resp, nil return m, resp, nil
} }
// DeleteIssueReaction deletes the reaction to an issue.
//
// GitHub API docs: https://developer.github.com/v3/reactions/#delete-an-issue-reaction
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)
return s.deleteReaction(ctx, url)
}
// DeleteIssueReactionByID deletes the reaction to an issue by repository ID.
//
// GitHub API docs: https://developer.github.com/v3/reactions/#delete-an-issue-reaction
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)
return s.deleteReaction(ctx, url)
}
// 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://developer.github.com/v3/reactions/#list-reactions-for-an-issue-comment
@ -196,7 +233,7 @@ func (s *ReactionsService) ListIssueCommentReactions(ctx context.Context, owner,
// 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".
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-an-issue-comment // GitHub API docs: https://developer.github.com/v3/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)
body := &Reaction{Content: String(content)} body := &Reaction{Content: String(content)}
@ -217,9 +254,27 @@ func (s ReactionsService) CreateIssueCommentReaction(ctx context.Context, owner,
return m, resp, nil return m, resp, nil
} }
// DeleteIssueCommentReaction deletes the reaction to an issue comment.
//
// GitHub API docs: https://developer.github.com/v3/reactions/#delete-an-issue-comment-reaction
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)
return s.deleteReaction(ctx, url)
}
// 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
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)
return s.deleteReaction(ctx, url)
}
// 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-an-issue-comment // GitHub API docs: https://developer.github.com/v3/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)
@ -249,8 +304,8 @@ func (s *ReactionsService) ListPullRequestCommentReactions(ctx context.Context,
// 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".
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-an-issue-comment // GitHub API docs: https://developer.github.com/v3/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)
body := &Reaction{Content: String(content)} body := &Reaction{Content: String(content)}
@ -271,9 +326,27 @@ func (s ReactionsService) CreatePullRequestCommentReaction(ctx context.Context,
return m, resp, nil return m, resp, nil
} }
// 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
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)
return s.deleteReaction(ctx, url)
}
// 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
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)
return s.deleteReaction(ctx, url)
}
// 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 // GitHub API docs: https://developer.github.com/v3/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)
@ -300,7 +373,7 @@ 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".
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-a-team-discussion // GitHub API docs: https://developer.github.com/v3/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)
@ -321,9 +394,27 @@ func (s *ReactionsService) CreateTeamDiscussionReaction(ctx context.Context, tea
return m, resp, nil return m, resp, nil
} }
// DeleteTeamDiscussionReaction deletes the reaction to a team discussion.
//
// GitHub API docs: https://developer.github.com/v3/reactions/#delete-team-discussion-reaction
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)
return s.deleteReaction(ctx, url)
}
// 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
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)
return s.deleteReaction(ctx, url)
}
// 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 // GitHub API docs: https://developer.github.com/v3/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)
@ -349,7 +440,7 @@ func (s *ReactionsService) ListTeamDiscussionCommentReactions(ctx context.Contex
// 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".
// //
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-a-team-discussion-comment // GitHub API docs: https://developer.github.com/v3/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)
@ -370,18 +461,31 @@ func (s *ReactionsService) CreateTeamDiscussionCommentReaction(ctx context.Conte
return m, resp, nil return m, resp, nil
} }
// DeleteReaction deletes a reaction. // DeleteTeamDiscussionCommentReaction deletes the reaction to a team discussion comment.
// //
// GitHub API docs: https://developer.github.com/v3/reaction/reactions/#delete-a-reaction-archive // GitHub API docs: https://developer.github.com/v3/reactions/#delete-team-discussion-comment-reaction
func (s *ReactionsService) DeleteReaction(ctx context.Context, id int64) (*Response, error) { func (s *ReactionsService) DeleteTeamDiscussionCommentReaction(ctx context.Context, org, teamSlug string, discussionNumber, commentNumber int, reactionID int64) (*Response, error) {
u := fmt.Sprintf("reactions/%v", id) url := fmt.Sprintf("orgs/%v/teams/%v/discussions/%v/comments/%v/reactions/%v", org, teamSlug, discussionNumber, commentNumber, reactionID)
req, err := s.client.NewRequest("DELETE", u, nil) return s.deleteReaction(ctx, url)
}
// 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
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)
return s.deleteReaction(ctx, url)
}
func (s *ReactionsService) deleteReaction(ctx context.Context, url string) (*Response, error) {
req, err := s.client.NewRequest(http.MethodDelete, url, nil)
if err != nil { if err != nil {
return nil, err return 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", mediaTypeReactionsPreview) req.Header.Set("Accept", mediaTypeReactionsPreview)
return s.client.Do(ctx, req, nil) return s.client.Do(ctx, req, nil)

View file

@ -120,7 +120,12 @@ type Repository struct {
// 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://developer.github.com/v3/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
// overrides the field parameter when both are used.
// Can be one of public, private or internal.
Visibility *string `json:"visibility,omitempty"`
} }
func (r Repository) String() string { func (r Repository) String() string {
@ -177,7 +182,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-user-repositories // GitHub API docs: https://developer.github.com/v3/repos/#list-repositories-for-a-user
// GitHub API docs: https://developer.github.com/v3/repos/#list-repositories-for-the-authenticated-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 != "" {
@ -263,7 +269,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-all-public-repositories // GitHub API docs: https://developer.github.com/v3/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 {
@ -296,6 +302,7 @@ type createRepoRequest struct {
Homepage *string `json:"homepage,omitempty"` Homepage *string `json:"homepage,omitempty"`
Private *bool `json:"private,omitempty"` Private *bool `json:"private,omitempty"`
Visibility *string `json:"visibility,omitempty"`
HasIssues *bool `json:"has_issues,omitempty"` HasIssues *bool `json:"has_issues,omitempty"`
HasProjects *bool `json:"has_projects,omitempty"` HasProjects *bool `json:"has_projects,omitempty"`
HasWiki *bool `json:"has_wiki,omitempty"` HasWiki *bool `json:"has_wiki,omitempty"`
@ -320,7 +327,8 @@ 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 // GitHub API docs: https://developer.github.com/v3/repos/#create-a-repository-for-the-authenticated-user
// GitHub API docs: https://developer.github.com/v3/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 != "" {
@ -334,6 +342,7 @@ func (s *RepositoriesService) Create(ctx context.Context, org string, repo *Repo
Description: repo.Description, Description: repo.Description,
Homepage: repo.Homepage, Homepage: repo.Homepage,
Private: repo.Private, Private: repo.Private,
Visibility: repo.Visibility,
HasIssues: repo.HasIssues, HasIssues: repo.HasIssues,
HasProjects: repo.HasProjects, HasProjects: repo.HasProjects,
HasWiki: repo.HasWiki, HasWiki: repo.HasWiki,
@ -353,7 +362,8 @@ func (s *RepositoriesService) Create(ctx context.Context, org string, repo *Repo
return nil, nil, err return nil, nil, err
} }
req.Header.Set("Accept", mediaTypeRepositoryTemplatePreview) acceptHeaders := []string{mediaTypeRepositoryTemplatePreview, mediaTypeRepositoryVisibilityPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
r := new(Repository) r := new(Repository)
resp, err := s.client.Do(ctx, req, r) resp, err := s.client.Do(ctx, req, r)
if err != nil { if err != nil {
@ -375,7 +385,7 @@ type TemplateRepoRequest struct {
// CreateFromTemplate generates a repository from a template. // CreateFromTemplate generates a repository from a template.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#create-repository-using-a-repository-template // GitHub API docs: https://developer.github.com/v3/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)
@ -396,7 +406,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 // GitHub API docs: https://developer.github.com/v3/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)
@ -406,7 +416,12 @@ 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://developer.github.com/v3/licenses/#get-a-repositorys-license
acceptHeaders := []string{mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview, mediaTypeRepositoryTemplatePreview} acceptHeaders := []string{
mediaTypeCodesOfConductPreview,
mediaTypeTopicsPreview,
mediaTypeRepositoryTemplatePreview,
mediaTypeRepositoryVisibilityPreview,
}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
repository := new(Repository) repository := new(Repository)
@ -420,7 +435,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-contents-of-a-repositorys-code-of-conduct // GitHub API docs: https://developer.github.com/v3/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)
@ -461,7 +476,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/#edit // GitHub API docs: https://developer.github.com/v3/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)
@ -469,7 +484,8 @@ func (s *RepositoriesService) Edit(ctx context.Context, owner, repo string, repo
return nil, nil, err return nil, nil, err
} }
req.Header.Set("Accept", mediaTypeRepositoryTemplatePreview) acceptHeaders := []string{mediaTypeRepositoryTemplatePreview, mediaTypeRepositoryVisibilityPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
r := new(Repository) r := new(Repository)
resp, err := s.client.Do(ctx, req, r) resp, err := s.client.Do(ctx, req, r)
if err != nil { if err != nil {
@ -614,7 +630,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-contributors // GitHub API docs: https://developer.github.com/v3/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)
@ -645,7 +661,7 @@ func (s *RepositoriesService) ListContributors(ctx context.Context, owner string
// "Python": 7769 // "Python": 7769
// } // }
// //
// GitHub API docs: https://developer.github.com/v3/repos/#list-languages // GitHub API docs: https://developer.github.com/v3/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)
@ -664,7 +680,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-teams // GitHub API docs: https://developer.github.com/v3/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)
@ -696,7 +712,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-tags // GitHub API docs: https://developer.github.com/v3/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)
@ -884,7 +900,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/#list-branches // GitHub API docs: https://developer.github.com/v3/repos/branches/#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)
@ -911,7 +927,7 @@ 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/#get-branch // GitHub API docs: https://developer.github.com/v3/repos/branches/#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) (*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) req, err := s.client.NewRequest("GET", u, nil)
@ -955,7 +971,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-required-status-checks-of-protected-branch // GitHub API docs: https://developer.github.com/v3/repos/branches/#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)
@ -977,7 +993,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/#list-required-status-checks-contexts-of-protected-branch // GitHub API docs: https://developer.github.com/v3/repos/branches/#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)
@ -1020,7 +1036,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/#remove-branch-protection // GitHub API docs: https://developer.github.com/v3/repos/branches/#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)
@ -1036,7 +1052,7 @@ func (s *RepositoriesService) RemoveBranchProtection(ctx context.Context, owner,
// 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-required-signatures-of-protected-branch // GitHub API docs: https://developer.github.com/v3/repos/branches/#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)
@ -1059,7 +1075,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/#add-required-signatures-of-protected-branch // GitHub API docs: https://developer.github.com/v3/repos/branches/#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)
@ -1081,7 +1097,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/#remove-required-signatures-of-protected-branch // GitHub API docs: https://developer.github.com/v3/repos/branches/#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)
@ -1097,7 +1113,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-required-status-checks-of-protected-branch // GitHub API docs: https://developer.github.com/v3/repos/branches/#update-status-check-potection
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)
@ -1116,7 +1132,7 @@ func (s *RepositoriesService) UpdateRequiredStatusChecks(ctx context.Context, ow
// 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-contents-of-a-repositorys-license // GitHub API docs: https://developer.github.com/v3/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)
@ -1135,7 +1151,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-enforcement-of-protected-branch // GitHub API docs: https://developer.github.com/v3/repos/branches/#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)
@ -1158,7 +1174,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-enforcement-of-protected-branch // GitHub API docs: https://developer.github.com/v3/repos/branches/#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)
@ -1181,7 +1197,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-enforcement-of-protected-branch // GitHub API docs: https://developer.github.com/v3/repos/branches/#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)
@ -1208,7 +1224,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/#remove-pull-request-review-enforcement-of-protected-branch // GitHub API docs: https://developer.github.com/v3/repos/branches/#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)
@ -1224,7 +1240,7 @@ func (s *RepositoriesService) RemovePullRequestReviewEnforcement(ctx context.Con
// 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-enforcement-of-protected-branch // GitHub API docs: https://developer.github.com/v3/repos/branches/#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)
@ -1247,7 +1263,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/#add-admin-enforcement-of-protected-branch // GitHub API docs: https://developer.github.com/v3/repos/branches/#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)
@ -1269,7 +1285,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/#remove-admin-enforcement-of-protected-branch // GitHub API docs: https://developer.github.com/v3/repos/branches/#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)
@ -1290,7 +1306,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/#list-all-topics-for-a-repository // GitHub API docs: https://developer.github.com/v3/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)
@ -1312,7 +1328,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-topics-for-a-repository // GitHub API docs: https://developer.github.com/v3/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{
@ -1341,7 +1357,7 @@ func (s *RepositoriesService) ReplaceAllTopics(ctx context.Context, owner, repo
// 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-protected-branch // GitHub API docs: https://developer.github.com/v3/repos/branches/#list-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)
@ -1364,7 +1380,7 @@ func (s *RepositoriesService) ListApps(ctx context.Context, owner, repo, branch
// //
// 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/#replace-app-restrictions-of-protected-branch // GitHub API docs: https://developer.github.com/v3/repos/branches/#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)
@ -1386,7 +1402,7 @@ func (s *RepositoriesService) ReplaceAppRestrictions(ctx context.Context, owner,
// //
// 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-restrictions-of-protected-branch // GitHub API docs: https://developer.github.com/v3/repos/branches/#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)
@ -1408,7 +1424,7 @@ func (s *RepositoriesService) AddAppRestrictions(ctx context.Context, owner, rep
// //
// 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-restrictions-of-protected-branch // GitHub API docs: https://developer.github.com/v3/repos/branches/#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)

View file

@ -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-collaborators // GitHub API docs: https://developer.github.com/v3/repos/collaborators/#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/#get // GitHub API docs: https://developer.github.com/v3/repos/collaborators/#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/#review-a-users-permission-level // GitHub API docs: https://developer.github.com/v3/repos/collaborators/#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)
@ -115,6 +115,8 @@ type RepositoryAddCollaboratorOptions struct {
// pull - team members can pull, but not push to or administer this repository // pull - team members can pull, but not push to or administer this repository
// push - team members can pull and push, but not administer this repository // push - team members can pull and push, but not administer this repository
// admin - team members can pull, push and administer this repository // admin - team members can pull, push and administer this repository
// maintain - team members can manage the repository without access to sensitive or destructive actions.
// triage - team members can proactively manage issues and pull requests without write access.
// //
// Default value is "push". This option is only valid for organization-owned repositories. // Default value is "push". This option is only valid for organization-owned repositories.
Permission string `json:"permission,omitempty"` Permission string `json:"permission,omitempty"`
@ -123,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-user-as-a-collaborator // GitHub API docs: https://developer.github.com/v3/repos/collaborators/#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)
@ -141,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-collaborator // GitHub API docs: https://developer.github.com/v3/repos/collaborators/#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

@ -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-comments-for-a-single-commit // GitHub API docs: https://developer.github.com/v3/repos/comments/#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)
@ -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-single-commit-comment // GitHub API docs: https://developer.github.com/v3/repos/comments/#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)

View file

@ -9,7 +9,6 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"net/url"
"time" "time"
) )
@ -22,7 +21,7 @@ type RepositoryCommit struct {
Commit *Commit `json:"commit,omitempty"` Commit *Commit `json:"commit,omitempty"`
Author *User `json:"author,omitempty"` Author *User `json:"author,omitempty"`
Committer *User `json:"committer,omitempty"` Committer *User `json:"committer,omitempty"`
Parents []Commit `json:"parents,omitempty"` Parents []*Commit `json:"parents,omitempty"`
HTMLURL *string `json:"html_url,omitempty"` HTMLURL *string `json:"html_url,omitempty"`
URL *string `json:"url,omitempty"` URL *string `json:"url,omitempty"`
CommentsURL *string `json:"comments_url,omitempty"` CommentsURL *string `json:"comments_url,omitempty"`
@ -30,7 +29,7 @@ type RepositoryCommit struct {
// Details about how many changes were made in this commit. Only filled in during GetCommit! // Details about how many changes were made in this commit. Only filled in during GetCommit!
Stats *CommitStats `json:"stats,omitempty"` Stats *CommitStats `json:"stats,omitempty"`
// Details about which files, and how this commit touched. Only filled in during GetCommit! // Details about which files, and how this commit touched. Only filled in during GetCommit!
Files []CommitFile `json:"files,omitempty"` Files []*CommitFile `json:"files,omitempty"`
} }
func (r RepositoryCommit) String() string { func (r RepositoryCommit) String() string {
@ -79,9 +78,9 @@ type CommitsComparison struct {
BehindBy *int `json:"behind_by,omitempty"` BehindBy *int `json:"behind_by,omitempty"`
TotalCommits *int `json:"total_commits,omitempty"` TotalCommits *int `json:"total_commits,omitempty"`
Commits []RepositoryCommit `json:"commits,omitempty"` Commits []*RepositoryCommit `json:"commits,omitempty"`
Files []CommitFile `json:"files,omitempty"` Files []*CommitFile `json:"files,omitempty"`
HTMLURL *string `json:"html_url,omitempty"` HTMLURL *string `json:"html_url,omitempty"`
PermalinkURL *string `json:"permalink_url,omitempty"` PermalinkURL *string `json:"permalink_url,omitempty"`
@ -124,7 +123,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 // GitHub API docs: https://developer.github.com/v3/repos/commits/#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)
@ -149,7 +148,7 @@ 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://developer.github.com/v3/repos/commits/#get-a-single-commit
// See also: https://developer.github.com/v3/git/commits/#get-a-single-commit provides the same functionality // GitHub API docs: https://developer.github.com/v3/repos/commits/#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,6 +167,8 @@ 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
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)
@ -196,9 +197,9 @@ 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-the-sha-1-of-a-commit-reference // GitHub API docs: https://developer.github.com/v3/repos/commits/#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, url.QueryEscape(ref)) u := fmt.Sprintf("repos/%v/%v/commits/%v", owner, repo, refURLEscape(ref))
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {

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/#retrieve-community-health-metrics // GitHub API docs: https://developer.github.com/v3/repos/community/#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

@ -94,7 +94,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-the-readme // GitHub API docs: https://developer.github.com/v3/repos/contents/#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)
@ -146,7 +146,7 @@ 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-contents // GitHub API docs: https://developer.github.com/v3/repos/contents/#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: path}).String()
u := fmt.Sprintf("repos/%s/%s/contents/%s", owner, repo, escapedPath) u := fmt.Sprintf("repos/%s/%s/contents/%s", owner, repo, escapedPath)
@ -177,7 +177,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-a-file // GitHub API docs: https://developer.github.com/v3/repos/contents/#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 +195,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/#update-a-file // GitHub API docs: https://developer.github.com/v3/repos/contents/#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)
@ -228,15 +228,15 @@ func (s *RepositoriesService) DeleteFile(ctx context.Context, owner, repo, path
return deleteResponse, resp, nil return deleteResponse, resp, nil
} }
// archiveFormat is used to define the archive type when calling GetArchiveLink. // ArchiveFormat is used to define the archive type when calling GetArchiveLink.
type archiveFormat string type ArchiveFormat string
const ( const (
// Tarball specifies an archive in gzipped tar format. // Tarball specifies an archive in gzipped tar format.
Tarball archiveFormat = "tarball" Tarball ArchiveFormat = "tarball"
// Zipball specifies an archive in zip format. // Zipball specifies an archive in zip format.
Zipball archiveFormat = "zipball" Zipball ArchiveFormat = "zipball"
) )
// GetArchiveLink returns an URL to download a tarball or zipball archive for a // GetArchiveLink returns an URL to download a tarball or zipball archive for a
@ -244,7 +244,7 @@ const (
// 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://developer.github.com/v3/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 != "" {
u += fmt.Sprintf("/%s", opts.Ref) u += fmt.Sprintf("/%s", opts.Ref)

View file

@ -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-single-deployment // GitHub API docs: https://developer.github.com/v3/repos/deployments/#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)
@ -129,21 +129,38 @@ func (s *RepositoriesService) CreateDeployment(ctx context.Context, owner, repo
return d, resp, nil return d, resp, nil
} }
// DeleteDeployment deletes an existing deployment for a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/deployments/#delete-a-deployment
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)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// DeploymentStatus represents the status of a // DeploymentStatus represents the status of a
// particular deployment. // particular deployment.
type DeploymentStatus struct { type DeploymentStatus struct {
ID *int64 `json:"id,omitempty"` ID *int64 `json:"id,omitempty"`
// State is the deployment state. // State is the deployment state.
// Possible values are: "pending", "success", "failure", "error", "inactive". // Possible values are: "pending", "success", "failure", "error",
// "inactive", "in_progress", "queued".
State *string `json:"state,omitempty"` State *string `json:"state,omitempty"`
Creator *User `json:"creator,omitempty"` Creator *User `json:"creator,omitempty"`
Description *string `json:"description,omitempty"` Description *string `json:"description,omitempty"`
TargetURL *string `json:"target_url,omitempty"` Environment *string `json:"environment,omitempty"`
NodeID *string `json:"node_id,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"` CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"` UpdatedAt *Timestamp `json:"updated_at,omitempty"`
TargetURL *string `json:"target_url,omitempty"`
DeploymentURL *string `json:"deployment_url,omitempty"` DeploymentURL *string `json:"deployment_url,omitempty"`
RepositoryURL *string `json:"repository_url,omitempty"` RepositoryURL *string `json:"repository_url,omitempty"`
NodeID *string `json:"node_id,omitempty"` EnvironmentURL *string `json:"environment_url,omitempty"`
LogURL *string `json:"log_url,omitempty"`
URL *string `json:"url,omitempty"`
} }
// DeploymentStatusRequest represents a deployment request // DeploymentStatusRequest represents a deployment request
@ -171,6 +188,10 @@ func (s *RepositoriesService) ListDeploymentStatuses(ctx context.Context, owner,
return nil, nil, err return nil, nil, err
} }
// TODO: remove custom Accept headers when APIs fully launch.
acceptHeaders := []string{mediaTypeDeploymentStatusPreview, mediaTypeExpandDeploymentStatusPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
var statuses []*DeploymentStatus var statuses []*DeploymentStatus
resp, err := s.client.Do(ctx, req, &statuses) resp, err := s.client.Do(ctx, req, &statuses)
if err != nil { if err != nil {
@ -182,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-single-deployment-status // GitHub API docs: https://developer.github.com/v3/repos/deployments/#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)

View file

@ -21,7 +21,7 @@ import (
type WebHookPayload struct { type WebHookPayload struct {
After *string `json:"after,omitempty"` After *string `json:"after,omitempty"`
Before *string `json:"before,omitempty"` Before *string `json:"before,omitempty"`
Commits []WebHookCommit `json:"commits,omitempty"` Commits []*WebHookCommit `json:"commits,omitempty"`
Compare *string `json:"compare,omitempty"` Compare *string `json:"compare,omitempty"`
Created *bool `json:"created,omitempty"` Created *bool `json:"created,omitempty"`
Deleted *bool `json:"deleted,omitempty"` Deleted *bool `json:"deleted,omitempty"`
@ -104,7 +104,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-hook // GitHub API docs: https://developer.github.com/v3/repos/hooks/#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 +131,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 // GitHub API docs: https://developer.github.com/v3/repos/hooks/#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 +155,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-single-hook // GitHub API docs: https://developer.github.com/v3/repos/hooks/#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 +173,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/#edit-a-hook // GitHub API docs: https://developer.github.com/v3/repos/hooks/#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 +191,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-hook // GitHub API docs: https://developer.github.com/v3/repos/hooks/#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 +203,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-hook // GitHub API docs: https://developer.github.com/v3/repos/hooks/#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 +215,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-a-push-hook // GitHub API docs: https://developer.github.com/v3/repos/hooks/#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-invitations-for-a-repository // GitHub API docs: https://developer.github.com/v3/repos/invitations/#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)

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 // GitHub API docs: https://developer.github.com/v3/repos/keys/#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 // GitHub API docs: https://developer.github.com/v3/repos/keys/#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 // GitHub API docs: https://developer.github.com/v3/repos/keys/#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)
@ -76,29 +76,9 @@ func (s *RepositoriesService) CreateKey(ctx context.Context, owner string, repo
return k, resp, nil return k, resp, nil
} }
// EditKey edits a deploy key.
//
// GitHub API docs: https://developer.github.com/v3/repos/keys/#edit
func (s *RepositoriesService) EditKey(ctx context.Context, owner string, repo string, id int64, key *Key) (*Key, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/keys/%v", owner, repo, id)
req, err := s.client.NewRequest("PATCH", u, key)
if err != nil {
return nil, nil, err
}
k := new(Key)
resp, err := s.client.Do(ctx, req, k)
if err != nil {
return nil, resp, err
}
return k, resp, nil
}
// DeleteKey deletes a deploy key. // DeleteKey deletes a deploy key.
// //
// GitHub API docs: https://developer.github.com/v3/repos/keys/#delete // GitHub API docs: https://developer.github.com/v3/repos/keys/#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/#perform-a-merge // GitHub API docs: https://developer.github.com/v3/repos/merging/#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/#enable-a-pages-site // GitHub API docs: https://developer.github.com/v3/repos/pages/#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)
@ -75,9 +75,38 @@ func (s *RepositoriesService) EnablePages(ctx context.Context, owner, repo strin
return enable, resp, nil return enable, resp, nil
} }
// PagesUpdate sets up parameters needed to update a GitHub Pages site.
type PagesUpdate struct {
// CNAME represents a custom domain for the repository.
// Leaving CNAME empty will remove the custom domain.
CNAME *string `json:"cname"`
// Source must include the branch name, and may optionally specify the subdirectory "/docs".
// Possible values are: "gh-pages", "master", and "master /docs".
Source *string `json:"source,omitempty"`
}
// 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
func (s *RepositoriesService) UpdatePages(ctx context.Context, owner, repo string, opts *PagesUpdate) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/pages", owner, repo)
req, err := s.client.NewRequest("PUT", u, opts)
if err != nil {
return nil, err
}
resp, err := s.client.Do(ctx, req, nil)
if err != nil {
return resp, err
}
return resp, nil
}
// 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/#disable-a-pages-site // GitHub API docs: https://developer.github.com/v3/repos/pages/#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)
@ -93,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-information-about-a-pages-site // GitHub API docs: https://developer.github.com/v3/repos/pages/#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)
@ -112,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-pages-builds // GitHub API docs: https://developer.github.com/v3/repos/pages/#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)
@ -136,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/#list-latest-pages-build // GitHub API docs: https://developer.github.com/v3/repos/pages/#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)
@ -155,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/#list-a-specific-pages-build // GitHub API docs: https://developer.github.com/v3/repos/pages/#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)
@ -174,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-page-build // GitHub API docs: https://developer.github.com/v3/repos/pages/#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

@ -33,7 +33,7 @@ type RepositoryRelease struct {
URL *string `json:"url,omitempty"` URL *string `json:"url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"` HTMLURL *string `json:"html_url,omitempty"`
AssetsURL *string `json:"assets_url,omitempty"` AssetsURL *string `json:"assets_url,omitempty"`
Assets []ReleaseAsset `json:"assets,omitempty"` Assets []*ReleaseAsset `json:"assets,omitempty"`
UploadURL *string `json:"upload_url,omitempty"` UploadURL *string `json:"upload_url,omitempty"`
ZipballURL *string `json:"zipball_url,omitempty"` ZipballURL *string `json:"zipball_url,omitempty"`
TarballURL *string `json:"tarball_url,omitempty"` TarballURL *string `json:"tarball_url,omitempty"`
@ -68,7 +68,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-for-a-repository // GitHub API docs: https://developer.github.com/v3/repos/releases/#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 +91,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-single-release // GitHub API docs: https://developer.github.com/v3/repos/releases/#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)
@ -178,7 +178,7 @@ 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/#edit-a-release // GitHub API docs: https://developer.github.com/v3/repos/releases/#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)
@ -219,7 +219,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-assets-for-a-release // GitHub API docs: https://developer.github.com/v3/repos/releases/#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 +242,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-single-release-asset // GitHub API docs: https://developer.github.com/v3/repos/releases/#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 +271,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-single-release-asset // GitHub API docs: https://developer.github.com/v3/repos/releases/#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 +333,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/#edit-a-release-asset // GitHub API docs: https://developer.github.com/v3/repos/releases/#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)

View file

@ -16,7 +16,7 @@ import (
type ContributorStats struct { type ContributorStats struct {
Author *Contributor `json:"author,omitempty"` Author *Contributor `json:"author,omitempty"`
Total *int `json:"total,omitempty"` Total *int `json:"total,omitempty"`
Weeks []WeeklyStats `json:"weeks,omitempty"` Weeks []*WeeklyStats `json:"weeks,omitempty"`
} }
func (c ContributorStats) String() string { func (c ContributorStats) String() string {
@ -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/#contributors // GitHub API docs: https://developer.github.com/v3/repos/statistics/#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/#commit-activity // GitHub API docs: https://developer.github.com/v3/repos/statistics/#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/#code-frequency // GitHub API docs: https://developer.github.com/v3/repos/statistics/#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/#participation // GitHub API docs: https://developer.github.com/v3/repos/statistics/#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/#punch-card // GitHub API docs: https://developer.github.com/v3/repos/statistics/#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)

View file

@ -8,7 +8,6 @@ package github
import ( import (
"context" "context"
"fmt" "fmt"
"net/url"
"time" "time"
) )
@ -44,9 +43,9 @@ func (r RepoStatus) String() string {
// ListStatuses lists the statuses of a repository at the specified // ListStatuses lists the statuses of a repository at the specified
// reference. ref can be a SHA, a branch name, or a tag name. // reference. ref can be a SHA, a branch name, or a tag name.
// //
// GitHub API docs: https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref // GitHub API docs: https://developer.github.com/v3/repos/statuses/#list-commit-statuses-for-a-reference
func (s *RepositoriesService) ListStatuses(ctx context.Context, owner, repo, ref string, opts *ListOptions) ([]*RepoStatus, *Response, error) { func (s *RepositoriesService) ListStatuses(ctx context.Context, owner, repo, ref string, opts *ListOptions) ([]*RepoStatus, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v/statuses", owner, repo, url.QueryEscape(ref)) u := fmt.Sprintf("repos/%v/%v/commits/%v/statuses", owner, repo, refURLEscape(ref))
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -69,9 +68,9 @@ func (s *RepositoriesService) ListStatuses(ctx context.Context, owner, repo, ref
// CreateStatus creates a new status for a repository at the specified // CreateStatus creates a new status for a repository at the specified
// reference. Ref can be a SHA, a branch name, or a tag name. // reference. Ref can be a SHA, a branch name, or a tag name.
// //
// GitHub API docs: https://developer.github.com/v3/repos/statuses/#create-a-status // GitHub API docs: https://developer.github.com/v3/repos/statuses/#create-a-commit-status
func (s *RepositoriesService) CreateStatus(ctx context.Context, owner, repo, ref string, status *RepoStatus) (*RepoStatus, *Response, error) { func (s *RepositoriesService) CreateStatus(ctx context.Context, owner, repo, ref string, status *RepoStatus) (*RepoStatus, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/statuses/%v", owner, repo, url.QueryEscape(ref)) u := fmt.Sprintf("repos/%v/%v/statuses/%v", owner, repo, refURLEscape(ref))
req, err := s.client.NewRequest("POST", u, status) req, err := s.client.NewRequest("POST", u, status)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -95,7 +94,7 @@ type CombinedStatus struct {
Name *string `json:"name,omitempty"` Name *string `json:"name,omitempty"`
SHA *string `json:"sha,omitempty"` SHA *string `json:"sha,omitempty"`
TotalCount *int `json:"total_count,omitempty"` TotalCount *int `json:"total_count,omitempty"`
Statuses []RepoStatus `json:"statuses,omitempty"` Statuses []*RepoStatus `json:"statuses,omitempty"`
CommitURL *string `json:"commit_url,omitempty"` CommitURL *string `json:"commit_url,omitempty"`
RepositoryURL *string `json:"repository_url,omitempty"` RepositoryURL *string `json:"repository_url,omitempty"`
@ -108,9 +107,9 @@ func (s CombinedStatus) String() string {
// GetCombinedStatus returns the combined status of a repository at the specified // GetCombinedStatus returns the combined status of a repository at the specified
// reference. ref can be a SHA, a branch name, or a tag name. // reference. ref can be a SHA, a branch name, or a tag name.
// //
// GitHub API docs: https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref // GitHub API docs: https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-reference
func (s *RepositoriesService) GetCombinedStatus(ctx context.Context, owner, repo, ref string, opts *ListOptions) (*CombinedStatus, *Response, error) { func (s *RepositoriesService) GetCombinedStatus(ctx context.Context, owner, repo, ref string, opts *ListOptions) (*CombinedStatus, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v/status", owner, repo, url.QueryEscape(ref)) u := fmt.Sprintf("repos/%v/%v/commits/%v/status", owner, repo, refURLEscape(ref))
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err

View file

@ -54,7 +54,7 @@ type TrafficBreakdownOptions struct {
// ListTrafficReferrers list the top 10 referrers over the last 14 days. // ListTrafficReferrers list the top 10 referrers over the last 14 days.
// //
// GitHub API docs: https://developer.github.com/v3/repos/traffic/#list-referrers // GitHub API docs: https://developer.github.com/v3/repos/traffic/#get-top-referral-sources
func (s *RepositoriesService) ListTrafficReferrers(ctx context.Context, owner, repo string) ([]*TrafficReferrer, *Response, error) { func (s *RepositoriesService) ListTrafficReferrers(ctx context.Context, owner, repo string) ([]*TrafficReferrer, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/traffic/popular/referrers", owner, repo) u := fmt.Sprintf("repos/%v/%v/traffic/popular/referrers", owner, repo)
@ -74,7 +74,7 @@ func (s *RepositoriesService) ListTrafficReferrers(ctx context.Context, owner, r
// ListTrafficPaths list the top 10 popular content over the last 14 days. // ListTrafficPaths list the top 10 popular content over the last 14 days.
// //
// GitHub API docs: https://developer.github.com/v3/repos/traffic/#list-paths // GitHub API docs: https://developer.github.com/v3/repos/traffic/#get-top-referral-paths
func (s *RepositoriesService) ListTrafficPaths(ctx context.Context, owner, repo string) ([]*TrafficPath, *Response, error) { func (s *RepositoriesService) ListTrafficPaths(ctx context.Context, owner, repo string) ([]*TrafficPath, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/traffic/popular/paths", owner, repo) u := fmt.Sprintf("repos/%v/%v/traffic/popular/paths", owner, repo)
@ -94,7 +94,7 @@ func (s *RepositoriesService) ListTrafficPaths(ctx context.Context, owner, repo
// ListTrafficViews get total number of views for the last 14 days and breaks it down either per day or week. // ListTrafficViews get total number of views for the last 14 days and breaks it down either per day or week.
// //
// GitHub API docs: https://developer.github.com/v3/repos/traffic/#views // GitHub API docs: https://developer.github.com/v3/repos/traffic/#get-page-views
func (s *RepositoriesService) ListTrafficViews(ctx context.Context, owner, repo string, opts *TrafficBreakdownOptions) (*TrafficViews, *Response, error) { func (s *RepositoriesService) ListTrafficViews(ctx context.Context, owner, repo string, opts *TrafficBreakdownOptions) (*TrafficViews, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/traffic/views", owner, repo) u := fmt.Sprintf("repos/%v/%v/traffic/views", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -118,7 +118,7 @@ func (s *RepositoriesService) ListTrafficViews(ctx context.Context, owner, repo
// ListTrafficClones get total number of clones for the last 14 days and breaks it down either per day or week for the last 14 days. // ListTrafficClones get total number of clones for the last 14 days and breaks it down either per day or week for the last 14 days.
// //
// GitHub API docs: https://developer.github.com/v3/repos/traffic/#views // GitHub API docs: https://developer.github.com/v3/repos/traffic/#get-repository-clones
func (s *RepositoriesService) ListTrafficClones(ctx context.Context, owner, repo string, opts *TrafficBreakdownOptions) (*TrafficClones, *Response, error) { func (s *RepositoriesService) ListTrafficClones(ctx context.Context, owner, repo string, opts *TrafficBreakdownOptions) (*TrafficClones, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/traffic/clones", owner, repo) u := fmt.Sprintf("repos/%v/%v/traffic/clones", owner, repo)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)

View file

@ -64,7 +64,7 @@ type searchParameters struct {
type RepositoriesSearchResult struct { type RepositoriesSearchResult struct {
Total *int `json:"total_count,omitempty"` Total *int `json:"total_count,omitempty"`
IncompleteResults *bool `json:"incomplete_results,omitempty"` IncompleteResults *bool `json:"incomplete_results,omitempty"`
Repositories []Repository `json:"items,omitempty"` Repositories []*Repository `json:"items,omitempty"`
} }
// Repositories searches repositories via various criteria. // Repositories searches repositories via various criteria.
@ -142,12 +142,12 @@ func (s *SearchService) Commits(ctx context.Context, query string, opts *SearchO
type IssuesSearchResult struct { type IssuesSearchResult struct {
Total *int `json:"total_count,omitempty"` Total *int `json:"total_count,omitempty"`
IncompleteResults *bool `json:"incomplete_results,omitempty"` IncompleteResults *bool `json:"incomplete_results,omitempty"`
Issues []Issue `json:"items,omitempty"` Issues []*Issue `json:"items,omitempty"`
} }
// Issues searches issues via various criteria. // Issues searches issues via various criteria.
// //
// GitHub API docs: https://developer.github.com/v3/search/#search-issues // GitHub API docs: https://developer.github.com/v3/search/#search-issues-and-pull-requests
func (s *SearchService) Issues(ctx context.Context, query string, opts *SearchOptions) (*IssuesSearchResult, *Response, error) { func (s *SearchService) Issues(ctx context.Context, query string, opts *SearchOptions) (*IssuesSearchResult, *Response, error) {
result := new(IssuesSearchResult) result := new(IssuesSearchResult)
resp, err := s.search(ctx, "issues", &searchParameters{Query: query}, opts, result) resp, err := s.search(ctx, "issues", &searchParameters{Query: query}, opts, result)
@ -158,7 +158,7 @@ func (s *SearchService) Issues(ctx context.Context, query string, opts *SearchOp
type UsersSearchResult struct { type UsersSearchResult struct {
Total *int `json:"total_count,omitempty"` Total *int `json:"total_count,omitempty"`
IncompleteResults *bool `json:"incomplete_results,omitempty"` IncompleteResults *bool `json:"incomplete_results,omitempty"`
Users []User `json:"items,omitempty"` Users []*User `json:"items,omitempty"`
} }
// Users searches users via various criteria. // Users searches users via various criteria.
@ -182,7 +182,7 @@ type TextMatch struct {
ObjectType *string `json:"object_type,omitempty"` ObjectType *string `json:"object_type,omitempty"`
Property *string `json:"property,omitempty"` Property *string `json:"property,omitempty"`
Fragment *string `json:"fragment,omitempty"` Fragment *string `json:"fragment,omitempty"`
Matches []Match `json:"matches,omitempty"` Matches []*Match `json:"matches,omitempty"`
} }
func (tm TextMatch) String() string { func (tm TextMatch) String() string {
@ -193,7 +193,7 @@ func (tm TextMatch) String() string {
type CodeSearchResult struct { type CodeSearchResult struct {
Total *int `json:"total_count,omitempty"` Total *int `json:"total_count,omitempty"`
IncompleteResults *bool `json:"incomplete_results,omitempty"` IncompleteResults *bool `json:"incomplete_results,omitempty"`
CodeResults []CodeResult `json:"items,omitempty"` CodeResults []*CodeResult `json:"items,omitempty"`
} }
// CodeResult represents a single search result. // CodeResult represents a single search result.
@ -203,7 +203,7 @@ type CodeResult struct {
SHA *string `json:"sha,omitempty"` SHA *string `json:"sha,omitempty"`
HTMLURL *string `json:"html_url,omitempty"` HTMLURL *string `json:"html_url,omitempty"`
Repository *Repository `json:"repository,omitempty"` Repository *Repository `json:"repository,omitempty"`
TextMatches []TextMatch `json:"text_matches,omitempty"` TextMatches []*TextMatch `json:"text_matches,omitempty"`
} }
func (c CodeResult) String() string { func (c CodeResult) String() string {

View file

@ -99,7 +99,7 @@ func (s *TeamsService) ListTeams(ctx context.Context, org string, opts *ListOpti
// GetTeamByID fetches a team, given a specified organization ID, by ID. // GetTeamByID fetches a team, given a specified organization ID, by ID.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#get-team-by-name // GitHub API docs: https://developer.github.com/v3/teams/#get-a-team-by-name
func (s *TeamsService) GetTeamByID(ctx context.Context, orgID, teamID int64) (*Team, *Response, error) { func (s *TeamsService) GetTeamByID(ctx context.Context, orgID, teamID int64) (*Team, *Response, error) {
u := fmt.Sprintf("organizations/%v/team/%v", orgID, teamID) u := fmt.Sprintf("organizations/%v/team/%v", orgID, teamID)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -118,7 +118,7 @@ func (s *TeamsService) GetTeamByID(ctx context.Context, orgID, teamID int64) (*T
// GetTeamBySlug fetches a team, given a specified organization name, by slug. // GetTeamBySlug fetches a team, given a specified organization name, by slug.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#get-team-by-name // GitHub API docs: https://developer.github.com/v3/teams/#get-a-team-by-name
func (s *TeamsService) GetTeamBySlug(ctx context.Context, org, slug string) (*Team, *Response, error) { func (s *TeamsService) GetTeamBySlug(ctx context.Context, org, slug string) (*Team, *Response, error) {
u := fmt.Sprintf("orgs/%v/teams/%v", org, slug) u := fmt.Sprintf("orgs/%v/teams/%v", org, slug)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -168,7 +168,7 @@ func (s NewTeam) String() string {
// CreateTeam creates a new team within an organization. // CreateTeam creates a new team within an organization.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#create-team // GitHub API docs: https://developer.github.com/v3/teams/#create-a-team
func (s *TeamsService) CreateTeam(ctx context.Context, org string, team NewTeam) (*Team, *Response, error) { func (s *TeamsService) CreateTeam(ctx context.Context, org string, team NewTeam) (*Team, *Response, error) {
u := fmt.Sprintf("orgs/%v/teams", org) u := fmt.Sprintf("orgs/%v/teams", org)
req, err := s.client.NewRequest("POST", u, team) req, err := s.client.NewRequest("POST", u, team)
@ -214,7 +214,7 @@ func copyNewTeamWithoutParent(team *NewTeam) *newTeamNoParent {
// EditTeamByID edits a team, given an organization ID, selected by ID. // EditTeamByID edits a team, given an organization ID, selected by ID.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#edit-team // GitHub API docs: https://developer.github.com/v3/teams/#update-a-team
func (s *TeamsService) EditTeamByID(ctx context.Context, orgID, teamID int64, team NewTeam, removeParent bool) (*Team, *Response, error) { func (s *TeamsService) EditTeamByID(ctx context.Context, orgID, teamID int64, team NewTeam, removeParent bool) (*Team, *Response, error) {
u := fmt.Sprintf("organizations/%v/team/%v", orgID, teamID) u := fmt.Sprintf("organizations/%v/team/%v", orgID, teamID)
@ -241,7 +241,7 @@ func (s *TeamsService) EditTeamByID(ctx context.Context, orgID, teamID int64, te
// EditTeamBySlug edits a team, given an organization name, by slug. // EditTeamBySlug edits a team, given an organization name, by slug.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#edit-team // GitHub API docs: https://developer.github.com/v3/teams/#update-a-team
func (s *TeamsService) EditTeamBySlug(ctx context.Context, org, slug string, team NewTeam, removeParent bool) (*Team, *Response, error) { func (s *TeamsService) EditTeamBySlug(ctx context.Context, org, slug string, team NewTeam, removeParent bool) (*Team, *Response, error) {
u := fmt.Sprintf("orgs/%v/teams/%v", org, slug) u := fmt.Sprintf("orgs/%v/teams/%v", org, slug)
@ -268,7 +268,7 @@ func (s *TeamsService) EditTeamBySlug(ctx context.Context, org, slug string, tea
// DeleteTeamByID deletes a team referenced by ID. // DeleteTeamByID deletes a team referenced by ID.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#delete-team // GitHub API docs: https://developer.github.com/v3/teams/#delete-a-team
func (s *TeamsService) DeleteTeamByID(ctx context.Context, orgID, teamID int64) (*Response, error) { func (s *TeamsService) DeleteTeamByID(ctx context.Context, orgID, teamID int64) (*Response, error) {
u := fmt.Sprintf("organizations/%v/team/%v", orgID, teamID) u := fmt.Sprintf("organizations/%v/team/%v", orgID, teamID)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -281,7 +281,7 @@ func (s *TeamsService) DeleteTeamByID(ctx context.Context, orgID, teamID int64)
// DeleteTeamBySlug deletes a team reference by slug. // DeleteTeamBySlug deletes a team reference by slug.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#delete-team // GitHub API docs: https://developer.github.com/v3/teams/#delete-a-team
func (s *TeamsService) DeleteTeamBySlug(ctx context.Context, org, slug string) (*Response, error) { func (s *TeamsService) DeleteTeamBySlug(ctx context.Context, org, slug string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/teams/%v", org, slug) u := fmt.Sprintf("orgs/%v/teams/%v", org, slug)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -342,7 +342,7 @@ func (s *TeamsService) ListChildTeamsByParentSlug(ctx context.Context, org, slug
// ListTeamReposByID lists the repositories given a team ID that the specified team has access to. // ListTeamReposByID lists the repositories given a team ID that the specified team has access to.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#list-team-repos // GitHub API docs: https://developer.github.com/v3/teams/#list-team-repositories
func (s *TeamsService) ListTeamReposByID(ctx context.Context, orgID, teamID int64, opts *ListOptions) ([]*Repository, *Response, error) { func (s *TeamsService) ListTeamReposByID(ctx context.Context, orgID, teamID int64, opts *ListOptions) ([]*Repository, *Response, error) {
u := fmt.Sprintf("organizations/%v/team/%v/repos", orgID, teamID) u := fmt.Sprintf("organizations/%v/team/%v/repos", orgID, teamID)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -370,7 +370,7 @@ func (s *TeamsService) ListTeamReposByID(ctx context.Context, orgID, teamID int6
// ListTeamReposBySlug lists the repositories given a team slug that the specified team has access to. // ListTeamReposBySlug lists the repositories given a team slug that the specified team has access to.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#list-team-repos // GitHub API docs: https://developer.github.com/v3/teams/#list-team-repositories
func (s *TeamsService) ListTeamReposBySlug(ctx context.Context, org, slug string, opts *ListOptions) ([]*Repository, *Response, error) { func (s *TeamsService) ListTeamReposBySlug(ctx context.Context, org, slug string, opts *ListOptions) ([]*Repository, *Response, error) {
u := fmt.Sprintf("orgs/%v/teams/%v/repos", org, slug) u := fmt.Sprintf("orgs/%v/teams/%v/repos", org, slug)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -400,7 +400,7 @@ func (s *TeamsService) ListTeamReposBySlug(ctx context.Context, org, slug string
// repository is managed by team, a Repository is returned which includes the // repository is managed by team, a Repository is returned which includes the
// permissions team has for that repo. // permissions team has for that repo.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#check-if-a-team-manages-a-repository // GitHub API docs: https://developer.github.com/v3/teams/#check-team-permissions-for-a-repository
func (s *TeamsService) IsTeamRepoByID(ctx context.Context, orgID, teamID int64, owner, repo string) (*Repository, *Response, error) { func (s *TeamsService) IsTeamRepoByID(ctx context.Context, orgID, teamID int64, owner, repo string) (*Repository, *Response, error) {
u := fmt.Sprintf("organizations/%v/team/%v/repos/%v/%v", orgID, teamID, owner, repo) u := fmt.Sprintf("organizations/%v/team/%v/repos/%v/%v", orgID, teamID, owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -424,7 +424,7 @@ func (s *TeamsService) IsTeamRepoByID(ctx context.Context, orgID, teamID int64,
// repository is managed by team, a Repository is returned which includes the // repository is managed by team, a Repository is returned which includes the
// permissions team has for that repo. // permissions team has for that repo.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#check-if-a-team-manages-a-repository // GitHub API docs: https://developer.github.com/v3/teams/#check-team-permissions-for-a-repository
func (s *TeamsService) IsTeamRepoBySlug(ctx context.Context, org, slug, owner, repo string) (*Repository, *Response, error) { func (s *TeamsService) IsTeamRepoBySlug(ctx context.Context, org, slug, owner, repo string) (*Repository, *Response, error) {
u := fmt.Sprintf("orgs/%v/teams/%v/repos/%v/%v", org, slug, owner, repo) u := fmt.Sprintf("orgs/%v/teams/%v/repos/%v/%v", org, slug, owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -452,6 +452,8 @@ type TeamAddTeamRepoOptions struct {
// pull - team members can pull, but not push to or administer this repository // pull - team members can pull, but not push to or administer this repository
// push - team members can pull and push, but not administer this repository // push - team members can pull and push, but not administer this repository
// admin - team members can pull, push and administer this repository // admin - team members can pull, push and administer this repository
// maintain - team members can manage the repository without access to sensitive or destructive actions.
// triage - team members can proactively manage issues and pull requests without write access.
// //
// If not specified, the team's permission attribute will be used. // If not specified, the team's permission attribute will be used.
Permission string `json:"permission,omitempty"` Permission string `json:"permission,omitempty"`
@ -461,7 +463,7 @@ type TeamAddTeamRepoOptions struct {
// The specified repository must be owned by the organization to which the team // The specified repository must be owned by the organization to which the team
// belongs, or a direct fork of a repository owned by the organization. // belongs, or a direct fork of a repository owned by the organization.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#add-team-repo // GitHub API docs: https://developer.github.com/v3/teams/#add-or-update-team-repository-permissions
func (s *TeamsService) AddTeamRepoByID(ctx context.Context, orgID, teamID int64, owner, repo string, opts *TeamAddTeamRepoOptions) (*Response, error) { func (s *TeamsService) AddTeamRepoByID(ctx context.Context, orgID, teamID int64, owner, repo string, opts *TeamAddTeamRepoOptions) (*Response, error) {
u := fmt.Sprintf("organizations/%v/team/%v/repos/%v/%v", orgID, teamID, owner, repo) u := fmt.Sprintf("organizations/%v/team/%v/repos/%v/%v", orgID, teamID, owner, repo)
req, err := s.client.NewRequest("PUT", u, opts) req, err := s.client.NewRequest("PUT", u, opts)
@ -476,7 +478,7 @@ func (s *TeamsService) AddTeamRepoByID(ctx context.Context, orgID, teamID int64,
// The specified repository must be owned by the organization to which the team // The specified repository must be owned by the organization to which the team
// belongs, or a direct fork of a repository owned by the organization. // belongs, or a direct fork of a repository owned by the organization.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#add-team-repo // GitHub API docs: https://developer.github.com/v3/teams/#add-or-update-team-repository-permissions
func (s *TeamsService) AddTeamRepoBySlug(ctx context.Context, org, slug, owner, repo string, opts *TeamAddTeamRepoOptions) (*Response, error) { func (s *TeamsService) AddTeamRepoBySlug(ctx context.Context, org, slug, owner, repo string, opts *TeamAddTeamRepoOptions) (*Response, error) {
u := fmt.Sprintf("orgs/%v/teams/%v/repos/%v/%v", org, slug, owner, repo) u := fmt.Sprintf("orgs/%v/teams/%v/repos/%v/%v", org, slug, owner, repo)
req, err := s.client.NewRequest("PUT", u, opts) req, err := s.client.NewRequest("PUT", u, opts)
@ -491,7 +493,7 @@ func (s *TeamsService) AddTeamRepoBySlug(ctx context.Context, org, slug, owner,
// team given the team ID. Note that this does not delete the repository, it // team given the team ID. Note that this does not delete the repository, it
// just removes it from the team. // just removes it from the team.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#remove-team-repo // GitHub API docs: https://developer.github.com/v3/teams/#remove-a-repository-from-a-team
func (s *TeamsService) RemoveTeamRepoByID(ctx context.Context, orgID, teamID int64, owner, repo string) (*Response, error) { func (s *TeamsService) RemoveTeamRepoByID(ctx context.Context, orgID, teamID int64, owner, repo string) (*Response, error) {
u := fmt.Sprintf("organizations/%v/team/%v/repos/%v/%v", orgID, teamID, owner, repo) u := fmt.Sprintf("organizations/%v/team/%v/repos/%v/%v", orgID, teamID, owner, repo)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -506,7 +508,7 @@ func (s *TeamsService) RemoveTeamRepoByID(ctx context.Context, orgID, teamID int
// team given the team slug. Note that this does not delete the repository, it // team given the team slug. Note that this does not delete the repository, it
// just removes it from the team. // just removes it from the team.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#remove-team-repo // GitHub API docs: https://developer.github.com/v3/teams/#remove-a-repository-from-a-team
func (s *TeamsService) RemoveTeamRepoBySlug(ctx context.Context, org, slug, owner, repo string) (*Response, error) { func (s *TeamsService) RemoveTeamRepoBySlug(ctx context.Context, org, slug, owner, repo string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/teams/%v/repos/%v/%v", org, slug, owner, repo) u := fmt.Sprintf("orgs/%v/teams/%v/repos/%v/%v", org, slug, owner, repo)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -518,7 +520,7 @@ func (s *TeamsService) RemoveTeamRepoBySlug(ctx context.Context, org, slug, owne
} }
// ListUserTeams lists a user's teams // ListUserTeams lists a user's teams
// GitHub API docs: https://developer.github.com/v3/teams/#list-user-teams // GitHub API docs: https://developer.github.com/v3/teams/#list-teams-for-the-authenticated-user
func (s *TeamsService) ListUserTeams(ctx context.Context, opts *ListOptions) ([]*Team, *Response, error) { func (s *TeamsService) ListUserTeams(ctx context.Context, opts *ListOptions) ([]*Team, *Response, error) {
u := "user/teams" u := "user/teams"
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -591,7 +593,7 @@ func (s *TeamsService) ListTeamProjectsBySlug(ctx context.Context, org, slug str
// ReviewTeamProjectsByID checks whether a team, given its ID, has read, write, or admin // ReviewTeamProjectsByID checks whether a team, given its ID, has read, write, or admin
// permissions for an organization project. // permissions for an organization project.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#review-a-team-project // GitHub API docs: https://developer.github.com/v3/teams/#check-team-permissions-for-a-project
func (s *TeamsService) ReviewTeamProjectsByID(ctx context.Context, orgID, teamID, projectID int64) (*Project, *Response, error) { func (s *TeamsService) ReviewTeamProjectsByID(ctx context.Context, orgID, teamID, projectID int64) (*Project, *Response, error) {
u := fmt.Sprintf("organizations/%v/team/%v/projects/%v", orgID, teamID, projectID) u := fmt.Sprintf("organizations/%v/team/%v/projects/%v", orgID, teamID, projectID)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -615,7 +617,7 @@ func (s *TeamsService) ReviewTeamProjectsByID(ctx context.Context, orgID, teamID
// ReviewTeamProjectsBySlug checks whether a team, given its slug, has read, write, or admin // ReviewTeamProjectsBySlug checks whether a team, given its slug, has read, write, or admin
// permissions for an organization project. // permissions for an organization project.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#review-a-team-project // GitHub API docs: https://developer.github.com/v3/teams/#check-team-permissions-for-a-project
func (s *TeamsService) ReviewTeamProjectsBySlug(ctx context.Context, org, slug string, projectID int64) (*Project, *Response, error) { func (s *TeamsService) ReviewTeamProjectsBySlug(ctx context.Context, org, slug string, projectID int64) (*Project, *Response, error) {
u := fmt.Sprintf("orgs/%v/teams/%v/projects/%v", org, slug, projectID) u := fmt.Sprintf("orgs/%v/teams/%v/projects/%v", org, slug, projectID)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -652,7 +654,7 @@ type TeamProjectOptions struct {
// To add a project to a team or update the team's permission on a project, the // To add a project to a team or update the team's permission on a project, the
// authenticated user must have admin permissions for the project. // authenticated user must have admin permissions for the project.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#add-or-update-team-project // GitHub API docs: https://developer.github.com/v3/teams/#add-or-update-team-project-permissions
func (s *TeamsService) AddTeamProjectByID(ctx context.Context, orgID, teamID, projectID int64, opts *TeamProjectOptions) (*Response, error) { func (s *TeamsService) AddTeamProjectByID(ctx context.Context, orgID, teamID, projectID int64, opts *TeamProjectOptions) (*Response, error) {
u := fmt.Sprintf("organizations/%v/team/%v/projects/%v", orgID, teamID, projectID) u := fmt.Sprintf("organizations/%v/team/%v/projects/%v", orgID, teamID, projectID)
req, err := s.client.NewRequest("PUT", u, opts) req, err := s.client.NewRequest("PUT", u, opts)
@ -671,7 +673,7 @@ func (s *TeamsService) AddTeamProjectByID(ctx context.Context, orgID, teamID, pr
// To add a project to a team or update the team's permission on a project, the // To add a project to a team or update the team's permission on a project, the
// authenticated user must have admin permissions for the project. // authenticated user must have admin permissions for the project.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#add-or-update-team-project // GitHub API docs: https://developer.github.com/v3/teams/#add-or-update-team-project-permissions
func (s *TeamsService) AddTeamProjectBySlug(ctx context.Context, org, slug string, projectID int64, opts *TeamProjectOptions) (*Response, error) { func (s *TeamsService) AddTeamProjectBySlug(ctx context.Context, org, slug string, projectID int64, opts *TeamProjectOptions) (*Response, error) {
u := fmt.Sprintf("orgs/%v/teams/%v/projects/%v", org, slug, projectID) u := fmt.Sprintf("orgs/%v/teams/%v/projects/%v", org, slug, projectID)
req, err := s.client.NewRequest("PUT", u, opts) req, err := s.client.NewRequest("PUT", u, opts)
@ -693,7 +695,7 @@ func (s *TeamsService) AddTeamProjectBySlug(ctx context.Context, org, slug strin
// or project. // or project.
// Note: This endpoint removes the project from the team, but does not delete it. // Note: This endpoint removes the project from the team, but does not delete it.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#remove-team-project // GitHub API docs: https://developer.github.com/v3/teams/#remove-a-project-from-a-team
func (s *TeamsService) RemoveTeamProjectByID(ctx context.Context, orgID, teamID, projectID int64) (*Response, error) { func (s *TeamsService) RemoveTeamProjectByID(ctx context.Context, orgID, teamID, projectID int64) (*Response, error) {
u := fmt.Sprintf("organizations/%v/team/%v/projects/%v", orgID, teamID, projectID) u := fmt.Sprintf("organizations/%v/team/%v/projects/%v", orgID, teamID, projectID)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -715,7 +717,7 @@ func (s *TeamsService) RemoveTeamProjectByID(ctx context.Context, orgID, teamID,
// or project. // or project.
// Note: This endpoint removes the project from the team, but does not delete it. // Note: This endpoint removes the project from the team, but does not delete it.
// //
// GitHub API docs: https://developer.github.com/v3/teams/#remove-team-project // GitHub API docs: https://developer.github.com/v3/teams/#remove-a-project-from-a-team
func (s *TeamsService) RemoveTeamProjectBySlug(ctx context.Context, org, slug string, projectID int64) (*Response, error) { func (s *TeamsService) RemoveTeamProjectBySlug(ctx context.Context, org, slug string, projectID int64) (*Response, error) {
u := fmt.Sprintf("orgs/%v/teams/%v/projects/%v", org, slug, projectID) u := fmt.Sprintf("orgs/%v/teams/%v/projects/%v", org, slug, projectID)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
@ -744,7 +746,7 @@ type IDPGroup struct {
// ListIDPGroupsInOrganization lists IDP groups available in an organization. // ListIDPGroupsInOrganization lists IDP groups available in an organization.
// //
// GitHub API docs: https://developer.github.com/v3/teams/team_sync/#list-idp-groups-in-an-organization // GitHub API docs: https://developer.github.com/v3/teams/team_sync/#list-idp-groups-for-an-organization
func (s *TeamsService) ListIDPGroupsInOrganization(ctx context.Context, org string, opts *ListCursorOptions) (*IDPGroupList, *Response, error) { func (s *TeamsService) ListIDPGroupsInOrganization(ctx context.Context, org string, opts *ListCursorOptions) (*IDPGroupList, *Response, error) {
u := fmt.Sprintf("orgs/%v/team-sync/groups", org) u := fmt.Sprintf("orgs/%v/team-sync/groups", org)
u, err := addOptions(u, opts) u, err := addOptions(u, opts)
@ -765,11 +767,12 @@ func (s *TeamsService) ListIDPGroupsInOrganization(ctx context.Context, org stri
return groups, resp, nil return groups, resp, nil
} }
// ListIDPGroupsForTeam lists IDP groups connected to a team on GitHub. // ListIDPGroupsForTeamByID lists IDP groups connected to a team on GitHub
// given organization and team IDs.
// //
// GitHub API docs: https://developer.github.com/v3/teams/team_sync/#list-idp-groups-for-a-team // GitHub API docs: https://developer.github.com/v3/teams/team_sync/#list-idp-groups-for-a-team
func (s *TeamsService) ListIDPGroupsForTeam(ctx context.Context, teamID string) (*IDPGroupList, *Response, error) { func (s *TeamsService) ListIDPGroupsForTeamByID(ctx context.Context, orgID, teamID int64) (*IDPGroupList, *Response, error) {
u := fmt.Sprintf("teams/%v/team-sync/group-mappings", teamID) u := fmt.Sprintf("organizations/%v/team/%v/team-sync/group-mappings", orgID, teamID)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
@ -784,12 +787,53 @@ func (s *TeamsService) ListIDPGroupsForTeam(ctx context.Context, teamID string)
return groups, resp, err return groups, resp, err
} }
// CreateOrUpdateIDPGroupConnections creates, updates, or removes a connection between a team // ListIDPGroupsForTeamBySlug lists IDP groups connected to a team on GitHub
// and an IDP group. // given organization name and team slug.
//
// GitHub API docs: https://developer.github.com/v3/teams/team_sync/#list-idp-groups-for-a-team
func (s *TeamsService) ListIDPGroupsForTeamBySlug(ctx context.Context, org, slug string) (*IDPGroupList, *Response, error) {
u := fmt.Sprintf("orgs/%v/teams/%v/team-sync/group-mappings", org, slug)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
groups := new(IDPGroupList)
resp, err := s.client.Do(ctx, req, groups)
if err != nil {
return nil, resp, err
}
return groups, resp, err
}
// CreateOrUpdateIDPGroupConnectionsByID creates, updates, or removes a connection
// between a team and an IDP group given organization and team IDs.
// //
// GitHub API docs: https://developer.github.com/v3/teams/team_sync/#create-or-update-idp-group-connections // GitHub API docs: https://developer.github.com/v3/teams/team_sync/#create-or-update-idp-group-connections
func (s *TeamsService) CreateOrUpdateIDPGroupConnections(ctx context.Context, teamID string, opts IDPGroupList) (*IDPGroupList, *Response, error) { func (s *TeamsService) CreateOrUpdateIDPGroupConnectionsByID(ctx context.Context, orgID, teamID int64, opts IDPGroupList) (*IDPGroupList, *Response, error) {
u := fmt.Sprintf("teams/%v/team-sync/group-mappings", teamID) u := fmt.Sprintf("organizations/%v/team/%v/team-sync/group-mappings", orgID, teamID)
req, err := s.client.NewRequest("PATCH", u, opts)
if err != nil {
return nil, nil, err
}
groups := new(IDPGroupList)
resp, err := s.client.Do(ctx, req, groups)
if err != nil {
return nil, resp, err
}
return groups, resp, nil
}
// CreateOrUpdateIDPGroupConnectionsBySlug creates, updates, or removes a connection
// between a team and an IDP group given organization name and team slug.
//
// GitHub API docs: https://developer.github.com/v3/teams/team_sync/#create-or-update-idp-group-connections
func (s *TeamsService) CreateOrUpdateIDPGroupConnectionsBySlug(ctx context.Context, org, slug string, opts IDPGroupList) (*IDPGroupList, *Response, error) {
u := fmt.Sprintf("orgs/%v/teams/%v/team-sync/group-mappings", org, slug)
req, err := s.client.NewRequest("PATCH", u, opts) req, err := s.client.NewRequest("PATCH", u, opts)
if err != nil { if err != nil {

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