-
Notifications
You must be signed in to change notification settings - Fork 1
/
support.go
109 lines (91 loc) · 2.25 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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"
const repoRefType = RefTypeBranch
func GetSuccessfulBuild() (JobResponse, error) {
return getLocalBuildResponse("echo Hello World")
}
func GetRemoteSuccessfulBuild() (JobResponse, error) {
return getRemoteBuildResponse("echo Hello World")
}
func GetFailedBuild() (JobResponse, error) {
return getLocalBuildResponse("exit 1")
}
func GetRemoteFailedBuild() (JobResponse, error) {
return getRemoteBuildResponse("exit 1")
}
func GetLongRunningBuild() (JobResponse, error) {
return getLocalBuildResponse("sleep 3600")
}
func GetRemoteLongRunningBuild() (JobResponse, error) {
return getRemoteBuildResponse("sleep 3600")
}
func getRemoteBuildResponse(commands string) (response JobResponse, err error) {
response = JobResponse{
GitInfo: GitInfo{
RepoURL: repoRemoteURL,
Sha: repoSHA,
BeforeSha: repoBeforeSHA,
Ref: repoRefName,
RefType: repoRefType,
},
Steps: Steps{
Step{
Name: StepNameScript,
Script: StepScript{commands},
When: StepWhenAlways,
AllowFailure: false,
},
},
}
return
}
func getLocalBuildResponse(commands string) (response JobResponse, err error) {
localRepoURL, err := getLocalRepoURL()
if err != nil {
return
}
response = JobResponse{
GitInfo: GitInfo{
RepoURL: localRepoURL,
Sha: repoSHA,
BeforeSha: repoBeforeSHA,
Ref: repoRefName,
RefType: repoRefType,
},
Steps: Steps{
Step{
Name: StepNameScript,
Script: StepScript{commands},
When: StepWhenAlways,
AllowFailure: false,
},
},
}
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
}