2020-09-11 06:29:19 +08:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2016-07-04 17:27:06 +08:00
|
|
|
// Copyright 2016 The Gogs Authors. All rights reserved.
|
2022-11-28 02:20:29 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2016-07-04 17:27:06 +08:00
|
|
|
|
|
|
|
package convert
|
|
|
|
|
|
|
|
import (
|
2020-09-11 06:29:19 +08:00
|
|
|
"strings"
|
|
|
|
|
2016-11-11 00:24:48 +08:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2020-09-11 06:29:19 +08:00
|
|
|
"code.gitea.io/gitea/modules/structs"
|
2016-07-04 17:27:06 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// ToCorrectPageSize makes sure page size is in allowed range.
|
|
|
|
func ToCorrectPageSize(size int) int {
|
|
|
|
if size <= 0 {
|
2020-06-09 10:46:51 +08:00
|
|
|
size = setting.API.DefaultPagingNum
|
2016-07-04 17:27:06 +08:00
|
|
|
} else if size > setting.API.MaxResponseItems {
|
|
|
|
size = setting.API.MaxResponseItems
|
|
|
|
}
|
|
|
|
return size
|
|
|
|
}
|
2020-09-11 06:29:19 +08:00
|
|
|
|
|
|
|
// ToGitServiceType return GitServiceType based on string
|
|
|
|
func ToGitServiceType(value string) structs.GitServiceType {
|
|
|
|
switch strings.ToLower(value) {
|
|
|
|
case "github":
|
|
|
|
return structs.GithubService
|
|
|
|
case "gitea":
|
|
|
|
return structs.GiteaService
|
|
|
|
case "gitlab":
|
|
|
|
return structs.GitlabService
|
|
|
|
case "gogs":
|
|
|
|
return structs.GogsService
|
2021-08-22 06:47:45 +08:00
|
|
|
case "onedev":
|
|
|
|
return structs.OneDevService
|
2021-11-15 03:11:10 +08:00
|
|
|
case "gitbucket":
|
|
|
|
return structs.GitBucketService
|
2024-09-11 07:49:42 +08:00
|
|
|
case "codecommit":
|
|
|
|
return structs.CodeCommitService
|
2020-09-11 06:29:19 +08:00
|
|
|
default:
|
|
|
|
return structs.PlainGitService
|
|
|
|
}
|
|
|
|
}
|