diff options
-rw-r--r-- | models/release.go | 13 | ||||
-rw-r--r-- | modules/auth/repo.go | 2 | ||||
-rw-r--r-- | routers/repo/release.go | 10 | ||||
-rw-r--r-- | templates/release/list.tmpl | 6 |
4 files changed, 22 insertions, 9 deletions
diff --git a/models/release.go b/models/release.go index 314b7a91a9..e5e81b9b67 100644 --- a/models/release.go +++ b/models/release.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "github.com/Unknwon/com" + // "github.com/Unknwon/com" "github.com/gogits/git" ) @@ -26,7 +26,8 @@ type Release struct { Title string TagName string LowerTagName string - SHA1 string + Target string + Sha1 string `xorm:"VARCHAR(40)"` NumCommits int NumCommitsBehind int `xorm:"-"` Note string `xorm:"TEXT"` @@ -59,9 +60,13 @@ func CreateRelease(gitRepo *git.Repository, rel *Release) error { } if !gitRepo.IsTagExist(rel.TagName) { - _, stderr, err := com.ExecCmdDir(gitRepo.Path, "git", "tag", rel.TagName, "-m", rel.Title) + commit, err := gitRepo.GetCommitOfBranch(rel.Target) if err != nil { - return errors.New(stderr) + return err + } + + if err = gitRepo.CreateTag(rel.TagName, commit.Id.String()); err != nil { + return err } } else { commit, err := gitRepo.GetCommitOfTag(rel.TagName) diff --git a/modules/auth/repo.go b/modules/auth/repo.go index 82cd078613..26ab7551ca 100644 --- a/modules/auth/repo.go +++ b/modules/auth/repo.go @@ -205,6 +205,7 @@ func (f *CreateLabelForm) Validate(errors *binding.Errors, req *http.Request, co type NewReleaseForm struct { TagName string `form:"tag_name" binding:"Required"` + Target string `form:"tag_target" binding:"Required"` Title string `form:"title" binding:"Required"` Content string `form:"content" binding:"Required"` Prerelease bool `form:"prerelease"` @@ -213,6 +214,7 @@ type NewReleaseForm struct { func (f *NewReleaseForm) Name(field string) string { names := map[string]string{ "TagName": "Tag name", + "Target": "Target", "Title": "Release title", "Content": "Release content", } diff --git a/routers/repo/release.go b/routers/repo/release.go index 14a14656d4..3e2449ecf3 100644 --- a/routers/repo/release.go +++ b/routers/repo/release.go @@ -79,7 +79,7 @@ func Releases(ctx *middleware.Context) { tags.rels[i] = &models.Release{ Title: rawTag, TagName: rawTag, - SHA1: commit.Id.String(), + Sha1: commit.Id.String(), } tags.rels[i].NumCommits, err = ctx.Repo.GitRepo.CommitsCount(commit.Id.String()) if err != nil { @@ -129,12 +129,18 @@ func ReleasesNewPost(ctx *middleware.Context, form auth.NewReleaseForm) { return } + if !ctx.Repo.GitRepo.IsBranchExist(form.Target) { + ctx.RenderWithErr("Target branch does not exist", "release/new", &form) + return + } + rel := &models.Release{ RepoId: ctx.Repo.Repository.Id, PublisherId: ctx.User.Id, Title: form.Title, TagName: form.TagName, - SHA1: ctx.Repo.Commit.Id.String(), + Target: form.Target, + Sha1: ctx.Repo.Commit.Id.String(), NumCommits: commitsCount, Note: form.Content, IsPrerelease: form.Prerelease, diff --git a/templates/release/list.tmpl b/templates/release/list.tmpl index edbc7467b4..2607dfacd9 100644 --- a/templates/release/list.tmpl +++ b/templates/release/list.tmpl @@ -11,12 +11,12 @@ </h4> <ul id="release-list" class="list-unstyled"> {{range .Releases}} - <li class="release-item clearfix" id="release-{{.SHA1}}"> + <li class="release-item clearfix" id="release-{{.Sha1}}"> {{if .PublisherId}} <div class="col-md-2 text-right"> {{if .IsPrerelease}}<span class="btn btn-warning status pre-release">Pre-Release</span>{{else}}<span class="btn btn-success status stable">Stable</span>{{end}} <a class="tag" href="{{$.RepoLink}}/src/{{.TagName}}" rel="nofollow"><i class="fa fa-tag"></i>{{.TagName}}</a> - <a class="commit" href="{{$.RepoLink}}/src/{{.SHA1}}" rel="nofollow"><i class="fa fa-code"></i>{{ShortSha .SHA1}}</a> + <a class="commit" href="{{$.RepoLink}}/src/{{.Sha1}}" rel="nofollow"><i class="fa fa-code"></i>{{ShortSha .Sha1}}</a> </div> <div class="col-md-10"> <h4 class="title"><a href="{{$.RepoLink}}/src/{{.TagName}}">{{.Title}}</a></h4> @@ -37,7 +37,7 @@ </div> {{else}} <div class="col-md-2 text-right"> - <a class="commit" href="{{$.RepoLink}}/src/{{.SHA1}}" rel="nofollow"><i class="fa fa-code"></i>{{ShortSha .SHA1}}</a> + <a class="commit" href="{{$.RepoLink}}/src/{{.Sha1}}" rel="nofollow"><i class="fa fa-code"></i>{{ShortSha .Sha1}}</a> </div> <div class="col-md-10"> <h5 class="title"><a href="{{$.RepoLink}}/src/{{.TagName}}" rel="nofollow">{{.TagName}}</a><i class="fa fa-tag"></i></h5> |