|
3 | 3 | import edu.umd.cs.findbugs.annotations.CheckForNull; |
4 | 4 | import edu.umd.cs.findbugs.annotations.NonNull; |
5 | 5 | import hudson.Extension; |
6 | | -import hudson.ExtensionList; |
7 | 6 | import hudson.Util; |
8 | 7 | import hudson.model.Job; |
9 | 8 | import hudson.model.Run; |
|
16 | 15 | import hudson.tasks.junit.TestResult; |
17 | 16 | import hudson.tasks.junit.TestResultSummary; |
18 | 17 | import hudson.tasks.junit.TrendTestResultSummary; |
| 18 | +import hudson.tasks.junit.HistoryTestResultSummary; |
19 | 19 | import io.jenkins.plugins.junit.storage.JunitTestResultStorage; |
20 | 20 | import io.jenkins.plugins.junit.storage.JunitTestResultStorageDescriptor; |
21 | 21 | import io.jenkins.plugins.junit.storage.TestResultImpl; |
@@ -230,7 +230,10 @@ public TestResultStorage(String job, int build) { |
230 | 230 | } |
231 | 231 |
|
232 | 232 | private <T> T query(Querier<T> querier) { |
233 | | - try (Connection connection = getConnectionSupplier().connection()) { |
| 233 | + try { |
| 234 | + // TODO move to try-with-resources, whenever I try close this I get (multiple queries needed): |
| 235 | + // org.postgresql.util.PSQLException: This statement has been closed. |
| 236 | + Connection connection = getConnectionSupplier().connection(); |
234 | 237 | return querier.run(connection); |
235 | 238 | } catch (SQLException x) { |
236 | 239 | throw new RuntimeException(x); |
@@ -415,6 +418,35 @@ public List<TestDurationResultSummary> getTestDurationResultSummary() { |
415 | 418 | }); |
416 | 419 | } |
417 | 420 |
|
| 421 | + public List<HistoryTestResultSummary> getHistorySummary(int offset) { |
| 422 | + return query(connection -> { |
| 423 | + try (PreparedStatement statement = connection.prepareStatement( |
| 424 | + "SELECT build, sum(duration) as duration, sum(case when errorDetails is not null then 1 else 0 end) as failCount, sum(case when skipped is not null then 1 else 0 end) as skipCount, sum(case when errorDetails is null and skipped is null then 1 else 0 end) as passCount FROM caseResults WHERE job = ? GROUP BY build ORDER BY build DESC LIMIT 25 OFFSET ?;" |
| 425 | + )) { |
| 426 | + statement.setString(1, job); |
| 427 | + statement.setInt(2, offset); |
| 428 | + try (ResultSet result = statement.executeQuery()) { |
| 429 | + |
| 430 | + List<HistoryTestResultSummary> historyTestResultSummaries = new ArrayList<>(); |
| 431 | + while (result.next()) { |
| 432 | + int buildNumber = result.getInt("build"); |
| 433 | + int duration = result.getInt("duration"); |
| 434 | + int passed = result.getInt("passCount"); |
| 435 | + int failed = result.getInt("failCount"); |
| 436 | + int skipped = result.getInt("skipCount"); |
| 437 | + |
| 438 | + Job<?, ?> theJob = Jenkins.get().getItemByFullName(getJobName(), Job.class); |
| 439 | + if (theJob != null) { |
| 440 | + Run<?, ?> run = theJob.getBuildByNumber(buildNumber); |
| 441 | + historyTestResultSummaries.add(new HistoryTestResultSummary(run, duration, failed, skipped, passed)); |
| 442 | + } |
| 443 | + } |
| 444 | + return historyTestResultSummaries; |
| 445 | + } |
| 446 | + } |
| 447 | + }); |
| 448 | + } |
| 449 | + |
418 | 450 | @Override |
419 | 451 | public int getCountOfBuildsWithTestResults() { |
420 | 452 | return query(connection -> { |
|
0 commit comments