generated from fallion/go-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_remote.go
43 lines (35 loc) · 1.01 KB
/
get_remote.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package integrations
import "os"
// GitRemote represents, well... a git remote
type GitRemote struct {
host string
project string
}
// GetGitRemote returns a GitRemote instance based on the environment variables found during runtime
func GetGitRemote() GitRemote {
project, isGitHub := os.LookupEnv("GITHUB_REPOSITORY")
if isGitHub {
return GitRemote{
// Assuming no self-hosted GitHub, not even sure if actions works there tbh
host: "github.com",
project: project,
}
}
// Otherwise it's GitLab
return GitRemote{
host: os.Getenv("CI_SERVER_HOST"),
project: os.Getenv("CI_PROJECT_PATH"),
}
}
// GetRemoteURL builds an URL pointing to the specific project on the remote provider
func (remote GitRemote) GetRemoteURL() string {
return "https://" + remote.host + "/" + remote.project
}
// Host returns the URL of the git host
func (remote GitRemote) Host() string {
return remote.host
}
// Project returns the name of the project
func (remote GitRemote) Project() string {
return remote.project
}