release/v1.15
Unknwon 2015-11-20 02:38:41 -05:00
parent 9b6c835715
commit 987dcc5372
13 changed files with 97 additions and 13 deletions

View File

@ -5,7 +5,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
![](public/img/gogs-large-resize.png) ![](public/img/gogs-large-resize.png)
##### Current version: 0.7.18 Beta ##### Current version: 0.7.19 Beta
<table> <table>
<tr> <tr>

View File

@ -514,6 +514,7 @@ func runWeb(ctx *cli.Context) {
m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost) m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost)
m.Get("/edit/:tagname", repo.EditRelease) m.Get("/edit/:tagname", repo.EditRelease)
m.Post("/edit/:tagname", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost) m.Post("/edit/:tagname", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost)
m.Post("/delete", repo.DeleteRelease)
}, reqRepoAdmin, middleware.RepoRef()) }, reqRepoAdmin, middleware.RepoRef())
m.Combo("/compare/*").Get(repo.CompareAndPullRequest). m.Combo("/compare/*").Get(repo.CompareAndPullRequest).

View File

@ -655,6 +655,10 @@ release.cancel = Cancel
release.publish = Publish Release release.publish = Publish Release
release.save_draft = Save Draft release.save_draft = Save Draft
release.edit_release = Edit Release release.edit_release = Edit Release
release.delete_release = Delete This Release
release.deletion = Release Deletion
release.deletion_desc = Delete this release will delete corresponding Git tag. Do you want to continue?
release.deletion_success = Release has been deleted successfully!
release.tag_name_already_exist = Release with this tag name has already existed. release.tag_name_already_exist = Release with this tag name has already existed.
release.downloads = Downloads release.downloads = Downloads

View File

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.7.18.1119 Beta" const APP_VER = "0.7.19.1120 Beta"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

View File

@ -330,6 +330,7 @@ func (err ErrReleaseAlreadyExist) Error() string {
} }
type ErrReleaseNotExist struct { type ErrReleaseNotExist struct {
ID int64
TagName string TagName string
} }
@ -339,7 +340,7 @@ func IsErrReleaseNotExist(err error) bool {
} }
func (err ErrReleaseNotExist) Error() string { func (err ErrReleaseNotExist) Error() string {
return fmt.Sprintf("Release tag does not exist [tag_name: %s]", err.TagName) return fmt.Sprintf("Release tag does not exist [id: %d, tag_name: %s]", err.ID, err.TagName)
} }
// __ __ ___. .__ __ // __ __ ___. .__ __

View File

