org_repo.go 1.1 KB

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