forked from electric-cloud/DSL-Samples
-
Notifications
You must be signed in to change notification settings - Fork 6
/
GenerateHtmlDocument.groovy
221 lines (193 loc) · 6.8 KB
/
GenerateHtmlDocument.groovy
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
CloudBees CD DSL: Generate HTML Report
This example illustrates how a Jira feature report could be redendered which
shows where features are by environment or stage
Approach
Sample data is included in a ec-groovy procedure step that uses the Groovy
library MarkupBuilder to generate an HTML document. The HTML includes styles
and a script. The generated report is linked in the Job Details.
*/
project "DSL-Samples",{
procedure "Feature Release Status Report",{
step 'Generate Report', shell: 'ec-groovy',
command: '''\
import com.electriccloud.client.groovy.ElectricFlow
import com.electriccloud.client.groovy.models.ActualParameter
import javax.script.*
import static groovy.json.JsonOutput.*
ElectricFlow ef = new ElectricFlow()
//ConfigObject TableData = new ConfigObject()
def Stages = [
'Planning',
'Dev',
'INT',
'Perf',
'PROD',
]
def JiraData = [
[
name: "ABC",
fixVersion: "2.0",
features: [
[
id: "ABC-1234", tooltip: 'New login function\\nStatus: DONE\\nCreated 2020-10-11',
stories: [
[ id: "ABC-1236", stage: "INT", status: "DONE" ],
[ id: "ABC-1237", stage: "PROD", status: "DONE" ],
],
],
[
id: "ABC-5432", tooltip: 'Page flipper\\nStatus: DONE\\nCreated 2020-11-19',
stories: [
[ id: "ABC-1478", stage: "Planning", status: "WIP" ],
[ id: "ABC-5434", stage: "Perf", status: "DONE" ],
[ id: "ABC-5435", stage: "Dev", status: "DONE" ],
[ id: "ABC-5436", stage: "INT", status: "DONE" ],
[ id: "ABC-5437", stage: "INT", status: "DONE" ],
]
]
]
],
[
name: "DEF",
fixVersion: "3.9",
features: [
[
id: "DEF-1234", tooltip: 'New login function\\nStatus: DONE\\nCreated 2020-10-11',
stories: [
[ id: "DEF-1235", stage: "Planning", status: "Waiting on ABC-1478" ],
[ id: "DEF-1236", stage: "INT", status: "DONE" ],
[ id: "DEF-1237", stage: "PROD", status: "DONE" ],
],
],
]
]
]
ConfigObject Projects = new ConfigObject()
ConfigObject Features = new ConfigObject()
ConfigObject TableData = new ConfigObject()
JiraData.each { project ->
Projects[project.name]["fixVersion"]=project.fixVersion
project.features.each { feature ->
Features[feature.id]["tooltip"] = feature.tooltip
}
Stages.each { Stage ->
project.features.each { feature ->
def stories = []
feature.stories.each { story ->
if (story.stage == Stage) stories.push(story)
}
if (stories) {
TableData[Stage][project.name][feature.id]=stories
}
}
}
}
//println Projects["ABC"]["fixVersion"]
//println Features["ABC-1234"]["tooltip"]
//println TableData["Planning"]["ABC"]["ABC-5432"][0].id
//println prettyPrint(toJson(TableData))
def fileName = "FeatureReleaseStatusReport.html"
File directory = new File("artifacts")
File fh = new File("artifacts" + '/' + fileName)
if (! directory.exists()) directory.mkdir()
def writer = new StringWriter() // html is written here by markup builder
def markup = new groovy.xml.MarkupBuilder(writer) // the builder
markup.html {
head {
title ('Feature Release Status Report')
link(rel:'stylesheet', href:'https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css')
script( '', src:'https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js' )
script( '', src:'https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js' )
}
style {
mkp.yieldUnescaped \'\'\'
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
/* Position the tooltip */
position: absolute;
z-index: 1;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}\'\'\'
}
body {
div ('class': 'container') {
h2('Feature Release Status Report')
p('Type something in the input field to search the table for feature ID, environment, component, or version:')
input(class:'form-control', id:'myInput', type:'text', placeholder:'Search..')
br()
table('class': 'table table-bordered table-striped') {
// Create the Stages Columns
thead() {
tr(style: 'background-color:#d1b3ff') {
Stages.each { stage ->
th(stage)
}
}
}
// Create the Name Columns
JiraData.each { project ->
td(colspan:"5", id:"project", style: 'background-color:#00bfff', "${project.name} - ${Projects[project.name].fixVersion}") // TODO: change the length of Stages
tr()
Stages.each { stage ->
td() {
TableData[stage][project.name].each { feature ->
div (style: 'width:100%; background-color:#df80ff; position:relative; padding:5px; border: 1px solid black;') {
//Features[feature.key]["tooltip"]
p(feature.key)
}
TableData[stage][project.name][feature.key].each { story ->
div (style: 'width:100%; background-color:#f9e6ff; position:relative; padding:5px; border: 1px solid black;') {
if (story.status == "DONE") {
p(" - ${story.id}")
} else {
p(" - ${story.id} : ${story.status}")
}
}
}
p()
}
}
}
tr()
}
}
} // div
script {
mkp.yieldUnescaped \'\'\'
$(document).ready(function(){
$("#myInput").on("keyup", function() {
var value = $(this).val().toLowerCase();
$("#myTable tr").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});\'\'\'
}
}
} // markup
fh << writer.toString()
ef.setProperty(
propertyName: "/myJob/report-urls/Report Data",
value: "/commander/jobSteps/$[/myJobStep/jobStepId]/${fileName}"
)
ef.setProperty(
propertyName: "/server/ec_ui/flowMenuExtension",
value: """<?xml version="1.0" encoding="UTF-8"?><menu><tab><label>Deploy Report</label><url>../commander/jobSteps/$[/myJobStep/jobStepId]/${fileName}</url></tab></menu>"""
)
'''.stripIndent()
}
}