Browse Source

Fix #197

for-closed-social
Unknown 10 years ago
parent
commit
9961f9a53c
4 changed files with 22 additions and 9 deletions
  1. +9
    -4
      models/release.go
  2. +2
    -0
      modules/auth/repo.go
  3. +8
    -2
      routers/repo/release.go
  4. +3
    -3
      templates/release/list.tmpl

+ 9
- 4
models/release.go View File

@ -9,7 +9,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/Unknwon/com"
// "github.com/Unknwon/com"
"github.com/gogits/git" "github.com/gogits/git"
) )
@ -26,7 +26,8 @@ type Release struct {
Title string Title string
TagName string TagName string
LowerTagName string LowerTagName string
SHA1 string
Target string
Sha1 string `xorm:"VARCHAR(40)"`
NumCommits int NumCommits int
NumCommitsBehind int `xorm:"-"` NumCommitsBehind int `xorm:"-"`
Note string `xorm:"TEXT"` Note string `xorm:"TEXT"`
@ -59,9 +60,13 @@ func CreateRelease(gitRepo *git.Repository, rel *Release) error {
} }
if !gitRepo.IsTagExist(rel.TagName) { 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 { if err != nil {
return errors.New(stderr)
return err
}
if err = gitRepo.CreateTag(rel.TagName, commit.Id.String()); err != nil {
return err
} }
} else { } else {
commit, err := gitRepo.GetCommitOfTag(rel.TagName) commit, err := gitRepo.GetCommitOfTag(rel.TagName)

+ 2
- 0
modules/auth/repo.go View File

@ -205,6 +205,7 @@ func (f *CreateLabelForm) Validate(errors *binding.Errors, req *http.Request, co
type NewReleaseForm struct { type NewReleaseForm struct {
TagName string `form:"tag_name" binding:"Required"` TagName string `form:"tag_name" binding:"Required"`
Target string `form:"tag_target" binding:"Required"`
Title string `form:"title" binding:"Required"` Title string `form:"title" binding:"Required"`
Content string `form:"content" binding:"Required"` Content string `form:"content" binding:"Required"`
Prerelease bool `form:"prerelease"` Prerelease bool `form:"prerelease"`
@ -213,6 +214,7 @@ type NewReleaseForm struct {
func (f *NewReleaseForm) Name(field string) string { func (f *NewReleaseForm) Name(field string) string {
names := map[string]string{ names := map[string]string{
"TagName": "Tag name", "TagName": "Tag name",
"Target": "Target",
"Title": "Release title", "Title": "Release title",
"Content": "Release content", "Content": "Release content",
} }

+ 8
- 2
routers/repo/release.go View File

@ -79,7 +79,7 @@ func Releases(ctx *middleware.Context) {
tags.rels[i] = &models.Release{ tags.rels[i] = &models.Release{
Title: rawTag, Title: rawTag,
TagName: rawTag, TagName: rawTag,
SHA1: commit.Id.String(),
Sha1: commit.Id.String(),
} }
tags.rels[i].NumCommits, err = ctx.Repo.GitRepo.CommitsCount(commit.Id.String()) tags.rels[i].NumCommits, err = ctx.Repo.GitRepo.CommitsCount(commit.Id.String())
if err != nil { if err != nil {
@ -129,12 +129,18 @@ func ReleasesNewPost(ctx *middleware.Context, form auth.NewReleaseForm) {
return return
} }
if !ctx.Repo.GitRepo.IsBranchExist(form.Target) {
ctx.RenderWithErr("Target branch does not exist", "release/new", &form)
return
}
rel := &models.Release{ rel := &models.Release{
RepoId: ctx.Repo.Repository.Id, RepoId: ctx.Repo.Repository.Id,
PublisherId: ctx.User.Id, PublisherId: ctx.User.Id,
Title: form.Title, Title: form.Title,
TagName: form.TagName, TagName: form.TagName,
SHA1: ctx.Repo.Commit.Id.String(),
Target: form.Target,
Sha1: ctx.Repo.Commit.Id.String(),
NumCommits: commitsCount, NumCommits: commitsCount,
Note: form.Content, Note: form.Content,
IsPrerelease: form.Prerelease, IsPrerelease: form.Prerelease,

+ 3
- 3
templates/release/list.tmpl View File

@ -11,12 +11,12 @@
</h4> </h4>
<ul id="release-list" class="list-unstyled"> <ul id="release-list" class="list-unstyled">
{{range .Releases}} {{range .Releases}}
<li class="release-item clearfix" id="release-{{.SHA1}}">
<li class="release-item clearfix" id="release-{{.Sha1}}">
{{if .PublisherId}} {{if .PublisherId}}
<div class="col-md-2 text-right"> <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}} {{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="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>
<div class="col-md-10"> <div class="col-md-10">
<h4 class="title"><a href="{{$.RepoLink}}/src/{{.TagName}}">{{.Title}}</a></h4> <h4 class="title"><a href="{{$.RepoLink}}/src/{{.TagName}}">{{.Title}}</a></h4>
@ -37,7 +37,7 @@
</div> </div>
{{else}} {{else}}
<div class="col-md-2 text-right"> <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>
<div class="col-md-10"> <div class="col-md-10">
<h5 class="title"><a href="{{$.RepoLink}}/src/{{.TagName}}" rel="nofollow">{{.TagName}}</a><i class="fa fa-tag"></i></h5> <h5 class="title"><a href="{{$.RepoLink}}/src/{{.TagName}}" rel="nofollow">{{.TagName}}</a><i class="fa fa-tag"></i></h5>

Loading…
Cancel
Save