Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

branch.go 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2017 The Gitea 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 private
  5. import (
  6. "code.gitea.io/gitea/models"
  7. macaron "gopkg.in/macaron.v1"
  8. )
  9. // GetProtectedBranchBy get protected branch information
  10. func GetProtectedBranchBy(ctx *macaron.Context) {
  11. repoID := ctx.ParamsInt64(":id")
  12. branchName := ctx.Params("*")
  13. protectBranch, err := models.GetProtectedBranchBy(repoID, branchName)
  14. if err != nil {
  15. ctx.JSON(500, map[string]interface{}{
  16. "err": err.Error(),
  17. })
  18. return
  19. } else if protectBranch != nil {
  20. ctx.JSON(200, protectBranch)
  21. } else {
  22. ctx.JSON(200, &models.ProtectedBranch{
  23. ID: 0,
  24. })
  25. }
  26. }
  27. // CanUserPush returns if user push
  28. func CanUserPush(ctx *macaron.Context) {
  29. pbID := ctx.ParamsInt64(":pbid")
  30. userID := ctx.ParamsInt64(":userid")
  31. protectBranch, err := models.GetProtectedBranchByID(pbID)
  32. if err != nil {
  33. ctx.JSON(500, map[string]interface{}{
  34. "err": err.Error(),
  35. })
  36. return
  37. } else if protectBranch != nil {
  38. ctx.JSON(200, map[string]interface{}{
  39. "can_push": protectBranch.CanUserPush(userID),
  40. })
  41. } else {
  42. ctx.JSON(200, map[string]interface{}{
  43. "can_push": false,
  44. })
  45. }
  46. }