1 Star 0 Fork 0

yangx282441848 / scm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
util.go 2.83 KB
一键复制 编辑 原始数据 按行查看 历史
Your Name 提交于 2021-10-11 10:02 . gitee
// Copyright 2017 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gitlab
import (
"net/url"
"strconv"
"strings"
"gitee.com/yangx282441848/scm/scm"
)
func encode(s string) string {
return strings.Replace(s, "/", "%2F", -1)
}
func encodePath(s string) string {
// Gitlab documentation provides inconsistent example for whether '.' should be escaped:
// https://docs.gitlab.com/ee/api/README.html#file-path-branches-and-tags-name-encoding
// https://docs.gitlab.com/ee/api/repository_files.html#get-file-from-repository
// Although not escaping '.' seems to work, we still escape it here to be safe.
return strings.Replace(url.PathEscape(s), ".", "%2E", -1)
}
func encodeListOptions(opts scm.ListOptions) string {
params := url.Values{}
if opts.Page != 0 {
params.Set("page", strconv.Itoa(opts.Page))
}
if opts.Size != 0 {
params.Set("per_page", strconv.Itoa(opts.Size))
}
return params.Encode()
}
func encodeMemberListOptions(opts scm.ListOptions) string {
params := url.Values{}
params.Set("membership", "true")
if opts.Page != 0 {
params.Set("page", strconv.Itoa(opts.Page))
}
if opts.Size != 0 {
params.Set("per_page", strconv.Itoa(opts.Size))
}
return params.Encode()
}
func encodeCommitListOptions(opts scm.CommitListOptions) string {
params := url.Values{}
if opts.Page != 0 {
params.Set("page", strconv.Itoa(opts.Page))
}
if opts.Size != 0 {
params.Set("per_page", strconv.Itoa(opts.Size))
}
if opts.Ref != "" {
params.Set("ref_name", opts.Ref)
}
return params.Encode()
}
func encodeIssueListOptions(opts scm.IssueListOptions) string {
params := url.Values{}
if opts.Page != 0 {
params.Set("page", strconv.Itoa(opts.Page))
}
if opts.Size != 0 {
params.Set("per_page", strconv.Itoa(opts.Size))
}
if opts.Open && opts.Closed {
params.Set("state", "all")
} else if opts.Closed {
params.Set("state", "closed")
} else if opts.Open {
params.Set("state", "opened")
}
return params.Encode()
}
func encodePullRequestListOptions(opts scm.PullRequestListOptions) string {
params := url.Values{}
if opts.Page != 0 {
params.Set("page", strconv.Itoa(opts.Page))
}
if opts.Size != 0 {
params.Set("per_page", strconv.Itoa(opts.Size))
}
if opts.Open && opts.Closed {
params.Set("state", "all")
} else if opts.Closed {
params.Set("state", "closed")
} else if opts.Open {
params.Set("state", "opened")
}
return params.Encode()
}
func encodeMilestoneListOptions(opts scm.MilestoneListOptions) string {
params := url.Values{}
if opts.Page != 0 {
params.Set("page", strconv.Itoa(opts.Page))
}
if opts.Size != 0 {
params.Set("per_page", strconv.Itoa(opts.Size))
}
if opts.Open && opts.Closed {
params.Set("state", "all")
} else if opts.Closed {
params.Set("state", "closed")
}
return params.Encode()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yangx282441848/scm.git
git@gitee.com:yangx282441848/scm.git
yangx282441848
scm
scm
v1.16.17

搜索帮助

344bd9b3 5694891 D2dac590 5694891