mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Output from 'dep status': PROJECT CONSTRAINT VERSION REVISION LATEST PKGS USED cloud.google.com/go v0.23.0 v0.23.0 0fd7230 v0.23.0 1 github.com/briandowns/openweathermap ^0.11.0 0.11 1b87579 0.11 1 github.com/gdamore/encoding branch master branch master b23993c b23993c 1 github.com/gdamore/tcell ^1.0.0 v1.0.0 061d51a v1.0.0 2 github.com/go-test/deep ^1.0.1 v1.0.1 6592d9c v1.0.1 1 github.com/golang/protobuf v1.1.0 v1.1.0 b4deda0 v1.1.0 1 github.com/google/go-github branch master branch master 2ae5df7 2ae5df7 1 github.com/google/go-querystring branch master branch master 53e6ce1 53e6ce1 1 github.com/jessevdk/go-flags ^1.4.0 v1.4.0 c6ca198 v1.4.0 1 github.com/lucasb-eyer/go-colorful v1.0 v1.0 345fbb3 v1.0 1 github.com/mattn/go-runewidth v0.0.2 v0.0.2 9e777a8 v0.0.2 1 github.com/olebedev/config branch master branch master 9a10d05 9a10d05 1 github.com/radovskyb/watcher ^1.0.2 v1.0.2 6145e14 v1.0.2 1 github.com/rivo/tview branch master branch master 71ecf1f 71ecf1f 1 github.com/yfronto/newrelic branch master branch master f7fa0c6 f7fa0c6 1 golang.org/x/net branch master branch master 1e49130 1e49130 2 golang.org/x/oauth2 branch master branch master 1e0a3fa 1e0a3fa 5 golang.org/x/text v0.3.0 v0.3.0 f21a4df v0.3.0 5 google.golang.org/api branch master branch master 00e3bb8 00e3bb8 4 google.golang.org/appengine v1.0.0 v1.0.0 150dc57 v1.0.0 10 gopkg.in/yaml.v2 ^2.2.1 v2.2.1 5420a8b v2.2.1 1 See https://golang.github.io/dep/docs/daily-dep.html
193 lines
6.4 KiB
Go
193 lines
6.4 KiB
Go
// Copyright 2013 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"
|
|
)
|
|
|
|
// WebHookPayload represents the data that is received from GitHub when a push
|
|
// event hook is triggered. The format of these payloads pre-date most of the
|
|
// GitHub v3 API, so there are lots of minor incompatibilities with the types
|
|
// defined in the rest of the API. Therefore, several types are duplicated
|
|
// here to account for these differences.
|
|
//
|
|
// GitHub API docs: https://help.github.com/articles/post-receive-hooks
|
|
type WebHookPayload struct {
|
|
After *string `json:"after,omitempty"`
|
|
Before *string `json:"before,omitempty"`
|
|
Commits []WebHookCommit `json:"commits,omitempty"`
|
|
Compare *string `json:"compare,omitempty"`
|
|
Created *bool `json:"created,omitempty"`
|
|
Deleted *bool `json:"deleted,omitempty"`
|
|
Forced *bool `json:"forced,omitempty"`
|
|
HeadCommit *WebHookCommit `json:"head_commit,omitempty"`
|
|
Pusher *User `json:"pusher,omitempty"`
|
|
Ref *string `json:"ref,omitempty"`
|
|
Repo *Repository `json:"repository,omitempty"`
|
|
Sender *User `json:"sender,omitempty"`
|
|
}
|
|
|
|
func (w WebHookPayload) String() string {
|
|
return Stringify(w)
|
|
}
|
|
|
|
// WebHookCommit represents the commit variant we receive from GitHub in a
|
|
// WebHookPayload.
|
|
type WebHookCommit struct {
|
|
Added []string `json:"added,omitempty"`
|
|
Author *WebHookAuthor `json:"author,omitempty"`
|
|
Committer *WebHookAuthor `json:"committer,omitempty"`
|
|
Distinct *bool `json:"distinct,omitempty"`
|
|
ID *string `json:"id,omitempty"`
|
|
Message *string `json:"message,omitempty"`
|
|
Modified []string `json:"modified,omitempty"`
|
|
Removed []string `json:"removed,omitempty"`
|
|
Timestamp *time.Time `json:"timestamp,omitempty"`
|
|
}
|
|
|
|
func (w WebHookCommit) String() string {
|
|
return Stringify(w)
|
|
}
|
|
|
|
// WebHookAuthor represents the author or committer of a commit, as specified
|
|
// in a WebHookCommit. The commit author may not correspond to a GitHub User.
|
|
type WebHookAuthor struct {
|
|
Email *string `json:"email,omitempty"`
|
|
Name *string `json:"name,omitempty"`
|
|
Username *string `json:"username,omitempty"`
|
|
}
|
|
|
|
func (w WebHookAuthor) String() string {
|
|
return Stringify(w)
|
|
}
|
|
|
|
// 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"`
|
|
}
|
|
|
|
func (h Hook) String() string {
|
|
return Stringify(h)
|
|
}
|
|
|
|
// CreateHook creates a Hook for the specified repository.
|
|
// Name and Config are required fields.
|
|
//
|
|
// 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)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
h := new(Hook)
|
|
resp, err := s.client.Do(ctx, req, h)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return h, resp, nil
|
|
}
|
|
|
|
// ListHooks lists all Hooks for the specified repository.
|
|
//
|
|
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#list
|
|
func (s *RepositoriesService) ListHooks(ctx context.Context, owner, repo string, opt *ListOptions) ([]*Hook, *Response, error) {
|
|
u := fmt.Sprintf("repos/%v/%v/hooks", 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
|
|
}
|
|
|
|
var hooks []*Hook
|
|
resp, err := s.client.Do(ctx, req, &hooks)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return hooks, resp, nil
|
|
}
|
|
|
|
// GetHook returns a single specified Hook.
|
|
//
|
|
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#get-single-hook
|
|
func (s *RepositoriesService) GetHook(ctx context.Context, owner, repo string, id int64) (*Hook, *Response, error) {
|
|
u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id)
|
|
req, err := s.client.NewRequest("GET", u, nil)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
hook := new(Hook)
|
|
resp, err := s.client.Do(ctx, req, hook)
|
|
return hook, resp, err
|
|
}
|
|
|
|
// EditHook updates a specified Hook.
|
|
//
|
|
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#edit-a-hook
|
|
func (s *RepositoriesService) EditHook(ctx context.Context, owner, repo string, id int64, hook *Hook) (*Hook, *Response, error) {
|
|
u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id)
|
|
req, err := s.client.NewRequest("PATCH", u, hook)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
h := new(Hook)
|
|
resp, err := s.client.Do(ctx, req, h)
|
|
return h, resp, err
|
|
}
|
|
|
|
// DeleteHook deletes a specified Hook.
|
|
//
|
|
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#delete-a-hook
|
|
func (s *RepositoriesService) DeleteHook(ctx context.Context, owner, repo string, id int64) (*Response, error) {
|
|
u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id)
|
|
req, err := s.client.NewRequest("DELETE", u, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return s.client.Do(ctx, req, nil)
|
|
}
|
|
|
|
// PingHook triggers a 'ping' event to be sent to the Hook.
|
|
//
|
|
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#ping-a-hook
|
|
func (s *RepositoriesService) PingHook(ctx context.Context, owner, repo string, id int64) (*Response, error) {
|
|
u := fmt.Sprintf("repos/%v/%v/hooks/%d/pings", owner, repo, id)
|
|
req, err := s.client.NewRequest("POST", u, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return s.client.Do(ctx, req, nil)
|
|
}
|
|
|
|
// TestHook triggers a test Hook by github.
|
|
//
|
|
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#test-a-push-hook
|
|
func (s *RepositoriesService) TestHook(ctx context.Context, owner, repo string, id int64) (*Response, error) {
|
|
u := fmt.Sprintf("repos/%v/%v/hooks/%d/tests", owner, repo, id)
|
|
req, err := s.client.NewRequest("POST", u, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return s.client.Do(ctx, req, nil)
|
|
}
|