mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-02 12:42:21 +00:00
Merge pull request #1272 from bradrydzewski/master
added an endpoint to fetch the last build for a given branch
This commit is contained in:
commit
7fc07e1430
5 changed files with 64 additions and 2 deletions
|
@ -31,8 +31,12 @@ func GetBuilds(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBuild(c *gin.Context) {
|
func GetBuild(c *gin.Context) {
|
||||||
repo := session.Repo(c)
|
if c.Param("number") == "latest" {
|
||||||
|
GetBuildLast(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
repo := session.Repo(c)
|
||||||
num, err := strconv.Atoi(c.Param("number"))
|
num, err := strconv.Atoi(c.Param("number"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithError(http.StatusBadRequest, err)
|
c.AbortWithError(http.StatusBadRequest, err)
|
||||||
|
@ -54,6 +58,25 @@ func GetBuild(c *gin.Context) {
|
||||||
c.IndentedJSON(http.StatusOK, &out)
|
c.IndentedJSON(http.StatusOK, &out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetBuildLast(c *gin.Context) {
|
||||||
|
repo := session.Repo(c)
|
||||||
|
branch := c.DefaultQuery("branch", repo.Branch)
|
||||||
|
|
||||||
|
build, err := store.GetBuildLast(c, repo, branch)
|
||||||
|
if err != nil {
|
||||||
|
c.String(http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
jobs, _ := store.GetJobList(c, build)
|
||||||
|
|
||||||
|
out := struct {
|
||||||
|
*model.Build
|
||||||
|
Jobs []*model.Job `json:"jobs"`
|
||||||
|
}{build, jobs}
|
||||||
|
|
||||||
|
c.IndentedJSON(http.StatusOK, &out)
|
||||||
|
}
|
||||||
|
|
||||||
func GetBuildLogs(c *gin.Context) {
|
func GetBuildLogs(c *gin.Context) {
|
||||||
repo := session.Repo(c)
|
repo := session.Repo(c)
|
||||||
|
|
||||||
|
|
|
@ -277,6 +277,42 @@ paths:
|
||||||
description: |
|
description: |
|
||||||
Unable to find the Repository or Build
|
Unable to find the Repository or Build
|
||||||
|
|
||||||
|
|
||||||
|
/repos/{owner}/{name}/builds/{number}:
|
||||||
|
get:
|
||||||
|
parameters:
|
||||||
|
- name: owner
|
||||||
|
in: path
|
||||||
|
type: string
|
||||||
|
description: owner of the repository
|
||||||
|
- name: name
|
||||||
|
in: path
|
||||||
|
type: string
|
||||||
|
description: name of the repository
|
||||||
|
- name: branch
|
||||||
|
in: query
|
||||||
|
type: string
|
||||||
|
description: name of the branch
|
||||||
|
required: false
|
||||||
|
- name: number
|
||||||
|
in: path
|
||||||
|
type: integer
|
||||||
|
description: sequential build number
|
||||||
|
tags:
|
||||||
|
- Builds
|
||||||
|
summary: Get the latest build
|
||||||
|
description: Returns the latest repository build.
|
||||||
|
security:
|
||||||
|
- accessToken: []
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: The build.
|
||||||
|
schema:
|
||||||
|
$ref: "#/definitions/Build"
|
||||||
|
404:
|
||||||
|
description: |
|
||||||
|
Unable to find the Repository or Build
|
||||||
|
|
||||||
post:
|
post:
|
||||||
parameters:
|
parameters:
|
||||||
- name: owner
|
- name: owner
|
||||||
|
|
|
@ -103,6 +103,7 @@ SELECT *
|
||||||
FROM builds
|
FROM builds
|
||||||
WHERE build_repo_id = ?
|
WHERE build_repo_id = ?
|
||||||
AND build_branch = ?
|
AND build_branch = ?
|
||||||
|
AND build_event = 'push'
|
||||||
ORDER BY build_number DESC
|
ORDER BY build_number DESC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
`
|
`
|
||||||
|
|
|
@ -165,12 +165,14 @@ func Test_buildstore(t *testing.T) {
|
||||||
Status: model.StatusFailure,
|
Status: model.StatusFailure,
|
||||||
Branch: "master",
|
Branch: "master",
|
||||||
Commit: "85f8c029b902ed9400bc600bac301a0aadb144ac",
|
Commit: "85f8c029b902ed9400bc600bac301a0aadb144ac",
|
||||||
|
Event: model.EventPush,
|
||||||
}
|
}
|
||||||
build2 := &model.Build{
|
build2 := &model.Build{
|
||||||
RepoID: 1,
|
RepoID: 1,
|
||||||
Status: model.StatusSuccess,
|
Status: model.StatusSuccess,
|
||||||
Branch: "master",
|
Branch: "master",
|
||||||
Commit: "85f8c029b902ed9400bc600bac301a0aadb144aa",
|
Commit: "85f8c029b902ed9400bc600bac301a0aadb144aa",
|
||||||
|
Event: model.EventPush,
|
||||||
}
|
}
|
||||||
err1 := s.Builds().Create(build1, []*model.Job{}...)
|
err1 := s.Builds().Create(build1, []*model.Job{}...)
|
||||||
err2 := s.Builds().Create(build2, []*model.Job{}...)
|
err2 := s.Builds().Create(build2, []*model.Job{}...)
|
||||||
|
|
|
@ -57,7 +57,7 @@ block content
|
||||||
p #{$result.Desc}
|
p #{$result.Desc}
|
||||||
aside
|
aside
|
||||||
h4 Endpoint
|
h4 Endpoint
|
||||||
pre #{$op.Method} #{$op.Path}
|
pre #{$op.Method} /api#{$op.Path}
|
||||||
each $param in $op.Params
|
each $param in $op.Params
|
||||||
if $param.Example
|
if $param.Example
|
||||||
h4 Example Request
|
h4 Example Request
|
||||||
|
|
Loading…
Reference in a new issue