1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Update dependencies

This commit is contained in:
Chris Cummer
2018-10-21 12:48:22 -07:00
parent 8f3ae94b4e
commit 3a0bcd21e7
132 changed files with 18033 additions and 9138 deletions

View File

@@ -96,6 +96,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) {
payload = &ReleaseEvent{}
case "RepositoryEvent":
payload = &RepositoryEvent{}
case "RepositoryVulnerabilityAlertEvent":
payload = &RepositoryVulnerabilityAlertEvent{}
case "StatusEvent":
payload = &StatusEvent{}
case "TeamEvent":

View File

@@ -8,6 +8,7 @@ package github
import (
"context"
"fmt"
"strings"
)
// StarredRepository is returned by ListStarred.
@@ -84,8 +85,9 @@ func (s *ActivityService) ListStarred(ctx context.Context, user string, opt *Act
return nil, nil, err
}
// TODO: remove custom Accept header when this API fully launches
req.Header.Set("Accept", mediaTypeStarringPreview)
// TODO: remove custom Accept header when APIs fully launch
acceptHeaders := []string{mediaTypeStarringPreview, mediaTypeTopicsPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
var repos []*StarredRepository
resp, err := s.client.Do(ctx, req, &repos)

View File

@@ -164,7 +164,7 @@ func (s *AppsService) ListUserInstallations(ctx context.Context, opt *ListOption
//
// GitHub API docs: https://developer.github.com/v3/apps/#create-a-new-installation-token
func (s *AppsService) CreateInstallationToken(ctx context.Context, id int64) (*InstallationToken, *Response, error) {
u := fmt.Sprintf("installations/%v/access_tokens", id)
u := fmt.Sprintf("app/installations/%v/access_tokens", id)
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {

View File

@@ -19,6 +19,7 @@ type ChecksService service
// CheckRun represents a GitHub check run on a repository associated with a GitHub app.
type CheckRun struct {
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
HeadSHA *string `json:"head_sha,omitempty"`
ExternalID *string `json:"external_id,omitempty"`
URL *string `json:"url,omitempty"`
@@ -47,14 +48,14 @@ type CheckRunOutput struct {
// CheckRunAnnotation represents an annotation object for a CheckRun output.
type CheckRunAnnotation struct {
FileName *string `json:"filename,omitempty"`
BlobHRef *string `json:"blob_href,omitempty"`
StartLine *int `json:"start_line,omitempty"`
EndLine *int `json:"end_line,omitempty"`
WarningLevel *string `json:"warning_level,omitempty"`
Message *string `json:"message,omitempty"`
Title *string `json:"title,omitempty"`
RawDetails *string `json:"raw_details,omitempty"`
Path *string `json:"path,omitempty"`
BlobHRef *string `json:"blob_href,omitempty"`
StartLine *int `json:"start_line,omitempty"`
EndLine *int `json:"end_line,omitempty"`
AnnotationLevel *string `json:"annotation_level,omitempty"`
Message *string `json:"message,omitempty"`
Title *string `json:"title,omitempty"`
RawDetails *string `json:"raw_details,omitempty"`
}
// CheckRunImage represents an image object for a CheckRun output.
@@ -67,6 +68,7 @@ type CheckRunImage struct {
// CheckSuite represents a suite of check runs.
type CheckSuite struct {
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
HeadBranch *string `json:"head_branch,omitempty"`
HeadSHA *string `json:"head_sha,omitempty"`
URL *string `json:"url,omitempty"`
@@ -401,20 +403,11 @@ func (s *ChecksService) CreateCheckSuite(ctx context.Context, owner, repo string
return checkSuite, resp, nil
}
// RequestCheckSuiteOptions sets up the parameters for a request check suite endpoint.
type RequestCheckSuiteOptions struct {
HeadSHA string `json:"head_sha"` // The sha of the head commit. (Required.)
}
// RequestCheckSuite triggers GitHub to create a new check suite, without pushing new code to a repository.
// ReRequestCheckSuite triggers GitHub to rerequest an existing check suite, without pushing new code to a repository.
//
// GitHub API docs: https://developer.github.com/v3/checks/suites/#request-check-suites
func (s *ChecksService) RequestCheckSuite(ctx context.Context, owner, repo string, opt RequestCheckSuiteOptions) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/check-suite-requests", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
return nil, err
}
// GitHub API docs: https://developer.github.com/v3/checks/suites/#rerequest-check-suite
func (s *ChecksService) ReRequestCheckSuite(ctx context.Context, owner, repo string, checkSuiteID int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/check-suites/%v/rerequest", owner, repo, checkSuiteID)
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {

View File

@@ -519,6 +519,7 @@ type PullRequestEvent struct {
// the pull request was closed with unmerged commits. If the action is "closed"
// and the merged key is true, the pull request was merged.
Action *string `json:"action,omitempty"`
Assignee *User `json:"assignee,omitempty"`
Number *int `json:"number,omitempty"`
PullRequest *PullRequest `json:"pull_request,omitempty"`
@@ -532,6 +533,10 @@ type PullRequestEvent struct {
Sender *User `json:"sender,omitempty"`
Installation *Installation `json:"installation,omitempty"`
Label *Label `json:"label,omitempty"` // Populated in "labeled" event deliveries.
// The following field is only present when the webhook is triggered on
// a repository belonging to an organization.
Organization *Organization `json:"organization,omitempty"`
}
// PullRequestReviewEvent is triggered when a review is submitted on a pull
@@ -705,6 +710,27 @@ type RepositoryEvent struct {
Installation *Installation `json:"installation,omitempty"`
}
// RepositoryVulnerabilityAlertEvent is triggered when a security alert is created, dismissed, or resolved.
//
// GitHub API docs: https://developer.github.com/v3/activity/events/types/#repositoryvulnerabilityalertevent
type RepositoryVulnerabilityAlertEvent struct {
// Action is the action that was performed. This can be: "create", "dismiss", "resolve".
Action *string `json:"action,omitempty"`
//The security alert of the vulnerable dependency.
Alert *struct {
ID *int64 `json:"id,omitempty"`
AffectedRange *string `json:"affected_range,omitempty"`
AffectedPackageName *string `json:"affected_package_name,omitempty"`
ExternalReference *string `json:"external_reference,omitempty"`
ExternalIdentifier *string `json:"external_identifier,omitempty"`
FixedIn *string `json:"fixed_in,omitempty"`
Dismisser *User `json:"dismisser,omitempty"`
DismissReason *string `json:"dismiss_reason,omitempty"`
DismissedAt *Timestamp `json:"dismissed_at,omitempty"`
} `json:"alert,omitempty"`
}
// StatusEvent is triggered when the status of a Git commit changes.
// The Webhook event name is "status".
//

View File

@@ -58,7 +58,7 @@ func (c CommitAuthor) String() string {
return Stringify(c)
}
// GetCommit fetchs the Commit object for a given SHA.
// GetCommit fetches the Commit object for a given SHA.
//
// GitHub API docs: https://developer.github.com/v3/git/commits/#get-a-commit
func (s *GitService) GetCommit(ctx context.Context, owner string, repo string, sha string) (*Commit, *Response, error) {

View File

@@ -33,7 +33,7 @@ type createTagRequest struct {
Tagger *CommitAuthor `json:"tagger,omitempty"`
}
// GetTag fetchs a tag from a repo given a SHA.
// GetTag fetches a tag from a repo given a SHA.
//
// GitHub API docs: https://developer.github.com/v3/git/tags/#get-a-tag
func (s *GitService) GetTag(ctx context.Context, owner string, repo string, sha string) (*Tag, *Response, error) {

View File

@@ -532,6 +532,14 @@ func (c *CheckRun) GetName() string {
return *c.Name
}
// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise.
func (c *CheckRun) GetNodeID() string {
if c == nil || c.NodeID == nil {
return ""
}
return *c.NodeID
}
// GetOutput returns the Output field.
func (c *CheckRun) GetOutput() *CheckRunOutput {
if c == nil {
@@ -564,6 +572,14 @@ func (c *CheckRun) GetURL() string {
return *c.URL
}
// GetAnnotationLevel returns the AnnotationLevel field if it's non-nil, zero value otherwise.
func (c *CheckRunAnnotation) GetAnnotationLevel() string {
if c == nil || c.AnnotationLevel == nil {
return ""
}
return *c.AnnotationLevel
}
// GetBlobHRef returns the BlobHRef field if it's non-nil, zero value otherwise.
func (c *CheckRunAnnotation) GetBlobHRef() string {
if c == nil || c.BlobHRef == nil {
@@ -580,14 +596,6 @@ func (c *CheckRunAnnotation) GetEndLine() int {
return *c.EndLine
}
// GetFileName returns the FileName field if it's non-nil, zero value otherwise.
func (c *CheckRunAnnotation) GetFileName() string {
if c == nil || c.FileName == nil {
return ""
}
return *c.FileName
}
// GetMessage returns the Message field if it's non-nil, zero value otherwise.
func (c *CheckRunAnnotation) GetMessage() string {
if c == nil || c.Message == nil {
@@ -596,6 +604,14 @@ func (c *CheckRunAnnotation) GetMessage() string {
return *c.Message
}
// GetPath returns the Path field if it's non-nil, zero value otherwise.
func (c *CheckRunAnnotation) GetPath() string {
if c == nil || c.Path == nil {
return ""
}
return *c.Path
}
// GetRawDetails returns the RawDetails field if it's non-nil, zero value otherwise.
func (c *CheckRunAnnotation) GetRawDetails() string {
if c == nil || c.RawDetails == nil {
@@ -620,14 +636,6 @@ func (c *CheckRunAnnotation) GetTitle() string {
return *c.Title
}
// GetWarningLevel returns the WarningLevel field if it's non-nil, zero value otherwise.
func (c *CheckRunAnnotation) GetWarningLevel() string {
if c == nil || c.WarningLevel == nil {
return ""
}
return *c.WarningLevel
}
// GetAction returns the Action field if it's non-nil, zero value otherwise.
func (c *CheckRunEvent) GetAction() string {
if c == nil || c.Action == nil {
@@ -796,6 +804,14 @@ func (c *CheckSuite) GetID() int64 {
return *c.ID
}
// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise.
func (c *CheckSuite) GetNodeID() string {
if c == nil || c.NodeID == nil {
return ""
}
return *c.NodeID
}
// GetRepository returns the Repository field.
func (c *CheckSuite) GetRepository() *Repository {
if c == nil {
@@ -2380,6 +2396,14 @@ func (d *DiscussionComment) GetNumber() int {
return *d.Number
}
// GetReactions returns the Reactions field.
func (d *DiscussionComment) GetReactions() *Reactions {
if d == nil {
return nil
}
return d.Reactions
}
// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise.
func (d *DiscussionComment) GetUpdatedAt() Timestamp {
if d == nil || d.UpdatedAt == nil {
@@ -3116,14 +3140,6 @@ func (h *Hook) GetID() int64 {
return *h.ID
}
// GetName returns the Name field if it's non-nil, zero value otherwise.
func (h *Hook) GetName() string {
if h == nil || h.Name == nil {
return ""
}
return *h.Name
}
// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise.
func (h *Hook) GetUpdatedAt() time.Time {
if h == nil || h.UpdatedAt == nil {
@@ -3860,6 +3876,14 @@ func (i *IssueComment) GetIssueURL() string {
return *i.IssueURL
}
// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise.
func (i *IssueComment) GetNodeID() string {
if i == nil || i.NodeID == nil {
return ""
}
return *i.NodeID
}
// GetReactions returns the Reactions field.
func (i *IssueComment) GetReactions() *Reactions {
if i == nil {
@@ -5524,6 +5548,22 @@ func (o *Organization) GetCreatedAt() time.Time {
return *o.CreatedAt
}
// GetDefaultRepoPermission returns the DefaultRepoPermission field if it's non-nil, zero value otherwise.
func (o *Organization) GetDefaultRepoPermission() string {
if o == nil || o.DefaultRepoPermission == nil {
return ""
}
return *o.DefaultRepoPermission
}
// GetDefaultRepoSettings returns the DefaultRepoSettings field if it's non-nil, zero value otherwise.
func (o *Organization) GetDefaultRepoSettings() string {
if o == nil || o.DefaultRepoSettings == nil {
return ""
}
return *o.DefaultRepoSettings
}
// GetDescription returns the Description field if it's non-nil, zero value otherwise.
func (o *Organization) GetDescription() string {
if o == nil || o.Description == nil {
@@ -5620,6 +5660,14 @@ func (o *Organization) GetLogin() string {
return *o.Login
}
// GetMembersCanCreateRepos returns the MembersCanCreateRepos field if it's non-nil, zero value otherwise.
func (o *Organization) GetMembersCanCreateRepos() bool {
if o == nil || o.MembersCanCreateRepos == nil {
return false
}
return *o.MembersCanCreateRepos
}
// GetMembersURL returns the MembersURL field if it's non-nil, zero value otherwise.
func (o *Organization) GetMembersURL() string {
if o == nil || o.MembersURL == nil {
@@ -5708,6 +5756,14 @@ func (o *Organization) GetTotalPrivateRepos() int {
return *o.TotalPrivateRepos
}
// GetTwoFactorRequirementEnabled returns the TwoFactorRequirementEnabled field if it's non-nil, zero value otherwise.
func (o *Organization) GetTwoFactorRequirementEnabled() bool {
if o == nil || o.TwoFactorRequirementEnabled == nil {
return false
}
return *o.TwoFactorRequirementEnabled
}
// GetType returns the Type field if it's non-nil, zero value otherwise.
func (o *Organization) GetType() string {
if o == nil || o.Type == nil {
@@ -6156,6 +6212,78 @@ func (p *PreReceiveHook) GetName() string {
return *p.Name
}
// GetHRef returns the HRef field if it's non-nil, zero value otherwise.
func (p *PRLink) GetHRef() string {
if p == nil || p.HRef == nil {
return ""
}
return *p.HRef
}
// GetComments returns the Comments field.
func (p *PRLinks) GetComments() *PRLink {
if p == nil {
return nil
}
return p.Comments
}
// GetCommits returns the Commits field.
func (p *PRLinks) GetCommits() *PRLink {
if p == nil {
return nil
}
return p.Commits
}
// GetHTML returns the HTML field.
func (p *PRLinks) GetHTML() *PRLink {
if p == nil {
return nil
}
return p.HTML
}
// GetIssue returns the Issue field.
func (p *PRLinks) GetIssue() *PRLink {
if p == nil {
return nil
}
return p.Issue
}
// GetReviewComment returns the ReviewComment field.
func (p *PRLinks) GetReviewComment() *PRLink {
if p == nil {
return nil
}
return p.ReviewComment
}
// GetReviewComments returns the ReviewComments field.
func (p *PRLinks) GetReviewComments() *PRLink {
if p == nil {
return nil
}
return p.ReviewComments
}
// GetSelf returns the Self field.
func (p *PRLinks) GetSelf() *PRLink {
if p == nil {
return nil
}
return p.Self
}
// GetStatuses returns the Statuses field.
func (p *PRLinks) GetStatuses() *PRLink {
if p == nil {
return nil
}
return p.Statuses
}
// GetBody returns the Body field if it's non-nil, zero value otherwise.
func (p *Project) GetBody() string {
if p == nil || p.Body == nil {
@@ -6884,6 +7012,14 @@ func (p *PullRequest) GetIssueURL() string {
return *p.IssueURL
}
// GetLinks returns the Links field.
func (p *PullRequest) GetLinks() *PRLinks {
if p == nil {
return nil
}
return p.Links
}
// GetMaintainerCanModify returns the MaintainerCanModify field if it's non-nil, zero value otherwise.
func (p *PullRequest) GetMaintainerCanModify() bool {
if p == nil || p.MaintainerCanModify == nil {
@@ -7228,6 +7364,14 @@ func (p *PullRequestEvent) GetAction() string {
return *p.Action
}
// GetAssignee returns the Assignee field.
func (p *PullRequestEvent) GetAssignee() *User {
if p == nil {
return nil
}
return p.Assignee
}
// GetChanges returns the Changes field.
func (p *PullRequestEvent) GetChanges() *EditChange {
if p == nil {
@@ -7260,6 +7404,14 @@ func (p *PullRequestEvent) GetNumber() int {
return *p.Number
}
// GetOrganization returns the Organization field.
func (p *PullRequestEvent) GetOrganization() *Organization {
if p == nil {
return nil
}
return p.Organization
}
// GetPullRequest returns the PullRequest field.
func (p *PullRequestEvent) GetPullRequest() *PullRequest {
if p == nil {
@@ -9804,6 +9956,14 @@ func (r *RepositoryTag) GetZipballURL() string {
return *r.ZipballURL
}
// GetAction returns the Action field if it's non-nil, zero value otherwise.
func (r *RepositoryVulnerabilityAlertEvent) GetAction() string {
if r == nil || r.Action == nil {
return ""
}
return *r.Action
}
// GetForkRepos returns the ForkRepos field if it's non-nil, zero value otherwise.
func (r *RepoStats) GetForkRepos() int {
if r == nil || r.ForkRepos == nil {
@@ -10564,6 +10724,14 @@ func (t *TeamDiscussion) GetPrivate() bool {
return *t.Private
}
// GetReactions returns the Reactions field.
func (t *TeamDiscussion) GetReactions() *Reactions {
if t == nil {
return nil
}
return t.Reactions
}
// GetTeamURL returns the TeamURL field if it's non-nil, zero value otherwise.
func (t *TeamDiscussion) GetTeamURL() string {
if t == nil || t.TeamURL == nil {

View File

@@ -375,7 +375,9 @@ type Response struct {
FirstPage int
LastPage int
Rate
// Explicitly specify the Rate type so Rate's String() receiver doesn't
// propagate to Response.
Rate Rate
}
// newResponse creates a new Response for the provided http.Response.
@@ -500,13 +502,23 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Res
err = CheckResponse(resp)
if err != nil {
// Even though there was an error, we still return the response
// in case the caller wants to inspect it further.
// However, if the error is AcceptedError, decode it below before
// returning from this function and closing the response body.
if _, ok := err.(*AcceptedError); !ok {
return response, err
// Special case for AcceptedErrors. If an AcceptedError
// has been encountered, the response's payload will be
// added to the AcceptedError and returned.
//
// Issue #1022
aerr, ok := err.(*AcceptedError)
if ok {
b, readErr := ioutil.ReadAll(resp.Body)
if readErr != nil {
return response, readErr
}
aerr.Raw = b
return response, aerr
}
return response, err
}
if v != nil {
@@ -608,7 +620,10 @@ func (r *RateLimitError) Error() string {
// Technically, 202 Accepted is not a real error, it's just used to
// indicate that results are not ready yet, but should be available soon.
// The request can be repeated after some time.
type AcceptedError struct{}
type AcceptedError struct {
// Raw contains the response body.
Raw []byte
}
func (*AcceptedError) Error() string {
return "job scheduled on GitHub side; try again later"

View File

@@ -228,7 +228,7 @@ func (s *IssuesService) ListByRepo(ctx context.Context, owner string, repo strin
}
// TODO: remove custom Accept headers when APIs fully launch.
acceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview}
acceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeLabelDescriptionSearchPreview, mediaTypeIntegrationPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
var issues []*Issue

View File

@@ -14,6 +14,7 @@ import (
// IssueComment represents a comment left on an issue.
type IssueComment struct {
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
Body *string `json:"body,omitempty"`
User *User `json:"user,omitempty"`
Reactions *Reactions `json:"reactions,omitempty"`

View File

@@ -41,42 +41,43 @@ const (
var (
// eventTypeMapping maps webhooks types to their corresponding go-github struct types.
eventTypeMapping = map[string]string{
"check_run": "CheckRunEvent",
"check_suite": "CheckSuiteEvent",
"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",
"marketplace_purchase": "MarketplacePurchaseEvent",
"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",
"check_run": "CheckRunEvent",
"check_suite": "CheckSuiteEvent",
"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",
"marketplace_purchase": "MarketplacePurchaseEvent",
"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",
"repository_vulnerability_alert": "RepositoryVulnerabilityAlertEvent",
"release": "ReleaseEvent",
"status": "StatusEvent",
"team": "TeamEvent",
"team_add": "TeamAddEvent",
"watch": "WatchEvent",
}
)
@@ -175,19 +176,19 @@ func ValidatePayload(r *http.Request, secretKey []byte) (payload []byte, err err
}
sig := r.Header.Get(signatureHeader)
if err := validateSignature(sig, body, secretKey); err != nil {
if err := ValidateSignature(sig, body, secretKey); err != nil {
return nil, err
}
return payload, nil
}
// validateSignature validates the signature for the given payload.
// ValidateSignature validates the signature for the given payload.
// signature is the GitHub hash signature delivered in the X-Hub-Signature header.
// payload is the JSON payload sent by GitHub Webhooks.
// secretKey is the GitHub Webhook secret message.
//
// GitHub API docs: https://developer.github.com/webhooks/securing/#validating-payloads-from-github
func validateSignature(signature string, payload, secretKey []byte) error {
func ValidateSignature(signature string, payload, secretKey []byte) error {
messageMAC, hashFunc, err := messageMAC(signature)
if err != nil {
return err

View File

@@ -19,31 +19,42 @@ type OrganizationsService service
// Organization represents a GitHub organization account.
type Organization struct {
Login *string `json:"login,omitempty"`
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
AvatarURL *string `json:"avatar_url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
Name *string `json:"name,omitempty"`
Company *string `json:"company,omitempty"`
Blog *string `json:"blog,omitempty"`
Location *string `json:"location,omitempty"`
Email *string `json:"email,omitempty"`
Description *string `json:"description,omitempty"`
PublicRepos *int `json:"public_repos,omitempty"`
PublicGists *int `json:"public_gists,omitempty"`
Followers *int `json:"followers,omitempty"`
Following *int `json:"following,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
TotalPrivateRepos *int `json:"total_private_repos,omitempty"`
OwnedPrivateRepos *int `json:"owned_private_repos,omitempty"`
PrivateGists *int `json:"private_gists,omitempty"`
DiskUsage *int `json:"disk_usage,omitempty"`
Collaborators *int `json:"collaborators,omitempty"`
BillingEmail *string `json:"billing_email,omitempty"`
Type *string `json:"type,omitempty"`
Plan *Plan `json:"plan,omitempty"`
Login *string `json:"login,omitempty"`
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
AvatarURL *string `json:"avatar_url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
Name *string `json:"name,omitempty"`
Company *string `json:"company,omitempty"`
Blog *string `json:"blog,omitempty"`
Location *string `json:"location,omitempty"`
Email *string `json:"email,omitempty"`
Description *string `json:"description,omitempty"`
PublicRepos *int `json:"public_repos,omitempty"`
PublicGists *int `json:"public_gists,omitempty"`
Followers *int `json:"followers,omitempty"`
Following *int `json:"following,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
TotalPrivateRepos *int `json:"total_private_repos,omitempty"`
OwnedPrivateRepos *int `json:"owned_private_repos,omitempty"`
PrivateGists *int `json:"private_gists,omitempty"`
DiskUsage *int `json:"disk_usage,omitempty"`
Collaborators *int `json:"collaborators,omitempty"`
BillingEmail *string `json:"billing_email,omitempty"`
Type *string `json:"type,omitempty"`
Plan *Plan `json:"plan,omitempty"`
TwoFactorRequirementEnabled *bool `json:"two_factor_requirement_enabled,omitempty"`
// DefaultRepoPermission can be one of: "read", "write", "admin", or "none". (Default: "read").
// It is only used in OrganizationsService.Edit.
DefaultRepoPermission *string `json:"default_repository_permission,omitempty"`
// DefaultRepoSettings can be one of: "read", "write", "admin", or "none". (Default: "read").
// It is only used in OrganizationsService.Get.
DefaultRepoSettings *string `json:"default_repository_settings,omitempty"`
// MembersCanCreateRepos default value is true and is only used in Organizations.Edit.
MembersCanCreateRepos *bool `json:"members_can_create_repositories,omitempty"`
// API URLs
URL *string `json:"url,omitempty"`

View File

@@ -49,12 +49,22 @@ func (s *OrganizationsService) GetHook(ctx context.Context, org string, id int64
}
// CreateHook creates a Hook for the specified org.
// Name and Config are required fields.
// Config is a required field.
//
// Note that only a subset of the hook fields are used and hook must
// not be nil.
//
// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#create-a-hook
func (s *OrganizationsService) CreateHook(ctx context.Context, org string, hook *Hook) (*Hook, *Response, error) {
u := fmt.Sprintf("orgs/%v/hooks", org)
req, err := s.client.NewRequest("POST", u, hook)
hookReq := &createHookRequest{
Events: hook.Events,
Active: hook.Active,
Config: hook.Config,
}
req, err := s.client.NewRequest("POST", u, hookReq)
if err != nil {
return nil, nil, err
}

View File

@@ -60,8 +60,13 @@ type PullRequest struct {
NodeID *string `json:"node_id,omitempty"`
RequestedReviewers []*User `json:"requested_reviewers,omitempty"`
Head *PullRequestBranch `json:"head,omitempty"`
Base *PullRequestBranch `json:"base,omitempty"`
// RequestedTeams is populated as part of the PullRequestEvent.
// See, https://developer.github.com/v3/activity/events/types/#pullrequestevent for an example.
RequestedTeams []*Team `json:"requested_teams,omitempty"`
Links *PRLinks `json:"_links,omitempty"`
Head *PullRequestBranch `json:"head,omitempty"`
Base *PullRequestBranch `json:"base,omitempty"`
// ActiveLockReason is populated only when LockReason is provided while locking the pull request.
// Possible values are: "off-topic", "too heated", "resolved", and "spam".
@@ -72,6 +77,23 @@ func (p PullRequest) String() string {
return Stringify(p)
}
// PRLink represents a single link object from Github pull request _links.
type PRLink struct {
HRef *string `json:"href,omitempty"`
}
// PRLinks represents the "_links" object in a Github pull request.
type PRLinks struct {
Self *PRLink `json:"self,omitempty"`
HTML *PRLink `json:"html,omitempty"`
Issue *PRLink `json:"issue,omitempty"`
Comments *PRLink `json:"comments,omitempty"`
ReviewComments *PRLink `json:"review_comments,omitempty"`
ReviewComment *PRLink `json:"review_comment,omitempty"`
Commits *PRLink `json:"commits,omitempty"`
Statuses *PRLink `json:"statuses,omitempty"`
}
// PullRequestBranch represents a base or head branch in a GitHub pull request.
type PullRequestBranch struct {
Label *string `json:"label,omitempty"`

View File

@@ -74,6 +74,7 @@ func (s *ReactionsService) ListCommentReactions(ctx context.Context, owner, repo
// CreateCommentReaction creates a reaction for a commit comment.
// Note that if you have already created a reaction of type content, the
// previously created reaction will be returned with Status: 200 OK.
// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray".
//
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-a-commit-comment
func (s ReactionsService) CreateCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) {
@@ -127,6 +128,7 @@ func (s *ReactionsService) ListIssueReactions(ctx context.Context, owner, repo s
// CreateIssueReaction creates a reaction for an issue.
// Note that if you have already created a reaction of type content, the
// previously created reaction will be returned with Status: 200 OK.
// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray".
//
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-an-issue
func (s ReactionsService) CreateIssueReaction(ctx context.Context, owner, repo string, number int, content string) (*Reaction, *Response, error) {
@@ -180,6 +182,7 @@ func (s *ReactionsService) ListIssueCommentReactions(ctx context.Context, owner,
// CreateIssueCommentReaction creates a reaction for an issue comment.
// Note that if you have already created a reaction of type content, the
// previously created reaction will be returned with Status: 200 OK.
// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray".
//
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-an-issue-comment
func (s ReactionsService) CreateIssueCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) {
@@ -233,6 +236,7 @@ func (s *ReactionsService) ListPullRequestCommentReactions(ctx context.Context,
// CreatePullRequestCommentReaction creates a reaction for a pull request review comment.
// Note that if you have already created a reaction of type content, the
// previously created reaction will be returned with Status: 200 OK.
// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray".
//
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-an-issue-comment
func (s ReactionsService) CreatePullRequestCommentReaction(ctx context.Context, owner, repo string, id int64, content string) (*Reaction, *Response, error) {
@@ -256,6 +260,103 @@ func (s ReactionsService) CreatePullRequestCommentReaction(ctx context.Context,
return m, resp, nil
}
// ListTeamDiscussionReactions lists the reactions for a team discussion.
//
// GitHub API docs: https://developer.github.com/v3/reactions/#list-reactions-for-a-team-discussion
func (s *ReactionsService) ListTeamDiscussionReactions(ctx context.Context, teamID int64, discussionNumber int, opt *ListOptions) ([]*Reaction, *Response, error) {
u := fmt.Sprintf("teams/%v/discussions/%v/reactions", teamID, discussionNumber)
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
}
req.Header.Set("Accept", mediaTypeReactionsPreview)
var m []*Reaction
resp, err := s.client.Do(ctx, req, &m)
if err != nil {
return nil, resp, err
}
return m, resp, nil
}
// CreateTeamDiscussionReaction creates a reaction for a team discussion.
// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray".
//
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-a-team-discussion
func (s *ReactionsService) CreateTeamDiscussionReaction(ctx context.Context, teamID int64, discussionNumber int, content string) (*Reaction, *Response, error) {
u := fmt.Sprintf("teams/%v/discussions/%v/reactions", teamID, discussionNumber)
body := &Reaction{Content: String(content)}
req, err := s.client.NewRequest("POST", u, body)
if err != nil {
return nil, nil, err
}
req.Header.Set("Accept", mediaTypeReactionsPreview)
m := &Reaction{}
resp, err := s.client.Do(ctx, req, m)
if err != nil {
return nil, resp, err
}
return m, resp, nil
}
// ListTeamDiscussionCommentReactions lists the reactions for a team discussion comment.
//
// GitHub API docs: https://developer.github.com/v3/reactions/#list-reactions-for-a-team-discussion-comment
func (s *ReactionsService) ListTeamDiscussionCommentReactions(ctx context.Context, teamID int64, discussionNumber, commentNumber int, opt *ListOptions) ([]*Reaction, *Response, error) {
u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v/reactions", teamID, discussionNumber, commentNumber)
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
}
req.Header.Set("Accept", mediaTypeReactionsPreview)
var m []*Reaction
resp, err := s.client.Do(ctx, req, &m)
return m, resp, nil
}
// CreateTeamDiscussionCommentReaction creates a reaction for a team discussion comment.
// The content should have one of the following values: "+1", "-1", "laugh", "confused", "heart", "hooray".
//
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-a-team-discussion-comment
func (s *ReactionsService) CreateTeamDiscussionCommentReaction(ctx context.Context, teamID int64, discussionNumber, commentNumber int, content string) (*Reaction, *Response, error) {
u := fmt.Sprintf("teams/%v/discussions/%v/comments/%v/reactions", teamID, discussionNumber, commentNumber)
body := &Reaction{Content: String(content)}
req, err := s.client.NewRequest("POST", u, body)
if err != nil {
return nil, nil, err
}
req.Header.Set("Accept", mediaTypeReactionsPreview)
m := &Reaction{}
resp, err := s.client.Do(ctx, req, m)
if err != nil {
return nil, resp, err
}
return m, resp, nil
}
// DeleteReaction deletes a reaction.
//
// GitHub API docs: https://developer.github.com/v3/reaction/reactions/#delete-a-reaction-archive

View File

@@ -56,6 +56,7 @@ type Repository struct {
AllowSquashMerge *bool `json:"allow_squash_merge,omitempty"`
AllowMergeCommit *bool `json:"allow_merge_commit,omitempty"`
Topics []string `json:"topics,omitempty"`
Archived *bool `json:"archived,omitempty"`
// Only provided when using RepositoriesService.Get while in preview
License *License `json:"license,omitempty"`
@@ -69,7 +70,6 @@ type Repository struct {
HasDownloads *bool `json:"has_downloads,omitempty"`
LicenseTemplate *string `json:"license_template,omitempty"`
GitignoreTemplate *string `json:"gitignore_template,omitempty"`
Archived *bool `json:"archived,omitempty"`
// Creating an organization repository. Required for non-owners.
TeamID *int64 `json:"team_id,omitempty"`
@@ -259,10 +259,40 @@ func (s *RepositoriesService) ListAll(ctx context.Context, opt *RepositoryListAl
return repos, resp, nil
}
// createRepoRequest is a subset of Repository and is used internally
// by Create to pass only the known fields for the endpoint.
//
// See https://github.com/google/go-github/issues/1014 for more
// information.
type createRepoRequest struct {
// Name is required when creating a repo.
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Homepage *string `json:"homepage,omitempty"`
Private *bool `json:"private,omitempty"`
HasIssues *bool `json:"has_issues,omitempty"`
HasProjects *bool `json:"has_projects,omitempty"`
HasWiki *bool `json:"has_wiki,omitempty"`
// Creating an organization repository. Required for non-owners.
TeamID *int64 `json:"team_id,omitempty"`
AutoInit *bool `json:"auto_init,omitempty"`
GitignoreTemplate *string `json:"gitignore_template,omitempty"`
LicenseTemplate *string `json:"license_template,omitempty"`
AllowSquashMerge *bool `json:"allow_squash_merge,omitempty"`
AllowMergeCommit *bool `json:"allow_merge_commit,omitempty"`
AllowRebaseMerge *bool `json:"allow_rebase_merge,omitempty"`
}
// Create a new repository. If an organization is specified, the new
// repository will be created under that org. If the empty string is
// specified, it will be created for the authenticated user.
//
// Note that only a subset of the repo fields are used and repo must
// not be nil.
//
// GitHub API docs: https://developer.github.com/v3/repos/#create
func (s *RepositoriesService) Create(ctx context.Context, org string, repo *Repository) (*Repository, *Response, error) {
var u string
@@ -272,7 +302,24 @@ func (s *RepositoriesService) Create(ctx context.Context, org string, repo *Repo
u = "user/repos"
}
req, err := s.client.NewRequest("POST", u, repo)
repoReq := &createRepoRequest{
Name: repo.Name,
Description: repo.Description,
Homepage: repo.Homepage,
Private: repo.Private,
HasIssues: repo.HasIssues,
HasProjects: repo.HasProjects,
HasWiki: repo.HasWiki,
TeamID: repo.TeamID,
AutoInit: repo.AutoInit,
GitignoreTemplate: repo.GitignoreTemplate,
LicenseTemplate: repo.LicenseTemplate,
AllowSquashMerge: repo.AllowSquashMerge,
AllowMergeCommit: repo.AllowMergeCommit,
AllowRebaseMerge: repo.AllowRebaseMerge,
}
req, err := s.client.NewRequest("POST", u, repoReq)
if err != nil {
return nil, nil, err
}

View File

@@ -8,6 +8,8 @@ package github
import (
"context"
"fmt"
"encoding/json"
)
// RepositoryListForksOptions specifies the optional parameters to the
@@ -78,10 +80,15 @@ func (s *RepositoriesService) CreateFork(ctx context.Context, owner, repo string
fork := new(Repository)
resp, err := s.client.Do(ctx, req, fork)
if _, ok := err.(*AcceptedError); ok {
return fork, resp, err
}
if err != nil {
// Persist AcceptedError's metadata to the Repository object.
if aerr, ok := err.(*AcceptedError); ok {
if err := json.Unmarshal(aerr.Raw, fork); err != nil {
return fork, resp, err
}
return fork, resp, err
}
return nil, resp, err
}

View File

@@ -69,27 +69,51 @@ func (w WebHookAuthor) String() string {
// Hook represents a GitHub (web and service) hook for a repository.
type Hook struct {
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
Name *string `json:"name,omitempty"`
URL *string `json:"url,omitempty"`
Events []string `json:"events,omitempty"`
Active *bool `json:"active,omitempty"`
Config map[string]interface{} `json:"config,omitempty"`
ID *int64 `json:"id,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
URL *string `json:"url,omitempty"`
ID *int64 `json:"id,omitempty"`
// Only the following fields are used when creating a hook.
// Config is required.
Config map[string]interface{} `json:"config,omitempty"`
Events []string `json:"events,omitempty"`
Active *bool `json:"active,omitempty"`
}
func (h Hook) String() string {
return Stringify(h)
}
// createHookRequest is a subset of Hook and is used internally
// by CreateHook to pass only the known fields for the endpoint.
//
// See https://github.com/google/go-github/issues/1015 for more
// information.
type createHookRequest struct {
// Config is required.
Config map[string]interface{} `json:"config,omitempty"`
Events []string `json:"events,omitempty"`
Active *bool `json:"active,omitempty"`
}
// CreateHook creates a Hook for the specified repository.
// Name and Config are required fields.
// Config is a required field.
//
// Note that only a subset of the hook fields are used and hook must
// not be nil.
//
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#create-a-hook
func (s *RepositoriesService) CreateHook(ctx context.Context, owner, repo string, hook *Hook) (*Hook, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks", owner, repo)
req, err := s.client.NewRequest("POST", u, hook)
hookReq := &createHookRequest{
Events: hook.Events,
Active: hook.Active,
Config: hook.Config,
}
req, err := s.client.NewRequest("POST", u, hookReq)
if err != nil {
return nil, nil, err
}

View File

@@ -19,24 +19,26 @@ import (
// RepositoryRelease represents a GitHub release in a repository.
type RepositoryRelease struct {
ID *int64 `json:"id,omitempty"`
TagName *string `json:"tag_name,omitempty"`
TargetCommitish *string `json:"target_commitish,omitempty"`
Name *string `json:"name,omitempty"`
Body *string `json:"body,omitempty"`
Draft *bool `json:"draft,omitempty"`
Prerelease *bool `json:"prerelease,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
PublishedAt *Timestamp `json:"published_at,omitempty"`
URL *string `json:"url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
AssetsURL *string `json:"assets_url,omitempty"`
Assets []ReleaseAsset `json:"assets,omitempty"`
UploadURL *string `json:"upload_url,omitempty"`
ZipballURL *string `json:"zipball_url,omitempty"`
TarballURL *string `json:"tarball_url,omitempty"`
Author *User `json:"author,omitempty"`
NodeID *string `json:"node_id,omitempty"`
TagName *string `json:"tag_name,omitempty"`
TargetCommitish *string `json:"target_commitish,omitempty"`
Name *string `json:"name,omitempty"`
Body *string `json:"body,omitempty"`
Draft *bool `json:"draft,omitempty"`
Prerelease *bool `json:"prerelease,omitempty"`
// The following fields are not used in CreateRelease or EditRelease:
ID *int64 `json:"id,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
PublishedAt *Timestamp `json:"published_at,omitempty"`
URL *string `json:"url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
AssetsURL *string `json:"assets_url,omitempty"`
Assets []ReleaseAsset `json:"assets,omitempty"`
UploadURL *string `json:"upload_url,omitempty"`
ZipballURL *string `json:"zipball_url,omitempty"`
TarballURL *string `json:"tarball_url,omitempty"`
Author *User `json:"author,omitempty"`
NodeID *string `json:"node_id,omitempty"`
}
func (r RepositoryRelease) String() string {
@@ -125,13 +127,40 @@ func (s *RepositoriesService) getSingleRelease(ctx context.Context, url string)
return release, resp, nil
}
// repositoryReleaseRequest is a subset of RepositoryRelease and
// is used internally by CreateRelease and EditRelease to pass
// only the known fields for these endpoints.
//
// See https://github.com/google/go-github/issues/992 for more
// information.
type repositoryReleaseRequest struct {
TagName *string `json:"tag_name,omitempty"`
TargetCommitish *string `json:"target_commitish,omitempty"`
Name *string `json:"name,omitempty"`
Body *string `json:"body,omitempty"`
Draft *bool `json:"draft,omitempty"`
Prerelease *bool `json:"prerelease,omitempty"`
}
// CreateRelease adds a new release for a repository.
//
// Note that only a subset of the release fields are used.
// See RepositoryRelease for more information.
//
// GitHub API docs: https://developer.github.com/v3/repos/releases/#create-a-release
func (s *RepositoriesService) CreateRelease(ctx context.Context, owner, repo string, release *RepositoryRelease) (*RepositoryRelease, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases", owner, repo)
req, err := s.client.NewRequest("POST", u, release)
releaseReq := &repositoryReleaseRequest{
TagName: release.TagName,
TargetCommitish: release.TargetCommitish,
Name: release.Name,
Body: release.Body,
Draft: release.Draft,
Prerelease: release.Prerelease,
}
req, err := s.client.NewRequest("POST", u, releaseReq)
if err != nil {
return nil, nil, err
}
@@ -146,11 +175,23 @@ func (s *RepositoriesService) CreateRelease(ctx context.Context, owner, repo str
// EditRelease edits a repository release.
//
// Note that only a subset of the release fields are used.
// See RepositoryRelease for more information.
//
// GitHub API docs: https://developer.github.com/v3/repos/releases/#edit-a-release
func (s *RepositoriesService) EditRelease(ctx context.Context, owner, repo string, id int64, release *RepositoryRelease) (*RepositoryRelease, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/%d", owner, repo, id)
req, err := s.client.NewRequest("PATCH", u, release)
releaseReq := &repositoryReleaseRequest{
TagName: release.TagName,
TargetCommitish: release.TargetCommitish,
Name: release.Name,
Body: release.Body,
Draft: release.Draft,
Prerelease: release.Prerelease,
}
req, err := s.client.NewRequest("PATCH", u, releaseReq)
if err != nil {
return nil, nil, err
}

View File

@@ -24,6 +24,7 @@ type DiscussionComment struct {
Number *int `json:"number,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
URL *string `json:"url,omitempty"`
Reactions *Reactions `json:"reactions,omitempty"`
}
func (c DiscussionComment) String() string {

View File

@@ -29,6 +29,7 @@ type TeamDiscussion struct {
Title *string `json:"title,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
URL *string `json:"url,omitempty"`
Reactions *Reactions `json:"reactions,omitempty"`
}
func (d TeamDiscussion) String() string {

View File

@@ -76,6 +76,7 @@ func (u User) String() string {
// user.
//
// GitHub API docs: https://developer.github.com/v3/users/#get-a-single-user
// and: https://developer.github.com/v3/users/#get-the-authenticated-user
func (s *UsersService) Get(ctx context.Context, user string) (*User, *Response, error) {
var u string
if user != "" {