1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-11-30 08:06:52 +02:00

Merge pull request #1341 from anibali/bitbucket_build_status

Add support for Bitbucket build status
This commit is contained in:
Brad Rydzewski 2015-11-20 22:27:46 -08:00
commit 0a266f42a9
3 changed files with 79 additions and 1 deletions

View File

@ -267,7 +267,27 @@ func (bb *Bitbucket) Script(u *model.User, r *model.Repo, b *model.Build) ([]byt
// Status sends the commit status to the remote system.
// An example would be the GitHub pull request status.
func (bb *Bitbucket) Status(u *model.User, r *model.Repo, b *model.Build, link string) error {
return nil
client := NewClientToken(
bb.Client,
bb.Secret,
&oauth2.Token{
AccessToken: u.Token,
RefreshToken: u.Secret,
},
)
status := getStatus(b.Status)
desc := getDesc(b.Status)
data := BuildStatus{
State: status,
Key: "Drone",
Url: link,
Desc: desc,
}
err := client.CreateStatus(r.Owner, r.Name, b.Commit, &data)
return err
}
// Netrc returns a .netrc file that can be used to clone
@ -459,3 +479,47 @@ func (bb *Bitbucket) pullHook(r *http.Request) (*model.Repo, *model.Build, error
Timestamp: hook.PullRequest.Updated.UTC().Unix(),
}, nil
}
const (
StatusPending = "INPROGRESS"
StatusSuccess = "SUCCESSFUL"
StatusFailure = "FAILED"
)
const (
DescPending = "this build is pending"
DescSuccess = "the build was successful"
DescFailure = "the build failed"
DescError = "oops, something went wrong"
)
// converts a Drone status to a BitBucket status.
func getStatus(status string) string {
switch status {
case model.StatusPending, model.StatusRunning:
return StatusPending
case model.StatusSuccess:
return StatusSuccess
case model.StatusFailure, model.StatusError, model.StatusKilled:
return StatusFailure
default:
return StatusFailure
}
}
// generates a description for the build based on
// the Drone status
func getDesc(status string) string {
switch status {
case model.StatusPending, model.StatusRunning:
return DescPending
case model.StatusSuccess:
return DescSuccess
case model.StatusFailure:
return DescFailure
case model.StatusError, model.StatusKilled:
return DescError
default:
return DescError
}
}

View File

@ -30,6 +30,7 @@ const (
pathHook = "%s/2.0/repositories/%s/%s/hooks/%s"
pathHooks = "%s/2.0/repositories/%s/%s/hooks?%s"
pathSource = "%s/1.0/repositories/%s/%s/src/%s/%s"
pathStatus = "%s/2.0/repositories/%s/%s/commit/%s/statuses/build"
)
type Client struct {
@ -133,6 +134,11 @@ func (c *Client) FindSource(owner, name, revision, path string) (*Source, error)
return out, err
}
func (c *Client) CreateStatus(owner, name, revision string, status *BuildStatus) error {
uri := fmt.Sprintf(pathStatus, base, owner, name, revision)
return c.do(uri, post, status, nil)
}
func (c *Client) do(rawurl, method string, in, out interface{}) error {
uri, err := url.Parse(rawurl)

View File

@ -21,6 +21,14 @@ type AccountResp struct {
Values []*Account `json:"values"`
}
type BuildStatus struct {
State string `json:"state"`
Key string `json:"key"`
Name string `json:"name,omitempty"`
Url string `json:"url"`
Desc string `json:"description,omitempty"`
}
type Email struct {
Email string `json:"email"`
IsConfirmed bool `json:"is_confirmed"`