org_repo.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. "github.com/gogs/gogs/models"
  7. "github.com/gogs/gogs/models/errors"
  8. "github.com/gogs/gogs/pkg/context"
  9. )
  10. func GetRepositoryByParams(c *context.APIContext) *models.Repository {
  11. repo, err := models.GetRepositoryByName(c.Org.Team.OrgID, c.Params(":reponame"))
  12. if err != nil {
  13. if errors.IsRepoNotExist(err) {
  14. c.Status(404)
  15. } else {
  16. c.Error(500, "GetRepositoryByName", err)
  17. }
  18. return nil
  19. }
  20. return repo
  21. }
  22. func AddTeamRepository(c *context.APIContext) {
  23. repo := GetRepositoryByParams(c)
  24. if c.Written() {
  25. return
  26. }
  27. if err := c.Org.Team.AddRepository(repo); err != nil {
  28. c.Error(500, "AddRepository", err)
  29. return
  30. }
  31. c.Status(204)
  32. }
  33. func RemoveTeamRepository(c *context.APIContext) {
  34. repo := GetRepositoryByParams(c)
  35. if c.Written() {
  36. return
  37. }
  38. if err := c.Org.Team.RemoveRepository(repo.ID); err != nil {
  39. c.Error(500, "RemoveRepository", err)
  40. return
  41. }
  42. c.Status(204)
  43. }