mirror of https://github.com/harness/drone.git
30 lines
494 B
Go
30 lines
494 B
Go
package request
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"github.com/go-chi/chi"
|
|
)
|
|
|
|
const (
|
|
RepoRefParamName = "rref"
|
|
)
|
|
|
|
var (
|
|
ErrRepoReferenceNotFound = errors.New("no repository reference found in request")
|
|
)
|
|
|
|
func GetRepoRef(r *http.Request) (string, error) {
|
|
rawRef := chi.URLParam(r, RepoRefParamName)
|
|
if rawRef == "" {
|
|
return "", ErrRepoReferenceNotFound
|
|
}
|
|
|
|
// paths are unescaped and lower
|
|
ref, err := url.PathUnescape(rawRef)
|
|
return strings.ToLower(ref), err
|
|
}
|