repo.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Copyright 2018 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 errors
  7. import "fmt"
  8. type RepoNotExist struct {
  9. ID int64
  10. UserID int64
  11. Name string
  12. }
  13. func IsRepoNotExist(err error) bool {
  14. _, ok := err.(RepoNotExist)
  15. return ok
  16. }
  17. func (err RepoNotExist) Error() string {
  18. return fmt.Sprintf("repository does not exist [id: %d, user_id: %d, name: %s]", err.ID, err.UserID, err.Name)
  19. }
  20. type ReachLimitOfRepo struct {
  21. Limit int
  22. }
  23. func IsReachLimitOfRepo(err error) bool {
  24. _, ok := err.(ReachLimitOfRepo)
  25. return ok
  26. }
  27. func (err ReachLimitOfRepo) Error() string {
  28. return fmt.Sprintf("user has reached maximum limit of repositories [limit: %d]", err.Limit)
  29. }
  30. type InvalidRepoReference struct {
  31. Ref string
  32. }
  33. func IsInvalidRepoReference(err error) bool {
  34. _, ok := err.(InvalidRepoReference)
  35. return ok
  36. }
  37. func (err InvalidRepoReference) Error() string {
  38. return fmt.Sprintf("invalid repository reference [ref: %s]", err.Ref)
  39. }
  40. type MirrorNotExist struct {
  41. RepoID int64
  42. }
  43. func IsMirrorNotExist(err error) bool {
  44. _, ok := err.(MirrorNotExist)
  45. return ok
  46. }
  47. func (err MirrorNotExist) Error() string {
  48. return fmt.Sprintf("mirror does not exist [repo_id: %d]", err.RepoID)
  49. }
  50. type BranchAlreadyExists struct {
  51. Name string
  52. }
  53. func IsBranchAlreadyExists(err error) bool {
  54. _, ok := err.(BranchAlreadyExists)
  55. return ok
  56. }
  57. func (err BranchAlreadyExists) Error() string {
  58. return fmt.Sprintf("branch already exists [name: %s]", err.Name)
  59. }
  60. type ErrBranchNotExist struct {
  61. Name string
  62. }
  63. func IsErrBranchNotExist(err error) bool {
  64. _, ok := err.(ErrBranchNotExist)
  65. return ok
  66. }
  67. func (err ErrBranchNotExist) Error() string {
  68. return fmt.Sprintf("branch does not exist [name: %s]", err.Name)
  69. }