org_repo.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Copyright 2018 Gitote. All rights reserved.
  3. //
  4. // This source code is licensed under the MIT license found in the
  5. // LICENSE file in the root directory of this source tree.
  6. package admin
  7. import (
  8. "gitote/gitote/models"
  9. "gitote/gitote/models/errors"
  10. "gitote/gitote/pkg/context"
  11. )
  12. func GetRepositoryByParams(c *context.APIContext) *models.Repository {
  13. repo, err := models.GetRepositoryByName(c.Org.Team.OrgID, c.Params(":reponame"))
  14. if err != nil {
  15. if errors.IsRepoNotExist(err) {
  16. c.Status(404)
  17. } else {
  18. c.Error(500, "GetRepositoryByName", err)
  19. }
  20. return nil
  21. }
  22. return repo
  23. }
  24. func AddTeamRepository(c *context.APIContext) {
  25. repo := GetRepositoryByParams(c)
  26. if c.Written() {
  27. return
  28. }
  29. if err := c.Org.Team.AddRepository(repo); err != nil {
  30. c.Error(500, "AddRepository", err)
  31. return
  32. }
  33. c.Status(204)
  34. }
  35. func RemoveTeamRepository(c *context.APIContext) {
  36. repo := GetRepositoryByParams(c)
  37. if c.Written() {
  38. return
  39. }
  40. if err := c.Org.Team.RemoveRepository(repo.ID); err != nil {
  41. c.Error(500, "RemoveRepository", err)
  42. return
  43. }
  44. c.Status(204)
  45. }