This repository has been archived on 2023-11-08. You can view files and clone it, but cannot push or open issues/pull-requests.
2023-01-12 05:11:26 +00:00
|
|
|
package forge
|
|
|
|
|
2023-01-13 05:07:57 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2023-01-12 05:11:26 +00:00
|
|
|
type Forge string
|
|
|
|
|
|
|
|
const (
|
|
|
|
ForgeGitea Forge = "gitea"
|
|
|
|
ForgeGitHub Forge = "github"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Release struct {
|
|
|
|
Name string
|
|
|
|
Assets []Asset
|
|
|
|
}
|
|
|
|
|
|
|
|
type Asset struct {
|
|
|
|
Name string
|
|
|
|
DownloadURL string
|
|
|
|
}
|
|
|
|
|
|
|
|
type Forger interface {
|
2023-01-13 05:07:57 +00:00
|
|
|
Name() string
|
2023-01-12 05:11:26 +00:00
|
|
|
Latest() (Release, error)
|
|
|
|
}
|
2023-01-13 05:07:57 +00:00
|
|
|
|
|
|
|
func splitURI(uri string) (string, []string, error) {
|
|
|
|
u, err := url.ParseRequestURI(uri)
|
|
|
|
if err != nil {
|
|
|
|
return "", nil, fmt.Errorf("could not parse URI: %w", err)
|
|
|
|
}
|
|
|
|
u.Scheme = "https"
|
|
|
|
paths := strings.FieldsFunc(u.Path, func(r rune) bool { return r == '/' })
|
|
|
|
u.Path = ""
|
|
|
|
return u.String(), paths, nil
|
|
|
|
}
|