release.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package auth
  5. import (
  6. "net/http"
  7. "reflect"
  8. "github.com/go-martini/martini"
  9. "github.com/gogits/gogs/modules/base"
  10. "github.com/gogits/gogs/modules/log"
  11. "github.com/gogits/gogs/modules/middleware/binding"
  12. )
  13. type NewReleaseForm struct {
  14. TagName string `form:"tag_name" binding:"Required"`
  15. Title string `form:"title" binding:"Required"`
  16. Content string `form:"content" binding:"Required"`
  17. Prerelease bool `form:"prerelease"`
  18. }
  19. func (f *NewReleaseForm) Name(field string) string {
  20. names := map[string]string{
  21. "TagName": "Tag name",
  22. "Title": "Release title",
  23. "Content": "Release content",
  24. }
  25. return names[field]
  26. }
  27. func (f *NewReleaseForm) Validate(errors *binding.BindingErrors, req *http.Request, context martini.Context) {
  28. if req.Method == "GET" || errors.Count() == 0 {
  29. return
  30. }
  31. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  32. data["HasError"] = true
  33. AssignForm(f, data)
  34. if len(errors.Overall) > 0 {
  35. for _, err := range errors.Overall {
  36. log.Error("NewReleaseForm.Validate: %v", err)
  37. }
  38. return
  39. }
  40. validate(errors, data, f)
  41. }