gitea源码

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Copyright 2020 The Gitea Authors. All rights reserved.
  3. // SPDX-License-Identifier: MIT
  4. package repo
  5. import (
  6. "context"
  7. "fmt"
  8. "path/filepath"
  9. "strings"
  10. user_model "code.gitea.io/gitea/models/user"
  11. "code.gitea.io/gitea/modules/util"
  12. )
  13. // ErrWikiAlreadyExist represents a "WikiAlreadyExist" kind of error.
  14. type ErrWikiAlreadyExist struct {
  15. Title string
  16. }
  17. // IsErrWikiAlreadyExist checks if an error is an ErrWikiAlreadyExist.
  18. func IsErrWikiAlreadyExist(err error) bool {
  19. _, ok := err.(ErrWikiAlreadyExist)
  20. return ok
  21. }
  22. func (err ErrWikiAlreadyExist) Error() string {
  23. return fmt.Sprintf("wiki page already exists [title: %s]", err.Title)
  24. }
  25. func (err ErrWikiAlreadyExist) Unwrap() error {
  26. return util.ErrAlreadyExist
  27. }
  28. // ErrWikiReservedName represents a reserved name error.
  29. type ErrWikiReservedName struct {
  30. Title string
  31. }
  32. // IsErrWikiReservedName checks if an error is an ErrWikiReservedName.
  33. func IsErrWikiReservedName(err error) bool {
  34. _, ok := err.(ErrWikiReservedName)
  35. return ok
  36. }
  37. func (err ErrWikiReservedName) Error() string {
  38. return "wiki title is reserved: " + err.Title
  39. }
  40. func (err ErrWikiReservedName) Unwrap() error {
  41. return util.ErrInvalidArgument
  42. }
  43. // ErrWikiInvalidFileName represents an invalid wiki file name.
  44. type ErrWikiInvalidFileName struct {
  45. FileName string
  46. }
  47. // IsErrWikiInvalidFileName checks if an error is an ErrWikiInvalidFileName.
  48. func IsErrWikiInvalidFileName(err error) bool {
  49. _, ok := err.(ErrWikiInvalidFileName)
  50. return ok
  51. }
  52. func (err ErrWikiInvalidFileName) Error() string {
  53. return "Invalid wiki filename: " + err.FileName
  54. }
  55. func (err ErrWikiInvalidFileName) Unwrap() error {
  56. return util.ErrInvalidArgument
  57. }
  58. // WikiCloneLink returns clone URLs of repository wiki.
  59. func (repo *Repository) WikiCloneLink(ctx context.Context, doer *user_model.User) *CloneLink {
  60. return repo.cloneLink(ctx, doer, repo.Name+".wiki")
  61. }
  62. // WikiPath returns wiki data path by given user and repository name.
  63. func WikiPath(userName, repoName string) string {
  64. return filepath.Join(user_model.UserPath(userName), strings.ToLower(repoName)+".wiki.git")
  65. }
  66. // WikiPath returns wiki data path for given repository.
  67. func (repo *Repository) WikiPath() string {
  68. return WikiPath(repo.OwnerName, repo.Name)
  69. }