Skip to content

Commit

Permalink
feat: Add column to jobs list
Browse files Browse the repository at this point in the history
see JENKINS-69063
  • Loading branch information
hypery2k committed Jun 3, 2024
1 parent dcc72a4 commit 5059ab1
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/main/java/hudson/plugins/logparser/LogParserColumn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package hudson.plugins.logparser;

import hudson.Extension;
import hudson.model.Job;
import hudson.model.Run;
import hudson.views.ListViewColumn;
import hudson.views.ListViewColumnDescriptor;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;

public class LogParserColumn extends ListViewColumn {
public int[] getResult(Job job) {
if (job == null) {
return null;
}
Run build = job.getLastCompletedBuild();
if (build == null) {
return null;
}
LogParserAction action = build.getAction(LogParserAction.class);
if (action == null) {
return null;
}
LogParserResult result = action.getResult();
if (result == null) {
return null;
}

return new int[]{result.getTotalErrors(), result.getTotalWarnings(), result.getTotalInfos(), result.getTotalDebugs()};
}

public String getUrl(Job job) {
if (job == null) {
return null;
}
Run build = job.getLastCompletedBuild();
if (build == null) {
return null;
}
return build.getUrl() + LogParserAction.getUrlNameStat();

Check warning on line 40 in src/main/java/hudson/plugins/logparser/LogParserColumn.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 11-40 are not covered by tests
}

@Extension
public static class LogParserColumnDescriptor extends ListViewColumnDescriptor {
@Override
public ListViewColumn newInstance(StaplerRequest req, JSONObject formData) throws FormException {
return new LogParserColumn();

Check warning on line 47 in src/main/java/hudson/plugins/logparser/LogParserColumn.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 47 is not covered by tests
}

@Override
public String getDisplayName() {
return Messages.LogParserColumn_Header();
}

@Override
public boolean shownByDefault() {
return false;

Check warning on line 57 in src/main/java/hudson/plugins/logparser/LogParserColumn.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 57 is not covered by tests
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<j:jelly xmlns:j="jelly:core">
<j:set var="result" value="${it.getResult(job)}"/>
<j:set var="url" value="${it.getUrl(job)}"/>
<td style="font-weight: bold">
<j:choose>
<j:when test="${url == null}">
</j:when>
<j:when test="${result == null}">
-
</j:when>
<j:otherwise>
<a href="${rootURL}/${url}">
<span style="color: ${%Error.color}">${%Error}${result[0]};</span>
<span style="color: ${%Warning.color}">${%Warning}${result[1]};</span>
<span style="color: ${%Info.color}">${%Info}${result[2]};</span>
<span style="color: ${%Debug.color}">${%Debug}${result[3]}</span>
</a>
</j:otherwise>
</j:choose>
</td>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Error=E:
Warning=W:
Info=I:
Debug=D:

Error.color=red
Warning.color=orange
Info.color=green
Debug.color=gray
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<j:jelly xmlns:j="jelly:core">
<th>${%LogParserColumn.Header}</th>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LogParserColumn.Header=Log parser
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LogParserColumn.Header=Log parser

0 comments on commit 5059ab1

Please sign in to comment.