1 Star 0 Fork 0

yangx282441848 / scm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
util.go 1.96 KB
一键复制 编辑 原始数据 按行查看 历史
Eoin McAfee 提交于 2021-09-24 15:30 . add release & milestone functionality
// 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 scm
import (
"regexp"
"strconv"
"strings"
)
// regular expression to extract the pull request number
// from the git ref (e.g. refs/pulls/{d}/head)
var re = regexp.MustCompile("\\d+")
// Split splits the full repository name into segments.
func Split(s string) (owner, name string) {
parts := strings.SplitN(s, "/", 2)
switch len(parts) {
case 1:
name = parts[0]
case 2:
owner = parts[0]
name = parts[1]
}
return
}
// Join joins the repository owner and name segments to
// create a fully qualified repository name.
func Join(owner, name string) string {
return owner + "/" + name
}
// TrimRef returns ref without the path prefix.
func TrimRef(ref string) string {
ref = strings.TrimPrefix(ref, "refs/heads/")
ref = strings.TrimPrefix(ref, "refs/tags/")
return ref
}
// ExpandRef returns name expanded to the fully qualified
// reference path (e.g refs/heads/master).
func ExpandRef(name, prefix string) string {
prefix = strings.TrimSuffix(prefix, "/")
if strings.HasPrefix(name, "refs/") {
return name
}
return prefix + "/" + name
}
// ExtractPullRequest returns name extraced pull request
// number from the reference path.
func ExtractPullRequest(ref string) int {
s := re.FindString(ref)
d, _ := strconv.Atoi(s)
return d
}
// IsBranch returns true if the reference path points to
// a branch.
func IsBranch(ref string) bool {
return strings.HasPrefix(ref, "refs/heads/")
}
// IsTag returns true if the reference path points to
// a tag object.
func IsTag(ref string) bool {
return strings.HasPrefix(ref, "refs/tags/")
}
// IsPullRequest returns true if the reference path points
// to a pull request object.
func IsPullRequest(ref string) bool {
return strings.HasPrefix(ref, "refs/pull/") ||
strings.HasPrefix(ref, "refs/pull-request/") ||
strings.HasPrefix(ref, "refs/merge-requests/")
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yangx282441848/scm.git
git@gitee.com:yangx282441848/scm.git
yangx282441848
scm
scm
v1.16.7

搜索帮助

344bd9b3 5694891 D2dac590 5694891