repositories.go 778 B

1234567891011121314151617181920212223242526272829303132
  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 v1
  5. import (
  6. "github.com/gogits/gogs/models"
  7. "github.com/gogits/gogs/modules/middleware"
  8. )
  9. func SearchCommits(ctx *middleware.Context) {
  10. userName := ctx.Query("username")
  11. repoName := ctx.Query("reponame")
  12. branch := ctx.Query("branch")
  13. keyword := ctx.Query("q")
  14. if len(keyword) == 0 {
  15. ctx.Render.JSON(404, nil)
  16. return
  17. }
  18. commits, err := models.SearchCommits(models.RepoPath(userName, repoName), branch, keyword)
  19. if err != nil {
  20. ctx.Render.JSON(200, map[string]interface{}{"ok": false})
  21. return
  22. }
  23. ctx.Render.JSON(200, map[string]interface{}{
  24. "ok": true,
  25. "commits": commits,
  26. })
  27. }