You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.go 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Copyright 2016 The Gogs Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package convert
  6. import (
  7. "strings"
  8. "code.gitea.io/gitea/modules/setting"
  9. "code.gitea.io/gitea/modules/structs"
  10. )
  11. // ToCorrectPageSize makes sure page size is in allowed range.
  12. func ToCorrectPageSize(size int) int {
  13. if size <= 0 {
  14. size = setting.API.DefaultPagingNum
  15. } else if size > setting.API.MaxResponseItems {
  16. size = setting.API.MaxResponseItems
  17. }
  18. return size
  19. }
  20. // ToGitServiceType return GitServiceType based on string
  21. func ToGitServiceType(value string) structs.GitServiceType {
  22. switch strings.ToLower(value) {
  23. case "github":
  24. return structs.GithubService
  25. case "gitea":
  26. return structs.GiteaService
  27. case "gitlab":
  28. return structs.GitlabService
  29. case "gogs":
  30. return structs.GogsService
  31. case "onedev":
  32. return structs.OneDevService
  33. default:
  34. return structs.PlainGitService
  35. }
  36. }