2015-09-30 01:21:17 +00:00
|
|
|
package github
|
|
|
|
|
|
|
|
import (
|
2015-10-30 21:47:46 +00:00
|
|
|
"crypto/tls"
|
2015-09-30 01:21:17 +00:00
|
|
|
"fmt"
|
2016-05-03 00:47:58 +00:00
|
|
|
"net"
|
2015-09-30 01:21:17 +00:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
2016-03-30 00:05:28 +00:00
|
|
|
"regexp"
|
2015-09-30 01:21:17 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/drone/drone/model"
|
2016-04-29 19:39:56 +00:00
|
|
|
"github.com/drone/drone/remote"
|
2015-09-30 01:21:17 +00:00
|
|
|
"github.com/drone/drone/shared/httputil"
|
|
|
|
|
|
|
|
"github.com/google/go-github/github"
|
2016-05-03 20:01:16 +00:00
|
|
|
"golang.org/x/net/context"
|
2016-05-03 00:47:58 +00:00
|
|
|
"golang.org/x/oauth2"
|
2015-09-30 01:21:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2016-05-03 00:47:58 +00:00
|
|
|
defaultURL = "https://github.com" // Default GitHub URL
|
|
|
|
defaultAPI = "https://api.github.com" // Default GitHub API URL
|
2015-09-30 01:21:17 +00:00
|
|
|
)
|
|
|
|
|
2016-05-03 00:47:58 +00:00
|
|
|
// Opts defines configuration options.
|
|
|
|
type Opts struct {
|
|
|
|
URL string // GitHub server url.
|
2016-05-27 18:22:32 +00:00
|
|
|
Context string // Context to display in status check
|
2016-05-03 00:47:58 +00:00
|
|
|
Client string // GitHub oauth client id.
|
|
|
|
Secret string // GitHub oauth client secret.
|
|
|
|
Scopes []string // GitHub oauth scopes
|
|
|
|
Username string // Optional machine account username.
|
|
|
|
Password string // Optional machine account password.
|
|
|
|
PrivateMode bool // GitHub is running in private mode.
|
|
|
|
SkipVerify bool // Skip ssl verification.
|
|
|
|
MergeRef bool // Clone pull requests using the merge ref.
|
|
|
|
}
|
|
|
|
|
|
|
|
// New returns a Remote implementation that integrates with a GitHub Cloud or
|
|
|
|
// GitHub Enterprise version control hosting provider.
|
|
|
|
func New(opts Opts) (remote.Remote, error) {
|
|
|
|
url, err := url.Parse(opts.URL)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
host, _, err := net.SplitHostPort(url.Host)
|
|
|
|
if err == nil {
|
|
|
|
url.Host = host
|
|
|
|
}
|
|
|
|
remote := &client{
|
|
|
|
API: defaultAPI,
|
|
|
|
URL: defaultURL,
|
2016-05-27 18:22:32 +00:00
|
|
|
Context: opts.Context,
|
2016-05-03 00:47:58 +00:00
|
|
|
Client: opts.Client,
|
|
|
|
Secret: opts.Secret,
|
2016-05-11 14:32:11 +00:00
|
|
|
Scopes: opts.Scopes,
|
2016-05-03 00:47:58 +00:00
|
|
|
PrivateMode: opts.PrivateMode,
|
|
|
|
SkipVerify: opts.SkipVerify,
|
|
|
|
MergeRef: opts.MergeRef,
|
|
|
|
Machine: url.Host,
|
|
|
|
Username: opts.Username,
|
|
|
|
Password: opts.Password,
|
|
|
|
}
|
|
|
|
if opts.URL != defaultURL {
|
|
|
|
remote.URL = strings.TrimSuffix(opts.URL, "/")
|
|
|
|
remote.API = remote.URL + "/api/v3/"
|
|
|
|
}
|
2016-08-25 22:00:07 +00:00
|
|
|
|
|
|
|
// Hack to enable oauth2 access in older GHE
|
|
|
|
oauth2.RegisterBrokenAuthHeaderProvider(remote.URL)
|
2016-05-03 00:47:58 +00:00
|
|
|
return remote, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type client struct {
|
2015-09-30 01:21:17 +00:00
|
|
|
URL string
|
2016-05-27 18:22:32 +00:00
|
|
|
Context string
|
2015-09-30 01:21:17 +00:00
|
|
|
API string
|
|
|
|
Client string
|
|
|
|
Secret string
|
2016-05-11 14:32:11 +00:00
|
|
|
Scopes []string
|
2016-05-03 00:47:58 +00:00
|
|
|
Machine string
|
|
|
|
Username string
|
|
|
|
Password string
|
2015-09-30 01:21:17 +00:00
|
|
|
PrivateMode bool
|
|
|
|
SkipVerify bool
|
2016-05-03 00:47:58 +00:00
|
|
|
MergeRef bool
|
2015-09-30 01:21:17 +00:00
|
|
|
}
|
|
|
|
|
2016-04-29 19:39:56 +00:00
|
|
|
// Login authenticates the session and returns the remote user details.
|
2016-05-03 00:47:58 +00:00
|
|
|
func (c *client) Login(res http.ResponseWriter, req *http.Request) (*model.User, error) {
|
|
|
|
config := c.newConfig(httputil.GetURL(req))
|
2015-09-30 01:21:17 +00:00
|
|
|
|
2016-05-03 00:47:58 +00:00
|
|
|
code := req.FormValue("code")
|
2015-09-30 01:21:17 +00:00
|
|
|
if len(code) == 0 {
|
2016-05-03 20:01:16 +00:00
|
|
|
// TODO(bradrydzewski) we really should be using a random value here and
|
|
|
|
// storing in a cookie for verification in the next stage of the workflow.
|
|
|
|
|
|
|
|
http.Redirect(res, req, config.AuthCodeURL("drone"), http.StatusSeeOther)
|
2016-04-29 19:39:56 +00:00
|
|
|
return nil, nil
|
2015-09-30 01:21:17 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 20:01:16 +00:00
|
|
|
token, err := config.Exchange(c.newContext(), code)
|
2015-09-30 01:21:17 +00:00
|
|
|
if err != nil {
|
2016-05-03 00:47:58 +00:00
|
|
|
return nil, err
|
2015-09-30 01:21:17 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 00:47:58 +00:00
|
|
|
client := c.newClientToken(token.AccessToken)
|
2016-05-03 20:01:16 +00:00
|
|
|
user, _, err := client.Users.Get("")
|
2016-05-03 00:47:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2015-09-30 01:21:17 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 20:01:16 +00:00
|
|
|
emails, _, err := client.Users.ListEmails(nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
email := matchingEmail(emails, c.API)
|
|
|
|
if email == nil {
|
|
|
|
return nil, fmt.Errorf("No verified Email address for GitHub account")
|
|
|
|
}
|
|
|
|
|
2016-05-03 00:47:58 +00:00
|
|
|
return &model.User{
|
2016-05-03 20:01:16 +00:00
|
|
|
Login: *user.Login,
|
|
|
|
Email: *email.Email,
|
2016-05-03 00:47:58 +00:00
|
|
|
Token: token.AccessToken,
|
2016-05-03 20:01:16 +00:00
|
|
|
Avatar: *user.AvatarURL,
|
2016-05-03 00:47:58 +00:00
|
|
|
}, nil
|
2015-09-30 01:21:17 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 00:47:58 +00:00
|
|
|
// Auth returns the GitHub user login for the given access token.
|
|
|
|
func (c *client) Auth(token, secret string) (string, error) {
|
|
|
|
client := c.newClientToken(token)
|
2015-09-30 01:21:17 +00:00
|
|
|
user, _, err := client.Users.Get("")
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return *user.Login, nil
|
|
|
|
}
|
|
|
|
|
2016-05-03 00:47:58 +00:00
|
|
|
// Teams returns a list of all team membership for the GitHub account.
|
|
|
|
func (c *client) Teams(u *model.User) ([]*model.Team, error) {
|
|
|
|
client := c.newClientToken(u.Token)
|
|
|
|
|
|
|
|
opts := new(github.ListOptions)
|
|
|
|
opts.Page = 1
|
2016-04-29 19:39:56 +00:00
|
|
|
|
|
|
|
var teams []*model.Team
|
2016-05-03 00:47:58 +00:00
|
|
|
for opts.Page > 0 {
|
|
|
|
list, resp, err := client.Organizations.List("", opts)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
teams = append(teams, convertTeamList(list)...)
|
|
|
|
opts.Page = resp.NextPage
|
2016-04-29 19:39:56 +00:00
|
|
|
}
|
|
|
|
return teams, nil
|
|
|
|
}
|
|
|
|
|
2016-11-11 18:56:48 +00:00
|
|
|
// TeamPerm returns the user permissions for the named GitHub organization.
|
|
|
|
func (c *client) TeamPerm(u *model.User, org string) (*model.Perm, error) {
|
|
|
|
client := c.newClientToken(u.Token)
|
|
|
|
membership, _, err := client.Organizations.GetOrgMembership(u.Login, org)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return convertTeamPerm(membership), nil
|
|
|
|
}
|
|
|
|
|
2016-05-03 00:47:58 +00:00
|
|
|
// Repo returns the named GitHub repository.
|
|
|
|
func (c *client) Repo(u *model.User, owner, name string) (*model.Repo, error) {
|
|
|
|
client := c.newClientToken(u.Token)
|
|
|
|
repo, _, err := client.Repositories.Get(owner, name)
|
2015-09-30 01:21:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-05-03 00:47:58 +00:00
|
|
|
return convertRepo(repo, c.PrivateMode), nil
|
|
|
|
}
|
2015-09-30 01:21:17 +00:00
|
|
|
|
2016-05-03 00:47:58 +00:00
|
|
|
// Repos returns a list of all repositories for GitHub account, including
|
|
|
|
// organization repositories.
|
|
|
|
func (c *client) Repos(u *model.User) ([]*model.RepoLite, error) {
|
|
|
|
client := c.newClientToken(u.Token)
|
2015-09-30 01:21:17 +00:00
|
|
|
|
2016-05-03 00:47:58 +00:00
|
|
|
opts := new(github.RepositoryListOptions)
|
|
|
|
opts.PerPage = 100
|
|
|
|
opts.Page = 1
|
2015-10-02 23:02:37 +00:00
|
|
|
|
2016-05-03 00:47:58 +00:00
|
|
|
var repos []*model.RepoLite
|
|
|
|
for opts.Page > 0 {
|
|
|
|
list, resp, err := client.Repositories.List("", opts)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
repos = append(repos, convertRepoList(list)...)
|
|
|
|
opts.Page = resp.NextPage
|
2015-10-02 23:02:37 +00:00
|
|
|
}
|
2016-05-03 00:47:58 +00:00
|
|
|
return repos, nil
|
2015-09-30 01:21:17 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 00:47:58 +00:00
|
|
|
// Perm returns the user permissions for the named GitHub repository.
|
|
|
|
func (c *client) Perm(u *model.User, owner, name string) (*model.Perm, error) {
|
|
|
|
client := c.newClientToken(u.Token)
|
|
|
|
repo, _, err := client.Repositories.Get(owner, name)
|
2015-09-30 01:21:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-05-03 00:47:58 +00:00
|
|
|
return convertPerm(repo), nil
|
2015-09-30 01:21:17 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 00:47:58 +00:00
|
|
|
// File fetches the file from the Bitbucket repository and returns its contents.
|
|
|
|
func (c *client) File(u *model.User, r *model.Repo, b *model.Build, f string) ([]byte, error) {
|
|
|
|
client := c.newClientToken(u.Token)
|
2015-09-30 01:21:17 +00:00
|
|
|
|
2016-05-03 00:47:58 +00:00
|
|
|
opts := new(github.RepositoryContentGetOptions)
|
|
|
|
opts.Ref = b.Commit
|
|
|
|
data, _, _, err := client.Repositories.GetContents(r.Owner, r.Name, f, opts)
|
2015-09-30 01:21:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-05-03 00:47:58 +00:00
|
|
|
return data.Decode()
|
2015-09-30 01:21:17 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 00:47:58 +00:00
|
|
|
// Netrc returns a netrc file capable of authenticating GitHub requests and
|
|
|
|
// cloning GitHub repositories. The netrc will use the global machine account
|
|
|
|
// when configured.
|
|
|
|
func (c *client) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error) {
|
|
|
|
if c.Password != "" {
|
|
|
|
return &model.Netrc{
|
|
|
|
Login: c.Username,
|
|
|
|
Password: c.Password,
|
|
|
|
Machine: c.Machine,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
return &model.Netrc{
|
|
|
|
Login: u.Token,
|
|
|
|
Password: "x-oauth-basic",
|
|
|
|
Machine: c.Machine,
|
|
|
|
}, nil
|
2015-09-30 01:21:17 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 20:01:16 +00:00
|
|
|
// Deactivate deactives the repository be removing registered push hooks from
|
|
|
|
// the GitHub repository.
|
|
|
|
func (c *client) Deactivate(u *model.User, r *model.Repo, link string) error {
|
|
|
|
client := c.newClientToken(u.Token)
|
|
|
|
hooks, _, err := client.Repositories.ListHooks(r.Owner, r.Name, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
match := matchingHooks(hooks, link)
|
|
|
|
if match == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
_, err = client.Repositories.DeleteHook(r.Owner, r.Name, *match.ID)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper function to return the GitHub oauth2 context using an HTTPClient that
|
|
|
|
// disables TLS verification if disabled in the remote settings.
|
|
|
|
func (c *client) newContext() context.Context {
|
|
|
|
if !c.SkipVerify {
|
|
|
|
return oauth2.NoContext
|
|
|
|
}
|
|
|
|
return context.WithValue(nil, oauth2.HTTPClient, &http.Client{
|
|
|
|
Transport: &http.Transport{
|
|
|
|
Proxy: http.ProxyFromEnvironment,
|
|
|
|
TLSClientConfig: &tls.Config{
|
|
|
|
InsecureSkipVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper function to return the GitHub oauth2 config
|
2016-05-03 00:47:58 +00:00
|
|
|
func (c *client) newConfig(redirect string) *oauth2.Config {
|
|
|
|
return &oauth2.Config{
|
|
|
|
ClientID: c.Client,
|
|
|
|
ClientSecret: c.Secret,
|
2016-05-27 18:22:32 +00:00
|
|
|
Scopes: c.Scopes,
|
2016-05-03 00:47:58 +00:00
|
|
|
Endpoint: oauth2.Endpoint{
|
|
|
|
AuthURL: fmt.Sprintf("%s/login/oauth/authorize", c.URL),
|
|
|
|
TokenURL: fmt.Sprintf("%s/login/oauth/access_token", c.URL),
|
|
|
|
},
|
|
|
|
RedirectURL: fmt.Sprintf("%s/authorize", redirect),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-03 20:01:16 +00:00
|
|
|
// helper function to return the GitHub oauth2 client
|
2016-05-03 00:47:58 +00:00
|
|
|
func (c *client) newClientToken(token string) *github.Client {
|
|
|
|
ts := oauth2.StaticTokenSource(
|
|
|
|
&oauth2.Token{AccessToken: token},
|
|
|
|
)
|
|
|
|
tc := oauth2.NewClient(oauth2.NoContext, ts)
|
|
|
|
if c.SkipVerify {
|
|
|
|
tc.Transport.(*oauth2.Transport).Base = &http.Transport{
|
|
|
|
Proxy: http.ProxyFromEnvironment,
|
|
|
|
TLSClientConfig: &tls.Config{
|
|
|
|
InsecureSkipVerify: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
github := github.NewClient(tc)
|
|
|
|
github.BaseURL, _ = url.Parse(c.API)
|
|
|
|
return github
|
|
|
|
}
|
|
|
|
|
2016-05-03 20:01:16 +00:00
|
|
|
// helper function to return matching user email.
|
|
|
|
func matchingEmail(emails []github.UserEmail, rawurl string) *github.UserEmail {
|
|
|
|
for _, email := range emails {
|
|
|
|
if email.Email == nil || email.Primary == nil || email.Verified == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if *email.Primary && *email.Verified {
|
|
|
|
return &email
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// github enterprise does not support verified email addresses so instead
|
|
|
|
// we'll return the first email address in the list.
|
|
|
|
if len(emails) != 0 && rawurl != defaultAPI {
|
|
|
|
return &emails[0]
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper function to return matching hook.
|
|
|
|
func matchingHooks(hooks []github.Hook, rawurl string) *github.Hook {
|
|
|
|
link, err := url.Parse(rawurl)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
for _, hook := range hooks {
|
|
|
|
if hook.ID == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
v, ok := hook.Config["url"]
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
s, ok := v.(string)
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
hookurl, err := url.Parse(s)
|
|
|
|
if err == nil && hookurl.Host == link.Host {
|
|
|
|
return &hook
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-05-03 00:47:58 +00:00
|
|
|
//
|
|
|
|
// TODO(bradrydzewski) refactor below functions
|
|
|
|
//
|
|
|
|
|
2015-09-30 01:21:17 +00:00
|
|
|
// Status sends the commit status to the remote system.
|
|
|
|
// An example would be the GitHub pull request status.
|
2016-05-03 00:47:58 +00:00
|
|
|
func (c *client) Status(u *model.User, r *model.Repo, b *model.Build, link string) error {
|
|
|
|
client := c.newClientToken(u.Token)
|
|
|
|
switch b.Event {
|
|
|
|
case "deployment":
|
2016-03-30 00:05:28 +00:00
|
|
|
return deploymentStatus(client, r, b, link)
|
2016-05-03 00:47:58 +00:00
|
|
|
default:
|
2016-05-27 18:22:32 +00:00
|
|
|
return repoStatus(client, r, b, link, c.Context)
|
2016-03-29 18:07:50 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-30 01:21:17 +00:00
|
|
|
|
2016-05-27 18:22:32 +00:00
|
|
|
func repoStatus(client *github.Client, r *model.Repo, b *model.Build, link, ctx string) error {
|
|
|
|
context := ctx
|
2016-05-12 16:34:30 +00:00
|
|
|
switch b.Event {
|
|
|
|
case model.EventPull:
|
|
|
|
context += "/pr"
|
|
|
|
default:
|
|
|
|
if len(b.Event) > 0 {
|
|
|
|
context += "/" + b.Event
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-30 01:21:17 +00:00
|
|
|
data := github.RepoStatus{
|
2016-05-12 16:34:30 +00:00
|
|
|
Context: github.String(context),
|
2016-05-03 00:47:58 +00:00
|
|
|
State: github.String(convertStatus(b.Status)),
|
|
|
|
Description: github.String(convertDesc(b.Status)),
|
2015-09-30 01:21:17 +00:00
|
|
|
TargetURL: github.String(link),
|
|
|
|
}
|
|
|
|
_, _, err := client.Repositories.CreateStatus(r.Owner, r.Name, b.Commit, &data)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-04-29 19:39:56 +00:00
|
|
|
var reDeploy = regexp.MustCompile(".+/deployments/(\\d+)")
|
|
|
|
|
2016-03-29 18:07:50 +00:00
|
|
|
func deploymentStatus(client *github.Client, r *model.Repo, b *model.Build, link string) error {
|
2016-04-29 19:39:56 +00:00
|
|
|
matches := reDeploy.FindStringSubmatch(b.Link)
|
2016-03-30 00:05:28 +00:00
|
|
|
if len(matches) != 2 {
|
|
|
|
return nil
|
|
|
|
}
|
2016-03-30 11:58:24 +00:00
|
|
|
id, _ := strconv.Atoi(matches[1])
|
2016-05-03 00:47:58 +00:00
|
|
|
|
2016-03-29 18:07:50 +00:00
|
|
|
data := github.DeploymentStatusRequest{
|
2016-05-03 00:47:58 +00:00
|
|
|
State: github.String(convertStatus(b.Status)),
|
|
|
|
Description: github.String(convertDesc(b.Status)),
|
2016-03-30 00:05:28 +00:00
|
|
|
TargetURL: github.String(link),
|
2016-03-29 18:07:50 +00:00
|
|
|
}
|
|
|
|
_, _, err := client.Repositories.CreateDeploymentStatus(r.Owner, r.Name, id, &data)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-09-30 01:21:17 +00:00
|
|
|
// Activate activates a repository by creating the post-commit hook and
|
|
|
|
// adding the SSH deploy key, if applicable.
|
2016-05-03 00:47:58 +00:00
|
|
|
func (c *client) Activate(u *model.User, r *model.Repo, link string) error {
|
2016-05-03 20:01:16 +00:00
|
|
|
if err := c.Deactivate(u, r, link); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-05-03 00:47:58 +00:00
|
|
|
client := c.newClientToken(u.Token)
|
2016-05-03 20:01:16 +00:00
|
|
|
hook := &github.Hook{
|
|
|
|
Name: github.String("web"),
|
|
|
|
Events: []string{
|
|
|
|
"push",
|
|
|
|
"pull_request",
|
|
|
|
"deployment",
|
|
|
|
},
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"url": link,
|
|
|
|
"content_type": "form",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
_, _, err := client.Repositories.CreateHook(r.Owner, r.Name, hook)
|
2015-09-30 01:21:17 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hook parses the post-commit hook from the Request body
|
|
|
|
// and returns the required data in a standard format.
|
2016-05-03 00:47:58 +00:00
|
|
|
func (c *client) Hook(r *http.Request) (*model.Repo, *model.Build, error) {
|
2016-05-03 20:01:16 +00:00
|
|
|
return parseHook(r, c.MergeRef)
|
2015-09-30 01:21:17 +00:00
|
|
|
}
|