2020-09-10 17:29:19 -05:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2016-07-04 04:27:06 -05:00
|
|
|
// Copyright 2016 The Gogs Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package convert
|
|
|
|
|
|
|
|
import (
|
2020-09-10 17:29:19 -05:00
|
|
|
"strings"
|
|
|
|
|
2016-11-10 11:24:48 -05:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2020-09-10 17:29:19 -05:00
|
|
|
"code.gitea.io/gitea/modules/structs"
|
2016-07-04 04:27:06 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// ToCorrectPageSize makes sure page size is in allowed range.
|
|
|
|
func ToCorrectPageSize(size int) int {
|
|
|
|
if size <= 0 {
|
2020-06-08 21:46:51 -05:00
|
|
|
size = setting.API.DefaultPagingNum
|
2016-07-04 04:27:06 -05:00
|
|
|
} else if size > setting.API.MaxResponseItems {
|
|
|
|
size = setting.API.MaxResponseItems
|
|
|
|
}
|
|
|
|
return size
|
|
|
|
}
|
2020-09-10 17:29:19 -05: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
|
|
|
|
default:
|
|
|
|
return structs.PlainGitService
|
|
|
|
}
|
|
|
|
}
|