forked from Gitlink/gitea-1156
add:/releases/latest
This commit is contained in:
parent
ad65d78976
commit
bd1c13569c
|
@ -242,6 +242,27 @@ func GetLatestReleaseByRepoID(repoID int64) (*Release, error) {
|
|||
return rel, nil
|
||||
}
|
||||
|
||||
// GetLatestReleaseByRepoID returns the latest release for a repository
|
||||
func GetLatestReleaseByRepoIDExt(repoID int64) (*Release, error) {
|
||||
cond := builder.NewCond().
|
||||
And(builder.Eq{"repo_id": repoID}).
|
||||
And(builder.Eq{"is_draft": false}).
|
||||
And(builder.Eq{"is_prerelease": false})
|
||||
|
||||
rel := new(Release)
|
||||
has, err := x.
|
||||
Desc("created_unix", "id").
|
||||
Where(cond).
|
||||
Get(rel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
return nil, ErrReleaseNotExist{0, "latest"}
|
||||
}
|
||||
|
||||
return rel, nil
|
||||
}
|
||||
|
||||
// GetReleasesByRepoIDAndNames returns a list of releases of repository according repoID and tagNames.
|
||||
func GetReleasesByRepoIDAndNames(ctx DBContext, repoID int64, tagNames []string) (rels []*Release, err error) {
|
||||
err = ctx.e.
|
||||
|
|
|
@ -775,6 +775,9 @@ func Routes() *web.Route {
|
|||
m.Get("/archive/*", reqRepoReader(models.UnitTypeCode), repo.GetArchive)
|
||||
|
||||
m.Get("/find", viewfile.FindFiles)
|
||||
m.Group("/releases", func() {
|
||||
m.Get("/latest", viewfile.LatestRelease)
|
||||
})
|
||||
m.Combo("/forks").Get(repo.ListForks).
|
||||
Post(reqToken(), reqRepoReader(models.UnitTypeCode), bind(api.CreateForkOption{}), repo.CreateFork)
|
||||
m.Group("/branches", func() {
|
||||
|
|
|
@ -159,3 +159,61 @@ func FindFileFromPathEtx(ctx *context.APIContext, treePath, ref, key string) (fi
|
|||
return
|
||||
|
||||
}
|
||||
|
||||
func LatestRelease(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/releases/latest repository latest
|
||||
// ---
|
||||
// summary: Get the last updated Release version of the repository., which is a custom interface ****
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
// in: path
|
||||
// description: name of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/release"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
var err error
|
||||
if ctx.Repo.GitRepo == nil {
|
||||
repoPath := models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
||||
ctx.Repo.GitRepo, err = git.OpenRepository(repoPath)
|
||||
if err != nil {
|
||||
ctx.ServerError("Reporef Invalid repo"+repoPath, err)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if ctx.Repo.GitRepo != nil {
|
||||
ctx.Repo.GitRepo.Close()
|
||||
}
|
||||
}()
|
||||
}
|
||||
release, err := models.GetLatestReleaseByRepoIDExt(ctx.Repo.Repository.ID)
|
||||
fmt.Println("****************ctx.Repo.Repository.ID:", ctx.Repo.Repository.ID, " ", release, " ", err)
|
||||
|
||||
if err != nil {
|
||||
if models.IsErrReleaseNotExist(err) {
|
||||
ctx.NotFound("LatestRelease", err)
|
||||
return
|
||||
}
|
||||
ctx.ServerError("GetLatestReleaseByRepoIDExt", err)
|
||||
return
|
||||
|
||||
}
|
||||
if err := release.LoadAttributes(); err != nil {
|
||||
ctx.ServerError("LoadAttributes", err)
|
||||
return
|
||||
}
|
||||
release.Publisher.Passwd = ""
|
||||
ctx.JSON(http.StatusOK, release)
|
||||
|
||||
}
|
||||
|
|
|
@ -8679,6 +8679,42 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/releases/latest": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"repository"
|
||||
],
|
||||
"summary": "Get the last updated Release version of the repository., which is a custom interface ****",
|
||||
"operationId": "latest",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "owner of the repo",
|
||||
"name": "owner",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "name of the repo",
|
||||
"name": "repo",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/release"
|
||||
},
|
||||
"404": {
|
||||
"$ref": "#/responses/notFound"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/releases/tags/{tag}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
|
|
Loading…
Reference in New Issue