-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjiraintegration.go
155 lines (123 loc) · 4.17 KB
/
jiraintegration.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package main
import (
"flag"
"fmt"
"os"
"github.com/guipal/jiraintegration/jirautils"
"github.com/howeyc/gopass"
"io/ioutil"
"strings"
)
func main() {
var directory, hostUrl, user, password, passwordFile, keys, jiraIssues, resultPath, format, stepsDirectory, stepsRepo string
var exportResult, importTest, executeTest, executeRemote, undefinedSteps bool
var filter int
flag.BoolVar(&exportResult, "export", false, "Export cucumber results to Jira")
flag.BoolVar(&importTest, "download_test", false, "Download test Scenarios from Jira")
flag.BoolVar(&executeTest, "execute", false, "Execute test Scenarios from $featuresDir")
flag.BoolVar(&executeRemote, "executeRemote", false, "Download, Execute & Upload test from/to $host server")
flag.BoolVar(&undefinedSteps, "getUndefinedSteps", false, "Get undefined steps definition for provided features")
flag.StringVar(&directory, "featuresDir", "./features", "Target directory for downloaded tests")
flag.StringVar(&stepsDirectory, "stepsDir", "./features/step_definitions", "Step definitions target directory")
flag.StringVar(&stepsRepo, "stepsRepo", "", "Url to repository containing steps definitions (cucumber structure needed in the repo root=/features)")
flag.IntVar(&filter, "filter", 0, "Filter query to retrieve tests")
flag.StringVar(&hostUrl, "host", "", "Jira server URL")
flag.StringVar(&user, "user", "", "Jira server user")
flag.StringVar(&format, "format", "", "Cucumber test result format")
flag.StringVar(&password, "password", "", "Jira server password")
flag.StringVar(&passwordFile, "passwordFile", "", "Jira server password file")
flag.StringVar(&keys, "keys", "", " Jira-keys list of test-set Issues separated by ';'")
flag.StringVar(&jiraIssues, "jiraIssues", "", " Jira-keys list of issues with associated test separated by ';'")
flag.StringVar(&resultPath, "resultFile", "", " Path to cucumber result file")
flag.Parse()
args := flag.Args()
if (importTest || exportResult || executeRemote) && hostUrl == "" {
fmt.Println("Missing host url, try " + os.Args[0] + " -h")
return
}
if (importTest || exportResult || executeRemote) && user == "" {
fmt.Println("Missing user, try " + os.Args[0] + " -h")
return
}
if !importTest && !exportResult && !executeRemote && !executeTest && !undefinedSteps {
executeTest = true
}
if (importTest || exportResult || executeRemote) && password == "" && passwordFile == "" {
fmt.Printf("Password: ")
pass, _ := gopass.GetPasswd()
password = string(pass)
} else {
if passwordFile != "" {
pass, _ := ioutil.ReadFile(passwordFile)
password = strings.TrimSpace(string(pass))
}
}
if jiraIssues != "" {
newKeys, err := jirautils.DownloadTestsForJiraIssues(hostUrl, directory, user, password, jiraIssues)
keys = newKeys
if err != nil {
fmt.Println(err)
}
}
if executeRemote {
if resultPath == "" {
resultPath = "./results.json"
}
if stepsRepo != "" {
var err1 error
stepsDirectory, err1 = jirautils.CloneStepsRepo(stepsRepo)
if err1 != nil {
os.Exit(1)
}
}
err := jirautils.ExecuteTestSet(hostUrl, filter, directory, stepsDirectory, user, password, keys, resultPath)
if err != nil {
fmt.Println(err)
}
} else {
if stepsRepo != "" {
var err1 error
stepsDirectory, err1 = jirautils.CloneStepsRepo(stepsRepo)
if err1 != nil {
os.Exit(1)
}
}
if importTest {
err := jirautils.DownloadTests(hostUrl, filter, directory, user, password, keys)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
if undefinedSteps {
err := jirautils.GetPendingCucumberSteps(directory, stepsDirectory)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
if executeTest {
if directory == "./features" && len(args) > 0 {
if exists, _ := jirautils.Exists(string(args[0])); exists {
directory = args[0]
}
}
err := jirautils.ExecuteCucumberTest(format, resultPath, directory)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
if exportResult {
if resultPath == "" {
fmt.Println("No file provided")
os.Exit(1)
}
err := jirautils.ExportTestExecution(hostUrl, resultPath, user, password)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
}
}