added an endpoint to fetch the last build for a given branch
This commit is contained in:
parent
cd7559cc6b
commit
377caf1b99
5 changed files with 64 additions and 2 deletions
|
@ -31,8 +31,12 @@ func GetBuilds(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"))
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusBadRequest, err)
|
||||
|
@ -54,6 +58,25 @@ func GetBuild(c *gin.Context) {
|
|||
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) {
|
||||
repo := session.Repo(c)
|
||||
|
||||
|
|
|
@ -277,6 +277,42 @@ paths:
|
|||
description: |
|
||||
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:
|
||||
parameters:
|
||||
- name: owner
|
||||
|
|
|
@ -103,6 +103,7 @@ SELECT *
|
|||
FROM builds
|
||||
WHERE build_repo_id = ?
|
||||
AND build_branch = ?
|
||||
AND build_event = 'push'
|
||||
ORDER BY build_number DESC
|
||||
LIMIT 1
|
||||
`
|
||||
|
|
|
@ -165,12 +165,14 @@ func Test_buildstore(t *testing.T) {
|
|||
Status: model.StatusFailure,
|
||||
Branch: "master",
|
||||
Commit: "85f8c029b902ed9400bc600bac301a0aadb144ac",
|
||||
Event: model.EventPush,
|
||||
}
|
||||
build2 := &model.Build{
|
||||
RepoID: 1,
|
||||
Status: model.StatusSuccess,
|
||||
Branch: "master",
|
||||
Commit: "85f8c029b902ed9400bc600bac301a0aadb144aa",
|
||||
Event: model.EventPush,
|
||||
}
|
||||
err1 := s.Builds().Create(build1, []*model.Job{}...)
|
||||
err2 := s.Builds().Create(build2, []*model.Job{}...)
|
||||
|
|
|
@ -57,7 +57,7 @@ block content
|
|||
p #{$result.Desc}
|
||||
aside
|
||||
h4 Endpoint
|
||||
pre #{$op.Method} #{$op.Path}
|
||||
pre #{$op.Method} /api#{$op.Path}
|
||||
each $param in $op.Params
|
||||
if $param.Example
|
||||
h4 Example Request
|
||||
|
|
Loading…
Reference in a new issue