#1550 deployment status hooks for github
This commit is contained in:
parent
8a6857a74b
commit
6ddc2abf47
1 changed files with 22 additions and 0 deletions
|
@ -236,7 +236,14 @@ func (g *Github) File(u *model.User, r *model.Repo, b *model.Build, f string) ([
|
|||
// An example would be the GitHub pull request status.
|
||||
func (g *Github) Status(u *model.User, r *model.Repo, b *model.Build, link string) error {
|
||||
client := NewClient(g.API, u.Token, g.SkipVerify)
|
||||
if ( b.Event == "deployment") {
|
||||
return deploymentStatus(client,r,b,link)
|
||||
} else {
|
||||
return repoStatus(client,r,b,link)
|
||||
}
|
||||
}
|
||||
|
||||
func repoStatus(client *github.Client, r *model.Repo, b *model.Build, link string) error {
|
||||
status := getStatus(b.Status)
|
||||
desc := getDesc(b.Status)
|
||||
data := github.RepoStatus{
|
||||
|
@ -249,6 +256,21 @@ func (g *Github) Status(u *model.User, r *model.Repo, b *model.Build, link strin
|
|||
return err
|
||||
}
|
||||
|
||||
func deploymentStatus(client *github.Client, r *model.Repo, b *model.Build, link string) error {
|
||||
// the deployment ID is only available in the the link to the build as the last element in the URL
|
||||
parts := strings.Split(b.Link,"/")
|
||||
id, _ := strconv.Atoi(parts[len(parts)-1])
|
||||
status := getStatus(b.Status)
|
||||
desc := getDesc(b.Status)
|
||||
data := github.DeploymentStatusRequest{
|
||||
State: github.String(status),
|
||||
Description: github.String(desc),
|
||||
TargetURL: github.String(link),
|
||||
}
|
||||
_, _, err := client.Repositories.CreateDeploymentStatus(r.Owner, r.Name, id, &data)
|
||||
return err
|
||||
}
|
||||
|
||||
// Netrc returns a .netrc file that can be used to clone
|
||||
// private repositories from a remote system.
|
||||
func (g *Github) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error) {
|
||||
|
|
Loading…
Reference in a new issue