新增:最后一个发行版接口
This commit is contained in:
parent
4a9ef64762
commit
3019b5ca6e
|
@ -86,6 +86,9 @@ func Routers() *web.Route {
|
|||
m.Combo("").Get(repo.GetPullRequest)
|
||||
})
|
||||
}, mustAllowPulls, reqRepoReader(unit_model.TypeCode), context.ReferencesGitRepo())
|
||||
m.Group("/releases", func() {
|
||||
m.Get("/latest", context.ReferencesGitRepo(), repo.GetLatestRelease)
|
||||
}, reqRepoReader(unit.TypeReleases))
|
||||
}, repoAssignment())
|
||||
})
|
||||
m.Post("/orgs", reqToken(), bind(gitea_api.CreateOrgOption{}), org.Create)
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package repo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
)
|
||||
|
||||
func GetLatestRelease(ctx *context.APIContext) {
|
||||
findOption := models.FindReleasesOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
Page: 1,
|
||||
PageSize: 1,
|
||||
},
|
||||
}
|
||||
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, findOption)
|
||||
fmt.Println("****************ctx.Repo.Repository.ID:", ctx.Repo.Repository.ID, " ", releases, " ", err)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetReleasesByRepoID", err)
|
||||
return
|
||||
}
|
||||
if len(releases) == 0 {
|
||||
ctx.NotFound("LastRelease is not present.")
|
||||
return
|
||||
}
|
||||
|
||||
release := releases[0]
|
||||
if err := release.LoadAttributes(); err != nil {
|
||||
ctx.ServerError("loadAttributes", err)
|
||||
return
|
||||
}
|
||||
|
||||
release.Publisher.Passwd = ""
|
||||
ctx.JSON(http.StatusOK, release)
|
||||
|
||||
}
|
Loading…
Reference in New Issue