@ -1375,8 +1375,8 @@ func ChangeMilestoneAssign(oldMid int64, issue *Issue) (err error) {
} }
// DeleteMilestoneByID deletes a milestone by given ID. // DeleteMilestoneByID deletes a milestone by given ID.
func DeleteMilestoneByID(mid int64) error { func DeleteMilestoneByID(id int64) error {
m, err := GetMilestoneByID(mid) m, err := GetMilestoneByID(id)
if err != nil { if err != nil {
if IsErrMilestoneNotExist(err) { if IsErrMilestoneNotExist(err) {
return nil return nil

View File

@ -5,6 +5,7 @@
package models package models
import ( import (
"fmt"
"sort" "sort"
"strings" "strings"
"time" "time"
@ -12,6 +13,7 @@ import (
"github.com/go-xorm/xorm" "github.com/go-xorm/xorm"
"github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/git"
"github.com/gogits/gogs/modules/process"
) )
// Release represents a release of repository. // Release represents a release of repository.
@ -99,7 +101,7 @@ func GetRelease(repoID int64, tagName string) (*Release, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} else if !isExist { } else if !isExist {
return nil, ErrReleaseNotExist{tagName} return nil, ErrReleaseNotExist{0, tagName}
} }
rel := &Release{RepoID: repoID, LowerTagName: strings.ToLower(tagName)} rel := &Release{RepoID: repoID, LowerTagName: strings.ToLower(tagName)}
@ -107,8 +109,21 @@ func GetRelease(repoID int64, tagName string) (*Release, error) {
return rel, err return rel, err
} }
// GetReleasesByRepoId returns a list of releases of repository. // GetReleaseByID returns release with given ID.
func GetReleasesByRepoId(repoID int64) (rels []*Release, err error) { func GetReleaseByID(id int64) (*Release, error) {
rel := new(Release)
has, err := x.Id(id).Get(rel)
if err != nil {
return nil, err
} else if !has {
return nil, ErrReleaseNotExist{id, ""}
}
return rel, nil
}
// GetReleasesByRepoID returns a list of releases of repository.
func GetReleasesByRepoID(repoID int64) (rels []*Release, err error) {
err = x.Desc("created").Find(&rels, Release{RepoID: repoID}) err = x.Desc("created").Find(&rels, Release{RepoID: repoID})
return rels, err return rels, err
} }
@ -147,3 +162,33 @@ func UpdateRelease(gitRepo *git.Repository, rel *Release) (err error) {
_, err = x.Id(rel.ID).AllCols().Update(rel) _, err = x.Id(rel.ID).AllCols().Update(rel)
return err return err
} }
// DeleteReleaseByID deletes a release and corresponding Git tag by given ID.
func DeleteReleaseByID(id int64) error {
rel, err := GetReleaseByID(id)
if err != nil {
return fmt.Errorf("GetReleaseByID: %v", err)
}
repo, err := GetRepositoryByID(rel.RepoID)
if err != nil {
return fmt.Errorf("GetRepositoryByID: %v", err)
}
repoPath, err := repo.RepoPath()
if err != nil {
return fmt.Errorf("RepoPath: %v", err)
}
_, stderr, err := process.ExecDir(-1, repoPath, fmt.Sprintf("Delete release [%d]", rel.ID),
"git", "tag", "-d", rel.TagName)
if err != nil && !strings.Contains(stderr, "not found") {
return fmt.Errorf("git tag -d: %v - %s", err, stderr)
}
if _, err = x.Id(rel.ID).Delete(new(Release)); err != nil {
return fmt.Errorf("Delete: %v", err)
}
return nil
}

File diff suppressed because one or more lines are too long

View File

@ -5,6 +5,7 @@
package git package git
import ( import (
"errors"
"path/filepath" "path/filepath"
) )
@ -21,6 +22,8 @@ func OpenRepository(repoPath string) (*Repository, error) {
repoPath, err := filepath.Abs(repoPath) repoPath, err := filepath.Abs(repoPath)
if err != nil { if err != nil {
return nil, err return nil, err
} else if !isDir(repoPath) {
return nil, errors.New("no such file or directory")
} }
return &Repository{Path: repoPath}, nil return &Repository{Path: repoPath}, nil

View File

@ -27,9 +27,9 @@ func Releases(ctx *middleware.Context) {
return return
} }
rels, err := models.GetReleasesByRepoId(ctx.Repo.Repository.ID) rels, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID)
if err != nil { if err != nil {
ctx.Handle(500, "GetReleasesByRepoId", err) ctx.Handle(500, "GetReleasesByRepoID", err)
return return
} }
@ -212,6 +212,7 @@ func EditRelease(ctx *middleware.Context) {
} }
return return
} }
ctx.Data["ID"] = rel.ID
ctx.Data["tag_name"] = rel.TagName ctx.Data["tag_name"] = rel.TagName
ctx.Data["tag_target"] = rel.Target ctx.Data["tag_target"] = rel.Target
ctx.Data["title"] = rel.Title ctx.Data["title"] = rel.Title
@ -257,3 +258,15 @@ func EditReleasePost(ctx *middleware.Context, form auth.EditReleaseForm) {
} }
ctx.Redirect(ctx.Repo.RepoLink + "/releases") ctx.Redirect(ctx.Repo.RepoLink + "/releases")
} }
func DeleteRelease(ctx *middleware.Context) {
if err := models.DeleteReleaseByID(ctx.QueryInt64("id")); err != nil {
ctx.Flash.Error("DeleteReleaseByID: " + err.Error())
} else {
ctx.Flash.Success(ctx.Tr("repo.release.deletion_success"))
}
ctx.JSON(200, map[string]interface{}{
"redirect": ctx.Repo.RepoLink + "/releases",
})
}

View File

@ -1 +1 @@
0.7.18.1119 Beta 0.7.19.1120 Beta

View File

@ -3,6 +3,7 @@
{{template "repo/header" .}} {{template "repo/header" .}}
<div class="ui container"> <div class="ui container">
{{template "repo/sidebar" .}} {{template "repo/sidebar" .}}
{{template "base/alert" .}}
<h2 class="ui header"> <h2 class="ui header">
{{.i18n.Tr "repo.release.releases"}} {{.i18n.Tr "repo.release.releases"}}
{{if .IsRepositoryAdmin}} {{if .IsRepositoryAdmin}}

View File

@ -68,6 +68,9 @@
<button class="ui green button"> <button class="ui green button">
{{.i18n.Tr "repo.release.edit_release"}} {{.i18n.Tr "repo.release.edit_release"}}
</button> </button>
<a class="ui red button delete-button" data-url="{{$.RepoLink}}/releases/delete" data-id="{{.ID}}">
{{$.i18n.Tr "repo.release.delete_release"}}
</a>
{{else}} {{else}}
<button class="ui green button"> <button class="ui green button">
{{.i18n.Tr "repo.release.publish"}} {{.i18n.Tr "repo.release.publish"}}
@ -80,4 +83,17 @@
</form> </form>
</div> </div>
</div> </div>
{{if .PageIsEditRelease}}
<div class="ui small basic delete modal">
<div class="ui icon header">
<i class="trash icon"></i>
{{.i18n.Tr "repo.release.deletion"}}
</div>
<div class="content">
<p>{{.i18n.Tr "repo.release.deletion_desc"}}</p>
</div>
{{template "base/delete_modal_actions" .}}
</div>
{{end}}
{{template "base/footer" .}} {{template "base/footer" .}}