org_repo.go 970 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2016 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 admin
  5. import (
  6. "gogs.io/gogs/internal/context"
  7. "gogs.io/gogs/internal/db"
  8. )
  9. func GetRepositoryByParams(c *context.APIContext) *db.Repository {
  10. repo, err := db.GetRepositoryByName(c.Org.Team.OrgID, c.Params(":reponame"))
  11. if err != nil {
  12. c.NotFoundOrError(err, "get repository by name")
  13. return nil
  14. }
  15. return repo
  16. }
  17. func AddTeamRepository(c *context.APIContext) {
  18. repo := GetRepositoryByParams(c)
  19. if c.Written() {
  20. return
  21. }
  22. if err := c.Org.Team.AddRepository(repo); err != nil {
  23. c.Error(err, "add repository")
  24. return
  25. }
  26. c.NoContent()
  27. }
  28. func RemoveTeamRepository(c *context.APIContext) {
  29. repo := GetRepositoryByParams(c)
  30. if c.Written() {
  31. return
  32. }
  33. if err := c.Org.Team.RemoveRepository(repo.ID); err != nil {
  34. c.Error(err, "remove repository")
  35. return
  36. }
  37. c.NoContent()
  38. }