From 255182965aa289e0f830ed110bd36bbf43c3dc7c Mon Sep 17 00:00:00 2001 From: Jay Wallace Date: Thu, 8 Jun 2017 22:10:32 -0700 Subject: [PATCH 1/4] updated go-github --- .../go-github/github/activity_events.go | 12 +- .../github/{integration.go => apps.go} | 14 +- ...n_installation.go => apps_installation.go} | 9 +- .../google/go-github/github/authorizations.go | 9 +- .../github.com/google/go-github/github/doc.go | 40 ++- .../google/go-github/github/event_types.go | 83 ++++- .../google/go-github/github/gen-accessors.go | 299 ----------------- .../google/go-github/github/gists.go | 7 +- .../google/go-github/github/git_commits.go | 1 + .../google/go-github/github/git_refs.go | 58 +++- .../google/go-github/github/git_trees.go | 1 + .../go-github/github/github-accessors.go | 308 ++++++++++++++---- .../google/go-github/github/github.go | 28 +- .../google/go-github/github/issues_events.go | 3 +- .../google/go-github/github/issues_labels.go | 3 +- .../go-github/github/issues_milestones.go | 6 +- .../google/go-github/github/messages.go | 75 +++-- .../google/go-github/github/misc.go | 55 ++++ .../google/go-github/github/orgs_members.go | 3 - .../github/orgs_outside_collaborators.go | 3 - .../google/go-github/github/orgs_projects.go | 60 ++++ .../google/go-github/github/orgs_teams.go | 7 +- .../go-github/github/orgs_users_blocking.go | 91 ++++++ .../google/go-github/github/pulls.go | 89 ++--- .../go-github/github/pulls_reviewers.go | 15 +- .../google/go-github/github/pulls_reviews.go | 35 +- .../google/go-github/github/repos.go | 78 ++++- .../go-github/github/repos_collaborators.go | 3 - .../google/go-github/github/repos_commits.go | 6 + .../github/repos_community_health.go | 57 ++++ .../google/go-github/github/repos_contents.go | 11 +- .../go-github/github/repos_invitations.go | 6 +- .../google/go-github/github/repos_pages.go | 7 +- .../google/go-github/github/repos_projects.go | 15 +- .../google/go-github/github/repos_releases.go | 3 +- .../google/go-github/github/search.go | 22 +- .../google/go-github/github/users.go | 9 +- .../google/go-github/github/users_blocking.go | 91 ++++++ .../google/go-github/github/users_gpg_keys.go | 22 +- .../go-github/github/without_appengine.go | 19 ++ vendor/vendor.json | 8 +- 41 files changed, 1103 insertions(+), 568 deletions(-) rename vendor/github.com/google/go-github/github/{integration.go => apps.go} (54%) rename vendor/github.com/google/go-github/github/{integration_installation.go => apps_installation.go} (72%) delete mode 100644 vendor/github.com/google/go-github/github/gen-accessors.go create mode 100644 vendor/github.com/google/go-github/github/orgs_projects.go create mode 100644 vendor/github.com/google/go-github/github/orgs_users_blocking.go create mode 100644 vendor/github.com/google/go-github/github/repos_community_health.go create mode 100644 vendor/github.com/google/go-github/github/users_blocking.go create mode 100644 vendor/github.com/google/go-github/github/without_appengine.go diff --git a/vendor/github.com/google/go-github/github/activity_events.go b/vendor/github.com/google/go-github/github/activity_events.go index 78219f8ab9cb..6b35056f4045 100644 --- a/vendor/github.com/google/go-github/github/activity_events.go +++ b/vendor/github.com/google/go-github/github/activity_events.go @@ -46,10 +46,10 @@ func (e *Event) ParsePayload() (payload interface{}, err error) { payload = &ForkEvent{} case "GollumEvent": payload = &GollumEvent{} - case "IntegrationInstallationEvent": - payload = &IntegrationInstallationEvent{} - case "IntegrationInstallationRepositoriesEvent": - payload = &IntegrationInstallationRepositoriesEvent{} + case "InstallationEvent": + payload = &InstallationEvent{} + case "InstallationRepositoriesEvent": + payload = &InstallationRepositoriesEvent{} case "IssueCommentEvent": payload = &IssueCommentEvent{} case "IssuesEvent": @@ -64,6 +64,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) { payload = &MilestoneEvent{} case "OrganizationEvent": payload = &OrganizationEvent{} + case "OrgBlockEvent": + payload = &OrgBlockEvent{} case "PageBuildEvent": payload = &PageBuildEvent{} case "PingEvent": @@ -90,6 +92,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) { payload = &RepositoryEvent{} case "StatusEvent": payload = &StatusEvent{} + case "TeamEvent": + payload = &TeamEvent{} case "TeamAddEvent": payload = &TeamAddEvent{} case "WatchEvent": diff --git a/vendor/github.com/google/go-github/github/integration.go b/vendor/github.com/google/go-github/github/apps.go similarity index 54% rename from vendor/github.com/google/go-github/github/integration.go rename to vendor/github.com/google/go-github/github/apps.go index 6d74e44f007c..ff3389382eed 100644 --- a/vendor/github.com/google/go-github/github/integration.go +++ b/vendor/github.com/google/go-github/github/apps.go @@ -7,17 +7,17 @@ package github import "context" -// IntegrationsService provides access to the installation related functions +// AppsService provides access to the installation related functions // in the GitHub API. // -// GitHub API docs: https://developer.github.com/v3/integrations/ -type IntegrationsService service +// GitHub API docs: https://developer.github.com/v3/apps/ +type AppsService service -// ListInstallations lists the installations that the current integration has. +// ListInstallations lists the installations that the current GitHub App has. // -// GitHub API docs: https://developer.github.com/v3/integrations/#find-installations -func (s *IntegrationsService) ListInstallations(ctx context.Context, opt *ListOptions) ([]*Installation, *Response, error) { - u, err := addOptions("integration/installations", opt) +// GitHub API docs: https://developer.github.com/v3/apps/#find-installations +func (s *AppsService) ListInstallations(ctx context.Context, opt *ListOptions) ([]*Installation, *Response, error) { + u, err := addOptions("app/installations", opt) if err != nil { return nil, nil, err } diff --git a/vendor/github.com/google/go-github/github/integration_installation.go b/vendor/github.com/google/go-github/github/apps_installation.go similarity index 72% rename from vendor/github.com/google/go-github/github/integration_installation.go rename to vendor/github.com/google/go-github/github/apps_installation.go index 933106400bfb..6a2779953157 100644 --- a/vendor/github.com/google/go-github/github/integration_installation.go +++ b/vendor/github.com/google/go-github/github/apps_installation.go @@ -7,22 +7,23 @@ package github import "context" -// Installation represents a GitHub integration installation. +// Installation represents a GitHub Apps installation. type Installation struct { ID *int `json:"id,omitempty"` Account *User `json:"account,omitempty"` AccessTokensURL *string `json:"access_tokens_url,omitempty"` RepositoriesURL *string `json:"repositories_url,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` } func (i Installation) String() string { return Stringify(i) } -// ListRepos lists the repositories that the current installation has access to. +// ListRepos lists the repositories that are accessible to the authenticated installation. // -// GitHub API docs: https://developer.github.com/v3/integrations/installations/#list-repositories -func (s *IntegrationsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repository, *Response, error) { +// GitHub API docs: https://developer.github.com/v3/apps/installations/#list-repositories +func (s *AppsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repository, *Response, error) { u, err := addOptions("installation/repositories", opt) if err != nil { return nil, nil, err diff --git a/vendor/github.com/google/go-github/github/authorizations.go b/vendor/github.com/google/go-github/github/authorizations.go index 181e83dfe54a..d87adc0bdc46 100644 --- a/vendor/github.com/google/go-github/github/authorizations.go +++ b/vendor/github.com/google/go-github/github/authorizations.go @@ -343,8 +343,13 @@ func (s *AuthorizationsService) Revoke(ctx context.Context, clientID string, tok // 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) ([]*Grant, *Response, error) { - req, err := s.client.NewRequest("GET", "applications/grants", nil) +func (s *AuthorizationsService) ListGrants(ctx context.Context, opt *ListOptions) ([]*Grant, *Response, error) { + u, err := addOptions("applications/grants", opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err } diff --git a/vendor/github.com/google/go-github/github/doc.go b/vendor/github.com/google/go-github/github/doc.go index 875f039648af..abbcf6406f46 100644 --- a/vendor/github.com/google/go-github/github/doc.go +++ b/vendor/github.com/google/go-github/github/doc.go @@ -63,6 +63,24 @@ See the oauth2 docs for complete instructions on using that library. For API methods that require HTTP Basic Authentication, use the BasicAuthTransport. +GitHub Apps authentication can be provided by the +https://github.com/bradleyfalzon/ghinstallation package. + + import "github.com/bradleyfalzon/ghinstallation" + + func main() { + // Wrap the shared transport for use with the integration ID 1 authenticating with installation ID 99. + itr, err := ghinstallation.NewKeyFromFile(http.DefaultTransport, 1, 99, "2016-10-19.private-key.pem") + if err != nil { + // Handle error. + } + + // Use installation transport with client + client := github.NewClient(&http.Client{Transport: itr}) + + // Use client... + } + Rate Limiting GitHub imposes a rate limit on all API clients. Unauthenticated clients are @@ -71,11 +89,10 @@ limited to 60 requests per hour, while authenticated clients can make up to that are not issued on behalf of a user, use the UnauthenticatedRateLimitedTransport. -The Rate method on a client returns the rate limit information based on the most -recent API call. This is updated on every call, but may be out of date if it's -been some time since the last API call and other clients have made subsequent -requests since then. You can always call RateLimits() directly to get the most -up-to-date rate limit data for the client. +The returned Response.Rate value contains the rate limit information +from the most recent API call. If a recent enough response isn't +available, you can use RateLimits to fetch the most up-to-date rate +limit data for the client. To detect an API rate limit error, you can check if its type is *github.RateLimitError: @@ -154,8 +171,19 @@ github.Response struct. if resp.NextPage == 0 { break } - opt.ListOptions.Page = resp.NextPage + opt.Page = resp.NextPage } +Google App Engine + +Go on App Engine Classic (which as of this writing uses Go 1.6) can not use +the "context" import and still relies on "golang.org/x/net/context". +As a result, if you wish to continue to use "go-github" on App Engine Classic, +you will need to rewrite all the "context" imports using the following command: + + gofmt -w -r '"context" -> "golang.org/x/net/context"' *.go + +See "with_appengine.go" for more details. + */ package github diff --git a/vendor/github.com/google/go-github/github/event_types.go b/vendor/github.com/google/go-github/github/event_types.go index 4fb5d955e8ad..c6b29b9a242d 100644 --- a/vendor/github.com/google/go-github/github/event_types.go +++ b/vendor/github.com/google/go-github/github/event_types.go @@ -165,28 +165,49 @@ type ProjectColumnChange struct { } `json:"name,omitempty"` } -// IntegrationInstallationEvent is triggered when an integration is created or deleted. -// The Webhook event name is "integration_installation". -// -// GitHub API docs: https://developer.github.com/early-access/integrations/webhooks/#integrationinstallationevent -type IntegrationInstallationEvent struct { - // The action that was performed. Possible values for an "integration_installation" - // event are: "created", "deleted". +// TeamChange represents the changes when a team has been edited. +type TeamChange struct { + Description *struct { + From *string `json:"from,omitempty"` + } `json:"description,omitempty"` + Name *struct { + From *string `json:"from,omitempty"` + } `json:"name,omitempty"` + Privacy *struct { + From *string `json:"from,omitempty"` + } `json:"privacy,omitempty"` + Repository *struct { + Permissions *struct { + From *struct { + Admin *bool `json:"admin,omitempty"` + Pull *bool `json:"pull,omitempty"` + Push *bool `json:"push,omitempty"` + } `json:"from,omitempty"` + } `json:"permissions,omitempty"` + } `json:"repository,omitempty"` +} + +// InstallationEvent is triggered when a GitHub App has been installed or uninstalled. +// The Webhook event name is "installation". +// +// GitHub API docs: https://developer.github.com/v3/activity/events/types/#installationevent +type InstallationEvent struct { + // The action that was performed. Can be either "created" or "deleted". Action *string `json:"action,omitempty"` Sender *User `json:"sender,omitempty"` Installation *Installation `json:"installation,omitempty"` } -// IntegrationInstallationRepositoriesEvent is triggered when an integration repository -// is added or removed. The Webhook event name is "integration_installation_repositories". +// InstallationRepositoriesEvent is triggered when a repository is added or +// removed from an installation. The Webhook event name is "installation_repositories". // -// GitHub API docs: https://developer.github.com/early-access/integrations/webhooks/#integrationinstallationrepositoriesevent -type IntegrationInstallationRepositoriesEvent struct { - // The action that was performed. Possible values for an "integration_installation_repositories" - // event are: "added", "removed". +// GitHub API docs: https://developer.github.com/v3/activity/events/types/#installationrepositoriesevent +type InstallationRepositoriesEvent struct { + // The action that was performed. Can be either "added" or "removed". Action *string `json:"action,omitempty"` RepositoriesAdded []*Repository `json:"repositories_added,omitempty"` RepositoriesRemoved []*Repository `json:"repositories_removed,omitempty"` + RepositorySelection *string `json:"repository_selection,omitempty"` Sender *User `json:"sender,omitempty"` Installation *Installation `json:"installation,omitempty"` } @@ -323,6 +344,22 @@ type OrganizationEvent struct { Installation *Installation `json:"installation,omitempty"` } +// OrgBlockEvent is triggered when an organization blocks or unblocks a user. +// The Webhook event name is "org_block". +// +// GitHub API docs: https://developer.github.com/v3/activity/events/types/#orgblockevent +type OrgBlockEvent struct { + // Action is the action that was performed. + // Can be "blocked" or "unblocked". + Action *string `json:"action,omitempty"` + BlockedUser *User `json:"blocked_user,omitempty"` + Organization *Organization `json:"organization,omitempty"` + Sender *User `json:"sender,omitempty"` + + // The following fields are only populated by Webhook events. + Installation *Installation `json:"installation,omitempty"` +} + // PageBuildEvent represents an attempted build of a GitHub Pages site, whether // successful or not. // The Webhook event name is "page_build". @@ -561,6 +598,7 @@ type PushEventRepository struct { MasterBranch *string `json:"master_branch,omitempty"` Organization *string `json:"organization,omitempty"` URL *string `json:"url,omitempty"` + ArchiveURL *string `json:"archive_url,omitempty"` HTMLURL *string `json:"html_url,omitempty"` StatusesURL *string `json:"statuses_url,omitempty"` GitURL *string `json:"git_url,omitempty"` @@ -636,6 +674,25 @@ type StatusEvent struct { Installation *Installation `json:"installation,omitempty"` } +// TeamEvent is triggered when an organization's team is created, modified or deleted. +// The Webhook event name is "team". +// +// Events of this type are not visible in timelines. These events are only used +// to trigger hooks. +// +// GitHub API docs: https://developer.github.com/v3/activity/events/types/#teamevent +type TeamEvent struct { + Action *string `json:"action,omitempty"` + Team *Team `json:"team,omitempty"` + Changes *TeamChange `json:"changes,omitempty"` + Repo *Repository `json:"repository,omitempty"` + + // The following fields are only populated by Webhook events. + Org *Organization `json:"organization,omitempty"` + Sender *User `json:"sender,omitempty"` + Installation *Installation `json:"installation,omitempty"` +} + // TeamAddEvent is triggered when a repository is added to a team. // The Webhook event name is "team_add". // diff --git a/vendor/github.com/google/go-github/github/gen-accessors.go b/vendor/github.com/google/go-github/github/gen-accessors.go deleted file mode 100644 index 131c56cbf009..000000000000 --- a/vendor/github.com/google/go-github/github/gen-accessors.go +++ /dev/null @@ -1,299 +0,0 @@ -// Copyright 2017 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. - -// +build ignore - -// gen-accessors generates accessor methods for structs with pointer fields. -// -// It is meant to be used by the go-github authors in conjunction with the -// go generate tool before sending a commit to GitHub. -package main - -import ( - "bytes" - "flag" - "fmt" - "go/ast" - "go/format" - "go/parser" - "go/token" - "io/ioutil" - "log" - "os" - "sort" - "strings" - "text/template" - "time" -) - -const ( - fileSuffix = "-accessors.go" -) - -var ( - verbose = flag.Bool("v", false, "Print verbose log messages") - - sourceTmpl = template.Must(template.New("source").Parse(source)) - - // blacklist lists which "struct.method" combos to not generate. - blacklist = map[string]bool{ - "RepositoryContent.GetContent": true, - "Client.GetBaseURL": true, - "Client.GetUploadURL": true, - "ErrorResponse.GetResponse": true, - "RateLimitError.GetResponse": true, - "AbuseRateLimitError.GetResponse": true, - } -) - -func logf(fmt string, args ...interface{}) { - if *verbose { - log.Printf(fmt, args...) - } -} - -func main() { - flag.Parse() - fset := token.NewFileSet() - - pkgs, err := parser.ParseDir(fset, ".", sourceFilter, 0) - if err != nil { - log.Fatal(err) - return - } - - for pkgName, pkg := range pkgs { - t := &templateData{ - filename: pkgName + fileSuffix, - Year: time.Now().Year(), - Package: pkgName, - Imports: map[string]string{}, - } - for filename, f := range pkg.Files { - logf("Processing %v...", filename) - if err := t.processAST(f); err != nil { - log.Fatal(err) - } - } - if err := t.dump(); err != nil { - log.Fatal(err) - } - } - logf("Done.") -} - -func (t *templateData) processAST(f *ast.File) error { - for _, decl := range f.Decls { - gd, ok := decl.(*ast.GenDecl) - if !ok { - continue - } - for _, spec := range gd.Specs { - ts, ok := spec.(*ast.TypeSpec) - if !ok { - continue - } - st, ok := ts.Type.(*ast.StructType) - if !ok { - continue - } - for _, field := range st.Fields.List { - se, ok := field.Type.(*ast.StarExpr) - if len(field.Names) == 0 || !ok { - continue - } - - fieldName := field.Names[0] - if key := fmt.Sprintf("%v.Get%v", ts.Name, fieldName); blacklist[key] { - logf("Method %v blacklisted; skipping.", key) - continue - } - - switch x := se.X.(type) { - case *ast.ArrayType: - t.addArrayType(x, ts.Name.String(), fieldName.String()) - case *ast.Ident: - t.addIdent(x, ts.Name.String(), fieldName.String()) - case *ast.MapType: - t.addMapType(x, ts.Name.String(), fieldName.String()) - case *ast.SelectorExpr: - t.addSelectorExpr(x, ts.Name.String(), fieldName.String()) - default: - logf("processAST: type %q, field %q, unknown %T: %+v", ts.Name, fieldName, x, x) - } - } - } - } - return nil -} - -func sourceFilter(fi os.FileInfo) bool { - return !strings.HasSuffix(fi.Name(), "_test.go") && !strings.HasSuffix(fi.Name(), fileSuffix) -} - -func (t *templateData) dump() error { - if len(t.Getters) == 0 { - logf("No getters for %v; skipping.", t.filename) - return nil - } - - // Sort getters by ReceiverType.FieldName - sort.Sort(byName(t.Getters)) - - var buf bytes.Buffer - if err := sourceTmpl.Execute(&buf, t); err != nil { - return err - } - clean, err := format.Source(buf.Bytes()) - if err != nil { - return err - } - - logf("Writing %v...", t.filename) - return ioutil.WriteFile(t.filename, clean, 0644) -} - -func newGetter(receiverType, fieldName, fieldType, zeroValue string) *getter { - return &getter{ - sortVal: strings.ToLower(receiverType) + "." + strings.ToLower(fieldName), - ReceiverVar: strings.ToLower(receiverType[:1]), - ReceiverType: receiverType, - FieldName: fieldName, - FieldType: fieldType, - ZeroValue: zeroValue, - } -} - -func (t *templateData) addArrayType(x *ast.ArrayType, receiverType, fieldName string) { - var eltType string - switch elt := x.Elt.(type) { - case *ast.Ident: - eltType = elt.String() - default: - logf("addArrayType: type %q, field %q: unknown elt type: %T %+v; skipping.", receiverType, fieldName, elt, elt) - return - } - - t.Getters = append(t.Getters, newGetter(receiverType, fieldName, "[]"+eltType, "nil")) -} - -func (t *templateData) addIdent(x *ast.Ident, receiverType, fieldName string) { - var zeroValue string - switch x.String() { - case "int": - zeroValue = "0" - case "string": - zeroValue = `""` - case "bool": - zeroValue = "false" - case "Timestamp": - zeroValue = "Timestamp{}" - default: // other structs handled by their receivers directly. - return - } - - t.Getters = append(t.Getters, newGetter(receiverType, fieldName, x.String(), zeroValue)) -} - -func (t *templateData) addMapType(x *ast.MapType, receiverType, fieldName string) { - var keyType string - switch key := x.Key.(type) { - case *ast.Ident: - keyType = key.String() - default: - logf("addMapType: type %q, field %q: unknown key type: %T %+v; skipping.", receiverType, fieldName, key, key) - return - } - - var valueType string - switch value := x.Value.(type) { - case *ast.Ident: - valueType = value.String() - default: - logf("addMapType: type %q, field %q: unknown value type: %T %+v; skipping.", receiverType, fieldName, value, value) - return - } - - fieldType := fmt.Sprintf("map[%v]%v", keyType, valueType) - zeroValue := fmt.Sprintf("map[%v]%v{}", keyType, valueType) - t.Getters = append(t.Getters, newGetter(receiverType, fieldName, fieldType, zeroValue)) -} - -func (t *templateData) addSelectorExpr(x *ast.SelectorExpr, receiverType, fieldName string) { - if strings.ToLower(fieldName[:1]) == fieldName[:1] { // non-exported field - return - } - - var xX string - if xx, ok := x.X.(*ast.Ident); ok { - xX = xx.String() - } - - switch xX { - case "time", "json": - if xX == "json" { - t.Imports["encoding/json"] = "encoding/json" - } else { - t.Imports[xX] = xX - } - fieldType := fmt.Sprintf("%v.%v", xX, x.Sel.Name) - zeroValue := fmt.Sprintf("%v.%v{}", xX, x.Sel.Name) - if xX == "time" && x.Sel.Name == "Duration" { - zeroValue = "0" - } - t.Getters = append(t.Getters, newGetter(receiverType, fieldName, fieldType, zeroValue)) - default: - logf("addSelectorExpr: xX %q, type %q, field %q: unknown x=%+v; skipping.", xX, receiverType, fieldName, x) - } -} - -type templateData struct { - filename string - Year int - Package string - Imports map[string]string - Getters []*getter -} - -type getter struct { - sortVal string // lower-case version of "ReceiverType.FieldName" - ReceiverVar string // the one-letter variable name to match the ReceiverType - ReceiverType string - FieldName string - FieldType string - ZeroValue string -} - -type byName []*getter - -func (b byName) Len() int { return len(b) } -func (b byName) Less(i, j int) bool { return b[i].sortVal < b[j].sortVal } -func (b byName) Swap(i, j int) { b[i], b[j] = b[j], b[i] } - -const source = `// Copyright {{.Year}} 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. - -// Code generated by gen-accessors; DO NOT EDIT. - -package {{.Package}} -{{with .Imports}} -import ( - {{- range . -}} - "{{.}}" - {{end -}} -) -{{end}} -{{range .Getters}} -// Get{{.FieldName}} returns the {{.FieldName}} field if it's non-nil, zero value otherwise. -func ({{.ReceiverVar}} *{{.ReceiverType}}) Get{{.FieldName}}() {{.FieldType}} { - if {{.ReceiverVar}} == nil || {{.ReceiverVar}}.{{.FieldName}} == nil { - return {{.ZeroValue}} - } - return *{{.ReceiverVar}}.{{.FieldName}} -} -{{end}} -` diff --git a/vendor/github.com/google/go-github/github/gists.go b/vendor/github.com/google/go-github/github/gists.go index e7d6586c6085..15276ea1d7ab 100644 --- a/vendor/github.com/google/go-github/github/gists.go +++ b/vendor/github.com/google/go-github/github/gists.go @@ -241,8 +241,13 @@ func (s *GistsService) Edit(ctx context.Context, id string, gist *Gist) (*Gist, // ListCommits lists commits of a gist. // // GitHub API docs: https://developer.github.com/v3/gists/#list-gist-commits -func (s *GistsService) ListCommits(ctx context.Context, id string) ([]*GistCommit, *Response, error) { +func (s *GistsService) ListCommits(ctx context.Context, id string, opt *ListOptions) ([]*GistCommit, *Response, error) { u := fmt.Sprintf("gists/%v/commits", id) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err diff --git a/vendor/github.com/google/go-github/github/git_commits.go b/vendor/github.com/google/go-github/github/git_commits.go index 22cb49afaf88..3c49a8a2992f 100644 --- a/vendor/github.com/google/go-github/github/git_commits.go +++ b/vendor/github.com/google/go-github/github/git_commits.go @@ -28,6 +28,7 @@ type Commit struct { Tree *Tree `json:"tree,omitempty"` Parents []Commit `json:"parents,omitempty"` Stats *CommitStats `json:"stats,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` URL *string `json:"url,omitempty"` Verification *SignatureVerification `json:"verification,omitempty"` diff --git a/vendor/github.com/google/go-github/github/git_refs.go b/vendor/github.com/google/go-github/github/git_refs.go index bd5df3f72ad3..e78fdc6c090b 100644 --- a/vendor/github.com/google/go-github/github/git_refs.go +++ b/vendor/github.com/google/go-github/github/git_refs.go @@ -7,6 +7,8 @@ package github import ( "context" + "encoding/json" + "errors" "fmt" "strings" ) @@ -45,7 +47,11 @@ type updateRefRequest struct { Force *bool `json:"force"` } -// GetRef fetches the Reference object for a given Git ref. +// GetRef fetches a single Reference object for a given Git ref. +// 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 func (s *GitService) GetRef(ctx context.Context, owner string, repo string, ref string) (*Reference, *Response, error) { @@ -58,13 +64,61 @@ func (s *GitService) GetRef(ctx context.Context, owner string, repo string, ref r := new(Reference) resp, err := s.client.Do(ctx, req, r) - if err != nil { + if _, ok := err.(*json.UnmarshalTypeError); ok { + // Multiple refs, means there wasn't an exact match. + return nil, resp, errors.New("no exact match found for this ref") + } else if err != nil { return nil, resp, err } return r, resp, nil } +// GetRefs fetches a slice of Reference objects for a given Git ref. +// If there is an exact match, only that ref is returned. +// If there is no exact match, GitHub returns all refs that start with ref. +// If returned error is nil, there will be at least 1 ref returned. +// For example: +// +// "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, ref) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + 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 // GitService.ListRefs method. type ReferenceListOptions struct { diff --git a/vendor/github.com/google/go-github/github/git_trees.go b/vendor/github.com/google/go-github/github/git_trees.go index bdd481f1ee13..4d6809a880e5 100644 --- a/vendor/github.com/google/go-github/github/git_trees.go +++ b/vendor/github.com/google/go-github/github/git_trees.go @@ -30,6 +30,7 @@ type TreeEntry struct { Type *string `json:"type,omitempty"` Size *int `json:"size,omitempty"` Content *string `json:"content,omitempty"` + URL *string `json:"url,omitempty"` } func (t TreeEntry) String() string { diff --git a/vendor/github.com/google/go-github/github/github-accessors.go b/vendor/github.com/google/go-github/github/github-accessors.go index fd3b31cc4637..0e6d14440f73 100644 --- a/vendor/github.com/google/go-github/github/github-accessors.go +++ b/vendor/github.com/google/go-github/github/github-accessors.go @@ -20,6 +20,14 @@ func (a *AbuseRateLimitError) GetRetryAfter() time.Duration { return *a.RetryAfter } +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (a *AdminEnforcement) GetURL() string { + if a == nil || a.URL == nil { + return "" + } + return *a.URL +} + // GetVerifiablePasswordAuthentication returns the VerifiablePasswordAuthentication field if it's non-nil, zero value otherwise. func (a *APIMeta) GetVerifiablePasswordAuthentication() bool { if a == nil || a.VerifiablePasswordAuthentication == nil { @@ -252,6 +260,38 @@ func (b *Branch) GetProtected() bool { return *b.Protected } +// GetBody returns the Body field if it's non-nil, zero value otherwise. +func (c *CodeOfConduct) GetBody() string { + if c == nil || c.Body == nil { + return "" + } + return *c.Body +} + +// GetKey returns the Key field if it's non-nil, zero value otherwise. +func (c *CodeOfConduct) GetKey() string { + if c == nil || c.Key == nil { + return "" + } + return *c.Key +} + +// GetName returns the Name field if it's non-nil, zero value otherwise. +func (c *CodeOfConduct) GetName() string { + if c == nil || c.Name == nil { + return "" + } + return *c.Name +} + +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (c *CodeOfConduct) GetURL() string { + if c == nil || c.URL == nil { + return "" + } + return *c.URL +} + // GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. func (c *CodeResult) GetHTMLURL() string { if c == nil || c.HTMLURL == nil { @@ -356,6 +396,14 @@ func (c *Commit) GetCommentCount() int { return *c.CommentCount } +// GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. +func (c *Commit) GetHTMLURL() string { + if c == nil || c.HTMLURL == nil { + return "" + } + return *c.HTMLURL +} + // GetMessage returns the Message field if it's non-nil, zero value otherwise. func (c *Commit) GetMessage() string { if c == nil || c.Message == nil { @@ -500,100 +548,84 @@ func (c *CommitFile) GetStatus() string { return *c.Status } -// GetAuthorDate returns the AuthorDate field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetAuthorDate() Timestamp { - if c == nil || c.AuthorDate == nil { - return Timestamp{} - } - return *c.AuthorDate -} - -// GetAuthorEmail returns the AuthorEmail field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetAuthorEmail() string { - if c == nil || c.AuthorEmail == nil { +// GetCommentsURL returns the CommentsURL field if it's non-nil, zero value otherwise. +func (c *CommitResult) GetCommentsURL() string { + if c == nil || c.CommentsURL == nil { return "" } - return *c.AuthorEmail -} - -// GetAuthorID returns the AuthorID field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetAuthorID() int { - if c == nil || c.AuthorID == nil { - return 0 - } - return *c.AuthorID + return *c.CommentsURL } -// GetAuthorName returns the AuthorName field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetAuthorName() string { - if c == nil || c.AuthorName == nil { +// GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. +func (c *CommitResult) GetHTMLURL() string { + if c == nil || c.HTMLURL == nil { return "" } - return *c.AuthorName + return *c.HTMLURL } -// GetCommitterDate returns the CommitterDate field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetCommitterDate() Timestamp { - if c == nil || c.CommitterDate == nil { - return Timestamp{} +// GetSHA returns the SHA field if it's non-nil, zero value otherwise. +func (c *CommitResult) GetSHA() string { + if c == nil || c.SHA == nil { + return "" } - return *c.CommitterDate + return *c.SHA } -// GetCommitterEmail returns the CommitterEmail field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetCommitterEmail() string { - if c == nil || c.CommitterEmail == nil { +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (c *CommitResult) GetURL() string { + if c == nil || c.URL == nil { return "" } - return *c.CommitterEmail + return *c.URL } -// GetCommitterID returns the CommitterID field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetCommitterID() int { - if c == nil || c.CommitterID == nil { +// GetAheadBy returns the AheadBy field if it's non-nil, zero value otherwise. +func (c *CommitsComparison) GetAheadBy() int { + if c == nil || c.AheadBy == nil { return 0 } - return *c.CommitterID + return *c.AheadBy } -// GetCommitterName returns the CommitterName field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetCommitterName() string { - if c == nil || c.CommitterName == nil { - return "" +// GetBehindBy returns the BehindBy field if it's non-nil, zero value otherwise. +func (c *CommitsComparison) GetBehindBy() int { + if c == nil || c.BehindBy == nil { + return 0 } - return *c.CommitterName + return *c.BehindBy } -// GetHash returns the Hash field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetHash() string { - if c == nil || c.Hash == nil { +// GetDiffURL returns the DiffURL field if it's non-nil, zero value otherwise. +func (c *CommitsComparison) GetDiffURL() string { + if c == nil || c.DiffURL == nil { return "" } - return *c.Hash + return *c.DiffURL } -// GetMessage returns the Message field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetMessage() string { - if c == nil || c.Message == nil { +// GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. +func (c *CommitsComparison) GetHTMLURL() string { + if c == nil || c.HTMLURL == nil { return "" } - return *c.Message + return *c.HTMLURL } -// GetAheadBy returns the AheadBy field if it's non-nil, zero value otherwise. -func (c *CommitsComparison) GetAheadBy() int { - if c == nil || c.AheadBy == nil { - return 0 +// GetPatchURL returns the PatchURL field if it's non-nil, zero value otherwise. +func (c *CommitsComparison) GetPatchURL() string { + if c == nil || c.PatchURL == nil { + return "" } - return *c.AheadBy + return *c.PatchURL } -// GetBehindBy returns the BehindBy field if it's non-nil, zero value otherwise. -func (c *CommitsComparison) GetBehindBy() int { - if c == nil || c.BehindBy == nil { - return 0 +// GetPermalinkURL returns the PermalinkURL field if it's non-nil, zero value otherwise. +func (c *CommitsComparison) GetPermalinkURL() string { + if c == nil || c.PermalinkURL == nil { + return "" } - return *c.BehindBy + return *c.PermalinkURL } // GetStatus returns the Status field if it's non-nil, zero value otherwise. @@ -612,6 +644,14 @@ func (c *CommitsComparison) GetTotalCommits() int { return *c.TotalCommits } +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (c *CommitsComparison) GetURL() string { + if c == nil || c.URL == nil { + return "" + } + return *c.URL +} + // GetIncompleteResults returns the IncompleteResults field if it's non-nil, zero value otherwise. func (c *CommitsSearchResult) GetIncompleteResults() bool { if c == nil || c.IncompleteResults == nil { @@ -652,6 +692,22 @@ func (c *CommitStats) GetTotal() int { return *c.Total } +// GetHealthPercentage returns the HealthPercentage field if it's non-nil, zero value otherwise. +func (c *CommunityHealthMetrics) GetHealthPercentage() int { + if c == nil || c.HealthPercentage == nil { + return 0 + } + return *c.HealthPercentage +} + +// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. +func (c *CommunityHealthMetrics) GetUpdatedAt() time.Time { + if c == nil || c.UpdatedAt == nil { + return time.Time{} + } + return *c.UpdatedAt +} + // GetAvatarURL returns the AvatarURL field if it's non-nil, zero value otherwise. func (c *Contributor) GetAvatarURL() string { if c == nil || c.AvatarURL == nil { @@ -1932,6 +1988,14 @@ func (i *Installation) GetAccessTokensURL() string { return *i.AccessTokensURL } +// GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. +func (i *Installation) GetHTMLURL() string { + if i == nil || i.HTMLURL == nil { + return "" + } + return *i.HTMLURL +} + // GetID returns the ID field if it's non-nil, zero value otherwise. func (i *Installation) GetID() int { if i == nil || i.ID == nil { @@ -1949,7 +2013,7 @@ func (i *Installation) GetRepositoriesURL() string { } // GetAction returns the Action field if it's non-nil, zero value otherwise. -func (i *IntegrationInstallationEvent) GetAction() string { +func (i *InstallationEvent) GetAction() string { if i == nil || i.Action == nil { return "" } @@ -1957,13 +2021,21 @@ func (i *IntegrationInstallationEvent) GetAction() string { } // GetAction returns the Action field if it's non-nil, zero value otherwise. -func (i *IntegrationInstallationRepositoriesEvent) GetAction() string { +func (i *InstallationRepositoriesEvent) GetAction() string { if i == nil || i.Action == nil { return "" } return *i.Action } +// GetRepositorySelection returns the RepositorySelection field if it's non-nil, zero value otherwise. +func (i *InstallationRepositoriesEvent) GetRepositorySelection() string { + if i == nil || i.RepositorySelection == nil { + return "" + } + return *i.RepositorySelection +} + // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (i *Invitation) GetCreatedAt() time.Time { if i == nil || i.CreatedAt == nil { @@ -2332,6 +2404,14 @@ func (l *Label) GetColor() string { return *l.Color } +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (l *Label) GetID() int { + if l == nil || l.ID == nil { + return 0 + } + return *l.ID +} + // GetName returns the Name field if it's non-nil, zero value otherwise. func (l *Label) GetName() string { if l == nil || l.Name == nil { @@ -2572,6 +2652,38 @@ func (m *MembershipEvent) GetScope() string { return *m.Scope } +// GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. +func (m *Metric) GetHTMLURL() string { + if m == nil || m.HTMLURL == nil { + return "" + } + return *m.HTMLURL +} + +// GetKey returns the Key field if it's non-nil, zero value otherwise. +func (m *Metric) GetKey() string { + if m == nil || m.Key == nil { + return "" + } + return *m.Key +} + +// GetName returns the Name field if it's non-nil, zero value otherwise. +func (m *Metric) GetName() string { + if m == nil || m.Name == nil { + return "" + } + return *m.Name +} + +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (m *Metric) GetURL() string { + if m == nil || m.URL == nil { + return "" + } + return *m.URL +} + // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (m *Migration) GetCreatedAt() string { if m == nil || m.CreatedAt == nil { @@ -2788,6 +2900,14 @@ func (n *NewPullRequest) GetIssue() int { return *n.Issue } +// GetMaintainerCanModify returns the MaintainerCanModify field if it's non-nil, zero value otherwise. +func (n *NewPullRequest) GetMaintainerCanModify() bool { + if n == nil || n.MaintainerCanModify == nil { + return false + } + return *n.MaintainerCanModify +} + // GetTitle returns the Title field if it's non-nil, zero value otherwise. func (n *NewPullRequest) GetTitle() string { if n == nil || n.Title == nil { @@ -3124,6 +3244,14 @@ func (o *OrganizationEvent) GetAction() string { return *o.Action } +// GetAction returns the Action field if it's non-nil, zero value otherwise. +func (o *OrgBlockEvent) GetAction() string { + if o == nil || o.Action == nil { + return "" + } + return *o.Action +} + // GetAction returns the Action field if it's non-nil, zero value otherwise. func (p *Page) GetAction() string { if p == nil || p.Action == nil { @@ -3612,6 +3740,14 @@ func (p *PullRequest) GetIssueURL() string { return *p.IssueURL } +// GetMaintainerCanModify returns the MaintainerCanModify field if it's non-nil, zero value otherwise. +func (p *PullRequest) GetMaintainerCanModify() bool { + if p == nil || p.MaintainerCanModify == nil { + return false + } + return *p.MaintainerCanModify +} + // GetMergeable returns the Mergeable field if it's non-nil, zero value otherwise. func (p *PullRequest) GetMergeable() bool { if p == nil || p.Mergeable == nil { @@ -3620,6 +3756,14 @@ func (p *PullRequest) GetMergeable() bool { return *p.Mergeable } +// GetMergeCommitSHA returns the MergeCommitSHA field if it's non-nil, zero value otherwise. +func (p *PullRequest) GetMergeCommitSHA() string { + if p == nil || p.MergeCommitSHA == nil { + return "" + } + return *p.MergeCommitSHA +} + // GetMerged returns the Merged field if it's non-nil, zero value otherwise. func (p *PullRequest) GetMerged() bool { if p == nil || p.Merged == nil { @@ -4028,6 +4172,14 @@ func (p *pullRequestUpdate) GetBody() string { return *p.Body } +// GetMaintainerCanModify returns the MaintainerCanModify field if it's non-nil, zero value otherwise. +func (p *pullRequestUpdate) GetMaintainerCanModify() bool { + if p == nil || p.MaintainerCanModify == nil { + return false + } + return *p.MaintainerCanModify +} + // GetState returns the State field if it's non-nil, zero value otherwise. func (p *pullRequestUpdate) GetState() string { if p == nil || p.State == nil { @@ -4236,6 +4388,14 @@ func (p *PushEventRepoOwner) GetName() string { return *p.Name } +// GetArchiveURL returns the ArchiveURL field if it's non-nil, zero value otherwise. +func (p *PushEventRepository) GetArchiveURL() string { + if p == nil || p.ArchiveURL == nil { + return "" + } + return *p.ArchiveURL +} + // GetCloneURL returns the CloneURL field if it's non-nil, zero value otherwise. func (p *PushEventRepository) GetCloneURL() string { if p == nil || p.CloneURL == nil { @@ -6204,6 +6364,14 @@ func (t *Team) GetID() int { return *t.ID } +// GetLDAPDN returns the LDAPDN field if it's non-nil, zero value otherwise. +func (t *Team) GetLDAPDN() string { + if t == nil || t.LDAPDN == nil { + return "" + } + return *t.LDAPDN +} + // GetMembersCount returns the MembersCount field if it's non-nil, zero value otherwise. func (t *Team) GetMembersCount() int { if t == nil || t.MembersCount == nil { @@ -6276,6 +6444,14 @@ func (t *Team) GetURL() string { return *t.URL } +// GetAction returns the Action field if it's non-nil, zero value otherwise. +func (t *TeamEvent) GetAction() string { + if t == nil || t.Action == nil { + return "" + } + return *t.Action +} + // GetDescription returns the Description field if it's non-nil, zero value otherwise. func (t *TeamLDAPMapping) GetDescription() string { if t == nil || t.Description == nil { @@ -6604,6 +6780,14 @@ func (t *TreeEntry) GetType() string { return *t.Type } +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (t *TreeEntry) GetURL() string { + if t == nil || t.URL == nil { + return "" + } + return *t.URL +} + // GetForce returns the Force field if it's non-nil, zero value otherwise. func (u *updateRefRequest) GetForce() bool { if u == nil || u.Force == nil { diff --git a/vendor/github.com/google/go-github/github/github.go b/vendor/github.com/google/go-github/github/github.go index 848814265e80..1fc22976d2ee 100644 --- a/vendor/github.com/google/go-github/github/github.go +++ b/vendor/github.com/google/go-github/github/github.go @@ -27,7 +27,7 @@ import ( ) const ( - libraryVersion = "4" + libraryVersion = "8" defaultBaseURL = "https://api.github.com/" uploadBaseURL = "https://uploads.github.com/" userAgent = "go-github/" + libraryVersion @@ -89,14 +89,17 @@ const ( // https://developer.github.com/changes/2016-09-14-Integrations-Early-Access/ mediaTypeIntegrationPreview = "application/vnd.github.machine-man-preview+json" - // https://developer.github.com/changes/2016-11-28-preview-org-membership/ - mediaTypeOrgMembershipPreview = "application/vnd.github.korra-preview+json" - // https://developer.github.com/changes/2017-01-05-commit-search-api/ mediaTypeCommitSearchPreview = "application/vnd.github.cloak-preview+json" - // https://developer.github.com/changes/2016-12-14-reviews-api/ - mediaTypePullRequestReviewsPreview = "application/vnd.github.black-cat-preview+json" + // https://developer.github.com/changes/2017-02-28-user-blocking-apis-and-webhook/ + mediaTypeBlockUsersPreview = "application/vnd.github.giant-sentry-fist-preview+json" + + // https://developer.github.com/changes/2017-02-09-community-health/ + mediaTypeRepositoryCommunityHealthMetricsPreview = "application/vnd.github.black-panther-preview+json" + + // https://developer.github.com/changes/2017-05-23-coc-api/ + mediaTypeCodesOfConductPreview = "application/vnd.github.scarlet-witch-preview+json" ) // A Client manages communication with the GitHub API. @@ -123,11 +126,11 @@ type Client struct { // Services used for talking to different parts of the GitHub API. Activity *ActivityService Admin *AdminService + Apps *AppsService Authorizations *AuthorizationsService Gists *GistsService Git *GitService Gitignores *GitignoresService - Integrations *IntegrationsService Issues *IssuesService Organizations *OrganizationsService Projects *ProjectsService @@ -212,11 +215,11 @@ func NewClient(httpClient *http.Client) *Client { c.common.client = c c.Activity = (*ActivityService)(&c.common) c.Admin = (*AdminService)(&c.common) + c.Apps = (*AppsService)(&c.common) c.Authorizations = (*AuthorizationsService)(&c.common) c.Gists = (*GistsService)(&c.common) c.Git = (*GitService)(&c.common) c.Gitignores = (*GitignoresService)(&c.common) - c.Integrations = (*IntegrationsService)(&c.common) c.Issues = (*IssuesService)(&c.common) c.Licenses = (*LicensesService)(&c.common) c.Migrations = (*MigrationService)(&c.common) @@ -390,13 +393,16 @@ func parseRate(r *http.Response) Rate { // The provided ctx must be non-nil. If it is canceled or times out, // ctx.Err() will be returned. func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error) { - req = req.WithContext(ctx) + ctx, req = withContext(ctx, req) rateLimitCategory := category(req.URL.Path) // If we've hit rate limit, don't make further requests before Reset time. if err := c.checkRateLimitBeforeDo(req, rateLimitCategory); err != nil { - return nil, err + return &Response{ + Response: err.Response, + Rate: err.Rate, + }, err } resp, err := c.client.Do(req) @@ -457,7 +463,7 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Res // current client state in order to quickly check if *RateLimitError can be immediately returned // from Client.Do, and if so, returns it so that Client.Do can skip making a network API call unnecessarily. // Otherwise it returns nil, and Client.Do should proceed normally. -func (c *Client) checkRateLimitBeforeDo(req *http.Request, rateLimitCategory rateLimitCategory) error { +func (c *Client) checkRateLimitBeforeDo(req *http.Request, rateLimitCategory rateLimitCategory) *RateLimitError { c.rateMu.Lock() rate := c.rateLimits[rateLimitCategory] c.rateMu.Unlock() diff --git a/vendor/github.com/google/go-github/github/issues_events.go b/vendor/github.com/google/go-github/github/issues_events.go index bede41901ffb..93e5d66fb4a0 100644 --- a/vendor/github.com/google/go-github/github/issues_events.go +++ b/vendor/github.com/google/go-github/github/issues_events.go @@ -44,7 +44,7 @@ type IssueEvent struct { // Someone unspecified @mentioned the Actor [sic] in an issue comment body. // // assigned, unassigned - // The Actor assigned the issue to or removed the assignment from the Assignee. + // The Assigner assigned the issue to or removed the assignment from the Assignee. // // labeled, unlabeled // The Actor added or removed the Label from the issue. @@ -65,6 +65,7 @@ type IssueEvent struct { // Only present on certain events; see above. Assignee *User `json:"assignee,omitempty"` + Assigner *User `json:"assigner,omitempty"` CommitID *string `json:"commit_id,omitempty"` Milestone *Milestone `json:"milestone,omitempty"` Label *Label `json:"label,omitempty"` diff --git a/vendor/github.com/google/go-github/github/issues_labels.go b/vendor/github.com/google/go-github/github/issues_labels.go index 5c0b821c31ed..b0e34c40f20e 100644 --- a/vendor/github.com/google/go-github/github/issues_labels.go +++ b/vendor/github.com/google/go-github/github/issues_labels.go @@ -12,13 +12,14 @@ import ( // Label represents a GitHub label on an Issue type Label struct { + ID *int `json:"id,omitempty"` URL *string `json:"url,omitempty"` Name *string `json:"name,omitempty"` Color *string `json:"color,omitempty"` } func (l Label) String() string { - return fmt.Sprint(*l.Name) + return Stringify(l) } // ListLabels lists all labels for a repository. diff --git a/vendor/github.com/google/go-github/github/issues_milestones.go b/vendor/github.com/google/go-github/github/issues_milestones.go index bc89816a6431..e6e882d14432 100644 --- a/vendor/github.com/google/go-github/github/issues_milestones.go +++ b/vendor/github.com/google/go-github/github/issues_milestones.go @@ -38,11 +38,11 @@ func (m Milestone) String() string { // IssuesService.ListMilestones method. type MilestoneListOptions struct { // State filters milestones based on their state. Possible values are: - // open, closed. Default is "open". + // open, closed, all. Default is "open". State string `url:"state,omitempty"` - // Sort specifies how to sort milestones. Possible values are: due_date, completeness. - // Default value is "due_date". + // Sort specifies how to sort milestones. Possible values are: due_on, completeness. + // Default value is "due_on". Sort string `url:"sort,omitempty"` // Direction in which to sort milestones. Possible values are: asc, desc. diff --git a/vendor/github.com/google/go-github/github/messages.go b/vendor/github.com/google/go-github/github/messages.go index a7ec65fba2c9..c0f315a7782e 100644 --- a/vendor/github.com/google/go-github/github/messages.go +++ b/vendor/github.com/google/go-github/github/messages.go @@ -33,42 +33,46 @@ const ( signatureHeader = "X-Hub-Signature" // eventTypeHeader is the GitHub header key used to pass the event type. eventTypeHeader = "X-Github-Event" + // deliveryIDHeader is the GitHub header key used to pass the unique ID for the webhook event. + deliveryIDHeader = "X-Github-Delivery" ) var ( // eventTypeMapping maps webhooks types to their corresponding go-github struct types. eventTypeMapping = map[string]string{ - "commit_comment": "CommitCommentEvent", - "create": "CreateEvent", - "delete": "DeleteEvent", - "deployment": "DeploymentEvent", - "deployment_status": "DeploymentStatusEvent", - "fork": "ForkEvent", - "gollum": "GollumEvent", - "integration_installation": "IntegrationInstallationEvent", - "integration_installation_repositories": "IntegrationInstallationRepositoriesEvent", - "issue_comment": "IssueCommentEvent", - "issues": "IssuesEvent", - "label": "LabelEvent", - "member": "MemberEvent", - "membership": "MembershipEvent", - "milestone": "MilestoneEvent", - "organization": "OrganizationEvent", - "page_build": "PageBuildEvent", - "ping": "PingEvent", - "project": "ProjectEvent", - "project_card": "ProjectCardEvent", - "project_column": "ProjectColumnEvent", - "public": "PublicEvent", - "pull_request_review": "PullRequestReviewEvent", - "pull_request_review_comment": "PullRequestReviewCommentEvent", - "pull_request": "PullRequestEvent", - "push": "PushEvent", - "repository": "RepositoryEvent", - "release": "ReleaseEvent", - "status": "StatusEvent", - "team_add": "TeamAddEvent", - "watch": "WatchEvent", + "commit_comment": "CommitCommentEvent", + "create": "CreateEvent", + "delete": "DeleteEvent", + "deployment": "DeploymentEvent", + "deployment_status": "DeploymentStatusEvent", + "fork": "ForkEvent", + "gollum": "GollumEvent", + "installation": "InstallationEvent", + "installation_repositories": "InstallationRepositoriesEvent", + "issue_comment": "IssueCommentEvent", + "issues": "IssuesEvent", + "label": "LabelEvent", + "member": "MemberEvent", + "membership": "MembershipEvent", + "milestone": "MilestoneEvent", + "organization": "OrganizationEvent", + "org_block": "OrgBlockEvent", + "page_build": "PageBuildEvent", + "ping": "PingEvent", + "project": "ProjectEvent", + "project_card": "ProjectCardEvent", + "project_column": "ProjectColumnEvent", + "public": "PublicEvent", + "pull_request_review": "PullRequestReviewEvent", + "pull_request_review_comment": "PullRequestReviewCommentEvent", + "pull_request": "PullRequestEvent", + "push": "PushEvent", + "repository": "RepositoryEvent", + "release": "ReleaseEvent", + "status": "StatusEvent", + "team": "TeamEvent", + "team_add": "TeamAddEvent", + "watch": "WatchEvent", } ) @@ -159,10 +163,19 @@ func validateSignature(signature string, payload, secretKey []byte) error { } // WebHookType returns the event type of webhook request r. +// +// GitHub API docs: https://developer.github.com/v3/repos/hooks/#webhook-headers func WebHookType(r *http.Request) string { return r.Header.Get(eventTypeHeader) } +// DeliveryID returns the unique delivery ID of webhook request r. +// +// GitHub API docs: https://developer.github.com/v3/repos/hooks/#webhook-headers +func DeliveryID(r *http.Request) string { + return r.Header.Get(deliveryIDHeader) +} + // ParseWebHook parses the event payload. For recognized event types, a // value of the corresponding struct type will be returned (as returned // by Event.ParsePayload()). An error will be returned for unrecognized event diff --git a/vendor/github.com/google/go-github/github/misc.go b/vendor/github.com/google/go-github/github/misc.go index 42d0d3033936..5b8082d3ce5b 100644 --- a/vendor/github.com/google/go-github/github/misc.go +++ b/vendor/github.com/google/go-github/github/misc.go @@ -83,6 +83,61 @@ func (c *Client) ListEmojis(ctx context.Context) (map[string]string, *Response, return emoji, resp, nil } +// CodeOfConduct represents a code of conduct. +type CodeOfConduct struct { + Name *string `json:"name,omitempty"` + Key *string `json:"key,omitempty"` + URL *string `json:"url,omitempty"` + Body *string `json:"body,omitempty"` +} + +func (c *CodeOfConduct) String() string { + return Stringify(c) +} + +// ListCodesOfConduct returns all codes of conduct. +// +// GitHub API docs: https://developer.github.com/v3/codes_of_conduct/#list-all-codes-of-conduct +func (c *Client) ListCodesOfConduct(ctx context.Context) ([]*CodeOfConduct, *Response, error) { + req, err := c.NewRequest("GET", "codes_of_conduct", nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeCodesOfConductPreview) + + var cs []*CodeOfConduct + resp, err := c.Do(ctx, req, &cs) + if err != nil { + return nil, resp, err + } + + return cs, resp, nil +} + +// GetCodeOfConduct returns an individual code of conduct. +// +// https://developer.github.com/v3/codes_of_conduct/#get-an-individual-code-of-conduct +func (c *Client) GetCodeOfConduct(ctx context.Context, key string) (*CodeOfConduct, *Response, error) { + u := fmt.Sprintf("codes_of_conduct/%s", key) + req, err := c.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeCodesOfConductPreview) + + coc := new(CodeOfConduct) + resp, err := c.Do(ctx, req, coc) + if err != nil { + return nil, resp, err + } + + return coc, resp, nil +} + // APIMeta represents metadata about the GitHub API. type APIMeta struct { // An Array of IP addresses in CIDR format specifying the addresses diff --git a/vendor/github.com/google/go-github/github/orgs_members.go b/vendor/github.com/google/go-github/github/orgs_members.go index 58fb01915338..f1209c7c4166 100644 --- a/vendor/github.com/google/go-github/github/orgs_members.go +++ b/vendor/github.com/google/go-github/github/orgs_members.go @@ -290,9 +290,6 @@ func (s *OrganizationsService) ListPendingOrgInvitations(ctx context.Context, or return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. - req.Header.Set("Accept", mediaTypeOrgMembershipPreview) - var pendingInvitations []*Invitation resp, err := s.client.Do(ctx, req, &pendingInvitations) if err != nil { diff --git a/vendor/github.com/google/go-github/github/orgs_outside_collaborators.go b/vendor/github.com/google/go-github/github/orgs_outside_collaborators.go index 10bc6f060099..e34f8653b578 100644 --- a/vendor/github.com/google/go-github/github/orgs_outside_collaborators.go +++ b/vendor/github.com/google/go-github/github/orgs_outside_collaborators.go @@ -40,9 +40,6 @@ func (s *OrganizationsService) ListOutsideCollaborators(ctx context.Context, org return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. - req.Header.Set("Accept", mediaTypeOrgMembershipPreview) - var members []*User resp, err := s.client.Do(ctx, req, &members) if err != nil { diff --git a/vendor/github.com/google/go-github/github/orgs_projects.go b/vendor/github.com/google/go-github/github/orgs_projects.go new file mode 100644 index 000000000000..e57cba97829e --- /dev/null +++ b/vendor/github.com/google/go-github/github/orgs_projects.go @@ -0,0 +1,60 @@ +// Copyright 2017 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" +) + +// ListProjects lists the projects for an organization. +// +// GitHub API docs: https://developer.github.com/v3/projects/#list-organization-projects +func (s *OrganizationsService) ListProjects(ctx context.Context, org string, opt *ProjectListOptions) ([]*Project, *Response, error) { + u := fmt.Sprintf("orgs/%v/projects", org) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeProjectsPreview) + + var projects []*Project + resp, err := s.client.Do(ctx, req, &projects) + if err != nil { + return nil, resp, err + } + + return projects, resp, nil +} + +// CreateProject creates a GitHub Project for the specified organization. +// +// GitHub API docs: https://developer.github.com/v3/projects/#create-an-organization-project +func (s *OrganizationsService) CreateProject(ctx context.Context, org string, opt *ProjectOptions) (*Project, *Response, error) { + u := fmt.Sprintf("orgs/%v/projects", org) + req, err := s.client.NewRequest("POST", u, opt) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeProjectsPreview) + + project := &Project{} + resp, err := s.client.Do(ctx, req, project) + if err != nil { + return nil, resp, err + } + + return project, resp, nil +} diff --git a/vendor/github.com/google/go-github/github/orgs_teams.go b/vendor/github.com/google/go-github/github/orgs_teams.go index 5bdd66dd2157..70b090d0d3ac 100644 --- a/vendor/github.com/google/go-github/github/orgs_teams.go +++ b/vendor/github.com/google/go-github/github/orgs_teams.go @@ -39,6 +39,10 @@ type Team struct { Organization *Organization `json:"organization,omitempty"` MembersURL *string `json:"members_url,omitempty"` RepositoriesURL *string `json:"repositories_url,omitempty"` + + // LDAPDN is only available in GitHub Enterprise and when the team + // membership is synchronized with LDAP. + LDAPDN *string `json:"ldap_dn,omitempty"` } func (t Team) String() string { @@ -414,9 +418,6 @@ func (s *OrganizationsService) ListPendingTeamInvitations(ctx context.Context, t return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. - req.Header.Set("Accept", mediaTypeOrgMembershipPreview) - var pendingInvitations []*Invitation resp, err := s.client.Do(ctx, req, &pendingInvitations) if err != nil { diff --git a/vendor/github.com/google/go-github/github/orgs_users_blocking.go b/vendor/github.com/google/go-github/github/orgs_users_blocking.go new file mode 100644 index 000000000000..b1aecf44532c --- /dev/null +++ b/vendor/github.com/google/go-github/github/orgs_users_blocking.go @@ -0,0 +1,91 @@ +// Copyright 2017 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" +) + +// ListBlockedUsers lists all the users blocked by an organization. +// +// GitHub API docs: https://developer.github.com/v3/orgs/blocking/#list-blocked-users +func (s *OrganizationsService) ListBlockedUsers(ctx context.Context, org string, opt *ListOptions) ([]*User, *Response, error) { + u := fmt.Sprintf("orgs/%v/blocks", org) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeBlockUsersPreview) + + var blockedUsers []*User + resp, err := s.client.Do(ctx, req, &blockedUsers) + if err != nil { + return nil, resp, err + } + + return blockedUsers, resp, nil +} + +// 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 +func (s *OrganizationsService) IsBlocked(ctx context.Context, org string, user string) (bool, *Response, error) { + u := fmt.Sprintf("orgs/%v/blocks/%v", org, user) + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return false, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeBlockUsersPreview) + + resp, err := s.client.Do(ctx, req, nil) + isBlocked, err := parseBoolResponse(err) + return isBlocked, resp, err +} + +// BlockUser blocks specified user from an organization. +// +// GitHub API docs: https://developer.github.com/v3/orgs/blocking/#block-a-user +func (s *OrganizationsService) BlockUser(ctx context.Context, org string, user string) (*Response, error) { + u := fmt.Sprintf("orgs/%v/blocks/%v", org, user) + + req, err := s.client.NewRequest("PUT", u, nil) + if err != nil { + return nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeBlockUsersPreview) + + return s.client.Do(ctx, req, nil) +} + +// UnblockUser unblocks specified user from an organization. +// +// GitHub API docs: https://developer.github.com/v3/orgs/blocking/#unblock-a-user +func (s *OrganizationsService) UnblockUser(ctx context.Context, org string, user string) (*Response, error) { + u := fmt.Sprintf("orgs/%v/blocks/%v", org, user) + + 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", mediaTypeBlockUsersPreview) + + return s.client.Do(ctx, req, nil) +} diff --git a/vendor/github.com/google/go-github/github/pulls.go b/vendor/github.com/google/go-github/github/pulls.go index 38b90f8796ae..51e4d95f4ce6 100644 --- a/vendor/github.com/google/go-github/github/pulls.go +++ b/vendor/github.com/google/go-github/github/pulls.go @@ -20,35 +20,37 @@ type PullRequestsService service // PullRequest represents a GitHub pull request on a repository. type PullRequest struct { - ID *int `json:"id,omitempty"` - Number *int `json:"number,omitempty"` - State *string `json:"state,omitempty"` - Title *string `json:"title,omitempty"` - Body *string `json:"body,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` - ClosedAt *time.Time `json:"closed_at,omitempty"` - MergedAt *time.Time `json:"merged_at,omitempty"` - User *User `json:"user,omitempty"` - Merged *bool `json:"merged,omitempty"` - Mergeable *bool `json:"mergeable,omitempty"` - MergedBy *User `json:"merged_by,omitempty"` - Comments *int `json:"comments,omitempty"` - Commits *int `json:"commits,omitempty"` - Additions *int `json:"additions,omitempty"` - Deletions *int `json:"deletions,omitempty"` - ChangedFiles *int `json:"changed_files,omitempty"` - URL *string `json:"url,omitempty"` - HTMLURL *string `json:"html_url,omitempty"` - IssueURL *string `json:"issue_url,omitempty"` - StatusesURL *string `json:"statuses_url,omitempty"` - DiffURL *string `json:"diff_url,omitempty"` - PatchURL *string `json:"patch_url,omitempty"` - ReviewCommentsURL *string `json:"review_comments_url,omitempty"` - ReviewCommentURL *string `json:"review_comment_url,omitempty"` - Assignee *User `json:"assignee,omitempty"` - Assignees []*User `json:"assignees,omitempty"` - Milestone *Milestone `json:"milestone,omitempty"` + ID *int `json:"id,omitempty"` + Number *int `json:"number,omitempty"` + State *string `json:"state,omitempty"` + Title *string `json:"title,omitempty"` + Body *string `json:"body,omitempty"` + CreatedAt *time.Time `json:"created_at,omitempty"` + UpdatedAt *time.Time `json:"updated_at,omitempty"` + ClosedAt *time.Time `json:"closed_at,omitempty"` + MergedAt *time.Time `json:"merged_at,omitempty"` + User *User `json:"user,omitempty"` + Merged *bool `json:"merged,omitempty"` + Mergeable *bool `json:"mergeable,omitempty"` + MergedBy *User `json:"merged_by,omitempty"` + MergeCommitSHA *string `json:"merge_commit_sha,omitempty"` + Comments *int `json:"comments,omitempty"` + Commits *int `json:"commits,omitempty"` + Additions *int `json:"additions,omitempty"` + Deletions *int `json:"deletions,omitempty"` + ChangedFiles *int `json:"changed_files,omitempty"` + URL *string `json:"url,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + IssueURL *string `json:"issue_url,omitempty"` + StatusesURL *string `json:"statuses_url,omitempty"` + DiffURL *string `json:"diff_url,omitempty"` + PatchURL *string `json:"patch_url,omitempty"` + ReviewCommentsURL *string `json:"review_comments_url,omitempty"` + ReviewCommentURL *string `json:"review_comment_url,omitempty"` + Assignee *User `json:"assignee,omitempty"` + Assignees []*User `json:"assignees,omitempty"` + Milestone *Milestone `json:"milestone,omitempty"` + MaintainerCanModify *bool `json:"maintainer_can_modify,omitempty"` Head *PullRequestBranch `json:"head,omitempty"` Base *PullRequestBranch `json:"base,omitempty"` @@ -164,11 +166,12 @@ func (s *PullRequestsService) GetRaw(ctx context.Context, owner string, repo str // NewPullRequest represents a new pull request to be created. type NewPullRequest struct { - Title *string `json:"title,omitempty"` - Head *string `json:"head,omitempty"` - Base *string `json:"base,omitempty"` - Body *string `json:"body,omitempty"` - Issue *int `json:"issue,omitempty"` + Title *string `json:"title,omitempty"` + Head *string `json:"head,omitempty"` + Base *string `json:"base,omitempty"` + Body *string `json:"body,omitempty"` + Issue *int `json:"issue,omitempty"` + MaintainerCanModify *bool `json:"maintainer_can_modify,omitempty"` } // Create a new pull request on the specified repository. @@ -191,16 +194,17 @@ func (s *PullRequestsService) Create(ctx context.Context, owner string, repo str } type pullRequestUpdate struct { - Title *string `json:"title,omitempty"` - Body *string `json:"body,omitempty"` - State *string `json:"state,omitempty"` - Base *string `json:"base,omitempty"` + Title *string `json:"title,omitempty"` + Body *string `json:"body,omitempty"` + State *string `json:"state,omitempty"` + Base *string `json:"base,omitempty"` + MaintainerCanModify *bool `json:"maintainer_can_modify,omitempty"` } // Edit a pull request. // pull must not be nil. // -// The following fields are editable: Title, Body, State, and Base.Ref. +// The following fields are editable: Title, Body, State, Base.Ref and MaintainerCanModify. // Base.Ref updates the base branch of the pull request. // // GitHub API docs: https://developer.github.com/v3/pulls/#update-a-pull-request @@ -212,9 +216,10 @@ func (s *PullRequestsService) Edit(ctx context.Context, owner string, repo strin u := fmt.Sprintf("repos/%v/%v/pulls/%d", owner, repo, number) update := &pullRequestUpdate{ - Title: pull.Title, - Body: pull.Body, - State: pull.State, + Title: pull.Title, + Body: pull.Body, + State: pull.State, + MaintainerCanModify: pull.MaintainerCanModify, } if pull.Base != nil { update.Base = pull.Base.Ref diff --git a/vendor/github.com/google/go-github/github/pulls_reviewers.go b/vendor/github.com/google/go-github/github/pulls_reviewers.go index efa3888964a2..bd94a6599b21 100644 --- a/vendor/github.com/google/go-github/github/pulls_reviewers.go +++ b/vendor/github.com/google/go-github/github/pulls_reviewers.go @@ -26,9 +26,6 @@ func (s *PullRequestsService) RequestReviewers(ctx context.Context, owner, repo return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypePullRequestReviewsPreview) - r := new(PullRequest) resp, err := s.client.Do(ctx, req, r) if err != nil { @@ -41,17 +38,18 @@ func (s *PullRequestsService) RequestReviewers(ctx context.Context, owner, repo // ListReviewers lists users whose reviews have been requested on the specified pull request. // // GitHub API docs: https://developer.github.com/v3/pulls/review_requests/#list-review-requests -func (s *PullRequestsService) ListReviewers(ctx context.Context, owner, repo string, number int) ([]*User, *Response, error) { +func (s *PullRequestsService) ListReviewers(ctx context.Context, owner, repo string, number int, opt *ListOptions) ([]*User, *Response, error) { u := fmt.Sprintf("repos/%v/%v/pulls/%d/requested_reviewers", owner, repo, number) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypePullRequestReviewsPreview) - var users []*User resp, err := s.client.Do(ctx, req, &users) if err != nil { @@ -77,8 +75,5 @@ func (s *PullRequestsService) RemoveReviewers(ctx context.Context, owner, repo s return nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypePullRequestReviewsPreview) - return s.client.Do(ctx, req, reviewers) } diff --git a/vendor/github.com/google/go-github/github/pulls_reviews.go b/vendor/github.com/google/go-github/github/pulls_reviews.go index c27b6a8c4733..c071338dabf1 100644 --- a/vendor/github.com/google/go-github/github/pulls_reviews.go +++ b/vendor/github.com/google/go-github/github/pulls_reviews.go @@ -65,17 +65,18 @@ func (r PullRequestReviewDismissalRequest) String() string { // 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 -func (s *PullRequestsService) ListReviews(ctx context.Context, owner, repo string, number int) ([]*PullRequestReview, *Response, error) { +func (s *PullRequestsService) ListReviews(ctx context.Context, owner, repo string, number int, opt *ListOptions) ([]*PullRequestReview, *Response, error) { u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews", owner, repo, number) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypePullRequestReviewsPreview) - var reviews []*PullRequestReview resp, err := s.client.Do(ctx, req, &reviews) if err != nil { @@ -100,9 +101,6 @@ func (s *PullRequestsService) GetReview(ctx context.Context, owner, repo string, return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypePullRequestReviewsPreview) - review := new(PullRequestReview) resp, err := s.client.Do(ctx, req, review) if err != nil { @@ -127,9 +125,6 @@ func (s *PullRequestsService) DeletePendingReview(ctx context.Context, owner, re return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypePullRequestReviewsPreview) - review := new(PullRequestReview) resp, err := s.client.Do(ctx, req, review) if err != nil { @@ -145,18 +140,19 @@ func (s *PullRequestsService) DeletePendingReview(ctx context.Context, owner, re // returned error format and remove this comment once it's fixed. // Read more about it here - https://github.com/google/go-github/issues/540 // -// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#get-a-single-reviews-comments -func (s *PullRequestsService) ListReviewComments(ctx context.Context, owner, repo string, number, reviewID int) ([]*PullRequestComment, *Response, error) { +// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#get-comments-for-a-single-review +func (s *PullRequestsService) ListReviewComments(ctx context.Context, owner, repo string, number, reviewID int, opt *ListOptions) ([]*PullRequestComment, *Response, error) { u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d/comments", owner, repo, number, reviewID) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypePullRequestReviewsPreview) - var comments []*PullRequestComment resp, err := s.client.Do(ctx, req, &comments) if err != nil { @@ -181,9 +177,6 @@ func (s *PullRequestsService) CreateReview(ctx context.Context, owner, repo stri return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypePullRequestReviewsPreview) - r := new(PullRequestReview) resp, err := s.client.Do(ctx, req, r) if err != nil { @@ -208,9 +201,6 @@ func (s *PullRequestsService) SubmitReview(ctx context.Context, owner, repo stri return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypePullRequestReviewsPreview) - r := new(PullRequestReview) resp, err := s.client.Do(ctx, req, r) if err != nil { @@ -235,9 +225,6 @@ func (s *PullRequestsService) DismissReview(ctx context.Context, owner, repo str return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypePullRequestReviewsPreview) - r := new(PullRequestReview) resp, err := s.client.Do(ctx, req, r) if err != nil { diff --git a/vendor/github.com/google/go-github/github/repos.go b/vendor/github.com/google/go-github/github/repos.go index 22dc42de9548..c3629daa5c24 100644 --- a/vendor/github.com/google/go-github/github/repos.go +++ b/vendor/github.com/google/go-github/github/repos.go @@ -25,6 +25,7 @@ type Repository struct { FullName *string `json:"full_name,omitempty"` Description *string `json:"description,omitempty"` Homepage *string `json:"homepage,omitempty"` + CodeOfConduct *CodeOfConduct `json:"code_of_conduct,omitempty"` DefaultBranch *string `json:"default_branch,omitempty"` MasterBranch *string `json:"master_branch,omitempty"` CreatedAt *Timestamp `json:"created_at,omitempty"` @@ -293,7 +294,7 @@ func (s *RepositoriesService) Get(ctx context.Context, owner, repo string) (*Rep // TODO: remove custom Accept header when the license support fully launches // https://developer.github.com/v3/licenses/#get-a-repositorys-license - acceptHeaders := []string{mediaTypeLicensesPreview, mediaTypeSquashPreview} + acceptHeaders := []string{mediaTypeLicensesPreview, mediaTypeSquashPreview, mediaTypeCodesOfConductPreview} req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) repository := new(Repository) @@ -305,6 +306,28 @@ func (s *RepositoriesService) Get(ctx context.Context, owner, repo string) (*Rep return repository, resp, nil } +// 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 +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) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeCodesOfConductPreview) + + coc := new(CodeOfConduct) + resp, err := s.client.Do(ctx, req, coc) + if err != nil { + return nil, resp, err + } + + return coc, resp, nil +} + // GetByID fetches a repository. // // Note: GetByID uses the undocumented GitHub API endpoint /repositories/:id. @@ -511,6 +534,7 @@ type Branch struct { type Protection struct { RequiredStatusChecks *RequiredStatusChecks `json:"required_status_checks"` RequiredPullRequestReviews *RequiredPullRequestReviews `json:"required_pull_request_reviews"` + EnforceAdmins *AdminEnforcement `json:"enforce_admins"` Restrictions *BranchRestrictions `json:"restrictions"` } @@ -518,12 +542,14 @@ type Protection struct { type ProtectionRequest struct { RequiredStatusChecks *RequiredStatusChecks `json:"required_status_checks"` RequiredPullRequestReviews *RequiredPullRequestReviews `json:"required_pull_request_reviews"` + EnforceAdmins bool `json:"enforce_admins"` Restrictions *BranchRestrictionsRequest `json:"restrictions"` } // RequiredStatusChecks represents the protection status of a individual branch. type RequiredStatusChecks struct { // Enforce required status checks for repository administrators. (Required.) + // Deprecated: Use EnforceAdmins instead. IncludeAdmins bool `json:"include_admins"` // Require branches to be up to date before merging. (Required.) Strict bool `json:"strict"` @@ -535,9 +561,16 @@ type RequiredStatusChecks struct { // RequiredPullRequestReviews represents the protection configuration for pull requests. type RequiredPullRequestReviews struct { // Enforce pull request reviews for repository administrators. (Required.) + // Deprecated: Use EnforceAdmins instead. IncludeAdmins bool `json:"include_admins"` } +// AdminEnforcement represents the configuration to enforce required status checks for repository administrators. +type AdminEnforcement struct { + URL *string `json:"url,omitempty"` + Enabled bool `json:"enabled"` +} + // BranchRestrictions represents the restriction that only certain users or // teams may push to a branch. type BranchRestrictions struct { @@ -629,6 +662,49 @@ func (s *RepositoriesService) GetBranchProtection(ctx context.Context, owner, re return p, resp, nil } +// 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 +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) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches + req.Header.Set("Accept", mediaTypeProtectedBranchesPreview) + + p := new(RequiredStatusChecks) + resp, err := s.client.Do(ctx, req, p) + if err != nil { + return nil, resp, err + } + + return p, resp, nil +} + +// 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 +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) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches + req.Header.Set("Accept", mediaTypeProtectedBranchesPreview) + + resp, err = s.client.Do(ctx, req, &contexts) + if err != nil { + return nil, resp, err + } + + return contexts, resp, nil +} + // UpdateBranchProtection updates the protection of a given branch. // // GitHub API docs: https://developer.github.com/v3/repos/branches/#update-branch-protection diff --git a/vendor/github.com/google/go-github/github/repos_collaborators.go b/vendor/github.com/google/go-github/github/repos_collaborators.go index ba89b6064a5c..76e8a1f0a114 100644 --- a/vendor/github.com/google/go-github/github/repos_collaborators.go +++ b/vendor/github.com/google/go-github/github/repos_collaborators.go @@ -70,9 +70,6 @@ func (s *RepositoriesService) GetPermissionLevel(ctx context.Context, owner, rep return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. - req.Header.Set("Accept", mediaTypeOrgMembershipPreview) - rpl := new(RepositoryPermissionLevel) resp, err := s.client.Do(ctx, req, rpl) if err != nil { diff --git a/vendor/github.com/google/go-github/github/repos_commits.go b/vendor/github.com/google/go-github/github/repos_commits.go index e516f1afd054..7ecf53104630 100644 --- a/vendor/github.com/google/go-github/github/repos_commits.go +++ b/vendor/github.com/google/go-github/github/repos_commits.go @@ -79,6 +79,12 @@ type CommitsComparison struct { Commits []RepositoryCommit `json:"commits,omitempty"` Files []CommitFile `json:"files,omitempty"` + + HTMLURL *string `json:"html_url,omitempty"` + PermalinkURL *string `json:"permalink_url,omitempty"` + DiffURL *string `json:"diff_url,omitempty"` + PatchURL *string `json:"patch_url,omitempty"` + URL *string `json:"url,omitempty"` // API URL. } func (c CommitsComparison) String() string { diff --git a/vendor/github.com/google/go-github/github/repos_community_health.go b/vendor/github.com/google/go-github/github/repos_community_health.go new file mode 100644 index 000000000000..b5c75d6f5622 --- /dev/null +++ b/vendor/github.com/google/go-github/github/repos_community_health.go @@ -0,0 +1,57 @@ +// Copyright 2017 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" + "time" +) + +// Metric represents the different fields for one file in community health files. +type Metric struct { + Name *string `json:"name"` + Key *string `json:"key"` + URL *string `json:"url"` + HTMLURL *string `json:"html_url"` +} + +// CommunityHealthFiles represents the different files in the community health metrics response. +type CommunityHealthFiles struct { + CodeOfConduct *Metric `json:"code_of_conduct"` + Contributing *Metric `json:"contributing"` + License *Metric `json:"license"` + Readme *Metric `json:"readme"` +} + +// CommunityHealthMetrics represents a response containing the community metrics of a repository. +type CommunityHealthMetrics struct { + HealthPercentage *int `json:"health_percentage"` + Files *CommunityHealthFiles `json:"files"` + UpdatedAt *time.Time `json:"updated_at"` +} + +// GetCommunityHealthMetrics retrieves all the community health metrics for a repository. +// +// GitHub API docs: https://developer.github.com/v3/repos/community/#retrieve-community-health-metrics +func (s *RepositoriesService) GetCommunityHealthMetrics(ctx context.Context, owner, repo string) (*CommunityHealthMetrics, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/community/profile", owner, repo) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeRepositoryCommunityHealthMetricsPreview) + + metrics := &CommunityHealthMetrics{} + resp, err := s.client.Do(ctx, req, metrics) + if err != nil { + return nil, resp, err + } + + return metrics, resp, nil +} diff --git a/vendor/github.com/google/go-github/github/repos_contents.go b/vendor/github.com/google/go-github/github/repos_contents.go index fa9fd556079c..f9adaf7a03cd 100644 --- a/vendor/github.com/google/go-github/github/repos_contents.go +++ b/vendor/github.com/google/go-github/github/repos_contents.go @@ -158,13 +158,13 @@ func (s *RepositoriesService) GetContents(ctx context.Context, owner, repo, path } fileUnmarshalError := json.Unmarshal(rawJSON, &fileContent) if fileUnmarshalError == nil { - return fileContent, nil, resp, fileUnmarshalError + return fileContent, nil, resp, nil } directoryUnmarshalError := json.Unmarshal(rawJSON, &directoryContent) if directoryUnmarshalError == nil { - return nil, directoryContent, resp, directoryUnmarshalError + return nil, directoryContent, resp, nil } - return nil, nil, resp, fmt.Errorf("unmarshalling failed for both file and directory content: %s and %s ", fileUnmarshalError, directoryUnmarshalError) + return nil, nil, resp, fmt.Errorf("unmarshalling failed for both file and directory content: %s and %s", fileUnmarshalError, directoryUnmarshalError) } // CreateFile creates a new file in a repository at the given path and returns @@ -248,10 +248,11 @@ func (s *RepositoriesService) GetArchiveLink(ctx context.Context, owner, repo st } var resp *http.Response // Use http.DefaultTransport if no custom Transport is configured + ctx, req = withContext(ctx, req) if s.client.client.Transport == nil { - resp, err = http.DefaultTransport.RoundTrip(req.WithContext(ctx)) + resp, err = http.DefaultTransport.RoundTrip(req) } else { - resp, err = s.client.client.Transport.RoundTrip(req.WithContext(ctx)) + resp, err = s.client.client.Transport.RoundTrip(req) } if err != nil { return nil, nil, err diff --git a/vendor/github.com/google/go-github/github/repos_invitations.go b/vendor/github.com/google/go-github/github/repos_invitations.go index a803a12da133..0a2b7c1987e3 100644 --- a/vendor/github.com/google/go-github/github/repos_invitations.go +++ b/vendor/github.com/google/go-github/github/repos_invitations.go @@ -90,5 +90,9 @@ func (s *RepositoriesService) UpdateInvitation(ctx context.Context, owner, repo invite := &RepositoryInvitation{} resp, err := s.client.Do(ctx, req, invite) - return invite, resp, err + if err != nil { + return nil, resp, err + } + + return invite, resp, nil } diff --git a/vendor/github.com/google/go-github/github/repos_pages.go b/vendor/github.com/google/go-github/github/repos_pages.go index 3d19b43db575..075f5742d119 100644 --- a/vendor/github.com/google/go-github/github/repos_pages.go +++ b/vendor/github.com/google/go-github/github/repos_pages.go @@ -61,8 +61,13 @@ func (s *RepositoriesService) GetPagesInfo(ctx context.Context, owner, repo stri // ListPagesBuilds lists the builds for a GitHub Pages site. // // GitHub API docs: https://developer.github.com/v3/repos/pages/#list-pages-builds -func (s *RepositoriesService) ListPagesBuilds(ctx context.Context, owner, repo string) ([]*PagesBuild, *Response, error) { +func (s *RepositoriesService) ListPagesBuilds(ctx context.Context, owner, repo string, opt *ListOptions) ([]*PagesBuild, *Response, error) { u := fmt.Sprintf("repos/%v/%v/pages/builds", owner, repo) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err diff --git a/vendor/github.com/google/go-github/github/repos_projects.go b/vendor/github.com/google/go-github/github/repos_projects.go index 9e1a4dbb2d58..770ffc76fa69 100644 --- a/vendor/github.com/google/go-github/github/repos_projects.go +++ b/vendor/github.com/google/go-github/github/repos_projects.go @@ -1,4 +1,4 @@ -// Copyright 2016 The go-github AUTHORS. All rights reserved. +// Copyright 2017 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. @@ -10,10 +10,19 @@ import ( "fmt" ) +// ProjectListOptions specifies the optional parameters to the +// OrganizationsService.ListProjects and RepositoriesService.ListProjects methods. +type ProjectListOptions struct { + // Indicates the state of the projects to return. Can be either open, closed, or all. Default: open + State string `url:"state,omitempty"` + + ListOptions +} + // ListProjects lists the projects for a repo. // // GitHub API docs: https://developer.github.com/v3/projects/#list-repository-projects -func (s *RepositoriesService) ListProjects(ctx context.Context, owner, repo string, opt *ListOptions) ([]*Project, *Response, error) { +func (s *RepositoriesService) ListProjects(ctx context.Context, owner, repo string, opt *ProjectListOptions) ([]*Project, *Response, error) { u := fmt.Sprintf("repos/%v/%v/projects", owner, repo) u, err := addOptions(u, opt) if err != nil { @@ -28,7 +37,7 @@ func (s *RepositoriesService) ListProjects(ctx context.Context, owner, repo stri // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeProjectsPreview) - projects := []*Project{} + var projects []*Project resp, err := s.client.Do(ctx, req, &projects) if err != nil { return nil, resp, err diff --git a/vendor/github.com/google/go-github/github/repos_releases.go b/vendor/github.com/google/go-github/github/repos_releases.go index 49fec8324eea..5c27565510ba 100644 --- a/vendor/github.com/google/go-github/github/repos_releases.go +++ b/vendor/github.com/google/go-github/github/repos_releases.go @@ -244,7 +244,8 @@ func (s *RepositoriesService) DownloadReleaseAsset(ctx context.Context, owner, r } defer func() { s.client.client.CheckRedirect = saveRedirect }() - resp, err := s.client.client.Do(req.WithContext(ctx)) + ctx, req = withContext(ctx, req) + resp, err := s.client.client.Do(req) if err != nil { if !strings.Contains(err.Error(), "disable redirect") { return nil, "", err diff --git a/vendor/github.com/google/go-github/github/search.go b/vendor/github.com/google/go-github/github/search.go index 0fdaad91921b..7668b8b62563 100644 --- a/vendor/github.com/google/go-github/github/search.go +++ b/vendor/github.com/google/go-github/github/search.go @@ -65,17 +65,17 @@ type CommitsSearchResult struct { // CommitResult represents a commit object as returned in commit search endpoint response. type CommitResult struct { - Hash *string `json:"hash,omitempty"` - Message *string `json:"message,omitempty"` - AuthorID *int `json:"author_id,omitempty"` - AuthorName *string `json:"author_name,omitempty"` - AuthorEmail *string `json:"author_email,omitempty"` - AuthorDate *Timestamp `json:"author_date,omitempty"` - CommitterID *int `json:"committer_id,omitempty"` - CommitterName *string `json:"committer_name,omitempty"` - CommitterEmail *string `json:"committer_email,omitempty"` - CommitterDate *Timestamp `json:"committer_date,omitempty"` - Repository *Repository `json:"repository,omitempty"` + SHA *string `json:"sha,omitempty"` + Commit *Commit `json:"commit,omitempty"` + Author *User `json:"author,omitempty"` + Committer *User `json:"committer,omitempty"` + Parents []*Commit `json:"parents,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + URL *string `json:"url,omitempty"` + CommentsURL *string `json:"comments_url,omitempty"` + + Repository *Repository `json:"repository,omitempty"` + Score *float64 `json:"score,omitempty"` } // Commits searches commits via various criteria. diff --git a/vendor/github.com/google/go-github/github/users.go b/vendor/github.com/google/go-github/github/users.go index d74439c7b040..83cfb45b5abb 100644 --- a/vendor/github.com/google/go-github/github/users.go +++ b/vendor/github.com/google/go-github/github/users.go @@ -172,8 +172,13 @@ func (s *UsersService) ListAll(ctx context.Context, opt *UserListOptions) ([]*Us // authenticated user. // // GitHub API docs: https://developer.github.com/v3/repos/invitations/#list-a-users-repository-invitations -func (s *UsersService) ListInvitations(ctx context.Context) ([]*RepositoryInvitation, *Response, error) { - req, err := s.client.NewRequest("GET", "user/repository_invitations", nil) +func (s *UsersService) ListInvitations(ctx context.Context, opt *ListOptions) ([]*RepositoryInvitation, *Response, error) { + u, err := addOptions("user/repository_invitations", opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err } diff --git a/vendor/github.com/google/go-github/github/users_blocking.go b/vendor/github.com/google/go-github/github/users_blocking.go new file mode 100644 index 000000000000..39e45601cc1e --- /dev/null +++ b/vendor/github.com/google/go-github/github/users_blocking.go @@ -0,0 +1,91 @@ +// Copyright 2017 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" +) + +// ListBlockedUsers lists all the blocked users by the authenticated user. +// +// GitHub API docs: https://developer.github.com/v3/users/blocking/#list-blocked-users +func (s *UsersService) ListBlockedUsers(ctx context.Context, opt *ListOptions) ([]*User, *Response, error) { + u := "user/blocks" + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeBlockUsersPreview) + + var blockedUsers []*User + resp, err := s.client.Do(ctx, req, &blockedUsers) + if err != nil { + return nil, resp, err + } + + return blockedUsers, resp, nil +} + +// IsBlocked reports whether specified user is blocked by the authenticated user. +// +// GitHub API docs: https://developer.github.com/v3/users/blocking/#check-whether-youve-blocked-a-user +func (s *UsersService) IsBlocked(ctx context.Context, user string) (bool, *Response, error) { + u := fmt.Sprintf("user/blocks/%v", user) + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return false, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeBlockUsersPreview) + + resp, err := s.client.Do(ctx, req, nil) + isBlocked, err := parseBoolResponse(err) + return isBlocked, resp, err +} + +// BlockUser blocks specified user for the authenticated user. +// +// GitHub API docs: https://developer.github.com/v3/users/blocking/#block-a-user +func (s *UsersService) BlockUser(ctx context.Context, user string) (*Response, error) { + u := fmt.Sprintf("user/blocks/%v", user) + + req, err := s.client.NewRequest("PUT", u, nil) + if err != nil { + return nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeBlockUsersPreview) + + return s.client.Do(ctx, req, nil) +} + +// UnblockUser unblocks specified user for the authenticated user. +// +// GitHub API docs: https://developer.github.com/v3/users/blocking/#unblock-a-user +func (s *UsersService) UnblockUser(ctx context.Context, user string) (*Response, error) { + u := fmt.Sprintf("user/blocks/%v", user) + + 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", mediaTypeBlockUsersPreview) + + return s.client.Do(ctx, req, nil) +} diff --git a/vendor/github.com/google/go-github/github/users_gpg_keys.go b/vendor/github.com/google/go-github/github/users_gpg_keys.go index 35cce0209232..be88c042ab77 100644 --- a/vendor/github.com/google/go-github/github/users_gpg_keys.go +++ b/vendor/github.com/google/go-github/github/users_gpg_keys.go @@ -40,12 +40,24 @@ type GPGEmail struct { Verified *bool `json:"verified,omitempty"` } -// ListGPGKeys lists the current user's GPG keys. It requires authentication +// ListGPGKeys lists the public GPG keys for a user. Passing the empty +// string will fetch keys for the authenticated user. It requires authentication // via Basic Auth or via OAuth with at least read:gpg_key scope. -// -// GitHub API docs: https://developer.github.com/v3/users/gpg_keys/#list-your-gpg-keys -func (s *UsersService) ListGPGKeys(ctx context.Context) ([]*GPGKey, *Response, error) { - req, err := s.client.NewRequest("GET", "user/gpg_keys", nil) + +// GitHub API docs: https://developer.github.com/v3/users/gpg_keys/#list-gpg-keys-for-a-user +func (s *UsersService) ListGPGKeys(ctx context.Context, user string, opt *ListOptions) ([]*GPGKey, *Response, error) { + var u string + if user != "" { + u = fmt.Sprintf("users/%v/gpg_keys", user) + } else { + u = "user/gpg_keys" + } + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err } diff --git a/vendor/github.com/google/go-github/github/without_appengine.go b/vendor/github.com/google/go-github/github/without_appengine.go new file mode 100644 index 000000000000..b0edc04db1d8 --- /dev/null +++ b/vendor/github.com/google/go-github/github/without_appengine.go @@ -0,0 +1,19 @@ +// Copyright 2017 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. + +// +build !appengine + +// This file provides glue for making github work without App Engine. + +package github + +import ( + "context" + "net/http" +) + +func withContext(ctx context.Context, req *http.Request) (context.Context, *http.Request) { + return ctx, req.WithContext(ctx) +} diff --git a/vendor/vendor.json b/vendor/vendor.json index ff93a45c70fd..62f38e8ead68 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -1623,10 +1623,12 @@ "revisionTime": "2016-11-17T03:31:26Z" }, { - "checksumSHA1": "nu3W9toub02L8S239VzXF+pevWM=", + "checksumSHA1": "JUiM+lVkaSVET43yWGhTZpnfdSE=", "path": "github.com/google/go-github/github", - "revision": "c1bdf188056730d883ce163c5f7400f25ba766d6", - "revisionTime": "2017-03-11T05:09:05Z" + "revision": "7a51fb928f52a196d5f31daefb8a489453ef54ff", + "revisionTime": "2017-06-04T03:01:11Z", + "version": "master", + "versionExact": "master" }, { "checksumSHA1": "Evpv9y6iPdy+8FeAVDmKrqV1sqo=", From 55dcfbe81fb4b508446b629992fc74af8630a0b3 Mon Sep 17 00:00:00 2001 From: Jay Wallace Date: Thu, 8 Jun 2017 22:16:16 -0700 Subject: [PATCH 2/4] use functions for setting data source attributes to properly handle nil values --- .../github/data_source_github_team.go | 10 +++--- .../github/data_source_github_user.go | 34 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/builtin/providers/github/data_source_github_team.go b/builtin/providers/github/data_source_github_team.go index c4b884fe6403..6a42fcbe93bb 100644 --- a/builtin/providers/github/data_source_github_team.go +++ b/builtin/providers/github/data_source_github_team.go @@ -50,11 +50,11 @@ func dataSourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error { return err } - d.SetId(strconv.Itoa(*team.ID)) - d.Set("name", *team.Name) - d.Set("description", *team.Description) - d.Set("privacy", *team.Privacy) - d.Set("permission", *team.Permission) + d.SetId(strconv.Itoa(team.GetID())) + d.Set("name", team.GetName()) + d.Set("description", team.GetDescription()) + d.Set("privacy", team.GetPrivacy()) + d.Set("permission", team.GetPermission()) return nil } diff --git a/builtin/providers/github/data_source_github_user.go b/builtin/providers/github/data_source_github_user.go index fc1f9a00ab2f..20dfd1f111d8 100644 --- a/builtin/providers/github/data_source_github_user.go +++ b/builtin/providers/github/data_source_github_user.go @@ -96,23 +96,23 @@ func dataSourceGithubUserRead(d *schema.ResourceData, meta interface{}) error { return err } - d.SetId(strconv.Itoa(*user.ID)) - d.Set("login", *user.Login) - d.Set("avatar_url", *user.AvatarURL) - d.Set("gravatar_id", *user.GravatarID) - d.Set("site_admin", *user.SiteAdmin) - d.Set("company", *user.Company) - d.Set("blog", *user.Blog) - d.Set("location", *user.Location) - d.Set("name", *user.Name) - d.Set("email", *user.Email) - d.Set("bio", *user.Bio) - d.Set("public_repos", *user.PublicRepos) - d.Set("public_gists", *user.PublicGists) - d.Set("followers", *user.Followers) - d.Set("following", *user.Following) - d.Set("created_at", *user.CreatedAt) - d.Set("updated_at", *user.UpdatedAt) + d.SetId(strconv.Itoa(user.GetID())) + d.Set("login", user.GetLogin()) + d.Set("avatar_url", user.GetAvatarURL()) + d.Set("gravatar_id", user.GetGravatarID()) + d.Set("site_admin", user.GetSiteAdmin()) + d.Set("company", user.GetCompany()) + d.Set("blog", user.GetBlog()) + d.Set("location", user.GetLocation()) + d.Set("name", user.GetName()) + d.Set("email", user.GetEmail()) + d.Set("bio", user.GetBio()) + d.Set("public_repos", user.GetPublicRepos()) + d.Set("public_gists", user.GetPublicGists()) + d.Set("followers", user.GetFollowers()) + d.Set("following", user.GetFollowing()) + d.Set("created_at", user.GetCreatedAt()) + d.Set("updated_at", user.GetUpdatedAt()) return nil } From d7a0fc6c7f7aa21d0188ac5ab90b79a49f301da3 Mon Sep 17 00:00:00 2001 From: Jay Wallace Date: Thu, 8 Jun 2017 23:08:18 -0700 Subject: [PATCH 3/4] add gpg_key and ssh_key primary keys as attributes to user data source --- .../github/data_source_github_user.go | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/builtin/providers/github/data_source_github_user.go b/builtin/providers/github/data_source_github_user.go index 20dfd1f111d8..e91418d35907 100644 --- a/builtin/providers/github/data_source_github_user.go +++ b/builtin/providers/github/data_source_github_user.go @@ -53,6 +53,14 @@ func dataSourceGithubUser() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "gpg_key": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "ssh_key": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, "bio": &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -90,8 +98,19 @@ func dataSourceGithubUserRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[INFO] Refreshing Gitub User: %s", username) client := meta.(*Organization).client + ctx := context.Background() + + user, _, err := client.Users.Get(ctx, username) + if err != nil { + return err + } + + gpg, _, err := client.Users.ListGPGKeys(ctx, username, nil) + if err != nil { + return err + } - user, _, err := client.Users.Get(context.TODO(), username) + ssh, _, err := client.Users.ListKeys(ctx, username, nil) if err != nil { return err } @@ -106,6 +125,8 @@ func dataSourceGithubUserRead(d *schema.ResourceData, meta interface{}) error { d.Set("location", user.GetLocation()) d.Set("name", user.GetName()) d.Set("email", user.GetEmail()) + d.Set("gpg_key", gpg[0].GetPublicKey()) + d.Set("ssh_key", ssh[0].GetKey()) d.Set("bio", user.GetBio()) d.Set("public_repos", user.GetPublicRepos()) d.Set("public_gists", user.GetPublicGists()) From 0eeb481fca364edeecef4a693ce4d30539181844 Mon Sep 17 00:00:00 2001 From: Jay Wallace Date: Thu, 8 Jun 2017 23:22:14 -0700 Subject: [PATCH 4/4] update docs and changelog --- CHANGELOG.md | 1 + website/source/docs/providers/github/d/user.html.markdown | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae74fee15836..36b0bb59f7f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ FEATURES: IMPROVEMENTS: * provider/rancher: Move to Rancher V2 API [GH-13908] +* provider/github: Added SSH and GPG key to user data source [GH-15211] diff --git a/website/source/docs/providers/github/d/user.html.markdown b/website/source/docs/providers/github/d/user.html.markdown index 48cff586656f..b3215ddb2c21 100644 --- a/website/source/docs/providers/github/d/user.html.markdown +++ b/website/source/docs/providers/github/d/user.html.markdown @@ -33,6 +33,8 @@ data "github_user" "example" { * `blog` - the user's blog location. * `location` - the user's location. * `email` - the user's email. + * `gpg_key` - the user's primary GPG key + * `ssh_key` - the user's primary SSH key * `bio` - the user's bio. * `public_repos` - the number of public repositories. * `public_gists` - the number of public gists.