org_repo.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. "gogs.io/gogs/internal/db/errors"
  9. )
  10. func GetRepositoryByParams(c *context.APIContext) *db.Repository {
  11. repo, err := db.GetRepositoryByName(c.Org.Team.OrgID, c.Params(":reponame"))
  12. if err != nil {
  13. c.NotFoundOrServerError("GetRepositoryByName", errors.IsRepoNotExist, err)
  14. return nil
  15. }
  16. return repo
  17. }
  18. func AddTeamRepository(c *context.APIContext) {
  19. repo := GetRepositoryByParams(c)
  20. if c.Written() {
  21. return
  22. }
  23. if err := c.Org.Team.AddRepository(repo); err != nil {
  24. c.ServerError("AddRepository", err)
  25. return
  26. }
  27. c.NoContent()
  28. }
  29. func RemoveTeamRepository(c *context.APIContext) {
  30. repo := GetRepositoryByParams(c)
  31. if c.Written() {
  32. return
  33. }
  34. if err := c.Org.Team.RemoveRepository(repo.ID); err != nil {
  35. c.ServerError("RemoveRepository", err)
  36. return
  37. }
  38. c.NoContent()
  39. }