You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.3 KiB

  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. "code.gitea.io/gitea/models"
  7. "code.gitea.io/gitea/modules/context"
  8. )
  9. // GetRepositoryByParams api for getting repository by orgnizition ID and repo name
  10. func GetRepositoryByParams(ctx *context.APIContext) *models.Repository {
  11. repo, err := models.GetRepositoryByName(ctx.Org.Team.OrgID, ctx.Params(":reponame"))
  12. if err != nil {
  13. if models.IsErrRepoNotExist(err) {
  14. ctx.Status(404)
  15. } else {
  16. ctx.Error(500, "GetRepositoryByName", err)
  17. }
  18. return nil
  19. }
  20. return repo
  21. }
  22. // AddTeamRepository api for adding a repository to a team
  23. func AddTeamRepository(ctx *context.APIContext) {
  24. repo := GetRepositoryByParams(ctx)
  25. if ctx.Written() {
  26. return
  27. }
  28. if err := ctx.Org.Team.AddRepository(repo); err != nil {
  29. ctx.Error(500, "AddRepository", err)
  30. return
  31. }
  32. ctx.Status(204)
  33. }
  34. // RemoveTeamRepository api for removing a repository from a team
  35. func RemoveTeamRepository(ctx *context.APIContext) {
  36. repo := GetRepositoryByParams(ctx)
  37. if ctx.Written() {
  38. return
  39. }
  40. if err := ctx.Org.Team.RemoveRepository(repo.ID); err != nil {
  41. ctx.Error(500, "RemoveRepository", err)
  42. return
  43. }
  44. ctx.Status(204)
  45. }