forked from adoptium/aqa-test-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitNewIssue.jsx
236 lines (215 loc) · 8.65 KB
/
GitNewIssue.jsx
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import React, { useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom';
import { params } from '../utils/query';
import { Button, Tooltip, Card } from 'antd';
import TestBreadcrumb from './TestBreadcrumb';
import { GithubOutlined } from '@ant-design/icons';
import { getParams } from '../utils/query';
import { fetchData } from '../utils/Utils';
import renderDuration from './Duration';
import { getGitDiffLinks } from '../utils/Utils';
import './table.css';
import moment from 'moment';
const DAY_FORMAT = 'MMM DD YYYY, hh:mm a';
const GitNewissue = () => {
const [state, setState] = useState({
body: '',
title: '',
});
const location = useLocation();
useEffect(() => {
async function updateData() {
const { testId, buildId } = getParams(location.search);
const originUrl = window.location.origin;
// fetch test data
const testData = await fetchData(`/api/getTestById?id=${testId}`);
const { testName, duration, testResult } = testData;
// fetch error in test output
const errorInOutput = await fetchData(
`/api/getErrorInOutput?id=${testData.testOutputId}`
);
const failureOutput = errorInOutput.output;
// fetch build data
const buildData = await fetchData(`/api/getData?_id=${buildId}`);
const {
artifactory,
buildName,
buildUrl,
machine,
timestamp,
javaVersion,
} = buildData[0];
let { rerunLink } = buildData[0];
if (rerunLink) {
rerunLink = rerunLink.replace(
/(\WTARGET=)([^&]*)/gi,
'$1' + testName
);
}
let firstSeenFailure = null;
let failCount = 0;
let failMachineUrlBody = '',
gitDiffLinksBody = '';
if (testResult === 'FAILED') {
let successBeforeFailure,
gitDiffLinks = null;
let machinesMap = {};
// get all history tests with strictly earlier timestamp
const response = await fetchData(
`/api/getHistoryPerTest?testId=${testId}&beforeTimestamp=${timestamp}&limit=100`
);
// add the current test result
machinesMap[machine] = 1;
failCount++;
for (let i = 0; i < response.length; i++) {
const previousResult = response[i].tests.testResult;
const previousMachine = response[i].machine;
if (previousResult === 'PASSED') {
successBeforeFailure = response[i];
break;
} else {
firstSeenFailure = response[i];
machinesMap[previousMachine] = machinesMap[
previousMachine
]
? machinesMap[previousMachine] + 1
: 1;
failCount++;
}
}
if (successBeforeFailure) {
if (firstSeenFailure) {
gitDiffLinks = getGitDiffLinks(
successBeforeFailure.javaVersion,
firstSeenFailure.javaVersion,
buildName
);
} else {
gitDiffLinks = getGitDiffLinks(
successBeforeFailure.javaVersion,
javaVersion,
buildName
);
}
gitDiffLinks.forEach((link) => {
gitDiffLinksBody += `${link}\n`;
});
}
Object.entries(machinesMap).forEach(([key, value]) => {
failMachineUrlBody += `The test failed on machine ${key} ${value} times \n`;
});
}
const buildStartTime = moment(parseInt(timestamp)).format(
DAY_FORMAT
);
const title = `${testName} ${testResult} in ${buildName}`;
const nl = '\n';
const testInfo =
testName && duration && machine && testId
? `**Test Info**${nl}` +
`Test Name: ${testName}${nl}` +
`Test Duration: ${renderDuration(duration)}${nl}` +
`Machine: ${machine}${nl}` +
`TRSS link for the test output: ${originUrl}/output/test${params(
{ id: testId }
)}${nl}` +
`${nl}${nl}`
: ``;
const buildInfo =
buildName && buildStartTime && buildUrl && buildId
? `**Build Info**${nl}` +
`Build Name: ${buildName}${nl}` +
`Jenkins Build start time: ${buildStartTime}${nl}` +
`Jenkins Build URL: ${buildUrl}${nl}` +
`TRSS link for the build: ${originUrl}/allTestsInfo${params(
{
buildId: buildId,
}
)}${nl}` +
`${nl}${nl}`
: ``;
const javaVersionInfo = javaVersion
? `**Java Version**${nl}${javaVersion}${nl}`
: ``;
const failureOutputInfo = failureOutput
? `${nl}**Console Output**${nl}` +
`\`\`\`${nl}${failureOutput}${nl}\`\`\``
: ``;
const firstSeenFailureInfo = firstSeenFailure
? `${nl}${nl}` +
`**This test has been failed ${failCount} times since ${moment(
firstSeenFailure.timestamp
).format(DAY_FORMAT)}**${nl}` +
(firstSeenFailure.javaVersion
? `**Java Version when the issue first seen**${nl}` +
`${firstSeenFailure.javaVersion}${nl}`
: ``) +
`Jenkins Build URL: ${firstSeenFailure.buildUrl}${nl}${nl}` +
failMachineUrlBody
: ``;
const gitDiffLinksBodyInfo = gitDiffLinksBody
? `${nl}**Git Diff of first seen failure and last success**${nl}` +
gitDiffLinksBody
: ``;
const artifactoryinfo = artifactory
? `${nl}${nl}[Artifacts](${artifactory})`
: ``;
const rerunLinkInfo = rerunLink
? `${nl}${nl}[Rerun in Grinder](${rerunLink})`
: ``;
const body =
testInfo +
buildInfo +
javaVersionInfo +
failureOutputInfo +
firstSeenFailureInfo +
gitDiffLinksBodyInfo +
artifactoryinfo +
rerunLinkInfo;
setState({
body,
title,
});
}
updateData();
}, [location]);
const { body, title } = state;
const { testId, testName, buildId } = getParams(location.search);
const urlParams = params({ title, body });
let issueUrl = 'https://github.com/adoptium/aqa-tests/';
let allowedHosts = ['trssrtp1.fyre.ibm.com'];
if (allowedHosts.includes(window.location.hostname)) {
issueUrl = 'https://github.com/eclipse-openj9/openj9/';
}
return (
<div>
<TestBreadcrumb
buildId={buildId}
testId={testId}
testName={testName}
/>
<Card
title={title}
bordered={true}
style={{ width: '100%' }}
extra={
<Tooltip title={`Create new issue at ${issueUrl}`}>
<a
href={`${issueUrl}issues/new${urlParams}`}
target="_blank"
rel="noopener noreferrer"
>
<Button size="large">
<GithubOutlined />
Create New Git Issue
</Button>
</a>
</Tooltip>
}
>
<pre className="card-body">{body}</pre>
</Card>
</div>
);
};
export default GitNewissue;