-
Notifications
You must be signed in to change notification settings - Fork 1
/
support.go
88 lines (70 loc) · 1.88 KB
/
support.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package common
import (
"os"
"path"
"runtime"
"strings"
)
const repoRemoteURL = "https://gitlab.com/gitlab-org/gitlab-test.git"
const repoSHA = "6907208d755b60ebeacb2e9dfea74c92c3449a1f"
const repoBeforeSHA = "c347ca2e140aa667b968e51ed0ffe055501fe4f4"
const repoRefName = "master"
func GetSuccessfulBuild() (GetBuildResponse, error) {
return getLocalBuildResponse("echo Hello World")
}
func GetRemoteSuccessfulBuild() (GetBuildResponse, error) {
return getRemoteBuildResponse("echo Hello World")
}
func GetFailedBuild() (GetBuildResponse, error) {
return getLocalBuildResponse("exit 1")
}
func GetRemoteFailedBuild() (GetBuildResponse, error) {
return getRemoteBuildResponse("exit 1")
}
func GetLongRunningBuild() (GetBuildResponse, error) {
return getLocalBuildResponse("sleep 3600")
}
func GetRemoteLongRunningBuild() (GetBuildResponse, error) {
return getRemoteBuildResponse("sleep 3600")
}
func getRemoteBuildResponse(commands string) (response GetBuildResponse, err error) {
response = GetBuildResponse{
Commands: commands,
RepoURL: repoRemoteURL,
Sha: repoSHA,
BeforeSha: repoBeforeSHA,
RefName: repoRefName,
}
return
}
func getLocalBuildResponse(commands string) (response GetBuildResponse, err error) {
localRepoURL, err := getLocalRepoURL()
if err != nil {
return
}
response = GetBuildResponse{
Commands: commands,
RepoURL: localRepoURL,
Sha: repoSHA,
BeforeSha: repoBeforeSHA,
RefName: repoRefName,
}
return
}
func getLocalRepoURL() (string, error) {
_, filename, _, _ := runtime.Caller(0)
directory := path.Dir(filename)
if strings.Contains(directory, "_test/_obj_test") {
pwd, err := os.Getwd()
if err != nil {
return "", err
}
directory = pwd
}
localRepoURL := path.Clean(directory + "/../tmp/gitlab-test/.git")
_, err := os.Stat(localRepoURL)
if err != nil {
return "", err
}
return localRepoURL, nil
}