repo.go 1.6 KB

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