woodpecker/remote/gitlab/client/util.go

44 lines
915 B
Go
Raw Normal View History

2015-12-12 12:20:01 +00:00
package client
import (
"net/url"
"strings"
)
2016-02-01 22:11:27 +00:00
var encodeMap = map[string]string{
".": "%252E",
}
2015-12-12 12:20:01 +00:00
func encodeParameter(value string) string {
2016-02-01 22:11:27 +00:00
value = url.QueryEscape(value)
for before, after := range encodeMap {
value = strings.Replace(value, before, after, -1)
}
return value
2015-12-12 12:20:01 +00:00
}
// Tag returns current tag for push event hook payload
// This function returns empty string for any other events
func (h *HookPayload) Tag() string {
return strings.TrimPrefix(h.Ref, "refs/tags/")
}
// Branch returns current branch for push event hook payload
// This function returns empty string for any other events
func (h *HookPayload) Branch() string {
return strings.TrimPrefix(h.Ref, "refs/heads/")
}
// Head returns the latest changeset for push event hook payload
func (h *HookPayload) Head() hCommit {
c := hCommit{}
for _, cm := range h.Commits {
if h.After == cm.Id {
return cm
}
}
return c
}