repo.go 2.6 KB

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