Skip to content

Commit d25487d

Browse files
committed
Add line number extraction for error explanation
1 parent b221610 commit d25487d

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

src/main/java/io/jenkins/plugins/explain_error/ErrorExplainer.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,17 @@ private String extractErrorLogs(Run<?, ?> run, String logPattern, int maxLines)
7070
Pattern pattern = Pattern.compile(logPattern, Pattern.CASE_INSENSITIVE);
7171
StringBuilder errorLogs = new StringBuilder();
7272

73-
for (String line : logLines) {
74-
if (pattern.matcher(line).find()) {
75-
errorLogs.append(line).append("\n");
76-
}
77-
}
73+
for (int i = 0; i < logLines.size(); i++) {
74+
String line = logLines.get(i);
75+
76+
if (pattern.matcher(line).find()) {
77+
int lineNumber = i + 1; // 1 indexing
78+
System.out.println("Matched error at line: " + lineNumber);
79+
80+
errorLogs.append("[Line ").append(lineNumber).append("] ")
81+
.append(line).append("\n");
82+
}
83+
}
7884

7985
return errorLogs.toString();
8086
}

src/main/resources/index.jelly

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
11
<?jelly escape-by-default='true'?>
2-
<div>
3-
AI-powered Jenkins plugin that explains pipeline and job failures with human-readable insights.
4-
</div>
2+
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout">
3+
4+
<l:layout title="AI Error Explanation">
5+
<l:main-panel>
6+
7+
<h2>AI Error Explanation</h2>
8+
9+
<p><b>Provider:</b> ${it.providerName}</p>
10+
<p><b>Generated at:</b> ${it.formattedTimestamp}</p>
11+
12+
<h3>Explanation</h3>
13+
<pre style="background:#f5f5f5; padding:12px; border-radius:6px;">
14+
${it.explanation}
15+
</pre>
16+
17+
<h3>Relevant Error Logs</h3>
18+
19+
<pre style="background:#272822; color:#f8f8f2; padding:12px; border-radius:6px; white-space:pre-wrap;">
20+
<j:forEach var="line" items="${it.originalErrorLogs.split('\n')}">
21+
${loop.index + 1}: ${line}
22+
</j:forEach>
23+
</pre>
24+
25+
</l:main-panel>
26+
</l:layout>
27+
28+
</j:jelly>
29+

0 commit comments

Comments
 (0)