org_repo.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2015 - Present, The Gogs Authors. All rights reserved.
  2. // Copyright 2018 - Present, 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. // GetRepositoryByParams gets repository with params
  13. func GetRepositoryByParams(c *context.APIContext) *models.Repository {
  14. repo, err := models.GetRepositoryByName(c.Org.Team.OrgID, c.Params(":reponame"))
  15. if err != nil {
  16. if errors.IsRepoNotExist(err) {
  17. c.Status(404)
  18. } else {
  19. c.Error(500, "GetRepositoryByName", err)
  20. }
  21. return nil
  22. }
  23. return repo
  24. }
  25. // AddTeamRepository api for adding a repository
  26. func AddTeamRepository(c *context.APIContext) {
  27. repo := GetRepositoryByParams(c)
  28. if c.Written() {
  29. return
  30. }
  31. if err := c.Org.Team.AddRepository(repo); err != nil {
  32. c.Error(500, "AddRepository", err)
  33. return
  34. }
  35. c.Status(204)
  36. }
  37. // RemoveTeamRepository api for removing a repository
  38. func RemoveTeamRepository(c *context.APIContext) {
  39. repo := GetRepositoryByParams(c)
  40. if c.Written() {
  41. return
  42. }
  43. if err := c.Org.Team.RemoveRepository(repo.ID); err != nil {
  44. c.Error(500, "RemoveRepository", err)
  45. return
  46. }
  47. c.Status(204)
  48. }