mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-19 21:03:13 +00:00
Gitlab commit statuses
This commit is contained in:
@@ -11,6 +11,7 @@ const (
|
|||||||
projectsUrl = "/projects"
|
projectsUrl = "/projects"
|
||||||
projectUrl = "/projects/:id"
|
projectUrl = "/projects/:id"
|
||||||
repoUrlRawFile = "/projects/:id/repository/blobs/:sha"
|
repoUrlRawFile = "/projects/:id/repository/blobs/:sha"
|
||||||
|
commitStatusUrl = "/projects/:id/statuses/:sha"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get a list of all projects owned by the authenticated user.
|
// Get a list of all projects owned by the authenticated user.
|
||||||
@@ -90,6 +91,28 @@ func (c *Client) RepoRawFile(id, sha, filepath string) ([]byte, error) {
|
|||||||
return contents, err
|
return contents, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
func (c *Client) SetStatus(id, sha, state, desc, ref, link string) error {
|
||||||
|
url, opaque := c.ResourceUrl(
|
||||||
|
commitStatusUrl,
|
||||||
|
QMap{
|
||||||
|
":id": id,
|
||||||
|
":sha": sha,
|
||||||
|
},
|
||||||
|
QMap{
|
||||||
|
"state": state,
|
||||||
|
"ref": ref,
|
||||||
|
"target_url": link,
|
||||||
|
"description": desc,
|
||||||
|
"context": "ci/drone",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
println(url, opaque)
|
||||||
|
_, err := c.Do("POST", url, opaque, nil)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Get a list of projects by query owned by the authenticated user.
|
// Get a list of projects by query owned by the authenticated user.
|
||||||
func (c *Client) SearchProjectId(namespace string, name string) (id int, err error) {
|
func (c *Client) SearchProjectId(namespace string, name string) (id int, err error) {
|
||||||
|
|
||||||
|
@@ -229,6 +229,22 @@ func (g *Gitlab) Script(user *model.User, repo *model.Repo, build *model.Build)
|
|||||||
// also if we want get MR status in gitlab we need implement a special plugin for gitlab,
|
// also if we want get MR status in gitlab we need implement a special plugin for gitlab,
|
||||||
// gitlab uses API to fetch build status on client side. But for now we skip this.
|
// gitlab uses API to fetch build status on client side. But for now we skip this.
|
||||||
func (g *Gitlab) Status(u *model.User, repo *model.Repo, b *model.Build, link string) error {
|
func (g *Gitlab) Status(u *model.User, repo *model.Repo, b *model.Build, link string) error {
|
||||||
|
client := NewClient(g.URL, u.Token, g.SkipVerify)
|
||||||
|
|
||||||
|
status := getStatus(b.Status)
|
||||||
|
desc := getDesc(b.Status)
|
||||||
|
|
||||||
|
client.SetStatus(
|
||||||
|
ns(repo.Owner, repo.Name),
|
||||||
|
b.Commit,
|
||||||
|
status,
|
||||||
|
desc,
|
||||||
|
strings.Replace(b.Ref, "refs/heads/", "", -1),
|
||||||
|
link,
|
||||||
|
)
|
||||||
|
|
||||||
|
// Gitlab statuses it's a new feature, just ignore error
|
||||||
|
// if gitlab version not support this
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -431,3 +447,57 @@ func (g *Gitlab) Scope() string {
|
|||||||
func (g *Gitlab) String() string {
|
func (g *Gitlab) String() string {
|
||||||
return "gitlab"
|
return "gitlab"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
StatusPending = "pending"
|
||||||
|
StatusRunning = "running"
|
||||||
|
StatusSuccess = "success"
|
||||||
|
StatusFailure = "failed"
|
||||||
|
StatusCanceled = "canceled"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DescPending = "this build is pending"
|
||||||
|
DescRunning = "this buils is running"
|
||||||
|
DescSuccess = "the build was successful"
|
||||||
|
DescFailure = "the build failed"
|
||||||
|
DescCanceled = "the build canceled"
|
||||||
|
)
|
||||||
|
|
||||||
|
// getStatus is a helper functin that converts a Drone
|
||||||
|
// status to a GitHub status.
|
||||||
|
func getStatus(status string) string {
|
||||||
|
switch status {
|
||||||
|
case model.StatusPending:
|
||||||
|
return StatusPending
|
||||||
|
case model.StatusRunning:
|
||||||
|
return StatusRunning
|
||||||
|
case model.StatusSuccess:
|
||||||
|
return StatusSuccess
|
||||||
|
case model.StatusFailure, model.StatusError:
|
||||||
|
return StatusFailure
|
||||||
|
case model.StatusKilled:
|
||||||
|
return StatusCanceled
|
||||||
|
default:
|
||||||
|
return StatusFailure
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// getDesc is a helper function that generates a description
|
||||||
|
// message for the build based on the status.
|
||||||
|
func getDesc(status string) string {
|
||||||
|
switch status {
|
||||||
|
case model.StatusPending:
|
||||||
|
return DescPending
|
||||||
|
case model.StatusRunning:
|
||||||
|
return DescRunning
|
||||||
|
case model.StatusSuccess:
|
||||||
|
return DescSuccess
|
||||||
|
case model.StatusFailure, model.StatusError:
|
||||||
|
return DescFailure
|
||||||
|
case model.StatusKilled:
|
||||||
|
return DescCanceled
|
||||||
|
default:
|
||||||
|
return DescFailure
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user